From fff16bff6928e14a6e5f342f5578f73b0b998733 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Sat, 5 Jul 2025 20:36:35 -0600 Subject: [PATCH] font/coretext: fix bitmap size calculation, prevent clipping Previously, many glyphs were having their top and right row/column of pixels clipped off due to not accounting for the slight bearing in the width and height calculation here. --- src/font/face/coretext.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 35f094848..89d771d95 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -356,8 +356,14 @@ pub const Face = struct { const x = glyph_size.x; const y = glyph_size.y; - const px_width: u32 = @intFromFloat(@ceil(width)); - const px_height: u32 = @intFromFloat(@ceil(height)); + // We have to include the fractional pixels that we won't be offsetting + // in our width and height calculations, that is, we offset by the floor + // of the bearings when we render the glyph, meaning there's still a bit + // of extra width to the area that's drawn in beyond just the width of + // the glyph itself, so we include that extra fraction of a pixel when + // calculating the width and height here. + const px_width: u32 = @intFromFloat(@ceil(width + rect.origin.x - @floor(rect.origin.x))); + const px_height: u32 = @intFromFloat(@ceil(height + rect.origin.y - @floor(rect.origin.y))); // Settings that are specific to if we are rendering text or emoji. const color: struct {