-
Notifications
You must be signed in to change notification settings - Fork 708
Interoperable font metrics via explicit font metrics overrides #4792
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
/cc @jfkthame |
The downside of any solution that relies on |
I suspect not applying this to local (or even generic) fonts might be entirely intentional. It's a good compromise idea - I still think we need There are other metrics to consider. Both x-height and cap-height are both in the OpenType PCLT table, and there are the baselines too (in the BASE table). All of these are stored only in one place in the font, so if this issue is purely about removing ambiguity and not about overriding metrics, then I'm not sure whether overriding these is important. |
I really appreciate any and all efforts that have the goal of fixing #2228 . This here ticket wouldn't solve my use-case in a way that's convenient enough - I'd first have to figure out which percentage values to fill in. A good solution would allow me (and other web developers) to ensure that the described cross-OS-differences won't happen (in modern standards-based browsers) - in a convenient and quick way, eg |
Any solution should be opt-in.
That's the responsibility of the web developer. They can apply it to the whole page or only to portions of it - it's up to them. I think that typically the property would be used for eg a large heading and that's it - the rest of the page would be smaller text (where the issue is eg negligible and which might not use the same font as the heading). In any case - it's the responsibility of the web developer to ensure consistent spacing and good typography etc. (That's the exact reason why I had posted #2228 😀 because I was trying to do just that.) |
One can already override font provided line spacing with CSS |
Setting |
Yes, you can set a specific line-height every time you use that font and get consistent cross-browser results for line-spacing. But it seems if you're overriding ascender/descender, on which the default value of line-height depends, you might also want to set the default line-height (edit: by setting the leading) as well. It's not necessary, but it will save you specifying |
It seems to me we could reasonably use CSS properties (not just font-face descriptors) here: something like
Then it might also be useful to have these as font-face descriptors, which would allow webfonts to override the result of An author could then choose to do something like
and expect to get consistent line-spacing behavior across browsers and platforms -- with the understanding that the result may not be the same as any given browser currently gives by default, but it's entirely under their control. I suppose the metrics properties (not descriptors) should probably accept absolute lengths, calc expressions, etc. for completeness, although em-based percentages would usually be the most sensible thing to use. The final piece would be to add a |
@khaledhosny wrote:
@faceless2 wrote:
The issue is not only about line-spacing 😀The issue is shown in the above screenshots. When it appears it appears even for a single line or word, on one OS vs another (more at #2228 ). @jfkthame wrote:
True! |
I believe this fails the “browsers having to parse font files” test. |
Just to make sure I understand, would these properties apply to the block container? Non-inherited? And would they override any/all ascent and descent values for every inline descendent? |
Yes - I figured you probably wouldn't be keen on this value (though we have
I haven't really thought about how inheritance etc ought to work... the suggestion that an author might write
was based on the idea that these properties would inherit (as percentages, to be resolved for each element against its used Just throwing ideas out, really, and happy to hear ideas on how it would best work (or why it wouldn't). |
If we allow custom overrides, values, percentages, etc. I'd prefer to not have those placed as descriptors in Background for not placing overrides in @litherum if I am not mistaken in skimming through the code, WebKit already has code for parsing several OpenType fields manually (for |
@jfkthame I would prefer to discuss properties (rather than @font-face descriptors) in a separate issue, as it has rather different implications and considerations than an @font-face descriptor. Also for the record, I don't think it's a good idea. Where to place the ascent/descent metrics is very font-dependent, and applying numbers fine-tuned to one font to another is liable to cause overlapping text. As for handling line-gaps and switching out how we measure the height of text, that's a css-inline issue, not a font issue, and is being handled there. [ in reply to https://github.com//issues/4792#issuecomment-588341590 ] |
There is another use case that would I think be solved by the proposal in this issue: matching fallback font metrics to emulate a web font, so as to minimize layout shift during page load. See here for one example; this can currently be combined with font face observation script libraries to dynamically update styles to remove the overrides. If we also add a descriptor such as:
(which would introduce a 0.1em extra spacing between letters) then we can also solve that use case, and avoid the use of these scripts. Using these scripts effectively is quite difficult since the script would have to be loaded extremely early in the page lifecycle. For that reason I think most sites don't use these libraries, even though they might improve page load UX. To use these overrides on a fallback font-family, the site would have to wrap it in an @font-face rather than a built-in font. |
See: #2228 (comment) and #5485 |
The PR was reviewed and has been merged. You can see it in the spec here. Well, now we need WPT tests :) |
I guess we also need to modify the JS https://drafts.csswg.org/css-font-loading-3/#fontface-interface |
Following the standardization of @font-face descriptors ascent-override, descent-override and line-gap-override, this patch uploads the existing test cases to WPT as test coverage. This resolves the "Need Testcase (WPT)" label in w3c/csswg-drafts#4792 Bug: 1098355 Change-Id: Iffadff1fb159e52ca5a0675259381401fbe90c99
Following the standardization of @font-face descriptors ascent-override, descent-override and line-gap-override, this patch uploads the existing test cases to WPT as test coverage. This resolves the "Need Testcase (WPT)" label in w3c/csswg-drafts#4792 Bug: 1098355 Change-Id: Iffadff1fb159e52ca5a0675259381401fbe90c99 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419585 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org> Cr-Commit-Position: refs/heads/master@{#808665}
Following the standardization of @font-face descriptors ascent-override, descent-override and line-gap-override, this patch uploads the existing test cases to WPT as test coverage. This resolves the "Need Testcase (WPT)" label in w3c/csswg-drafts#4792 Bug: 1098355 Change-Id: Iffadff1fb159e52ca5a0675259381401fbe90c99 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419585 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org> Cr-Commit-Position: refs/heads/master@{#808665}
Following the standardization of @font-face descriptors ascent-override, descent-override and line-gap-override, this patch uploads the existing test cases to WPT as test coverage. This resolves the "Need Testcase (WPT)" label in w3c/csswg-drafts#4792 Bug: 1098355 Change-Id: Iffadff1fb159e52ca5a0675259381401fbe90c99 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419585 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org> Cr-Commit-Position: refs/heads/master@{#808665}
Yes, indeed |
Does this need a separate WG resolution? I hope not. |
No additional resolution needed. It follows directly from the existing resolution. |
Could anyone review #5538? Just a trivial patch adding attributes to |
Demo: https://codepen.io/yisi/pen/xxVmzOM
@font-face {
font-family: 'STSongti-SC-Regular-punctuation';
advance-override: -0.4;
src: local(STSongti-SC-Regular);
unicode-range: U+b7;
} |
@yisibl Thanks for trying the prototype 😄
|
…escriptors to WPT, a=testonly Automatic update from web-platform-tests Upload tests for font metrics override descriptors to WPT Following the standardization of @font-face descriptors ascent-override, descent-override and line-gap-override, this patch uploads the existing test cases to WPT as test coverage. This resolves the "Need Testcase (WPT)" label in w3c/csswg-drafts#4792 Bug: 1098355 Change-Id: Iffadff1fb159e52ca5a0675259381401fbe90c99 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419585 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org> Cr-Commit-Position: refs/heads/master@{#808665} -- wpt-commits: fba18cc5e2fb20eb8059b3d26009f4921e61a84b wpt-pr: 25638
…escriptors to WPT, a=testonly Automatic update from web-platform-tests Upload tests for font metrics override descriptors to WPT Following the standardization of @font-face descriptors ascent-override, descent-override and line-gap-override, this patch uploads the existing test cases to WPT as test coverage. This resolves the "Need Testcase (WPT)" label in w3c/csswg-drafts#4792 Bug: 1098355 Change-Id: Iffadff1fb159e52ca5a0675259381401fbe90c99 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419585 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org> Cr-Commit-Position: refs/heads/master@{#808665} -- wpt-commits: fba18cc5e2fb20eb8059b3d26009f4921e61a84b wpt-pr: 25638
[css-font-loading-3] Add override attributes to FontFace interface following resolution in #4792
…escriptors to WPT, a=testonly Automatic update from web-platform-tests Upload tests for font metrics override descriptors to WPT Following the standardization of font-face descriptors ascent-override, descent-override and line-gap-override, this patch uploads the existing test cases to WPT as test coverage. This resolves the "Need Testcase (WPT)" label in w3c/csswg-drafts#4792 Bug: 1098355 Change-Id: Iffadff1fb159e52ca5a0675259381401fbe90c99 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419585 Reviewed-by: Chris Harrelson <chrishtrchromium.org> Commit-Queue: Xiaocheng Hu <xiaochenghchromium.org> Cr-Commit-Position: refs/heads/master{#808665} -- wpt-commits: fba18cc5e2fb20eb8059b3d26009f4921e61a84b wpt-pr: 25638 UltraBlame original commit: bf45a57ead94d683e460e9a7fd00fcad492f99bb
…escriptors to WPT, a=testonly Automatic update from web-platform-tests Upload tests for font metrics override descriptors to WPT Following the standardization of font-face descriptors ascent-override, descent-override and line-gap-override, this patch uploads the existing test cases to WPT as test coverage. This resolves the "Need Testcase (WPT)" label in w3c/csswg-drafts#4792 Bug: 1098355 Change-Id: Iffadff1fb159e52ca5a0675259381401fbe90c99 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419585 Reviewed-by: Chris Harrelson <chrishtrchromium.org> Commit-Queue: Xiaocheng Hu <xiaochenghchromium.org> Cr-Commit-Position: refs/heads/master{#808665} -- wpt-commits: fba18cc5e2fb20eb8059b3d26009f4921e61a84b wpt-pr: 25638 UltraBlame original commit: bf45a57ead94d683e460e9a7fd00fcad492f99bb
…escriptors to WPT, a=testonly Automatic update from web-platform-tests Upload tests for font metrics override descriptors to WPT Following the standardization of font-face descriptors ascent-override, descent-override and line-gap-override, this patch uploads the existing test cases to WPT as test coverage. This resolves the "Need Testcase (WPT)" label in w3c/csswg-drafts#4792 Bug: 1098355 Change-Id: Iffadff1fb159e52ca5a0675259381401fbe90c99 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419585 Reviewed-by: Chris Harrelson <chrishtrchromium.org> Commit-Queue: Xiaocheng Hu <xiaochenghchromium.org> Cr-Commit-Position: refs/heads/master{#808665} -- wpt-commits: fba18cc5e2fb20eb8059b3d26009f4921e61a84b wpt-pr: 25638 UltraBlame original commit: bf45a57ead94d683e460e9a7fd00fcad492f99bb
Thanks all! Wrote a post: https://tobireif.com/posts/ensuring_the_correct_vertical_position_of_large_text/ |
Migrated from #2228 (comment)
In font files, there exist at least three different ascent/descent values:
ascender
anddescender
from thehhea
tablesTypoAscender
andsTypoDescender
from theOS/2
tableusWinAscent
andusWinDescent
from theOS/2
tableDifferent browsers / OSes use different values. In fact, some even use values that are not present in the font file at all. This leads to content being laid out differently on different browsers / OSes. #2228 is an example of one. There have been others.
There have been efforts to try to introduce "interoperable" metrics into CSS (#3978 is one, #938 is related, there are a few others too), to force browsers to agree on which metrics they use. Many of the existing proposals so far have some downsides:
However, interoperable font metrics are desirable for many page authors. Here's a compromise proposal that (I believe) solves all the above problems:
What if we add a new descriptor into
@font-face
to let the CSS author override the metrics of the font? Something like this:Those percentage values are resolved by multiplying by the font size (em box). Negative values are illegal. The browser doesn't have to parse any font files, all browsers will agree on the resolved value, and all text in all situations drawn with that font will use these values.
There's already precedent for this: the
font-feature-values
andfont-variation-values
descriptors in@font-face
overrides the defaults present in the font file.The text was updated successfully, but these errors were encountered: