From e803505aad864067258ef8d6efd5145a8167a7d0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 27 Apr 2020 18:02:53 +0530 Subject: [PATCH] CoreText: When centering glyphs ignore negative origins This is needed for FiraCode ligatures to line up correctly. See https://github.com/kovidgoyal/kitty/issues/2591#issuecomment-619937030 --- kitty/core_text.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kitty/core_text.m b/kitty/core_text.m index 9e25a42da..5da81b2ea 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -506,8 +506,10 @@ do_render(CTFontRef ct_font, bool bold, bool italic, hb_glyph_info_t *info, hb_g render_alpha_mask(render_buf, canvas, &src, &dest, canvas_width, canvas_width); } if (num_cells && (center_glyph || (num_cells == 2 && *was_colored))) { - // center glyphs (two cell emoji and PUA glyphs) - CGFloat delta = (((CGFloat)canvas_width - br.size.width) / 2.f) - br.origin.x; + // center glyphs (two cell emoji, PUA glyphs, ligatures, etc) + CGFloat delta = (((CGFloat)canvas_width - br.size.width) / 2.f); + // FiraCode ligatures result in negative origins + if (br.origin.x > 0) delta -= br.origin.x; if (delta >= 1.f) right_shift_canvas(canvas, canvas_width, cell_height, (unsigned)(delta)); } return true;