[dev] [PATCH] st: Use ascent + descent for font height to avoid clipping underscores.

From: Bobby Powers <bobbypowers_AT_gmail.com>
Date: Sun, 10 Mar 2013 15:55:11 -0400

My preferred font:

  "Monospace:pixelsize=15:antialias=true:autohint=false:hintstyle=hintfull"

Has an issue with st where the _'s were being overwritten when text on
the next line was drawn. This didn't happen in gnome-terminal, which
uses pango for its font rendering. Pango's Xft backend uses ascent +
descent rather than height. This appears to date back to at least
2004 (pango commit 5bf0c1d0) so I'm not sure their exact reasoning,
but it fixes the Monospace font height issue I am seeing.
---
 st.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/st.c b/st.c
index fc9ed70..436a60b 100644
--- a/st.c
+++ b/st.c
_AT_@ -2493,7 +2493,12 @@ xloadfont(Font *f, FcPattern *pattern) {
 	f->lbearing = 0;
 	f->rbearing = f->match->max_advance_width;
 
-	f->height = f->match->height;
+	/* pango's get_glyph_extents_xft uses ascent + descent rather
+	 * than height.  In some cases ("Monospace:pixelsize=15" at
+	 * least) height is 1 px smaller than ascent + descent, which
+	 * leads to underscores getting clipped and appearing as
+	 * spaces. */
+	f->height = f->ascent + f->descent;
 	f->width = f->lbearing + f->rbearing;
 
 	return 0;
-- 
1.8.1.4
Received on Sun Mar 10 2013 - 20:55:11 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 10 2013 - 21:00:08 CET