XftFontLoadGlyphs for mono font returns wrong info in extents from XftTextExtentsUtf8 for variable chars
XftTextExtentsUtf8()
is returning xOff
member of extents
with seemingly the wrong value when variable fonts are in use, in particular when ligatures are present in the monospace font. xOff
seems to be populated with the largest width of any character present, and some ligatures (like for <=>
) are 3x the "normal" character size. This causes terminals like st
which rely on xOff extent value to render the fonts with huge inter-glyph spaces (ie unusable), and urxvt
to reject the font.
This happens for me with Inconsolata font, the old version works fine, but using Inconsolata 3 (which is a variable font with ligatures), it has massive spaces between chars.
(https://fonts.google.com/download?family=Inconsolata and extract just Inconsolata-VariableFont_wdth,wght.ttf
)
Github issue for background here: https://github.com/googlefonts/Inconsolata/issues/42
in this comment on that bug, a fix was offered, which still seems to work with the master libxft
branch:
diff --git a/src/xftglyphs.c b/src/xftglyphs.c
index 7f89e24..3a3dfd2 100644
--- a/src/xftglyphs.c
+++ b/src/xftglyphs.c
@@ -847,11 +847,11 @@ XftFontLoadGlyphs (Display *dpy,
if (font->info.load_flags & FT_LOAD_VERTICAL_LAYOUT)
{
xftg->metrics.xOff = 0;
- xftg->metrics.yOff = (short)(-font->public.max_advance_width);
+ xftg->metrics.yOff = (short)(-TRUNC(ROUND(glyphslot->advance.y)));
}
else
{
- xftg->metrics.xOff = (short)(font->public.max_advance_width);
+ xftg->metrics.xOff = (short)(TRUNC(ROUND(glyphslot->advance.x)));
xftg->metrics.yOff = 0;
}
}
As this seems to fix the issue, if it is the right fix, could you please apply? Thanks.
P.S. original patch author @JasonBrownDeveloper had used advance.x
for both, which I assumed was a typo.