[csswg-drafts] [css-fonts] Proposal to expose font metrics (#4780)

chriskirknielsen has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-fonts] Proposal to expose font metrics ==
# 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](https://twitter.com/heydonworks/status/1225116968568721408))
* 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](https://github.com/w3c/csswg-drafts/issues/3240) and the `leading-trim` proposal
* Cleaner adjustment for a `:first-letter` drop-cap
* Fix various UI alignment issues (see [Weston Thayer's article on Font Metrics for examples](http://westonthayer.com/writing/intro-to-font-metrics/))
* … 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:

```css
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](https://opentype.js.org/font-inspector.html), 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](https://github.com/bramstein/fontfaceobserver) 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.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4780 using your GitHub account

Received on Sunday, 16 February 2020 20:30:56 UTC