Skip to content

Conversation

@eerii
Copy link
Member

@eerii eerii commented Oct 9, 2025

9d77743

Implement font-size: math.
https://bugs.webkit.org/show_bug.cgi?id=49309

Reviewed by Frédéric Wang.

Parse `font-size: math` and add the logic to compute the
scale of the font https://www.w3.org/TR/css-fonts-4/#valdef-font-size-math.
This is gated behind the `CSSMathDepth` preference.
A new user agent spreadsheet is added to keep the legacy behaviour when
the preference is not enabled.

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/math-script-level-and-math-style/math-script-level-002.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/math-script-level-and-math-style/math-script-level-004.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/mathml/relations/css-styling/scriptlevel-001-expected.txt: Renamed from LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/css-styling/scriptlevel-001-expected.txt.
* LayoutTests/imported/w3c/web-platform-tests/mathml/relations/css-styling/size-containment-001.tentative-expected.txt: Renamed from LayoutTests/platform/glib/imported/w3c/web-platform-tests/mathml/relations/css-styling/size-containment-001.tentative-expected.txt.
* LayoutTests/mathml/presentation/scripts-subsup-expected.html:
* LayoutTests/mathml/presentation/scripts-subsup.html:
* LayoutTests/mathml/presentation/scripts-underover-expected.html:
* LayoutTests/mathml/presentation/scripts-underover.html:
* LayoutTests/platform/glib/TestExpectations:
* LayoutTests/platform/glib/accessibility/math-multiscript-attributes-expected.txt:
* LayoutTests/platform/glib/mathml/opentype/horizontal-expected.txt:
* LayoutTests/platform/glib/mathml/opentype/horizontal-munderover-expected.txt:
* LayoutTests/platform/glib/mathml/opentype/opentype-stretchy-horizontal-expected.txt:
* LayoutTests/platform/glib/mathml/presentation/bug159513-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/css-styling/scriptlevel-001-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/css-styling/size-containment-001.tentative-expected.txt:
* LayoutTests/platform/ios/mathml/opentype/opentype-stretchy-horizontal-expected.txt:
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/mathml/relations/css-styling/scriptlevel-001-expected.txt: Removed.
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/mathml/relations/css-styling/size-containment-001.tentative-expected.txt:
* LayoutTests/platform/mac/mathml/opentype/opentype-stretchy-horizontal-expected.txt:
* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-input.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/css/CSSProperties.json:
* Source/WebCore/css/CSSValueKeywords.in:
* Source/WebCore/css/mathml.css:
(mroot > :not(:first-child)):
(msub > :not(:first-child),):
* Source/WebCore/css/mathmlFontSizeMath.css: Added.
(#if defined(ENABLE_MATHML) && ENABLE_MATHML):
(math):
* Source/WebCore/css/mathmlLegacyFontSizeMath.css: Added.
(#if defined(ENABLE_MATHML) && ENABLE_MATHML):
(msub > :not(:first-child),):
* Source/WebCore/css/parser/CSSParserContext.cpp:
(WebCore::applyUASheetBehaviorsToContext):
(WebCore::add):
* Source/WebCore/css/parser/CSSParserContext.h:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Font.cpp:
(WebCore::CSSPropertyParserHelpers::consumeFontSizeUnresolved):
* Source/WebCore/style/InspectorCSSOMWrappers.cpp:
(WebCore::Style::InspectorCSSOMWrappers::collectDocumentWrappers):
* Source/WebCore/style/StyleBuilderCustom.h:
(WebCore::Style::BuilderCustom::determineMathDepthScale):
(WebCore::Style::BuilderCustom::applyValueFontSize):
* Source/WebCore/style/StyleResolveForFont.cpp:
(WebCore::Style::fontSizeFromUnresolvedFontSize):
* Source/WebCore/style/UserAgentStyle.cpp:
(WebCore::Style::UserAgentStyle::ensureDefaultStyleSheetsForElement):
* Source/WebCore/style/UserAgentStyle.h:

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

37465a6

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🛠 wpe-cairo-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-wk2-stress 🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-intel-wk2
✅ 🛠 tv-sim ✅ 🛠 mac-safer-cpp
✅ 🛠 watch
✅ 🛠 watch-sim

@eerii eerii marked this pull request as draft October 9, 2025 13:55
@eerii
Copy link
Member Author

eerii commented Oct 9, 2025

Depends on #52063

@eerii eerii self-assigned this Oct 25, 2025
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Oct 27, 2025
@eerii eerii marked this pull request as ready for review October 28, 2025 10:36
Copy link
Contributor

@fred-wang fred-wang left a comment

Choose a reason for hiding this comment

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

I thought I had left comments the other day, but not sure it worked.

@fred-wang
Copy link
Contributor

I'm not super familiar with the CSS code, so would be good to have a second reviewer advice.

@Ahmad-S792 Ahmad-S792 added MathML For bugs specific to MathML. and removed merging-blocked Applied to prevent a change from being merged labels Nov 6, 2025
</table>

<div style="position: absolute; top: 250px; left: 10px;">
<!-- This verifies that the scripts are drawn smaller. -->
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe you can explain a bit more that this is a 0.71 scale factor because that's the default value suggested by the spec when the current font does not have a MATH table.

(If we upstream that, it's likely this won't work well in Firefox, because it will try to pick a math font)

Copy link
Member Author

Choose a reason for hiding this comment

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

I have tested this on Firefox and while it does work for me, you are right that it may not always work depending on the font configuration. We should also probably split this test if we upstream it because the two parts (the table and the small scripts) are not that related and have different fuzzing ranges.

@eerii eerii force-pushed the font-size-math branch 2 times, most recently from e428fde to 37465a6 Compare December 18, 2025 09:21
@fred-wang fred-wang added safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks and removed merging-blocked Applied to prevent a change from being merged labels Dec 18, 2025
@webkit-ews-buildbot webkit-ews-buildbot added merge-queue Applied to send a pull request to merge-queue and removed safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks labels Dec 20, 2025
@webkit-ews-buildbot
Copy link
Collaborator

Safe-Merge-Queue: Build #78487.

https://bugs.webkit.org/show_bug.cgi?id=49309

Reviewed by Frédéric Wang.

Parse `font-size: math` and add the logic to compute the
scale of the font https://www.w3.org/TR/css-fonts-4/#valdef-font-size-math.
This is gated behind the `CSSMathDepth` preference.
A new user agent spreadsheet is added to keep the legacy behaviour when
the preference is not enabled.

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/math-script-level-and-math-style/math-script-level-002.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/math-script-level-and-math-style/math-script-level-004.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/mathml/relations/css-styling/scriptlevel-001-expected.txt: Renamed from LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/css-styling/scriptlevel-001-expected.txt.
* LayoutTests/imported/w3c/web-platform-tests/mathml/relations/css-styling/size-containment-001.tentative-expected.txt: Renamed from LayoutTests/platform/glib/imported/w3c/web-platform-tests/mathml/relations/css-styling/size-containment-001.tentative-expected.txt.
* LayoutTests/mathml/presentation/scripts-subsup-expected.html:
* LayoutTests/mathml/presentation/scripts-subsup.html:
* LayoutTests/mathml/presentation/scripts-underover-expected.html:
* LayoutTests/mathml/presentation/scripts-underover.html:
* LayoutTests/platform/glib/TestExpectations:
* LayoutTests/platform/glib/accessibility/math-multiscript-attributes-expected.txt:
* LayoutTests/platform/glib/mathml/opentype/horizontal-expected.txt:
* LayoutTests/platform/glib/mathml/opentype/horizontal-munderover-expected.txt:
* LayoutTests/platform/glib/mathml/opentype/opentype-stretchy-horizontal-expected.txt:
* LayoutTests/platform/glib/mathml/presentation/bug159513-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/css-styling/scriptlevel-001-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/mathml/relations/css-styling/size-containment-001.tentative-expected.txt:
* LayoutTests/platform/ios/mathml/opentype/opentype-stretchy-horizontal-expected.txt:
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/mathml/relations/css-styling/scriptlevel-001-expected.txt: Removed.
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/mathml/relations/css-styling/size-containment-001.tentative-expected.txt:
* LayoutTests/platform/mac/mathml/opentype/opentype-stretchy-horizontal-expected.txt:
* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-input.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/css/CSSProperties.json:
* Source/WebCore/css/CSSValueKeywords.in:
* Source/WebCore/css/mathml.css:
(mroot > :not(:first-child)):
(msub > :not(:first-child),):
* Source/WebCore/css/mathmlFontSizeMath.css: Added.
(#if defined(ENABLE_MATHML) && ENABLE_MATHML):
(math):
* Source/WebCore/css/mathmlLegacyFontSizeMath.css: Added.
(#if defined(ENABLE_MATHML) && ENABLE_MATHML):
(msub > :not(:first-child),):
* Source/WebCore/css/parser/CSSParserContext.cpp:
(WebCore::applyUASheetBehaviorsToContext):
(WebCore::add):
* Source/WebCore/css/parser/CSSParserContext.h:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Font.cpp:
(WebCore::CSSPropertyParserHelpers::consumeFontSizeUnresolved):
* Source/WebCore/style/InspectorCSSOMWrappers.cpp:
(WebCore::Style::InspectorCSSOMWrappers::collectDocumentWrappers):
* Source/WebCore/style/StyleBuilderCustom.h:
(WebCore::Style::BuilderCustom::determineMathDepthScale):
(WebCore::Style::BuilderCustom::applyValueFontSize):
* Source/WebCore/style/StyleResolveForFont.cpp:
(WebCore::Style::fontSizeFromUnresolvedFontSize):
* Source/WebCore/style/UserAgentStyle.cpp:
(WebCore::Style::UserAgentStyle::ensureDefaultStyleSheetsForElement):
* Source/WebCore/style/UserAgentStyle.h:

Canonical link: https://commits.webkit.org/304802@main
@webkit-commit-queue
Copy link
Collaborator

Committed 304802@main (9d77743): https://commits.webkit.org/304802@main

Reviewed commits have been landed. Closing PR #52066 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 9d77743 into WebKit:main Dec 20, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Dec 20, 2025
@eerii eerii deleted the font-size-math branch December 20, 2025 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MathML For bugs specific to MathML.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants