Skip to content

Commit

Permalink
Use pango_font_metrics_get_height() to calculate font height
Browse files Browse the repository at this point in the history
With newer versions of Pango and some fonts, the bottom of the
text is clipped (making underscores invisible). Use the correct
calculation when needed to avoid this.

Based on an original fix by Jeff Teunissen.

Closes hexchat#2449.
  • Loading branch information
jlevon committed Sep 3, 2020
1 parent 71eb79f commit 86ae618
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/fe-gtk/xtext.c
Expand Up @@ -283,8 +283,21 @@ backend_font_open (GtkXText *xtext, char *name)
metrics = pango_context_get_metrics (context, xtext->font->font, lang);
xtext->font->ascent = pango_font_metrics_get_ascent (metrics) / PANGO_SCALE;
xtext->font->descent = pango_font_metrics_get_descent (metrics) / PANGO_SCALE;

/*
* In later versions of pango, a font's height should be calculated like
* this to account for line gap; a typical symptom of not doing so is
* cutting off the underscore on some fonts.
*/
#if PANGO_VERSION_CHECK(1, 44, 0)
xtext->fontsize = pango_font_metrics_get_height (metrics) / PANGO_SCALE + 1;
#else
xtext->fontsize = xtext->font->ascent + xtext->font->descent;
#endif

pango_font_metrics_unref (metrics);
}

static int
backend_get_text_width_emph (GtkXText *xtext, guchar *str, int len, int emphasis)
{
Expand Down Expand Up @@ -3479,8 +3492,6 @@ gtk_xtext_set_font (GtkXText *xtext, char *name)
if (xtext->font == NULL)
return FALSE;

xtext->fontsize = xtext->font->ascent + xtext->font->descent;

{
char *time_str;
int stamp_size = xtext_get_stamp_str (time(0), &time_str);
Expand Down

0 comments on commit 86ae618

Please sign in to comment.