From 2e77ef3d4bd89114c851cdb04878ba07573a7664 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 16 Nov 2026 17:09:52 +0530 Subject: [PATCH] FreeType: Move rescaled glyphs right to eliminate left overhang As with the CoreText renderer, a glyph that is rescaled to fit its cell is moved so that its ink starts at the left edge of the cell, so that marks that hang to the left of it, as in polytonic Greek capitals, are no longer cut off. --- docs/changelog.rst | 2 +- kitty/freetype.c | 6 +++++- kitty_tests/fonts.py | 8 +++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 27af59039..8c3e57709 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -256,7 +256,7 @@ Detailed list of changes healing alternates of the Monaspace and 0xProto fonts, being rendered smaller than the surrounding text at some font sizes -- macOS: Fix accents and breathing marks that hang to the left of wide glyphs, +- Fix accents and breathing marks that hang to the left of wide glyphs, such as polytonic Greek capitals, being cut off diff --git a/kitty/freetype.c b/kitty/freetype.c index 48bd99788..129d6e7f6 100644 --- a/kitty/freetype.c +++ b/kitty/freetype.c @@ -670,7 +670,7 @@ typedef struct { size_t start_x, width, stride; size_t rows; FT_Pixel_Mode pixel_mode; - bool needs_free; + bool needs_free, rescaled; unsigned int factor, right_edge; int bitmap_left, bitmap_top; } ProcessedBitmap; @@ -791,6 +791,7 @@ render_bitmap( fg->fcm.cell_height)) { free_processed_bitmap(ans); if (!render_bitmap(self, glyph_id, ans, cell_width, cell_height, num_cells, bold, italic, false, fg)) return false; + ans->rescaled = true; if (!set_font_size(self, char_width, char_height, self->xdpi, self->ydpi, 0, fg->fcm.cell_height)) return false; } else return false; } @@ -1178,6 +1179,9 @@ place_bitmap_in_canvas( // Calculate column bounds int32_t xoff = (int32_t)(x_offset + bm->bitmap_left); if (debug_placement) printf(" bitmap_left: %d xoff: %d", bm->bitmap_left, xoff); + // A rescaled glyph, such as a letter with marks that hang to the left of + // its cell, shift it so the marks are not cut off + if (bm->rescaled && xoff < 0) xoff = 0; if (xoff < 0) src.left += -xoff; else dest.left = xoff; // Move the dest start column back if the width overflows because of it, but only if we are not in a very long/infinite ligature diff --git a/kitty_tests/fonts.py b/kitty_tests/fonts.py index 5878708ca..7b44c4f64 100644 --- a/kitty_tests/fonts.py +++ b/kitty_tests/fonts.py @@ -555,11 +555,9 @@ class Rendering(FontBaseTest): # at most 23 rows. Drawn at full size it covers at least 27. height, width, cell_width = self.glyph_ink('LiberationMono-Regular.ttf', 'Ὦ', 32) self.assertLessEqual(height, 23) - if is_macos: - # The rescaled glyph is moved into the cell so that the marks are - # not cut off and it spans the whole cell. The FreeType renderer - # still crops whatever lies to the left of the cell. - self.assertGreaterEqual(width, cell_width - 1) + # The rescaled glyph is moved into the cell so that the marks are + # not cut off and it spans the whole cell. + self.assertGreaterEqual(width, cell_width - 1) def test_shaping(self):