-
Notifications
You must be signed in to change notification settings - Fork 711
[css-fonts] Proposal to expose font metrics #4780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The x-height is already exposed as the |
@SelenIT I was aware of the |
Also note #838 for stroke widths. |
Which font does this refer to? |
@Crissov I could see that being quite useful as well!
@litherum It would target the currently-used font. I imagine that would be the best way to go about it. Say you had a rule for paragraphs such as This way, if you were providing calculations for some alignment, you would always have values that are consistent with the font, and not hardcoded based on the best-case scenario. |
What about an element where none of the characters in it are supported by Source Sans Pro, but are supported by Arial? In such an element, you probably let want the metrics to come from Arial, since that’s what all the text is rendered with. |
This is a great question, as it poses: if the furthest fallback font is an emoji font for example, it might have vastly different sizing compared to, say, a wide fantasy-type font. I would assume most authors would pick sensible fallbacks to keep this issue at a minimal. Additionally, this would probably gracefully degrade, but this would require testing, as I am only assuming. Not to mention CJK writing systems could trigger quite different edge cases. |
We've already answered this question with other metrics, e.g. capheight, xheight - we use the first available font. I imagine that would apply here too. Clearly that means the values returned for generic fonts like "serif" will be pretty arbitrary, as they are for x-height. But I suspect that's not the use case the OP had in mind. I like this proposal. Combined with #4792, I think it would give authors who are prepared to get their hands dirty with |
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
leading-trim
proposal:first-letter
drop-capSyntax
I'd like to propose a syntax similar to custom properties or environment variables that would be familiar to most authors:
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.
The text was updated successfully, but these errors were encountered: