diff --git a/kitty/core_text.m b/kitty/core_text.m index 5057fc225..4ddbcbe98 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -134,7 +134,12 @@ cell_size(Face *self) { if (w > width) width = w; } } - return Py_BuildValue("I", width); + // See https://stackoverflow.com/questions/5511830/how-does-line-spacing-work-in-core-text-and-why-is-it-different-from-nslayoutm + CGFloat leading = MAX(0, self->leading); + leading = floor(leading + 0.5); + CGFloat line_height = floor(self->ascent + 0.5) + floor(self->descent + 0.5) + leading; + CGFloat ascender_delta = (leading > 0) ? 0 : floor(0.2 * line_height + 0.5); + return Py_BuildValue("II", width, (unsigned int)(line_height + ascender_delta)); #undef count } diff --git a/kitty/fonts/core_text.py b/kitty/fonts/core_text.py index c3751a3b9..7003acfb9 100644 --- a/kitty/fonts/core_text.py +++ b/kitty/fonts/core_text.py @@ -25,8 +25,7 @@ def set_font_family(family, size_in_pts, ignore_dpi_failure=False): for italic in (False, True): main_font[(bold, italic)] = Face(family, bold, italic, True, size_in_pts, dpi) mf = main_font[(False, False)] - cell_width = mf.cell_size() - cell_height = ceil_int(mf.ascent + mf.descent) + cell_width, cell_height = mf.cell_size() CellTexture = ctypes.c_ubyte * (cell_width * cell_height) WideCellTexture = ctypes.c_ubyte * (2 * cell_width * cell_height) baseline = int(round(mf.ascent))