Repository navigation
cairo: report the cap height and measure the x-height - #243
Merged
Merged
Conversation
CairoFontInfo never set capHeight, so -[NSFont capHeight] returned 0 for every font on the cairo backend, and xHeight was estimated as 60 percent of the ascender, which is off by 10 to 15 percent for common faces. Both are now taken from the extents of the letters H and x of the scaled font, so applications that centre text on one of these metrics place it where the eye expects.
probonopd
added a commit
to gershwin-desktop/gershwin-developer
that referenced
this pull request
Sep 28, 2026
On the cairo backend -[NSFont capHeight] was always 0 and -xHeight a guess of 60 percent of the ascender, so any table cell or control that centres its text on one of those metrics drew it several points too high; the AppGarden sidebar showed it plainly. The patch takes both values from the extents of the letters H and x of the scaled font, which works for every face cairo renders. Sent upstream as gnustep/libs-back#243; the stripped diff and the PR text sit next to the patch.
fredkiefer
reviewed
Sep 28, 2026
fredkiefer
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On the cairo backend
-[NSFont capHeight]is 0 for every font, and-xHeightis a fixed 60 percent of the ascender rather than the font's own value. Anything that centres a line of text on one of these metrics, a table cell or a custom control drawing its own label, then sits several points too high. Seen with a hand-drawn source list cell whose labels were visibly above the row centre.Reproducer, a small tool printing the metrics of three fonts:
Before (master, Inter as the system font):
After:
Inter's cap height is 0.727 em, so 9.46 at 13 points is the real value, and its x-height is 0.546 em, so the old estimate was 6 percent high. The change takes both from
cairo_scaled_font_text_extentsof "H" and "x" on the scaled font, which works for every face cairo renders, and keeps the old estimate for the x-height only when the face has no "x" glyph.The second commit fixes
-boundingRectForGlyph:on the same backend, which returned cairo's y-down extents unchanged:y_bearingis the top of the ink measured downwards from the origin, so the rect sat below the baseline in the font's y-up coordinates, unlike the Xlib and Xft backends, which return the origin at the bottom of the ink. Same tool, printing the rect of four glyphs of the 13 point system font, before:After:
The origin is now
-(y_bearing + height): the bottom of the ink, 2.81 points below the baseline for the descender ofg, on the baseline forHandx.cc @pkgdemon