From 55254acaad0c85660f1faf469151fa421fc671cc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 30 Jun 2023 17:12:24 -0700 Subject: [PATCH] coretext: fix emoji placement --- src/font/face/coretext.zig | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 36e585533..029bfef12 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -215,7 +215,7 @@ pub const Face = struct { }); ctx.setAllowsFontSmoothing(true); - ctx.setShouldSmoothFonts(true); // The amadeus "enthicken" + ctx.setShouldSmoothFonts(false); // The amadeus "enthicken" ctx.setAllowsFontSubpixelQuantization(true); ctx.setShouldSubpixelQuantizeFonts(true); ctx.setAllowsFontSubpixelPositioning(true); @@ -247,6 +247,18 @@ pub const Face = struct { atlas.set(region, buf); const offset_y: i32 = offset_y: { + // For non-scalable colorized fonts, we assume they are pictographic + // and just center the glyph. So far this has only applied to emoji + // fonts. Emoji fonts don't always report a correct ascender/descender + // (mainly Apple Emoji) so we just center them. Also, since emoji font + // aren't scalable, cell_baseline is incorrect anyways. + // + // NOTE(mitchellh): I don't know if this is right, this doesn't + // _feel_ right, but it makes all my limited test cases work. + if (color.color) { + break :offset_y @intFromFloat(self.metrics.cell_height); + } + // Our Y coordinate in 3D is (0, 0) bottom left, +y is UP. // We need to calculate our baseline from the bottom of a cell. const baseline_from_bottom = self.metrics.cell_height - self.metrics.cell_baseline; @@ -258,6 +270,17 @@ pub const Face = struct { break :offset_y @intFromFloat(@ceil(baseline_with_offset)); }; + log.warn("FONT FONT FONT width={} height={} render_x={} render_y={} offset_y={} ascent={} cell_height={} cell_baseline={}", .{ + glyph_width, + glyph_height, + render_x, + render_y, + offset_y, + glyph_ascent, + self.metrics.cell_height, + self.metrics.cell_baseline, + }); + return .{ .width = glyph_width, .height = glyph_height,