Skip to content
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

[css-fonts-4] Unclear serialisation of calc expressions in @font-face font-stretch/style/weight descriptors #7964

Closed
drott opened this issue Oct 27, 2022 · 9 comments

Comments

@drott
Copy link
Collaborator

drott commented Oct 27, 2022

css/css-fonts/variations/at-font-face-descriptors.html defines various expectations for what should happen with calc() expressions, but does not consistently do that, some are evaluated, some are not.

This issue is spun off of recent WebKit WPT test merge where expectations were changed from evaluated and clamped calc() results to unevaluated calc() results when reading back the descriptor.
WebKit/WebKit@c3e9369

Generally, the css-values specification suggest simplification:
https://w3c.github.io/csswg-drafts/css-values-4/#calc-simplification

We need to define what the serialized value of the font property-descriptors font-weight, font-stretch, font-style in
https://drafts.csswg.org/css-fonts-4/#font-prop-desc should be.

@drott drott added the css-fonts-4 Current Work label Oct 27, 2022
@drott drott changed the title [css-fonts] Unclear serialisation of calc expressions in @font-face font-stretch/style/weight descriptors [css-fonts-4] Unclear serialisation of calc expressions in @font-face font-stretch/style/weight descriptors Oct 27, 2022
drott referenced this issue in WebKit/WebKit Oct 27, 2022
…ue for font-style

https://bugs.webkit.org/show_bug.cgi?id=246960
rdar://101517323

Reviewed by Darin Adler.

css/css-fonts/variations/at-font-face-descriptors.html assumes `font-style: oblique calc(91deg)` gets serialized to `font-style: oblique 90deg` in the specified style, which should not be the case according to the spec: https://drafts.csswg.org/css-values-3/#calc-range

> (Clamping is not performed on specified values.)

* LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/variations/at-font-face-descriptors-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/variations/at-font-face-descriptors.html:

Canonical link: https://commits.webkit.org/258633@main
@jfkthame
Copy link
Contributor

jfkthame commented Oct 27, 2022

Generally, the css-values specification suggest simplification: https://w3c.github.io/csswg-drafts/css-values-4/#calc-simplification

"Simplification" as described there doesn't include clamping, though, does it?

In 8.1.4. Range Checking, we read:

Parse-time range-checking of values is not performed within calc(), and therefore out-of-range values do not cause the declaration to become invalid. However, the value resulting from an expression must be clamped to the range allowed in the target context. Clamping is performed on computed values to the extent possible, and also on used values if computation was unable to sufficiently simplify the expression to allow range-checking. (Clamping is not performed on specified values.)

So I guess the answer depends whether the serialized values of these descriptors are treated like specified or computed (or used) values. I'm not sure what that means in relation to @font-face descriptors (as opposed to CSS properties). Is there a general convention for this, or do we need to specify it in each case?

@nt1m
Copy link
Member

nt1m commented Oct 27, 2022

So I guess the answer depends whether the serialized values of these descriptors are treated like specified or computed (or used) values. I'm not sure what that means in relation to @font-face descriptors (as opposed to CSS properties). Is there a general convention for this, or do we need to specify it in each case?

The test we're pointing out is setting and reading .style.fontStyle. You can't directly set the computed style, so this definitely qualifies as "specified" to me.

@tabatkins
Copy link
Member

"Serialized" vs "computed" concepts don't actually apply to at-rule descriptors, as they're related to the cascade. So yeah, this is indeed underspecified.

I don't have a strong opinion on whether we clamp or not here, but I lean weakly towards "don't clamp" for the same reasons @nt1m gave.

@drott
Copy link
Collaborator Author

drott commented Oct 28, 2022

I don't have a strong opinion on whether we clamp or not here, but I lean weakly towards "don't clamp" for the same reasons @nt1m gave.

It seems to me "unclamped" would still leave it undefined whether calc() expressions should be only simplified but left there literally, or evaluated/computed and then left unclamped.

FWIW, leaving things unclamped or having to return csstext as specified literally would prevent the implementation from storing specified values in a more pre-computed, more efficient or canonical way. Instead the implementation would need to keep a backup of the original css text which may not be identical to what it's using internally. The as-specified text/values do not need to be stored, as there is no need to re-compute values after cascading.

I tend to think, keeping only a evaluated and simplified form seems to be the better choice:

  • If a descriptor is specified twice, we would already simplify towards returning only one value when accessing the serialized value.
  • Similarly, the serialization of @font-palette-values and @font-feature-values is also underspe'ed, which we may want to fix at the same time. In particular in @font-feature-values, there are many examples of how values can be overridden, or redundantly specified (Examples 60 and 61 of https://www.w3.org/TR/css-fonts-4/#font-feature-values-syntax) - Here, it would be very cumbersome to store the original form instead of a canonical form with only the actively used values.
  • In issue [css-fonts] Missing serialisation for 0 ranged descriptors inside @font-face #7925 we're discussing the simplification of 0 sized ranges for font-weight, font-stretch, font-style ranges and the proposal to collapse these into a single value seems to have received support there.

@nt1m
Copy link
Member

nt1m commented Oct 28, 2022

For consistency's sake I would prefer the serialization of the descriptors to be the same as the CSS properties, makes it easier (on the WebKit side at least) to implement serialization/parsing without duplicating code or extra code-paths.

@jfkthame
Copy link
Contributor

How much of a benefit is that, really? The values of the descriptors don't entirely correspond to properties: e.g. the font-weight, -stretch and -style descriptors have an auto value that doesn't exist for the related properties; and they (optionally) take a range, whereas the properties take a single value. (And some property values aren't allowed in the descriptors: bolder, lighter.) So some distinction clearly needs to be made.

@svgeesus
Copy link
Contributor

I agree with @jfkthame that the grammar of properties and descriptors is related but not identical. And agree with @drott that consensus seems to be forming on simplifying zero-ranged descriptors; but descriptors with a non-zero range have values that the corresponding property does not allow.

So a general rule of simplifying to a canonical form seems clearer.

@svgeesus
Copy link
Contributor

svgeesus commented Mar 1, 2023

I added some more to 13.2. Serializing font-related at-rules , explicitly noting the principle of last-defined values and also coalescing blocks.

I made the serialized form be sorted alphabetically, but I am not sure if or where that is specified for descriptor values.

I haven't added anything about simplifying calc expressions, and would like to see a good example.

@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed [css-fonts-4] Unclear serialisation of calc expressions in `@font-face` font-stretch/style/weight descriptors, and agreed to the following:

  • RESOLVED: math function simplifcation for descriptors is as if they were specified properties, and descriptors with math functions use the specified-value serialization rules
The full IRC log of that discussion <emeyer> TabAtkins: Fundamental issue is that simplification rules for math functions refer to resolution stages
<emeyer> …Those don’t apply in descriptors
<emeyer> …So what are the rules for serialization, and do they match?
<emeyer> …Apple wants serialization to be the same as CSS properties, which makes sense
<emeyer> …Not sure if we’re compat-constrained or not
<emeyer> dbaron: The one thought I have is that descriptors seem a lot like specified values
<emeyer> TabAtkins: Agreed
<emeyer> emilio: Agreed
<emeyer> TabAtkins: I think it’s reasonable to say we treat things the same
<emeyer> astearns: We could resolve on that and see if anyone complains
<emeyer> TabAtkins: proposed resolution: math function simplifcation for descriptors as if they were specified properties, and descriptors with math functions use the same serialization rules as properties
<emeyer> RESOLVED: math function simplifcation for descriptors is as if they were specified properties, and descriptors with math functions use the specified-value serialization rules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants