+ se->xftfont = XftFontOpenXlfd (s->dpy, screen_number (s->xgwa.screen),
+ pattern);
+
+ /* Sometimes we get fonts with screwed up metrics. For example:
+ -b&h-lucida-medium-r-normal-sans-40-289-100-100-p-0-iso8859-1
+
+ When using XDrawString, XTextExtents and XTextExtents16, it is rendered
+ as a scaled-up bitmap font. The character M has rbearing 70, ascent 68
+ and width 78, which is correct for the glyph as rendered.
+
+ But when using XftDrawStringUtf8 and XftTextExtentsUtf8, it is rendered
+ at the original, smaller, un-scaled size, with rbearing 26, ascent 25
+ and... width 77!
+
+ So it's taking the *size* from the unscaled font, the *advancement* from
+ the scaled-up version, and then *not* actually scaling it up. Awesome.
+
+ So, after loading the font, measure the M, and if its advancement is more
+ than 20% larger than its rbearing, reject the font.
+
+ ------------------------------------------------------------------------
+
+ Some observations on this nonsense from Dave Odell:
+
+ 1. -*-lucidatypewriter-bold-r-normal-*-*-480-*-*-*-*-iso8859-1 normally
+ resolves to /usr/share/fonts/X11/100dpi/lutBS24-ISO8859-1.pcf.gz.
+
+ -*-lucidatypewriter-* is from the 'xfonts-100dpi' package in
+ Debian/Ubuntu. It's usually (54.46% of systems), but not always,
+ installed whenever an X.org server (57.96% of systems) is. It might
+ be a good idea for this and xfonts-75dpi to be recommended
+ dependencies of XScreenSaver in Debian, but that's neither here nor
+ there. https://qa.debian.org/popcon.php?package=xorg
+ https://qa.debian.org/popcon.php?package=xfonts-100dpi
+
+ 2. It normally resolves to the PCF font... but not always.
+
+ Fontconfig has /etc/fonts/conf.d/ (it's /opt/local/etc/fonts/conf.d/
+ with MacPorts) containing symlinks to configuration files. And both
+ Debian and Ubuntu normally has a 70-no-bitmaps.conf, installed as part
+ of the 'fontconfig-config' package. And the 70-no-bitmaps.conf
+ symlink... disables bitmap fonts.
+
+ Without bitmap fonts, I get DejaVu Sans.
+
+ 3. There's another symlink of interest here:
+ /etc/fonts/conf.d/10-scale-bitmap-fonts.conf. This adds space to the
+ right of glyphs of bitmap fonts when the requested size of the font is
+ larger than the actual bitmap font. Ubuntu and MacPorts has this one.
+
+ This specifically is causing text to have excessive character spacing.
+
+ (jwz asks: WHY WOULD ANYONE EVER WANT THIS BEHAVIOR?)
+
+ 4. Notice that I'm only talking about Debian and Ubuntu. Other distros
+ will probably have different symlinks in /etc/fonts/conf.d/. So yes,
+ this can be an issue on Linux as well as MacOS.
+ */
+ {
+ XGlyphInfo extents;
+ int rbearing, width;
+ float ratio;
+ float min = 0.8;
+
+ XftTextExtentsUtf8 (s->dpy, se->xftfont, (FcChar8 *) "M", 1, &extents);
+ rbearing = extents.width - extents.x;
+ width = extents.xOff;
+ ratio = rbearing / (float) width;