-
Notifications
You must be signed in to change notification settings - Fork 757
Description
Introduction
It would be useful to expose metrics from the font that is being used by the browser.
These values would be normalised across all fonts, and not defined as an additional metadata in font files. This would insure backward compatibility with all fonts.
Use cases
- Align inline icons (Heydon Pickering's thread resonated with me a lot)
- Large headings can sometimes have some horizontal space before the first glyph that cause misalignment with the body of text below — this could help adjust this in a non-hacky way
- Ties in with leading control and the
leading-trimproposal - Cleaner adjustment for a
:first-letterdrop-cap - Fix various UI alignment issues (see Weston Thayer's article on Font Metrics for examples)
- … and fun typography experiments of course!
Syntax
I'd like to propose a syntax similar to custom properties or environment variables that would be familiar to most authors:
font(--x-height)
font(--ascender)
font(--descender)
font(--cap-height)
/* etc. */The double hyphen syntax could be a quoted value instead, such as font("x-height"), but maybe that should be kept for custom ident in font files.
Questions
These metrics are available with tools like Font Inspector, but are they passed along to the browser when it loads in the font? If not, I realise this proposal would not be feasible.
Limitations
I can imagine that the rise of variable fonts also means a single font can have multiple x-heights based on the different parameters, and I am not sure if this should be handled by browsers or authors.
One argument for it to be handled by browsers is that authors cannot predict a font that failed to load (unless using something like Font Face Observer to apply styles conditionally…).
Thanks for your time reading this. Please let me know if this has already been discussed, or if there is any interest in this.