summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Persch <chpe@src.gnome.org>2021-08-28 21:18:52 +0200
committerChristian Persch <chpe@src.gnome.org>2021-08-28 22:01:05 +0200
commit0ef4f4b3558426d98d840316f3f4dfa80e3a0c6e (patch)
treeba3a58f34d0f0b9006c36f1ee4a6de3f23b92755
parent0e069018082d9736e15fe8ba93a47a0f4a787e39 (diff)
downloadvte-0ef4f4b3558426d98d840316f3f4dfa80e3a0c6e.tar.gz
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)
-rw-r--r--src/fonts-pangocairo.cc12
1 files changed, 11 insertions, 1 deletions
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 */