From 3fdb6a496de60a198560dc0489ec8e64c57c6b64 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 10 Dec 2023 17:08:20 -0800 Subject: [PATCH 1/3] font/coretext: calculate advance_x properly --- src/font/face/coretext.zig | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 0ce09d2c7..188a3bce8 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -397,6 +397,10 @@ pub const Face = struct { break :offset_y @intFromFloat(@ceil(baseline_with_offset)); }; + // Get our advance + var advances: [glyphs.len]macos.graphics.Size = undefined; + _ = self.font.getAdvancesForGlyphs(.horizontal, &glyphs, &advances); + // std.log.warn("renderGlyph rect={} width={} height={} render_x={} render_y={} offset_y={} ascent={} cell_height={} cell_baseline={}", .{ // rect, // width, @@ -416,10 +420,7 @@ pub const Face = struct { .offset_y = offset_y, .atlas_x = region.x, .atlas_y = region.y, - - // This is not used, so we don't bother calculating it. If we - // ever need it, we can calculate it using getAdvancesForGlyph. - .advance_x = 0, + .advance_x = @floatCast(advances[0].width), }; } From 5e9ddb5e6594f9beadc5f1c876e3903c9a01177e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 10 Dec 2023 17:08:32 -0800 Subject: [PATCH 2/3] renderer/metal: offset zero-advance glyphs by the cell width --- src/renderer/Metal.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index d328772df..9f7356d4b 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -1787,6 +1787,15 @@ pub fn updateCell( .emoji => .fg_color, }; + // If this glyph doesn't have an advance, then we assume it is + // connected to the previous glyph (perhaps an unsafe assumption...) + // and offset by the cell width. + // Related: https://github.com/mitchellh/ghostty/issues/1046 + const extra_offset: i32 = if (glyph.advance_x == 0) + @intCast(self.grid_metrics.cell_width) + else + 0; + self.cells.appendAssumeCapacity(.{ .mode = mode, .grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) }, @@ -1795,7 +1804,7 @@ pub fn updateCell( .bg_color = bg, .glyph_pos = .{ glyph.atlas_x, glyph.atlas_y }, .glyph_size = .{ glyph.width, glyph.height }, - .glyph_offset = .{ glyph.offset_x, glyph.offset_y }, + .glyph_offset = .{ glyph.offset_x + extra_offset, glyph.offset_y }, }); } From 3e9a6e4de50ccf1843d33b1f91d42abf12cc3252 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 10 Dec 2023 17:10:00 -0800 Subject: [PATCH 3/3] renderer/opengl: apply extra offset for zero-advance glyphs --- src/renderer/OpenGL.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index a9972930e..9ba9f0921 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -1490,6 +1490,15 @@ pub fn updateCell( .emoji => .fg_color, }; + // If this glyph doesn't have an advance, then we assume it is + // connected to the previous glyph (perhaps an unsafe assumption...) + // and offset by the cell width. + // Related: https://github.com/mitchellh/ghostty/issues/1046 + const extra_offset: i32 = if (glyph.advance_x == 0) + @intCast(self.grid_metrics.cell_width) + else + 0; + self.cells.appendAssumeCapacity(.{ .mode = mode, .grid_col = @intCast(x), @@ -1499,7 +1508,7 @@ pub fn updateCell( .glyph_y = glyph.atlas_y, .glyph_width = glyph.width, .glyph_height = glyph.height, - .glyph_offset_x = glyph.offset_x, + .glyph_offset_x = glyph.offset_x + extra_offset, .glyph_offset_y = glyph.offset_y, .r = colors.fg.r, .g = colors.fg.g,