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
This commit is contained in:
Kovid Goyal 2020-04-27 18:02:53 +05:30
parent ad1ff455a0
commit e803505aad
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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); render_alpha_mask(render_buf, canvas, &src, &dest, canvas_width, canvas_width);
} }
if (num_cells && (center_glyph || (num_cells == 2 && *was_colored))) { if (num_cells && (center_glyph || (num_cells == 2 && *was_colored))) {
// center glyphs (two cell emoji and PUA glyphs) // center glyphs (two cell emoji, PUA glyphs, ligatures, etc)
CGFloat delta = (((CGFloat)canvas_width - br.size.width) / 2.f) - br.origin.x; 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)); if (delta >= 1.f) right_shift_canvas(canvas, canvas_width, cell_height, (unsigned)(delta));
} }
return true; return true;