From c565c561fd7fa0de1c946d92c615053ecfd024b8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 2 Oct 2022 11:20:55 -0700 Subject: [PATCH] Use Apple Emoji font on Mac --- pkg/macos/text/font_collection.zig | 9 +++++++-- src/Window.zig | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/macos/text/font_collection.zig b/pkg/macos/text/font_collection.zig index 1ae124bc4..d32ce6f37 100644 --- a/pkg/macos/text/font_collection.zig +++ b/pkg/macos/text/font_collection.zig @@ -52,6 +52,11 @@ fn debugDumpList(list: *foundation.Array) !void { defer name.release(); const cstr = name.cstring(&buf, .utf8).?; + var family_buf: [128]u8 = undefined; + const family = desc.copyAttribute(.family_name); + defer family.release(); + const family_cstr = family.cstring(&family_buf, .utf8).?; + var buf2: [128]u8 = undefined; const url = desc.copyAttribute(.url); defer url.release(); @@ -72,7 +77,7 @@ fn debugDumpList(list: *foundation.Array) !void { ""; }; - std.log.warn("i={d} name={s} path={s}", .{ i, cstr, path }); + std.log.warn("i={d} name={s} family={s} path={s}", .{ i, cstr, family_cstr, path }); } } } @@ -112,7 +117,7 @@ test "from descriptors" { try testing.expect(list.getCount() > 0); - //try debugDumpList(list); + // try debugDumpList(list); } test "from descriptors no match" { diff --git a/src/Window.zig b/src/Window.zig index c84909bfd..1c693886a 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -312,6 +312,21 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo } } + // If we're on Mac, then we try to use the Apple Emoji font for Emoji. + if (builtin.os.tag == .macos and font.Discover != void) { + var disco = font.Discover.init(); + defer disco.deinit(); + var disco_it = try disco.discover(.{ + .family = "Apple Color Emoji", + .size = font_size.points, + }); + defer disco_it.deinit(); + if (try disco_it.next()) |face| { + log.debug("font emoji: {s}", .{try face.name()}); + try group.addFace(alloc, .regular, face); + } + } + // Our built-in font will be used as a backup try group.addFace( alloc,