diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 97508006f..f75a13d52 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -94,12 +94,13 @@ pub const Face = struct { // of the bitmap. We use the rounded up width/height of the bounding rect. var bounding: [1]macos.graphics.Rect = undefined; _ = self.font.getBoundingRectForGlyphs(.horizontal, &glyphs, &bounding); - const width = @floatToInt(u32, @ceil(bounding[0].size.width)); - const height = @floatToInt(u32, @ceil(bounding[0].size.height)); + const glyph_width = @floatToInt(u32, @ceil(bounding[0].size.width)); + const width = @floatToInt(u32, self.metrics.cell_width); + const height = @floatToInt(u32, self.metrics.cell_height); // This bitmap is blank. I've seen it happen in a font, I don't know why. // If it is empty, we just return a valid glyph struct that does nothing. - if (width == 0 or height == 0) return font.Glyph{ + if (glyph_width == 0) return font.Glyph{ .width = 0, .height = 0, .offset_x = 0, @@ -138,7 +139,7 @@ pub const Face = struct { ctx.setGrayStrokeColor(1, 1); ctx.setTextDrawingMode(.fill_stroke); ctx.setTextMatrix(macos.graphics.AffineTransform.identity()); - ctx.setTextPosition(0, self.metrics.cell_height - self.metrics.cell_baseline); + ctx.setTextPosition(0, @intToFloat(f32, height) - self.metrics.cell_baseline); var pos = [_]macos.graphics.Point{.{ .x = 0, .y = 0 }}; self.font.drawGlyphs(&glyphs, &pos, ctx); @@ -150,7 +151,11 @@ pub const Face = struct { .width = width, .height = height, .offset_x = 0, - .offset_y = 0, + + // Offset is full cell height because for CoreText we render + // an entire cell. + .offset_y = @floatToInt(i32, self.metrics.cell_height), + .atlas_x = region.x, .atlas_y = region.y, .advance_x = @floatCast(f32, advances[0].width),