From 0ef4f4b3558426d98d840316f3f4dfa80e3a0c6e Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sat, 28 Aug 2021 21:18:52 +0200 Subject: fonts: More metrics sanity checks The pango font metrics for some fonts return a height lower than the height measured from the U+0020..U+007E characters. Using the metrics in this case may lead to the descenders getting cut off from characters in the last line, depending on the padding available. Change the code to only use the pango metrics when its height is at least that of the measured characters. Fixes: https://gitlab.gnome.org/GNOME/gnome-terminal/-/issues/340 (cherry picked from commit 6c24f146a0f6a3829e3d36a3c2c3601e638e3a50) --- src/fonts-pangocairo.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/fonts-pangocairo.cc b/src/fonts-pangocairo.cc index fc0f4e54..dca252c3 100644 --- a/src/fonts-pangocairo.cc +++ b/src/fonts-pangocairo.cc @@ -245,7 +245,12 @@ FontInfo::FontInfo(PangoContext *context) auto const width = PANGO_PIXELS_CEIL(pango_font_metrics_get_approximate_char_width(metrics.get())); #endif /* 0 */ - if (ascent > 0 && height > 0) { + /* Sometimes, the metrics return a lower height than the one we measured + * in measure_font(), causing cut-off at the bottom of the last line, see + * https://gitlab.gnome.org/GNOME/gnome-terminal/-/issues/340 . Therefore + * we only use the metrics when its height is at least that which we measured. + */ + if (ascent > 0 && height > m_height) { _vte_debug_print(VTE_DEBUG_PANGOCAIRO, "Using pango metrics\n"); m_ascent = ascent; @@ -253,6 +258,11 @@ FontInfo::FontInfo(PangoContext *context) #if 0 m_width = width; #endif + } else if (ascent >= 0 && height > 0) { + _vte_debug_print(VTE_DEBUG_PANGOCAIRO, "Disregarding pango metrics due to incorrect height (%d < %d)\n", + height, m_height); + } else { + _vte_debug_print(VTE_DEBUG_PANGOCAIRO, "Not using pango metrics due to not providing height or ascent\n"); } } #endif /* pango >= 1.44 */ -- cgit v1.2.1