Re: [hackers] [dwm][PATCH] drw: use cap height for optical text centering

From: Storkman <storkman_AT_storkman.nl>
Date: Tue, 19 May 2026 23:28:17 +0200

On Tue, May 19, 2026 at 09:37:42PM +0200, Alessio Artoni wrote:
> > You could potentially read sCapHeight from the 'OS/2' table through FreeType.
> > (See: https://st.suckless.org/patches/fontmetrics/st-fontmetrics-0.9.3.diff)
>
> I explored this first. The issue is that FT_Get_Sfnt_Table is a FreeType
> function, not an Xft function. Xft links FreeType internally, but
> calling FT_Get_Sfnt_Table directly requires adding -lfreetype to LDFLAGS.

Right. It just so happens that st already includes -lfreetype, even though
it's not needed there.

Incidentally, I've finally managed to dig through the freetype spaghetti
and found this:

        * 1. If the OS/2 table exists and the fsSelection bit 7 is set
        * (USE_TYPO_METRICS), trust the font and use the sTypo* metrics.
        * 2. Otherwise, use the `hhea' table's metrics.

Turns out that some fonts with OS/2 metrics different than hhea don't set
this bit, which maybe possibly is a mistake on their part…

> Measuring H via XftTextExtents8 uses only Xft, which is already linked.
> No new dependency. And it works for fonts without an OS/2 table (bitmap
> fonts, some CJK fonts where sCapHeight is 0).

Yeah. st actually gets the cell width by averaging the advances of all
printable ASCII glyphs, which I also hate, but it demonstrably works just fine!

> That said, the right long-term fix is for Xft to expose cap height
> directly. I've opened an issue upstream for that:
> https://gitlab.freedesktop.org/xorg/lib/libxft/-/work_items/26

For some reason I had the impression Xft was effectively on life support,
but it looks like they've been closing issues as recently as 6 months ago,
so fingers crossed.

-- 
Storkman
Received on Tue May 19 2026 - 23:28:17 CEST

This archive was generated by hypermail 2.3.0 : Tue May 19 2026 - 23:36:37 CEST