Re: [csswg-drafts] [css-fonts-5] Computed value of `font-size-adjust: from-font` (#9050)

After experimenting with `from-font` a bit, I'm persuaded that the behavior in the spec (computing `from-font` to a number based on the element's "first available font", so that descendants will inherit the number, not the keyword) is the right thing to do.

Consider content such as
```
  <p style="font-family:serif">Here's some text with a bit of <tt>typewriter text</tt> in it.</p>
  <p style="font-family:sans-serif">Here's some text with a bit of <tt>typewriter text</tt> in it.</p>
```
Depending on the fonts in use, the "typewriter" (monospaced) text often looks somewhat mis-sized compared to the surrounding serif or sans-serif. This is somewhere `font-size-adjust` should be able to help.

We could set `font-size-adjust` on the paragraphs with an explicit value:
```
  <p style="font-family:serif; font-size-adjust:0.5">Here's some text with a bit of <tt>typewriter text</tt> in it.</p>
  <p style="font-family:sans-serif; font-size-adjust:0.5">Here's some text with a bit of <tt>typewriter text</tt> in it.</p>
```
which works to harmonize the monospaced font with its surroundings, but *also* resizes the main font of the paragraph, unless the number is chosen such that it exactly matches that font's ex-height factor.

Time for `from-font` to come to the rescue! Using this, we can set the `font-size-adjust` factor without having to manually determine the exact value for the main font in use (which we might not even know). So let's do it:
```
  <p style="font-family:serif; font-size-adjust:from-font">Here's some text with a bit of <tt>typewriter text</tt> in it.</p>
  <p style="font-family:sans-serif; font-size-adjust:from-font">Here's some text with a bit of <tt>typewriter text</tt> in it.</p>
```
This should ensure that the main paragraph font is untouched by `font-size-adjust`, while the embedded monospace text gets harmonized with it.

But that *only* works if `from-font` is computed to a number, so that the `<tt>` element inherits the factor that was computed from the metrics of the surrounding paragraph's font. If it were to inherit the keyword value `from-font`, it would then set its own factor based on the monospace font's metrics, and no adjustment would happen!

So the spec is correct to say that `from-font` computes to a number.


-- 
GitHub Notification of comment by jfkthame
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9050#issuecomment-1653474447 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 27 July 2023 12:01:30 UTC