Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: d026972d8525840d8dc263f1b40941125d4efcd2
https://github.com/WebKit/WebKit/commit/d026972d8525840d8dc263f1b40941125d4efcd2
Author: Brent Fulgham <[email protected]>
Date: 2026-03-12 (Thu, 12 Mar 2026)
Changed paths:
M LayoutTests/fast/text/font-weight-download-3-expected.txt
M LayoutTests/fast/text/font-weight-fallback-expected.html
M LayoutTests/fast/text/font-weight-fallback.html
A
LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-face-unicode-range-stretch-isolation-expected.html
A
LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-face-unicode-range-stretch-isolation-ref.html
A
LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-face-unicode-range-stretch-isolation.html
M LayoutTests/platform/glib/fast/css/font-face-multiple-faces-expected.txt
M LayoutTests/platform/gtk/fast/css/font-face-multiple-faces-expected.png
A LayoutTests/platform/gtk/fast/text/font-weight-fallback-expected.html
A LayoutTests/platform/wpe/fast/text/font-weight-fallback-expected.html
M Source/WebCore/css/CSSFontFaceSet.cpp
M Source/WebCore/platform/graphics/FontSelectionAlgorithm.cpp
M Source/WebCore/platform/graphics/FontSelectionAlgorithm.h
Log Message:
-----------
Font-faces with different styles should not be mixed in a CSSSegmentedFontFace
https://bugs.webkit.org/show_bug.cgi?id=120499
rdar://32566994
Reviewed by Vitor Roriz.
This patch is inspired by a Blink change:
https://chromium.googlesource.com/chromium/blink/+/7823ceba809d5c05bffeeb9e732e92fe76fab7e9
Before this patch, when a glyph for the character to be rendered is not
in the matched @font-face, glyph from other @font-face (with different
style) in the family or system font with the same name were used as fallback.
This behavior does not follow the font matching algorithm
(http://www.w3.org/TR/css3-fonts/#font-matching-algorithm):
"6. If no matching face exists or the matched face does not contain a glyph
for the character to be rendered, the next family name is selected and
the previous three steps repeated. Glyphs from other faces in the family
are not considered."
Previously, CSSFontFaceSet::fontFace() was sorting all candidate faces by
distance and
adding all of them to the CSSSegmentedFontFace. This allowed faces with
worse-matching
traits to supply glyphs for characters covered by their unicode-range,
violating the spec.
The fix uses FontSelectionAlgorithm's filter to eliminate "non-best" candidates
before
populating the segmented face. Only faces that tie at the best distance for all
three
properties (width, style, weight) are eligible to supply glyphs.
This work also revealed that the test expectation for
fast/text/font-weight-download-3.html
was wrong. The previous expected file showed "Ahem.otf" being downloaded, which
was
incorrect because it had a font-weight of 900 (while the test restricts weight
to 100).
A similar issue needed to be corrected it fast/text/font-weight-fallback.html.
The test
references two fonts, one that matches the requested weight, the other having
the
characters needed to render the content. Neither font should be used, according
to the
spec, and it should fall back to a system font (which is what Firefox and
Chrome do).
This test was revised to confirm this behavior works according to spec.
Because of GTK's installed fonts (at least on the bots) the test results had to
be
rebaselined because the corrected font fallback logic resulted in a slightly
different
output (Courier is not a viable choice since is not a good match to the
required weight
700) so it resolves to a system font.
Test:
imported/w3c/web-platform-tests/css/css-fonts/font-face-unicode-range-stretch-isolation.html
* LayoutTests/fast/text/font-weight-download-3-expected.txt: Rebaselined.
* LayoutTests/fast/text/font-weight-fallback-expected.html: Rebaselined.
* LayoutTests/fast/text/font-weight-fallback.html: Correct test.
*
LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-face-unicode-range-stretch-isolation-expected.html:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-face-unicode-range-stretch-isolation-ref.html:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-face-unicode-range-stretch-isolation.html:
Added.
* LayoutTests/platform/glib/fast/css/font-face-multiple-faces-expected.txt:
Rebaselined.
* LayoutTests/platform/gtk/fast/css/font-face-multiple-faces-expected.png:
Rebaselined.
* LayoutTests/platform/gtk/fast/text/font-weight-fallback-expected.html: Added.
* LayoutTests/platform/wpe/fast/text/font-weight-fallback-expected.html: Added.
* Source/WebCore/css/CSSFontFaceSet.cpp:
(WebCore::CSSFontFaceSet::fontFace):
* Source/WebCore/platform/graphics/FontSelectionAlgorithm.cpp:
(WebCore::FontSelectionAlgorithm::FontSelectionAlgorithm):
(WebCore::FontSelectionAlgorithm::ensureEliminatedCapabilities):
(WebCore::FontSelectionAlgorithm::eliminatedCapabilities):
(WebCore::FontSelectionAlgorithm::indexOfBestCapabilities):
* Source/WebCore/platform/graphics/FontSelectionAlgorithm.h:
Canonical link: https://commits.webkit.org/309121@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications