Skip to content

script: Return list of matching fonts from FontFaceSet.load - #47564

Merged
simonwuelker merged 3 commits into
servo:mainfrom
simonwuelker:fontfaceset-load-return-relevant-subset
Aug 29, 2026
Merged

simonwuelker merged 3 commits into
servo:mainfrom
simonwuelker:fontfaceset-load-return-relevant-subset

Conversation

@simonwuelker

Copy link
Copy Markdown
Member

FontFaceSet.load receives a CSS font shorthand and is supposed to query matching faces in the set, wait for all of them to load and then return a list of the corresponding FontFace objects. Currently we instead wait for document.fonts.ready and return an empty list. This change begins implementing the font query. Font matching is done in a naive manner for now, we simply return all fonts with a matching font-family. Its unclear to me how proper matching should be done, as this needs to happen before the font data is available. Still, this is progress.

Testing: New tests start to pass
Part of #21565

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Aug 27, 2026

[@font-face matching for quoted and unquoted ui-serif (drawing text in a canvas)]
expected: FAIL

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +368 to +371
pub(crate) fn is_connected_to_font_face_rule(
&self,
target_rule: &ServoArc<FontFaceRuleInfo>,
) -> bool {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that this code now compares the info arc instead of the stylo rule. As we noted before, the stylo rule cannot be used to identify the info struct. I also added a note about this on the relevant struct.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Aug 28, 2026
Signed-off-by: Simon Wülker <[email protected]>
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Aug 29, 2026
@simonwuelker
simonwuelker enabled auto-merge August 29, 2026 18:07
@simonwuelker
simonwuelker added this pull request to the merge queue Aug 29, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Aug 29, 2026
Merged via the queue into servo:main with commit a8d5fda Aug 29, 2026
36 checks passed
@simonwuelker
simonwuelker deleted the fontfaceset-load-return-relevant-subset branch August 29, 2026 19:04
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Aug 29, 2026
jschwe pushed a commit to openharmony-rs/servo-ohos that referenced this pull request Sep 18, 2026
… of servo#47564)

`FontFaceSet.load` receives a CSS `font` shorthand and is supposed to
query matching faces in the set, wait for all of them to load and then
return a list of the corresponding `FontFace` objects. Currently we
instead wait for `document.fonts.ready` and return an empty list. This
change begins implementing the font query. Font matching is done in a
naive manner for now, we simply return all fonts with a matching
`font-family`. Its unclear to me how proper matching should be done, as
this needs to happen before the font data is available. Still, this is
progress.

Testing: New tests start to pass
Part of servo#21565

Fork note: backport of upstream a8d5fda (servo#47564), which landed a few
hours after base/2026-08-29. `fonts: Only load @font-face fonts that the
page uses` needs the font query: with lazy loading, `document.fonts.load()`
is what asks for a face that nothing on the page uses yet, and without this
commit it never finds one. The subject differs from upstream's only because
STACK.md cannot hold backticks.

Drop at the next sync: every later base contains a8d5fda, so this commit
applies empty and becomes a `Superseded-by: a8d5fda` placeholder (runbook
decision 3).

Validation: `./mach test-wpt --release --processes 1 css/css-font-loading css/css-fonts html/canvas/element/text html/canvas/offscreen/text` (947 tests) shows no unexpected result beyond those plain ohos-main already has on the host (font-variant-emoji-1 FAIL, font-variant-emoji-2 and matching/font-unicode-presented-as-emoji-outline PASS); upstream's new expectations for fontfaceset-load-var, fontfaceset-load-css-wide-keywords, font-face-range-order and font-face-style-normal hold. One run failed font-feature-settings-descriptor-01; five reruns pass on both this commit and ohos-main.
AI-assisted: Yes (agent session; clean `git cherry-pick -x` of upstream a8d5fda, subject reworded for STACK.md, no code changes)
Signed-off-by: Simon Wülker <[email protected]>
(cherry picked from commit a8d5fda)
Signed-off-by: Jonathan Schwender <[email protected]>
jschwe pushed a commit to openharmony-rs/servo-ohos that referenced this pull request Sep 18, 2026
… of servo#47564)

`FontFaceSet.load` receives a CSS `font` shorthand and is supposed to
query matching faces in the set, wait for all of them to load and then
return a list of the corresponding `FontFace` objects. Currently we
instead wait for `document.fonts.ready` and return an empty list. This
change begins implementing the font query. Font matching is done in a
naive manner for now, we simply return all fonts with a matching
`font-family`. Its unclear to me how proper matching should be done, as
this needs to happen before the font data is available. Still, this is
progress.

Testing: New tests start to pass
Part of servo#21565

Fork note: backport of upstream a8d5fda (servo#47564), which landed a few
hours after base/2026-08-29. `fonts: Only load @font-face fonts that the
page uses` needs the font query: with lazy loading, `document.fonts.load()`
is what asks for a face that nothing on the page uses yet, and without this
commit it never finds one. The subject differs from upstream's only because
STACK.md cannot hold backticks.

Drop at the next sync: every later base contains a8d5fda, so this commit
applies empty and becomes a `Superseded-by: a8d5fda` placeholder (runbook
decision 3).

Validation: `./mach test-wpt --release --processes 1 css/css-font-loading css/css-fonts html/canvas/element/text html/canvas/offscreen/text` (947 tests) shows no unexpected result beyond those plain ohos-main already has on the host (font-variant-emoji-1 FAIL, font-variant-emoji-2 and matching/font-unicode-presented-as-emoji-outline PASS); upstream's new expectations for fontfaceset-load-var, fontfaceset-load-css-wide-keywords, font-face-range-order and font-face-style-normal hold. One run failed font-feature-settings-descriptor-01; five reruns pass on both this commit and ohos-main.
AI-assisted: Yes (agent session; clean `git cherry-pick -x` of upstream a8d5fda, subject reworded for STACK.md, no code changes)
Signed-off-by: Simon Wülker <[email protected]>
(cherry picked from commit a8d5fda)
Signed-off-by: Jonathan Schwender <[email protected]>
jschwe pushed a commit to openharmony-rs/servo-ohos that referenced this pull request Sep 18, 2026
… of servo#47564)

`FontFaceSet.load` receives a CSS `font` shorthand and is supposed to
query matching faces in the set, wait for all of them to load and then
return a list of the corresponding `FontFace` objects. Currently we
instead wait for `document.fonts.ready` and return an empty list. This
change begins implementing the font query. Font matching is done in a
naive manner for now, we simply return all fonts with a matching
`font-family`. Its unclear to me how proper matching should be done, as
this needs to happen before the font data is available. Still, this is
progress.

Testing: New tests start to pass
Part of servo#21565

Fork note: backport of upstream a8d5fda (servo#47564), which landed a few
hours after base/2026-08-29. `fonts: Only load @font-face fonts that the
page uses` needs the font query: with lazy loading, `document.fonts.load()`
is what asks for a face that nothing on the page uses yet, and without this
commit it never finds one. The subject differs from upstream's only because
STACK.md cannot hold backticks.

Drop at the next sync: every later base contains a8d5fda, so this commit
applies empty and becomes a `Superseded-by: a8d5fda` placeholder (runbook
decision 3).

Validation: `./mach test-wpt --release --processes 1 css/css-font-loading css/css-fonts html/canvas/element/text html/canvas/offscreen/text` (947 tests) shows no unexpected result beyond those plain ohos-main already has on the host (font-variant-emoji-1 FAIL, font-variant-emoji-2 and matching/font-unicode-presented-as-emoji-outline PASS); upstream's new expectations for fontfaceset-load-var, fontfaceset-load-css-wide-keywords, font-face-range-order and font-face-style-normal hold. One run failed font-feature-settings-descriptor-01; five reruns pass on both this commit and ohos-main.
AI-assisted: Yes (agent session; clean `git cherry-pick -x` of upstream a8d5fda, subject reworded for STACK.md, no code changes)
Signed-off-by: Simon Wülker <[email protected]>
(cherry picked from commit a8d5fda)
Signed-off-by: Jonathan Schwender <[email protected]>
RichardTjokroutomo pushed a commit to RichardTjokroutomo/servo that referenced this pull request Oct 6, 2026
…47564)

`FontFaceSet.load` receives a CSS `font` shorthand and is supposed to
query matching faces in the set, wait for all of them to load and then
return a list of the corresponding `FontFace` objects. Currently we
instead wait for `document.fonts.ready` and return an empty list. This
change begins implementing the font query. Font matching is done in a
naive manner for now, we simply return all fonts with a matching
`font-family`. Its unclear to me how proper matching should be done, as
this needs to happen before the font data is available. Still, this is
progress.

Testing: New tests start to pass
Part of servo#21565

---------

Signed-off-by: Simon Wülker <[email protected]>
jschwe pushed a commit to openharmony-rs/servo-ohos that referenced this pull request Oct 9, 2026
… of servo#47564)

Dropped in favour of upstream a8d5fda (servo#47564), which this commit
backported and which every base from base/2026-10-08 on contains.
Equivalence: `git log --cherry-mark base/2026-10-08...pre-sync/2026-10-08`
marks this commit `=` (identical patch-id to a8d5fda); the rebase
stopped only because later upstream commits rewrote the same lines
(Rc<Promise> → RootedPromise/TracedPromise). Verified by the sync of
2026-10-08.

This empty placeholder is removed in the next sync's fold step.

Superseded-by: a8d5fda
Validation: patch-id identity with a8d5fda (`git log --cherry-mark`); the stack's font WPT set (css/css-font-loading, css/css-fonts) is run on the rebased stack by the 2026-10-08 sync.
AI-assisted: Yes (agent session; 2026-10-08 sync -- emptied in favor of upstream a8d5fda, which has the identical patch (`git log --cherry-mark`))
Signed-off-by: Jonathan Schwender <[email protected]>
jschwe added a commit to openharmony-rs/servo-ohos that referenced this pull request Oct 9, 2026
Every @font-face rule was fetched, sanitised and kept in memory as soon as
its stylesheet applied, even when no style used its family or its
unicode-range covered no character on the page. CSS Fonts 4 requires user
agents to only download fonts that are used.

A new rule now only registers an unloaded face, matched by its descriptors.
Font matching asks for the face once it selects it for a character, and the
loads it asked for start after layout. `FontFace.load()` and
`FontFaceSet.load()` ask for faces the same way. Faces whose sources are all
`local()` are still loaded right away.

Because matching now decides which faces load, adding @font-face rules
dirties the document so that text is matched again, `document.fonts.ready`
flushes layout, and a reflow that starts loads makes it pending again.

The font store now holds templates for faces whose data has not been
downloaded. `FontGroupFamilyTemplate::font_if_matches` skips them, but
`FontContext::matching_templates` and `FontContext::font` are also used
directly by the SVG font resolver, which would hit the "Should never create
a web font without data" panic in `PlatformFont::new_from_template` for any
SVG `<text>` using a web font. `FontContext::font` returns `None` for a web
font template without data, without caching the failure, so the face can be
used once it has loaded. The SVG font resolver asks for the face to be
loaded, like layout does when it matches one, and falls back to the next
family in the meantime.

An element whose font-family names a web font but that has no text never
picks the font for a character, but its first available font is needed
too, for instance for `line-height: normal` and font-relative lengths, and
Chrome and Firefox load it. After an element is restyled, layout asks for
the first available font of its style to be loaded if it is a web font that
has not been fetched. Only elements whose font differs from their parent's
are looked at, nothing is done while the document has no web fonts, and the
lookup runs once per font group. It does not create fonts, so system fonts
are not loaded for elements that never draw text.

Testing: A new WPT test checks that unused faces stay "unloaded". A canvas
test that expected a font not used by the page to be loaded now fails, as it
does in Chrome, Firefox and Safari. svg/painting/svg-with-outline.html,
css/css-transforms/transform-box/view-box-mutation-002.html and
resize-observer/svg.html keep their expected results instead of crashing,
and content-security-policy/font-src/font-stylesheet-font-blocked.sub.html
(a body without text) and preload/preload-resource-match.https.html (an
empty paragraph) still see the font fetched.

Fork note: second of four patches, meant for upstream. The upstream-based
version (branch lazy-webfonts) does not have the two fixes for SVG text and
for elements without text yet, which the servo-ohos PR 12 try run found.
Motivation: generated-UI pages that link Google Fonts CJK families declare
hundreds of unicode-range subsets (441 @font-face rules on the "keai"
concert-article test page), and Servo downloaded all of them (437 files,
10.5 MiB) where ArkWeb downloads 64.

Relies on: the previous patch (the load state on `FontFaceRuleInfo`, which is
how matching tells unloaded faces apart and how `FontFace.status` shows it);
upstream a8d5fda (servo#47564, its `FontFaceSet.load` font query is what makes
`document.fonts.load()` ask for faces); matching going through
`FontGroupFamilyTemplate::font_if_matches` and `char_in_unicode_range`
(components/shared/fonts/font_template.rs); `LayoutThread::reflow` returning a
`ReflowResult` and `can_skip_reflow_request_entirely` gating it; and the
readiness checks in `Document::maybe_fulfill_font_ready_promise` and
`Window::maybe_resolve_pending_screenshot_readiness_requests` reading
`FontContext::web_fonts_still_loading`.

Drop when upstream loads @font-face rules lazily: the test this patch adds,
css/css-font-loading/fontface-unused-stays-unloaded.html, passes on plain
upstream.

Validation: `./mach test-wpt --release --processes 1 css/css-font-loading css/css-fonts html/canvas/element/text html/canvas/offscreen/text` (948 tests): the new fontface-unused-stays-unloaded passes; 2d.text.draw.fontface.notinpage now fails as in Chrome/Firefox/Safari; six "(drawing text in a canvas)" subtests of generic-family-keywords-003 failed with this patch on base/2026-08-29 (Chrome and Firefox pass them) and pass again since base/2026-10-08, so their expectations were dropped; the two @font-face layer-override subtests of css/css-cascade/layer-font-face-override (FAIL on plain upstream) pass with this patch, so their expectations were dropped too; matching/font-unicode-PUA subtests are intermittent (test race, both results seen); the only other unexpected result, font-variant-emoji-1 FAIL, also happens on plain ohos-main. `./mach test-wpt --release svg resize-observer css/css-transforms/transform-box` (1355 tests): all as expected (svg-with-outline, view-box-mutation-002 and resize-observer/svg crash without the SVG font resolver change). `./mach test-wpt --release css/css-fonts css/css-font-loading css/css-flexbox css/css-grid css/cssom-view css/css-inline css/css-text html/canvas/element/text html/canvas/offscreen/text content-security-policy/font-src preload svg` (8650 tests): no new unexpected results besides font-variant-emoji-1 and the known intermittent grid-self-alignment-fit-content-001; font-stylesheet-font-blocked.sub.html and preload-resource-match.https.html pass, and fail without the first-available-font change. Host release build, keai page served locally over HTTP/1.1 keep-alive (3 runs each): font files fetched 437 -> 66, RSS 525.3 -> 471.6 MiB, heap 340.1 -> 286.4 MiB, `--exit -o` screenshot byte-identical to ohos-main. The servo-webfont-eager-download reproducer (6 @font-face rules, 1 needed) fetches 1 font instead of 6. On a PLR-AL00, production build with `--features tracing-hitrace`, the keai page served from the host through `hdc rport`, measured with this patch and the next two applied (they change invalidation, not which fonts load): 437 -> 66 font files per load in each of 5 `servoperf page` loads, and PSS 30 s after launch 507.6 -> 467.9 MB (-7.8%, 4 interleaved loads each, every pair 35-49 MB apart).
AI-assisted: Yes (agent session; designed with the maintainer, written and tested by the agent, ported from upstream main to ohos-main's Rc<Promise> API)
AI-assisted: Yes (agent session; root-caused from the servo-ohos PR 12 try run and written by the agent)
AI-assisted: Yes (agent session; 2026-10-08 sync -- conflict resolution for upstream's RootedPromise and `icu_locale_core` changes, resolved to the code of the upstream-bound lazy-webfonts branch; MANIFEST.json entry re-inserted; dropped the generic-family-keywords-003 and layer-font-face-override FAIL expectations that now pass)
AI-assisted: Yes (agent session; 2026-10-09 restack -- folded in "fonts: Do not create fonts for web font faces that are not loaded yet" and "fonts: Load the first available web font of elements without text", which fixed regressions of this patch; the upstream FontFaceSet.load change replaces the dropped backport placeholder in "Relies on")
Signed-off-by: Jonathan Schwender <[email protected]>
Psychpsyo pushed a commit to Psychpsyo/servo that referenced this pull request Oct 12, 2026
…47564)

`FontFaceSet.load` receives a CSS `font` shorthand and is supposed to
query matching faces in the set, wait for all of them to load and then
return a list of the corresponding `FontFace` objects. Currently we
instead wait for `document.fonts.ready` and return an empty list. This
change begins implementing the font query. Font matching is done in a
naive manner for now, we simply return all fonts with a matching
`font-family`. Its unclear to me how proper matching should be done, as
this needs to happen before the font data is available. Still, this is
progress.

Testing: New tests start to pass
Part of servo#21565

---------

Signed-off-by: Simon Wülker <[email protected]>
jschwe added a commit to openharmony-rs/servo-ohos that referenced this pull request Oct 13, 2026
Every @font-face rule was fetched, sanitised and kept in memory as soon as
its stylesheet applied, even when no style used its family or its
unicode-range covered no character on the page. CSS Fonts 4 requires user
agents to only download fonts that are used.

A new rule now only registers an unloaded face, matched by its descriptors.
Font matching asks for the face once it selects it for a character, and the
loads it asked for start after layout. `FontFace.load()` and
`FontFaceSet.load()` ask for faces the same way. Faces whose sources are all
`local()` are still loaded right away.

Because matching now decides which faces load, adding @font-face rules
dirties the document so that text is matched again, `document.fonts.ready`
flushes layout, and a reflow that starts loads makes it pending again.

The font store now holds templates for faces whose data has not been
downloaded. `FontGroupFamilyTemplate::font_if_matches` skips them, but
`FontContext::matching_templates` and `FontContext::font` are also used
directly by the SVG font resolver, which would hit the "Should never create
a web font without data" panic in `PlatformFont::new_from_template` for any
SVG `<text>` using a web font. `FontContext::font` returns `None` for a web
font template without data, without caching the failure, so the face can be
used once it has loaded. The SVG font resolver asks for the face to be
loaded, like layout does when it matches one, and falls back to the next
family in the meantime.

An element whose font-family names a web font but that has no text never
picks the font for a character, but its first available font is needed
too, for instance for `line-height: normal` and font-relative lengths, and
Chrome and Firefox load it. After an element is restyled, layout asks for
the first available font of its style to be loaded if it is a web font that
has not been fetched. Only elements whose font differs from their parent's
are looked at, nothing is done while the document has no web fonts, and the
lookup runs once per font group. It does not create fonts, so system fonts
are not loaded for elements that never draw text.

Testing: A new WPT test checks that unused faces stay "unloaded". A canvas
test that expected a font not used by the page to be loaded now fails, as it
does in Chrome, Firefox and Safari. svg/painting/svg-with-outline.html,
css/css-transforms/transform-box/view-box-mutation-002.html and
resize-observer/svg.html keep their expected results instead of crashing,
and content-security-policy/font-src/font-stylesheet-font-blocked.sub.html
(a body without text) and preload/preload-resource-match.https.html (an
empty paragraph) still see the font fetched.

Fork note: second of four patches, meant for upstream. The upstream-based
version (branch lazy-webfonts) does not have the two fixes for SVG text and
for elements without text yet, which the servo-ohos PR 12 try run found.
Motivation: generated-UI pages that link Google Fonts CJK families declare
hundreds of unicode-range subsets (441 @font-face rules on the "keai"
concert-article test page), and Servo downloaded all of them (437 files,
10.5 MiB) where ArkWeb downloads 64.

Relies on: the previous patch (the load state on `FontFaceRuleInfo`, which is
how matching tells unloaded faces apart and how `FontFace.status` shows it);
upstream a8d5fda (servo#47564, its `FontFaceSet.load` font query is what makes
`document.fonts.load()` ask for faces); matching going through
`FontGroupFamilyTemplate::font_if_matches` and `char_in_unicode_range`
(components/shared/fonts/font_template.rs); `LayoutThread::reflow` returning a
`ReflowResult` and `can_skip_reflow_request_entirely` gating it; and the
readiness checks in `Document::maybe_fulfill_font_ready_promise` and
`Window::maybe_resolve_pending_screenshot_readiness_requests` reading
`FontContext::web_fonts_still_loading`.

Drop when upstream loads @font-face rules lazily: the test this patch adds,
css/css-font-loading/fontface-unused-stays-unloaded.html, passes on plain
upstream.

Validation: `./mach test-wpt --release --processes 1 css/css-font-loading css/css-fonts html/canvas/element/text html/canvas/offscreen/text` (948 tests): the new fontface-unused-stays-unloaded passes; 2d.text.draw.fontface.notinpage now fails as in Chrome/Firefox/Safari; six "(drawing text in a canvas)" subtests of generic-family-keywords-003 failed with this patch on base/2026-08-29 (Chrome and Firefox pass them) and pass again since base/2026-10-08, so their expectations were dropped; the two @font-face layer-override subtests of css/css-cascade/layer-font-face-override (FAIL on plain upstream) pass with this patch, so their expectations were dropped too; matching/font-unicode-PUA subtests are intermittent (test race, both results seen); the only other unexpected result, font-variant-emoji-1 FAIL, also happens on plain ohos-main. `./mach test-wpt --release svg resize-observer css/css-transforms/transform-box` (1355 tests): all as expected (svg-with-outline, view-box-mutation-002 and resize-observer/svg crash without the SVG font resolver change). `./mach test-wpt --release css/css-fonts css/css-font-loading css/css-flexbox css/css-grid css/cssom-view css/css-inline css/css-text html/canvas/element/text html/canvas/offscreen/text content-security-policy/font-src preload svg` (8650 tests): no new unexpected results besides font-variant-emoji-1 and the known intermittent grid-self-alignment-fit-content-001; font-stylesheet-font-blocked.sub.html and preload-resource-match.https.html pass, and fail without the first-available-font change. Host release build, keai page served locally over HTTP/1.1 keep-alive (3 runs each): font files fetched 437 -> 66, RSS 525.3 -> 471.6 MiB, heap 340.1 -> 286.4 MiB, `--exit -o` screenshot byte-identical to ohos-main. The servo-webfont-eager-download reproducer (6 @font-face rules, 1 needed) fetches 1 font instead of 6. On a PLR-AL00, production build with `--features tracing-hitrace`, the keai page served from the host through `hdc rport`, measured with this patch and the next two applied (they change invalidation, not which fonts load): 437 -> 66 font files per load in each of 5 `servoperf page` loads, and PSS 30 s after launch 507.6 -> 467.9 MB (-7.8%, 4 interleaved loads each, every pair 35-49 MB apart).
AI-assisted: Yes (agent session; designed with the maintainer, written and tested by the agent, ported from upstream main to ohos-main's Rc<Promise> API)
AI-assisted: Yes (agent session; root-caused from the servo-ohos PR 12 try run and written by the agent)
AI-assisted: Yes (agent session; 2026-10-08 sync -- conflict resolution for upstream's RootedPromise and `icu_locale_core` changes, resolved to the code of the upstream-bound lazy-webfonts branch; MANIFEST.json entry re-inserted; dropped the generic-family-keywords-003 and layer-font-face-override FAIL expectations that now pass)
AI-assisted: Yes (agent session; 2026-10-09 restack -- folded in "fonts: Do not create fonts for web font faces that are not loaded yet" and "fonts: Load the first available web font of elements without text", which fixed regressions of this patch; the upstream FontFaceSet.load change replaces the dropped backport placeholder in "Relies on")
Signed-off-by: Jonathan Schwender <[email protected]>
jschwe added a commit to openharmony-rs/servo-ohos that referenced this pull request Oct 22, 2026
Every @font-face rule was fetched, sanitised and kept in memory as soon as
its stylesheet applied, even when no style used its family or its
unicode-range covered no character on the page. CSS Fonts 4 requires user
agents to only download fonts that are used.

A new rule now only registers an unloaded face, matched by its descriptors.
Font matching asks for the face once it selects it for a character, and the
loads it asked for start after layout. `FontFace.load()` and
`FontFaceSet.load()` ask for faces the same way. Faces whose sources are all
`local()` are still loaded right away.

Because matching now decides which faces load, adding @font-face rules
dirties the document so that text is matched again, `document.fonts.ready`
flushes layout, and a reflow that starts loads makes it pending again.

The font store now holds templates for faces whose data has not been
downloaded. `FontGroupFamilyTemplate::font_if_matches` skips them, but
`FontContext::matching_templates` and `FontContext::font` are also used
directly by the SVG font resolver, which would hit the "Should never create
a web font without data" panic in `PlatformFont::new_from_template` for any
SVG `<text>` using a web font. `FontContext::font` returns `None` for a web
font template without data, without caching the failure, so the face can be
used once it has loaded. The SVG font resolver asks for the face to be
loaded, like layout does when it matches one, and falls back to the next
family in the meantime.

An element whose font-family names a web font but that has no text never
picks the font for a character, but its first available font is needed
too, for instance for `line-height: normal` and font-relative lengths, and
Chrome and Firefox load it. After an element is restyled, layout asks for
the first available font of its style to be loaded if it is a web font that
has not been fetched. Only elements whose font differs from their parent's
are looked at, nothing is done while the document has no web fonts, and the
lookup runs once per font group. It does not create fonts, so system fonts
are not loaded for elements that never draw text.

Testing: A new WPT test checks that unused faces stay "unloaded". A canvas
test that expected a font not used by the page to be loaded now fails, as it
does in Chrome, Firefox and Safari. svg/painting/svg-with-outline.html,
css/css-transforms/transform-box/view-box-mutation-002.html and
resize-observer/svg.html keep their expected results instead of crashing,
and content-security-policy/font-src/font-stylesheet-font-blocked.sub.html
(a body without text) and preload/preload-resource-match.https.html (an
empty paragraph) still see the font fetched.

Fork note: second of four patches, meant for upstream. The upstream-based
version (branch lazy-webfonts) does not have the two fixes for SVG text and
for elements without text yet, which the servo-ohos PR 12 try run found.
Motivation: generated-UI pages that link Google Fonts CJK families declare
hundreds of unicode-range subsets (441 @font-face rules on the "keai"
concert-article test page), and Servo downloaded all of them (437 files,
10.5 MiB) where ArkWeb downloads 64.

Relies on: the previous patch (the load state on `FontFaceRuleInfo`, which is
how matching tells unloaded faces apart and how `FontFace.status` shows it);
upstream a8d5fda (servo#47564, its `FontFaceSet.load` font query is what makes
`document.fonts.load()` ask for faces); matching going through
`FontGroupFamilyTemplate::font_if_matches` and `char_in_unicode_range`
(components/shared/fonts/font_template.rs); `LayoutThread::reflow` returning a
`ReflowResult` and `can_skip_reflow_request_entirely` gating it; and the
readiness checks in `Document::maybe_fulfill_font_ready_promise` and
`Window::maybe_resolve_pending_screenshot_readiness_requests` reading
`FontContext::web_fonts_still_loading`.

Drop when upstream loads @font-face rules lazily: the test this patch adds,
css/css-font-loading/fontface-unused-stays-unloaded.html, passes on plain
upstream.

Validation: `./mach test-wpt --release --processes 1 css/css-font-loading css/css-fonts html/canvas/element/text html/canvas/offscreen/text` (948 tests): the new fontface-unused-stays-unloaded passes; 2d.text.draw.fontface.notinpage now fails as in Chrome/Firefox/Safari; six "(drawing text in a canvas)" subtests of generic-family-keywords-003 failed with this patch on base/2026-08-29 (Chrome and Firefox pass them) and pass again since base/2026-10-08, so their expectations were dropped; the two @font-face layer-override subtests of css/css-cascade/layer-font-face-override (FAIL on plain upstream) pass with this patch, so their expectations were dropped too; matching/font-unicode-PUA subtests are intermittent (test race, both results seen); the only other unexpected result, font-variant-emoji-1 FAIL, also happens on plain ohos-main. `./mach test-wpt --release svg resize-observer css/css-transforms/transform-box` (1355 tests): all as expected (svg-with-outline, view-box-mutation-002 and resize-observer/svg crash without the SVG font resolver change). `./mach test-wpt --release css/css-fonts css/css-font-loading css/css-flexbox css/css-grid css/cssom-view css/css-inline css/css-text html/canvas/element/text html/canvas/offscreen/text content-security-policy/font-src preload svg` (8650 tests): no new unexpected results besides font-variant-emoji-1 and the known intermittent grid-self-alignment-fit-content-001; font-stylesheet-font-blocked.sub.html and preload-resource-match.https.html pass, and fail without the first-available-font change. Host release build, keai page served locally over HTTP/1.1 keep-alive (3 runs each): font files fetched 437 -> 66, RSS 525.3 -> 471.6 MiB, heap 340.1 -> 286.4 MiB, `--exit -o` screenshot byte-identical to ohos-main. The servo-webfont-eager-download reproducer (6 @font-face rules, 1 needed) fetches 1 font instead of 6. On a PLR-AL00, production build with `--features tracing-hitrace`, the keai page served from the host through `hdc rport`, measured with this patch and the next two applied (they change invalidation, not which fonts load): 437 -> 66 font files per load in each of 5 `servoperf page` loads, and PSS 30 s after launch 507.6 -> 467.9 MB (-7.8%, 4 interleaved loads each, every pair 35-49 MB apart).
AI-assisted: Yes (agent session; designed with the maintainer, written and tested by the agent, ported from upstream main to ohos-main's Rc<Promise> API)
AI-assisted: Yes (agent session; root-caused from the servo-ohos PR 12 try run and written by the agent)
AI-assisted: Yes (agent session; 2026-10-08 sync -- conflict resolution for upstream's RootedPromise and `icu_locale_core` changes, resolved to the code of the upstream-bound lazy-webfonts branch; MANIFEST.json entry re-inserted; dropped the generic-family-keywords-003 and layer-font-face-override FAIL expectations that now pass)
AI-assisted: Yes (agent session; 2026-10-09 restack -- folded in "fonts: Do not create fonts for web font faces that are not loaded yet" and "fonts: Load the first available web font of elements without text", which fixed regressions of this patch; the upstream FontFaceSet.load change replaces the dropped backport placeholder in "Relies on")
Signed-off-by: Jonathan Schwender <[email protected]>
jschwe added a commit to openharmony-rs/servo-ohos that referenced this pull request Oct 30, 2026
Every @font-face rule was fetched, sanitised and kept in memory as soon as
its stylesheet applied, even when no style used its family or its
unicode-range covered no character on the page. CSS Fonts 4 requires user
agents to only download fonts that are used.

A new rule now only registers an unloaded face, matched by its descriptors.
Font matching asks for the face once it selects it for a character, and the
loads it asked for start after layout. `FontFace.load()` and
`FontFaceSet.load()` ask for faces the same way. Faces whose sources are all
`local()` are still loaded right away.

Because matching now decides which faces load, adding @font-face rules
dirties the document so that text is matched again, `document.fonts.ready`
flushes layout, and a reflow that starts loads makes it pending again.

The font store now holds templates for faces whose data has not been
downloaded. `FontGroupFamilyTemplate::font_if_matches` skips them, but
`FontContext::matching_templates` and `FontContext::font` are also used
directly by the SVG font resolver, which would hit the "Should never create
a web font without data" panic in `PlatformFont::new_from_template` for any
SVG `<text>` using a web font. `FontContext::font` returns `None` for a web
font template without data, without caching the failure, so the face can be
used once it has loaded. The SVG font resolver asks for the face to be
loaded, like layout does when it matches one, and falls back to the next
family in the meantime.

An element whose font-family names a web font but that has no text never
picks the font for a character, but its first available font is needed
too, for instance for `line-height: normal` and font-relative lengths, and
Chrome and Firefox load it. After an element is restyled, layout asks for
the first available font of its style to be loaded if it is a web font that
has not been fetched. Only elements whose font differs from their parent's
are looked at, nothing is done while the document has no web fonts, and the
lookup runs once per font group. It does not create fonts, so system fonts
are not loaded for elements that never draw text.

Testing: A new WPT test checks that unused faces stay "unloaded". A canvas
test that expected a font not used by the page to be loaded now fails, as it
does in Chrome, Firefox and Safari. svg/painting/svg-with-outline.html,
css/css-transforms/transform-box/view-box-mutation-002.html and
resize-observer/svg.html keep their expected results instead of crashing,
and content-security-policy/font-src/font-stylesheet-font-blocked.sub.html
(a body without text) and preload/preload-resource-match.https.html (an
empty paragraph) still see the font fetched.

Fork note: second of four patches, meant for upstream. The upstream-based
version (branch lazy-webfonts) does not have the two fixes for SVG text and
for elements without text yet, which the servo-ohos PR 12 try run found.
Motivation: generated-UI pages that link Google Fonts CJK families declare
hundreds of unicode-range subsets (441 @font-face rules on the "keai"
concert-article test page), and Servo downloaded all of them (437 files,
10.5 MiB) where ArkWeb downloads 64.

Relies on: the previous patch (the load state on `FontFaceRuleInfo`, which is
how matching tells unloaded faces apart and how `FontFace.status` shows it);
upstream a8d5fda (servo#47564, its `FontFaceSet.load` font query is what makes
`document.fonts.load()` ask for faces); matching going through
`FontGroupFamilyTemplate::font_if_matches` and `char_in_unicode_range`
(components/shared/fonts/font_template.rs); `LayoutThread::reflow` returning a
`ReflowResult` and `can_skip_reflow_request_entirely` gating it; and the
readiness checks in `Document::maybe_fulfill_font_ready_promise` and
`Window::maybe_resolve_pending_screenshot_readiness_requests` reading
`FontContext::web_fonts_still_loading`.

Drop when upstream loads @font-face rules lazily: the test this patch adds,
css/css-font-loading/fontface-unused-stays-unloaded.html, passes on plain
upstream.

Validation: `./mach test-wpt --release --processes 1 css/css-font-loading css/css-fonts html/canvas/element/text html/canvas/offscreen/text` (948 tests): the new fontface-unused-stays-unloaded passes; 2d.text.draw.fontface.notinpage now fails as in Chrome/Firefox/Safari; six "(drawing text in a canvas)" subtests of generic-family-keywords-003 failed with this patch on base/2026-08-29 (Chrome and Firefox pass them) and pass again since base/2026-10-08, so their expectations were dropped; the two @font-face layer-override subtests of css/css-cascade/layer-font-face-override (FAIL on plain upstream) pass with this patch, so their expectations were dropped too; matching/font-unicode-PUA subtests are intermittent (test race, both results seen); the only other unexpected result, font-variant-emoji-1 FAIL, also happens on plain ohos-main. `./mach test-wpt --release svg resize-observer css/css-transforms/transform-box` (1355 tests): all as expected (svg-with-outline, view-box-mutation-002 and resize-observer/svg crash without the SVG font resolver change). `./mach test-wpt --release css/css-fonts css/css-font-loading css/css-flexbox css/css-grid css/cssom-view css/css-inline css/css-text html/canvas/element/text html/canvas/offscreen/text content-security-policy/font-src preload svg` (8650 tests): no new unexpected results besides font-variant-emoji-1 and the known intermittent grid-self-alignment-fit-content-001; font-stylesheet-font-blocked.sub.html and preload-resource-match.https.html pass, and fail without the first-available-font change. Host release build, keai page served locally over HTTP/1.1 keep-alive (3 runs each): font files fetched 437 -> 66, RSS 525.3 -> 471.6 MiB, heap 340.1 -> 286.4 MiB, `--exit -o` screenshot byte-identical to ohos-main. The servo-webfont-eager-download reproducer (6 @font-face rules, 1 needed) fetches 1 font instead of 6. On a PLR-AL00, production build with `--features tracing-hitrace`, the keai page served from the host through `hdc rport`, measured with this patch and the next two applied (they change invalidation, not which fonts load): 437 -> 66 font files per load in each of 5 `servoperf page` loads, and PSS 30 s after launch 507.6 -> 467.9 MB (-7.8%, 4 interleaved loads each, every pair 35-49 MB apart).
AI-assisted: Yes (agent session; designed with the maintainer, written and tested by the agent, ported from upstream main to ohos-main's Rc<Promise> API)
AI-assisted: Yes (agent session; root-caused from the servo-ohos PR 12 try run and written by the agent)
AI-assisted: Yes (agent session; 2026-10-08 sync -- conflict resolution for upstream's RootedPromise and `icu_locale_core` changes, resolved to the code of the upstream-bound lazy-webfonts branch; MANIFEST.json entry re-inserted; dropped the generic-family-keywords-003 and layer-font-face-override FAIL expectations that now pass)
AI-assisted: Yes (agent session; 2026-10-09 restack -- folded in "fonts: Do not create fonts for web font faces that are not loaded yet" and "fonts: Load the first available web font of elements without text", which fixed regressions of this patch; the upstream FontFaceSet.load change replaces the dropped backport placeholder in "Relies on")
Signed-off-by: Jonathan Schwender <[email protected]>
jschwe added a commit to openharmony-rs/servo-ohos that referenced this pull request Nov 9, 2026
Every @font-face rule was fetched, sanitised and kept in memory as soon as
its stylesheet applied, even when no style used its family or its
unicode-range covered no character on the page. CSS Fonts 4 requires user
agents to only download fonts that are used.

A new rule now only registers an unloaded face, matched by its descriptors.
Font matching asks for the face once it selects it for a character, and the
loads it asked for start after layout. `FontFace.load()` and
`FontFaceSet.load()` ask for faces the same way. Faces whose sources are all
`local()` are still loaded right away.

Because matching now decides which faces load, adding @font-face rules
dirties the document so that text is matched again, `document.fonts.ready`
flushes layout, and a reflow that starts loads makes it pending again.

The font store now holds templates for faces whose data has not been
downloaded. `FontGroupFamilyTemplate::font_if_matches` skips them, but
`FontContext::matching_templates` and `FontContext::font` are also used
directly by the SVG font resolver, which would hit the "Should never create
a web font without data" panic in `PlatformFont::new_from_template` for any
SVG `<text>` using a web font. `FontContext::font` returns `None` for a web
font template without data, without caching the failure, so the face can be
used once it has loaded. The SVG font resolver asks for the face to be
loaded, like layout does when it matches one, and falls back to the next
family in the meantime.

An element whose font-family names a web font but that has no text never
picks the font for a character, but its first available font is needed
too, for instance for `line-height: normal` and font-relative lengths, and
Chrome and Firefox load it. After an element is restyled, layout asks for
the first available font of its style to be loaded if it is a web font that
has not been fetched. Only elements whose font differs from their parent's
are looked at, nothing is done while the document has no web fonts, and the
lookup runs once per font group. It does not create fonts, so system fonts
are not loaded for elements that never draw text.

Testing: A new WPT test checks that unused faces stay "unloaded". A canvas
test that expected a font not used by the page to be loaded now fails, as it
does in Chrome, Firefox and Safari. svg/painting/svg-with-outline.html,
css/css-transforms/transform-box/view-box-mutation-002.html and
resize-observer/svg.html keep their expected results instead of crashing,
and content-security-policy/font-src/font-stylesheet-font-blocked.sub.html
(a body without text) and preload/preload-resource-match.https.html (an
empty paragraph) still see the font fetched.

Fork note: second of four patches, meant for upstream. The upstream-based
version (branch lazy-webfonts) does not have the two fixes for SVG text and
for elements without text yet, which the servo-ohos PR 12 try run found.
Motivation: generated-UI pages that link Google Fonts CJK families declare
hundreds of unicode-range subsets (441 @font-face rules on the "keai"
concert-article test page), and Servo downloaded all of them (437 files,
10.5 MiB) where ArkWeb downloads 64.

Relies on: the previous patch (the load state on `FontFaceRuleInfo`, which is
how matching tells unloaded faces apart and how `FontFace.status` shows it);
upstream a8d5fda (servo#47564, its `FontFaceSet.load` font query is what makes
`document.fonts.load()` ask for faces); matching going through
`FontGroupFamilyTemplate::font_if_matches` and `char_in_unicode_range`
(components/shared/fonts/font_template.rs); `LayoutThread::reflow` returning a
`ReflowResult` and `can_skip_reflow_request_entirely` gating it; and the
readiness checks in `Document::maybe_fulfill_font_ready_promise` and
`Window::maybe_resolve_pending_screenshot_readiness_requests` reading
`FontContext::web_fonts_still_loading`.

Drop when upstream loads @font-face rules lazily: the test this patch adds,
css/css-font-loading/fontface-unused-stays-unloaded.html, passes on plain
upstream.

Two of upstream's MathML reftests, mo-lspace-rspace-dynamic and
operator-dictionary-empty-and-three-chars, pass on plain upstream and
fail with this patch. Their screenshots differ from the references only
in the red square that
`ensure_for_match_reftest("has_operator_spacing")` of
mathml/support/feature-detection.js adds when it measures no operator
spacing, which Servo doesn't implement. Why the check passes on plain
upstream wasn't traced; since servo#49485, upstream expects
operator-dictionary-empty-and-three-chars to fail as well.

Validation: `./mach test-wpt --release --processes 1 css/css-font-loading css/css-fonts html/canvas/element/text html/canvas/offscreen/text` (948 tests): the new fontface-unused-stays-unloaded passes; 2d.text.draw.fontface.notinpage now fails as in Chrome/Firefox/Safari; six "(drawing text in a canvas)" subtests of generic-family-keywords-003 failed with this patch on base/2026-08-29 (Chrome and Firefox pass them) and pass again since base/2026-10-08, so their expectations were dropped; the two @font-face layer-override subtests of css/css-cascade/layer-font-face-override (FAIL on plain upstream) pass with this patch, so their expectations were dropped too; matching/font-unicode-PUA subtests are intermittent (test race, both results seen); the only other unexpected result, font-variant-emoji-1 FAIL, also happens on plain ohos-main. `./mach test-wpt --release svg resize-observer css/css-transforms/transform-box` (1355 tests): all as expected (svg-with-outline, view-box-mutation-002 and resize-observer/svg crash without the SVG font resolver change). `./mach test-wpt --release css/css-fonts css/css-font-loading css/css-flexbox css/css-grid css/cssom-view css/css-inline css/css-text html/canvas/element/text html/canvas/offscreen/text content-security-policy/font-src preload svg` (8650 tests): no new unexpected results besides font-variant-emoji-1 and the known intermittent grid-self-alignment-fit-content-001; font-stylesheet-font-blocked.sub.html and preload-resource-match.https.html pass, and fail without the first-available-font change. Host release build, keai page served locally over HTTP/1.1 keep-alive (3 runs each): font files fetched 437 -> 66, RSS 525.3 -> 471.6 MiB, heap 340.1 -> 286.4 MiB, `--exit -o` screenshot byte-identical to ohos-main. The servo-webfont-eager-download reproducer (6 @font-face rules, 1 needed) fetches 1 font instead of 6. On a HarmonyOS phone, production build with `--features tracing-hitrace`, the keai page served from the host through `hdc rport`, measured with this patch and the next two applied (they change invalidation, not which fonts load): 437 -> 66 font files per load in each of 5 `servoperf page` loads, and PSS 30 s after launch 507.6 -> 467.9 MB (-7.8%, 4 interleaved loads each, every pair 35-49 MB apart). 2026-11-09 sync: `./mach test-wpt --processes 8 --timeout-multiplier 2 mathml` with release builds (2026-10-29): both reftests pass with the stack up to the previous patch and fail from this one on, with SpiderMonkey and QuickJS. Release builds of this sync's stack: font-face-unicode-range-no-match-no-download.html passes in the full QuickJS run and three runs with each engine, and fails on plain 0.8.0; the table-cell subtest of first-baseline-block-in-inline-001.html passes on plain 0.8.0, passes 3 of 3 times with the stack up to the previous patch and fails 3 of 3 times with this one, and passes 3 of 3 times when it measures after the load event.
AI-assisted: Yes (agent session; designed with the maintainer, written and tested by the agent, ported from upstream main to ohos-main's Rc<Promise> API)
AI-assisted: Yes (agent session; root-caused from the servo-ohos PR 12 try run and written by the agent)
AI-assisted: Yes (agent session; 2026-10-08 sync -- conflict resolution for upstream's RootedPromise and `icu_locale_core` changes, resolved to the code of the upstream-bound lazy-webfonts branch; MANIFEST.json entry re-inserted; dropped the generic-family-keywords-003 and layer-font-face-override FAIL expectations that now pass)
AI-assisted: Yes (agent session; 2026-10-09 restack -- folded in "fonts: Do not create fonts for web font faces that are not loaded yet" and "fonts: Load the first available web font of elements without text", which fixed regressions of this patch; the upstream FontFaceSet.load change replaces the dropped backport placeholder in "Relies on")
AI-assisted: Yes (agent session; 2026-11-09 sync -- folded in "fixup! fonts: Only load @font-face fonts that the page uses" (bisected and written by the agent between syncs): the expectations of two MathML reftests that fail with this patch, of which upstream's WPT sync (servo#49485) now has the same for operator-dictionary-empty-and-three-chars; upstream's WPT sync (servo#49485) added font-face-unicode-range-no-match-no-download.html with a FAIL expectation, and it passes with this patch, so the expectation goes; the same sync added first-baseline-block-in-inline-001.html, whose table-cell subtest passes on plain 0.8.0 and fails with this patch (bisected): the test measures while parsing, before Ahem, which this patch only fetches on use, has loaded; upstream's test fix servo#49502 (bisected) makes it wait, backported at the end of the stack)
Signed-off-by: Jonathan Schwender <[email protected]>
jschwe added a commit to openharmony-rs/servo-ohos that referenced this pull request Nov 10, 2026
Every @font-face rule was fetched, sanitised and kept in memory as soon as
its stylesheet applied, even when no style used its family or its
unicode-range covered no character on the page. CSS Fonts 4 requires user
agents to only download fonts that are used.

A new rule now only registers an unloaded face, matched by its descriptors.
Font matching asks for the face once it selects it for a character, and the
loads it asked for start after layout. `FontFace.load()` and
`FontFaceSet.load()` ask for faces the same way. Faces whose sources are all
`local()` are still loaded right away.

Because matching now decides which faces load, adding @font-face rules
dirties the document so that text is matched again, `document.fonts.ready`
flushes layout, and a reflow that starts loads makes it pending again.

The font store now holds templates for faces whose data has not been
downloaded. `FontGroupFamilyTemplate::font_if_matches` skips them, but
`FontContext::matching_templates` and `FontContext::font` are also used
directly by the SVG font resolver, which would hit the "Should never create
a web font without data" panic in `PlatformFont::new_from_template` for any
SVG `<text>` using a web font. `FontContext::font` returns `None` for a web
font template without data, without caching the failure, so the face can be
used once it has loaded. The SVG font resolver asks for the face to be
loaded, like layout does when it matches one, and falls back to the next
family in the meantime.

An element whose font-family names a web font but that has no text never
picks the font for a character, but its first available font is needed
too, for instance for `line-height: normal` and font-relative lengths, and
Chrome and Firefox load it. After an element is restyled, layout asks for
the first available font of its style to be loaded if it is a web font that
has not been fetched. Only elements whose font differs from their parent's
are looked at, nothing is done while the document has no web fonts, and the
lookup runs once per font group. It does not create fonts, so system fonts
are not loaded for elements that never draw text.

Testing: A new WPT test checks that unused faces stay "unloaded". A canvas
test that expected a font not used by the page to be loaded now fails, as it
does in Chrome, Firefox and Safari. svg/painting/svg-with-outline.html,
css/css-transforms/transform-box/view-box-mutation-002.html and
resize-observer/svg.html keep their expected results instead of crashing,
and content-security-policy/font-src/font-stylesheet-font-blocked.sub.html
(a body without text) and preload/preload-resource-match.https.html (an
empty paragraph) still see the font fetched.

Fork note: second of four patches, meant for upstream. The upstream-based
version (branch lazy-webfonts) does not have the two fixes for SVG text and
for elements without text yet, which the servo-ohos PR 12 try run found.
Motivation: generated-UI pages that link Google Fonts CJK families declare
hundreds of unicode-range subsets (441 @font-face rules on the "keai"
concert-article test page), and Servo downloaded all of them (437 files,
10.5 MiB) where ArkWeb downloads 64.

Relies on: the previous patch (the load state on `FontFaceRuleInfo`, which is
how matching tells unloaded faces apart and how `FontFace.status` shows it);
upstream a8d5fda (servo#47564, its `FontFaceSet.load` font query is what makes
`document.fonts.load()` ask for faces); matching going through
`FontGroupFamilyTemplate::font_if_matches` and `char_in_unicode_range`
(components/shared/fonts/font_template.rs); `LayoutThread::reflow` returning a
`ReflowResult` and `can_skip_reflow_request_entirely` gating it; and the
readiness checks in `Document::maybe_fulfill_font_ready_promise` and
`Window::maybe_resolve_pending_screenshot_readiness_requests` reading
`FontContext::web_fonts_still_loading`.

Drop when upstream loads @font-face rules lazily: the test this patch adds,
css/css-font-loading/fontface-unused-stays-unloaded.html, passes on plain
upstream.

Two of upstream's MathML reftests, mo-lspace-rspace-dynamic and
operator-dictionary-empty-and-three-chars, pass on plain upstream and
fail with this patch. Their screenshots differ from the references only
in the red square that
`ensure_for_match_reftest("has_operator_spacing")` of
mathml/support/feature-detection.js adds when it measures no operator
spacing, which Servo doesn't implement. Why the check passes on plain
upstream wasn't traced; since servo#49485, upstream expects
operator-dictionary-empty-and-three-chars to fail as well.

Validation: `./mach test-wpt --release --processes 1 css/css-font-loading css/css-fonts html/canvas/element/text html/canvas/offscreen/text` (948 tests): the new fontface-unused-stays-unloaded passes; 2d.text.draw.fontface.notinpage now fails as in Chrome/Firefox/Safari; six "(drawing text in a canvas)" subtests of generic-family-keywords-003 failed with this patch on base/2026-08-29 (Chrome and Firefox pass them) and pass again since base/2026-10-08, so their expectations were dropped; the two @font-face layer-override subtests of css/css-cascade/layer-font-face-override (FAIL on plain upstream) pass with this patch, so their expectations were dropped too; matching/font-unicode-PUA subtests are intermittent (test race, both results seen); the only other unexpected result, font-variant-emoji-1 FAIL, also happens on plain ohos-main. `./mach test-wpt --release svg resize-observer css/css-transforms/transform-box` (1355 tests): all as expected (svg-with-outline, view-box-mutation-002 and resize-observer/svg crash without the SVG font resolver change). `./mach test-wpt --release css/css-fonts css/css-font-loading css/css-flexbox css/css-grid css/cssom-view css/css-inline css/css-text html/canvas/element/text html/canvas/offscreen/text content-security-policy/font-src preload svg` (8650 tests): no new unexpected results besides font-variant-emoji-1 and the known intermittent grid-self-alignment-fit-content-001; font-stylesheet-font-blocked.sub.html and preload-resource-match.https.html pass, and fail without the first-available-font change. Host release build, keai page served locally over HTTP/1.1 keep-alive (3 runs each): font files fetched 437 -> 66, RSS 525.3 -> 471.6 MiB, heap 340.1 -> 286.4 MiB, `--exit -o` screenshot byte-identical to ohos-main. The servo-webfont-eager-download reproducer (6 @font-face rules, 1 needed) fetches 1 font instead of 6. On a HarmonyOS phone, production build with `--features tracing-hitrace`, the keai page served from the host through `hdc rport`, measured with this patch and the next two applied (they change invalidation, not which fonts load): 437 -> 66 font files per load in each of 5 `servoperf page` loads, and PSS 30 s after launch 507.6 -> 467.9 MB (-7.8%, 4 interleaved loads each, every pair 35-49 MB apart). 2026-11-09 sync: `./mach test-wpt --processes 8 --timeout-multiplier 2 mathml` with release builds (2026-10-29): both reftests pass with the stack up to the previous patch and fail from this one on, with SpiderMonkey and QuickJS. Release builds of this sync's stack: font-face-unicode-range-no-match-no-download.html passes in the full QuickJS run and three runs with each engine, and fails on plain 0.8.0; the table-cell subtest of first-baseline-block-in-inline-001.html passes on plain 0.8.0, passes 3 of 3 times with the stack up to the previous patch and fails 3 of 3 times with this one, and passes 3 of 3 times when it measures after the load event.
AI-assisted: Yes (agent session; designed with the maintainer, written and tested by the agent, ported from upstream main to ohos-main's Rc<Promise> API)
AI-assisted: Yes (agent session; root-caused from the servo-ohos PR 12 try run and written by the agent)
AI-assisted: Yes (agent session; 2026-10-08 sync -- conflict resolution for upstream's RootedPromise and `icu_locale_core` changes, resolved to the code of the upstream-bound lazy-webfonts branch; MANIFEST.json entry re-inserted; dropped the generic-family-keywords-003 and layer-font-face-override FAIL expectations that now pass)
AI-assisted: Yes (agent session; 2026-10-09 restack -- folded in "fonts: Do not create fonts for web font faces that are not loaded yet" and "fonts: Load the first available web font of elements without text", which fixed regressions of this patch; the upstream FontFaceSet.load change replaces the dropped backport placeholder in "Relies on")
AI-assisted: Yes (agent session; 2026-11-09 sync -- folded in "fixup! fonts: Only load @font-face fonts that the page uses" (bisected and written by the agent between syncs): the expectations of two MathML reftests that fail with this patch, of which upstream's WPT sync (servo#49485) now has the same for operator-dictionary-empty-and-three-chars; upstream's WPT sync (servo#49485) added font-face-unicode-range-no-match-no-download.html with a FAIL expectation, and it passes with this patch, so the expectation goes; the same sync added first-baseline-block-in-inline-001.html, whose table-cell subtest passes on plain 0.8.0 and fails with this patch (bisected): the test measures while parsing, before Ahem, which this patch only fetches on use, has loaded; upstream's test fix servo#49502 (bisected) makes it wait, backported at the end of the stack)
Signed-off-by: Jonathan Schwender <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants