[vte] fonts: More metrics sanity checks



commit 6c24f146a0f6a3829e3d36a3c2c3601e638e3a50
Author: Christian Persch <chpe src gnome org>
Date:   Sat Aug 28 21:18:52 2021 +0200

    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

 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 3fa24f64..cd22c83d 100644
--- a/src/fonts-pangocairo.cc
+++ b/src/fonts-pangocairo.cc
@@ -238,7 +238,12 @@ FontInfo::FontInfo(vte::glib::RefPtr<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;
@@ -246,6 +251,11 @@ FontInfo::FontInfo(vte::glib::RefPtr<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 */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]