mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
font: fix some coretext rendering issues
This commit is contained in:
@ -94,12 +94,13 @@ pub const Face = struct {
|
|||||||
// of the bitmap. We use the rounded up width/height of the bounding rect.
|
// of the bitmap. We use the rounded up width/height of the bounding rect.
|
||||||
var bounding: [1]macos.graphics.Rect = undefined;
|
var bounding: [1]macos.graphics.Rect = undefined;
|
||||||
_ = self.font.getBoundingRectForGlyphs(.horizontal, &glyphs, &bounding);
|
_ = self.font.getBoundingRectForGlyphs(.horizontal, &glyphs, &bounding);
|
||||||
const width = @floatToInt(u32, @ceil(bounding[0].size.width));
|
const glyph_width = @floatToInt(u32, @ceil(bounding[0].size.width));
|
||||||
const height = @floatToInt(u32, @ceil(bounding[0].size.height));
|
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.
|
// 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 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,
|
.width = 0,
|
||||||
.height = 0,
|
.height = 0,
|
||||||
.offset_x = 0,
|
.offset_x = 0,
|
||||||
@ -138,7 +139,7 @@ pub const Face = struct {
|
|||||||
ctx.setGrayStrokeColor(1, 1);
|
ctx.setGrayStrokeColor(1, 1);
|
||||||
ctx.setTextDrawingMode(.fill_stroke);
|
ctx.setTextDrawingMode(.fill_stroke);
|
||||||
ctx.setTextMatrix(macos.graphics.AffineTransform.identity());
|
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 }};
|
var pos = [_]macos.graphics.Point{.{ .x = 0, .y = 0 }};
|
||||||
self.font.drawGlyphs(&glyphs, &pos, ctx);
|
self.font.drawGlyphs(&glyphs, &pos, ctx);
|
||||||
@ -150,7 +151,11 @@ pub const Face = struct {
|
|||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
.offset_x = 0,
|
.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_x = region.x,
|
||||||
.atlas_y = region.y,
|
.atlas_y = region.y,
|
||||||
.advance_x = @floatCast(f32, advances[0].width),
|
.advance_x = @floatCast(f32, advances[0].width),
|
||||||
|
Reference in New Issue
Block a user