Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: dedced319ff7e3e3a4b6ec83c4467d023ae53d37
      
https://github.com/WebKit/WebKit/commit/dedced319ff7e3e3a4b6ec83c4467d023ae53d37
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-09-07 (Mon, 07 Sep 2026)

  Changed paths:
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-ex-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-ex.html
    M LayoutTests/platform/glib/svg/W3C-SVG-1.1/coords-units-03-b-expected.txt
    M LayoutTests/platform/glib/svg/text/exs-display-none-expected.txt
    M LayoutTests/platform/ios/svg/W3C-SVG-1.1/coords-units-03-b-expected.txt
    M LayoutTests/platform/ios/svg/text/exs-display-none-expected.txt
    M LayoutTests/platform/mac/svg/W3C-SVG-1.1/coords-units-03-b-expected.txt
    M LayoutTests/platform/mac/svg/text/exs-display-none-expected.txt
    M LayoutTests/svg/animations/svglength-animation-px-to-exs.html
    M Source/WebCore/svg/SVGLengthContext.cpp

  Log Message:
  -----------
  SVGLength resolves 'ex' by rounding the font's x-height up to a whole pixel
https://bugs.webkit.org/show_bug.cgi?id=322716
rdar://185984854

Reviewed by Sam Weinig.

This patch aligns WebKit with Gecko / Firefox and Blink / Chromium.

SVGLengthContext resolved the 'ex' unit by applying std::ceil() to the
primary font's x-height before multiplying, so the SVG DOM
(baseVal.value / valueInSpecifiedUnits) disagreed with getComputedStyle
for the same element: e.g. Helvetica at 20px (x-height ~10.459px) gave
x="2ex" as 22 (2 x ceil(10.459)) via the DOM but 20.898438px via
getComputedStyle. Per spec, 'ex' resolves against the computed font
x-height with no rounding:
https://w3c.github.io/svgwg/svg2-draft/types.html#__svg__SVGLength__value

The ceil() dated back to SVG 1.1; SVG 2 does not mandate any such
rounding.

The ceil() carried a comment noting it existed solely to get a pixel
match against the W3C SVG 1.1 expected output of coords-units-03-b.svg,
and that it might be best to remove it if it ever caused problems in
real-world cases. That is now the case: WebKit is the only engine still
applying this rounding, Firefox and Chrome both dropped it, and SVG 2
says nothing about rounding 'ex'. We therefore knowingly deviate from
the SVG 1.1 test (rebaselining coords-units-03-b) in favor of interop
with other browsers and conformance to SVG 2.

Remove the ceil() in both conversion directions.

Test: imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-ex.html

* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-ex-expected.txt:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-ex.html:
 Added.
  Re-fetch x.baseVal[0] after setAttribute() so the fractional-x-height
  subtest reads the live SVGLength instead of a detached wrapper.
* LayoutTests/platform/mac/svg/W3C-SVG-1.1/coords-units-03-b-expected.txt: 
Rebaselined.
* LayoutTests/platform/mac/svg/text/exs-display-none-expected.txt: Ditto.
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/coords-units-03-b-expected.txt: 
Ditto.
* LayoutTests/platform/ios/svg/text/exs-display-none-expected.txt: Ditto.
* LayoutTests/platform/glib/svg/W3C-SVG-1.1/coords-units-03-b-expected.txt: 
Ditto.
* LayoutTests/platform/glib/svg/text/exs-display-none-expected.txt: Ditto.
* LayoutTests/svg/animations/svglength-animation-px-to-exs.html: Updated.
* Source/WebCore/svg/SVGLengthContext.cpp:
(WebCore::SVGLengthContext::convertValueFromUserUnitsToEXS const):
(WebCore::SVGLengthContext::convertValueFromEXSToUserUnits const):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to