Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 51ec1112daafae8037a6330c87597eba1342582c
      
https://github.com/WebKit/WebKit/commit/51ec1112daafae8037a6330c87597eba1342582c
  Author: Karl Dubost <[email protected]>
  Date:   2026-08-04 (Tue, 04 Aug 2026)

  Changed paths:
    M LayoutTests/platform/ios/svg/batik/text/verticalText-expected.txt
    M 
LayoutTests/platform/ios/svg/text/textLength-tspan-in-textPath-expected.txt
    M 
LayoutTests/platform/mac-tahoe-wk2-lbse-text/svg/text/textLength-tspan-in-textPath-expected.txt
    M 
LayoutTests/platform/mac/svg/text/textLength-tspan-in-textPath-expected.txt
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/platform/graphics/Path.cpp
    M Source/WebCore/platform/graphics/Path.h
    A Source/WebCore/platform/graphics/PathArcLengthMapper.cpp
    A Source/WebCore/platform/graphics/PathArcLengthMapper.h
    A Source/WebCore/platform/graphics/PathCurveSubdivision.h
    M Source/WebCore/platform/graphics/PathTraversalState.cpp
    M Source/WebCore/platform/graphics/PathTraversalState.h
    M Source/WebCore/rendering/svg/SVGTextLayoutEngine.cpp
    M Source/WebCore/rendering/svg/SVGTextLayoutEngine.h

  Log Message:
  -----------
  <textPath> layout re-walks the whole path per glyph  (TextOnPathSimple)
https://bugs.webkit.org/show_bug.cgi?id=318396
rdar://181181810

Reviewed by Said Abou-Hallawa.

PerformanceTests/SVG/TextOnPathSimple.html lays out about 39x slower
than Chromium, and it gets worse as the path grows with the text.

layoutTextOnLineOrPath asked Path::traversalStateAtLength() for a point
once per glyph. That call keeps nothing between calls, so every glyph
walked the path from the start and re-split every curve. N glyphs on M
segments cost O(N*M).

This flattens the path once into a table of (point, accumulated length)
and binary searches it per glyph: O(M + N*log M). PathArcLengthMapper
subdivides curves exactly as PathTraversalState did, so glyph positions
are unchanged.

The subdivision loop they share now lives once in PathCurveSubdivision.h.

Two space glyphs move by 0.01px, from adding leaf lengths in one running
sum instead of per element:
  * svg/text/textLength-tspan-in-textPath.html 606.91 to 606.90,
  * and svg/batik/text/verticalText.svg 27.99 to 28.00 on ios.
Their baselines are updated.

Note that this does not fully close the gap with the other engines.
Building the table now costs more than querying it, so there is more to
win.

* LayoutTests/platform/ios/svg/batik/text/verticalText-expected.txt:
* LayoutTests/platform/ios/svg/text/textLength-tspan-in-textPath-expected.txt:
* 
LayoutTests/platform/mac-tahoe-wk2-lbse-text/svg/text/textLength-tspan-in-textPath-expected.txt:
* LayoutTests/platform/mac/svg/text/textLength-tspan-in-textPath-expected.txt:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/graphics/Path.cpp:
(WebCore::Path::arcLengthMapper const):
* Source/WebCore/platform/graphics/Path.h:
* Source/WebCore/platform/graphics/PathArcLengthMapper.cpp: Added.
(WebCore::PathArcLengthMapper::addVertex):
(WebCore::PathArcLengthMapper::appendPathElement):
(WebCore::PathArcLengthMapper::positionAtLength const):
* Source/WebCore/platform/graphics/PathArcLengthMapper.h: Copied from 
Source/WebCore/platform/graphics/PathTraversalState.h.
(WebCore::PathArcLengthMapper::appendPathElement):
(WebCore::PathArcLengthMapper::totalLength const):
* Source/WebCore/platform/graphics/PathCurveSubdivision.h: Added.
(WebCore::distanceLine):
(WebCore::QuadraticBezier::QuadraticBezier):
(WebCore::QuadraticBezier::approximateDistance const):
(WebCore::QuadraticBezier::split const):
(WebCore::CubicBezier::CubicBezier):
(WebCore::CubicBezier::approximateDistance const):
(WebCore::CubicBezier::split const):
(WebCore::forEachFlattenedCurveLeaf):
* Source/WebCore/platform/graphics/PathTraversalState.cpp:
(WebCore::curveLength):
(WebCore::distanceLine): Deleted.
(WebCore::QuadraticBezier::QuadraticBezier): Deleted.
(WebCore::QuadraticBezier::approximateDistance const): Deleted.
(WebCore::QuadraticBezier::split const): Deleted.
(WebCore::CubicBezier::CubicBezier): Deleted.
(WebCore::CubicBezier::approximateDistance const): Deleted.
(WebCore::CubicBezier::split const): Deleted.
* Source/WebCore/platform/graphics/PathTraversalState.h:
* Source/WebCore/rendering/svg/SVGTextLayoutEngine.cpp:
(WebCore::SVGTextLayoutEngine::beginTextPathLayout):
(WebCore::SVGTextLayoutEngine::layoutTextOnLineOrPath):
* Source/WebCore/rendering/svg/SVGTextLayoutEngine.h:

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



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

Reply via email to