From ab606c6cfde2c9c38bfcfce0450621a109661afb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 8 Jan 2024 07:57:42 -0800 Subject: [PATCH 1/2] font: autoitalic should only apply to text presentation Fixes #1256 --- src/font/Group.zig | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/font/Group.zig b/src/font/Group.zig index ad5600660..c08f7bd34 100644 --- a/src/font/Group.zig +++ b/src/font/Group.zig @@ -265,11 +265,16 @@ pub fn italicize(self: *Group) !void { const list = self.faces.get(.regular); if (list.items.len == 0) return; - // The font must be loaded. - break :regular try self.faceFromIndex(.{ - .style = .regular, - .idx = 0, - }); + // Find our first font that is text. + for (0..list.items.len) |i| { + const face = try self.faceFromIndex(.{ + .style = .regular, + .idx = @intCast(i), + }); + if (face.presentation == .text) break :regular face; + } + + return; }; // Try to italicize it. From bc80073ffd7c7e095fb6f4e1d2a443aa0074289a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 8 Jan 2024 08:01:04 -0800 Subject: [PATCH 2/2] core: add emoji fallback on macOS after built-in font This doesn't fix any issues, but it slightly improves performance since we'll try our text font first which is most likely to hit most input. --- src/Surface.zig | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index c78959288..aa75bb0e6 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -410,21 +410,6 @@ pub fn init( _ = try group.addFace(.bold_italic, .{ .deferred = face }); } else log.warn("font-family-bold-italic not found: {s}", .{family}); } - - // On macOS, always search for and add the Apple Emoji font - // as our preferred emoji font for fallback. We do this in case - // people add other emoji fonts to their system, we always want to - // prefer the official one. Users can override this by explicitly - // specifying a font-family for emoji. - if (comptime builtin.os.tag == .macos) { - var disco_it = try disco.discover(alloc, .{ - .family = "Apple Color Emoji", - }); - defer disco_it.deinit(); - if (try disco_it.next()) |face| { - _ = try group.addFace(.regular, .{ .fallback_deferred = face }); - } - } } // Our built-in font will be used as a backup @@ -440,6 +425,22 @@ pub fn init( // Auto-italicize if we have to. try group.italicize(); + // On macOS, always search for and add the Apple Emoji font + // as our preferred emoji font for fallback. We do this in case + // people add other emoji fonts to their system, we always want to + // prefer the official one. Users can override this by explicitly + // specifying a font-family for emoji. + if (comptime builtin.os.tag == .macos) apple_emoji: { + const disco = group.discover orelse break :apple_emoji; + var disco_it = try disco.discover(alloc, .{ + .family = "Apple Color Emoji", + }); + defer disco_it.deinit(); + if (try disco_it.next()) |face| { + _ = try group.addFace(.regular, .{ .fallback_deferred = face }); + } + } + // Emoji fallback. We don't include this on Mac since Mac is expected // to always have the Apple Emoji available on the system. if (builtin.os.tag != .macos or font.Discover == void) {