From 47704f24c15f6b04c6ced7d3e14edf69897714ad Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 13 Dec 2017 08:22:26 +0530 Subject: [PATCH] CoreText: Get rid of the line height fudge factor It was leading to larger line heights than in iTerm on High Sierra with Menlo. Also as per Apple documentation, line height should be ascent + descent + leading. https://developer.apple.com/library/content/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TypoFeatures/TextSystemFeatures.html --- kitty/core_text.m | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/kitty/core_text.m b/kitty/core_text.m index 05c41cf44..3ab5f5eda 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -228,6 +228,7 @@ harfbuzz_font_for_face(PyObject* s) { void cell_metrics(PyObject *s, unsigned int* cell_width, unsigned int* cell_height, unsigned int* baseline, unsigned int* underline_position, unsigned int* underline_thickness) { + // See https://developer.apple.com/library/content/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/TypoFeatures/TextSystemFeatures.html CTFace *self = (CTFace*)s; #define count (128 - 32) unichar chars[count+1] = {0}; @@ -242,15 +243,10 @@ cell_metrics(PyObject *s, unsigned int* cell_width, unsigned int* cell_height, u if (w > width) width = w; } } - // 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); - *cell_width = width; *cell_height = (unsigned int)(line_height + ascender_delta); + *cell_width = width; + *cell_height = (unsigned int)floor(self->ascent + self->descent + MAX(0, self->leading) + 0.5); *underline_position = (unsigned int)self->underline_position; *underline_thickness = (unsigned int)self->underline_thickness; - // See https://developer.apple.com/library/content/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/TypoFeatures/TextSystemFeatures.html *baseline = (unsigned int)self->ascent; }