[webkit-changes] [WebKit/WebKit] 7ba7f4: unicode-range may cause us to use Times's font met...

Myles C. Maxfield noreply at github.com
Fri Mar 31 21:54:45 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 7ba7f4d9fb851ed545353bb489d4b929f7f5e8cd
      https://github.com/WebKit/WebKit/commit/7ba7f4d9fb851ed545353bb489d4b929f7f5e8cd
  Author: Myles C. Maxfield <mmaxfield at apple.com>
  Date:   2023-03-31 (Fri, 31 Mar 2023)

  Changed paths:
    A LayoutTests/http/tests/text/primary-font-interstitial-expected.html
    A LayoutTests/http/tests/text/primary-font-interstitial.html
    A LayoutTests/http/tests/text/resources/Gulf-regular.ttf
    M Source/WebCore/platform/graphics/FontCascadeFonts.h
    M Source/WebCore/platform/graphics/FontRanges.h

  Log Message:
  -----------
  unicode-range may cause us to use Times's font metrics erroneously
https://bugs.webkit.org/show_bug.cgi?id=244757

Reviewed by Darin Adler.

When we lay out a line, we use the metrics of the primary font inside our computation to determine line height.
If the content just says `font-family: a, b`; then it's clear that `a` is the primary font. However, `a` can
actually be a composite font, as such:

```
@font-face {
    font-family: a;
    src: url("MyFont.ttf");
    unicode-range: some range;
}
@font-face {
    font-family: a;
    src: url("MyOtherFont.ttf");
    unicode-range: a distinct range that doesn't intersect the other font's range;
}
```

In this situation, when laying out a line, should we use the metrics from MyFont.ttf or MyOtherFont.ttf?

The spec isn't prescriptive here, so it's kind of up to us to determine what to do. What we actually do is
from FontCascadeFonts::primaryFont():
A) If one of the `unicode-range`s includes the space character, use that one (last one wins if there are
      multiple). If we need to download this font, do so.
B) If none of the `unicode-range`s includes the space character, then use the last @font-face block, but
      set the flag to forbid downloads from occuring.

When we ask for a font that hasn't finished loading yet, the font object we get back is an "interstitial"
font, which just means it's a temporary invisible font to use until the real one finishes downloading. The
interstitial font is hardcoded to always be Times. When we set the flag to forbid downloads from occurring,
the font we get back is this "interstitial" font, but we'll never switch from the interstitial font to the
real one - because the real one will never finish downloading because it never started downloading! So we
just use the metrics from Times indefinitely, which is a surprising result!

The solution here is just to allow downloads in both cases A) and B) above. By allowing downloads in case
B), we start the font loading process which means we'll eventually switch off of using Times's metrics.

Test: http/tests/text/primary-font-interstitial.html

* LayoutTests/http/tests/text/primary-font-interstitial-expected.html: Added.
* LayoutTests/http/tests/text/primary-font-interstitial.html: Added.
* LayoutTests/http/tests/text/resources/Gulf-regular.ttf: Added.
* Source/WebCore/platform/graphics/FontCascadeFonts.h:
(WebCore::FontCascadeFonts::primaryFont):

Canonical link: https://commits.webkit.org/262464@main




More information about the webkit-changes mailing list