From 5555a66638fe758a73529414c16fef1ce0e0901f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 6 Aug 2020 14:06:06 +0530 Subject: [PATCH] Adjust cell height automatically for buggy fonts that draw brackets outside the bounding box See https://github.com/cormullion/juliamono/issues/14 --- docs/changelog.rst | 2 ++ kitty/core_text.m | 2 +- kitty/freetype.c | 13 ++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 8a52efeec..9486d4a0a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -14,6 +14,8 @@ To update |kitty|, :doc:`follow the instructions `. - Fix a regression in the previous release that could cause an exception during startup in rare circumstances (:iss:`2896`) +- Adjust cell height automatically for buggy fonts that draw brackets outside the bounding box + 0.18.2 [2020-07-28] -------------------- diff --git a/kitty/core_text.m b/kitty/core_text.m index 5606df8ed..3d1b4d174 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -336,7 +336,7 @@ cell_metrics(PyObject *s, unsigned int* cell_width, unsigned int* cell_height, u *strikethrough_thickness = *underline_thickness; // float line_height = MAX(1, floor(self->ascent + self->descent + MAX(0, self->leading) + 0.5)); // Let CoreText's layout engine calculate the line height. Slower, but hopefully more accurate. -#define W "AQWMH_gyl " +#define W "A{Q](WMH_gyl " CFStringRef ts = CFSTR(W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W W); #undef W CFMutableAttributedStringRef test_string = CFAttributedStringCreateMutable(kCFAllocatorDefault, CFStringGetLength(ts)); diff --git a/kitty/freetype.c b/kitty/freetype.c index 3917cb894..2148b57b8 100644 --- a/kitty/freetype.c +++ b/kitty/freetype.c @@ -125,11 +125,14 @@ static inline unsigned int calc_cell_height(Face *self, bool for_metrics) { unsigned int ans = font_units_to_pixels_y(self, self->height); if (for_metrics) { - unsigned int underscore_height = get_height_for_char(self, '_'); - if (underscore_height > ans) { - if (global_state.debug_font_fallback) printf( - "Increasing cell height by %u pixels to work around buggy font that renders underscore outside the bounding box\n", underscore_height - ans); - return underscore_height; + static const char chars[] = "_{[("; + for (unsigned i = 0; i < arraysz(chars) - 1; i++) { + unsigned int char_height = get_height_for_char(self, chars[i]); + if (char_height > ans) { + if (global_state.debug_font_fallback) printf( + "Increasing cell height by %u pixels to work around buggy font that renders '%c' outside the bounding box\n", char_height - ans, chars[i]); + ans = char_height; + } } } return ans;