You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9bca990
Browse filesBrowse the repository at this point in the historyBrowse files
[SVG text] Implement the SVG 2 text layout algorithm
https://bugs.webkit.org/show_bug.cgi?id=327817
rdar://problem/190204825
Reviewed by NOBODY (OOPS!).
The old SVGTextLayoutEngine is built around assumptions of the legacy line layout. We can do better.
This patch adds SVGTextLayoutAlgorithm which implements the text layout algorithm as described by
the SVG 2 specification (https://w3c.github.io/svgwg/svg2-draft/text.html#TextLayoutAlgorithm). The
code maps directly to spec language making it much more readable than the old code.
It is also more correct. Following the spec steps fixes textLength with x/y lists and on text paths,
and lengthAdjust="spacingAndGlyphs" and whitespace collapsing now match Chrome and Firefox.
It also performs better. The old implementation measured text repeatedly, checked grapheme cluster
boundaries for every character and used hash maps for temporary storage. The new one caches the
measurements, skips the cluster checks for 8-bit text and uses index-based storage.
On a microbenchmark with 10k text labels text changes are about 25% faster. Speedometer
Charts-observable-plot improves by about 1% and React-Stockcharts-SVG by about 0.5%.
The new path is behind the internal SVG2TextLayoutAlgorithmEnabled flag, off by default for now.
* LayoutTests/svg/text/textLength-spacing-absolute-positions-expected.txt: Added.
* LayoutTests/svg/text/textLength-spacing-absolute-positions.html: Added.
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/rendering/svg/RenderSVGInlineText.cpp:
(WebCore::RenderSVGInlineText::setTextInternal):
(WebCore::RenderSVGInlineText::styleDidChange):
(WebCore::RenderSVGInlineText::updateScaledFont):
Invalidate the cached text metrics.
* Source/WebCore/rendering/svg/RenderSVGInlineText.h:
* Source/WebCore/rendering/svg/RenderSVGText.cpp:
(WebCore::RenderSVGText::shouldHandleSubtreeMutations const):
(WebCore::RenderSVGText::subtreeTextDidChange):
(WebCore::RenderSVGText::layout):
Skip the layout attribute building with the new path.
(WebCore::RenderSVGText::computePerCharacterLayoutInformation):
(WebCore::RenderSVGText::usesSVGTextLayoutAlgorithm const):
* Source/WebCore/rendering/svg/RenderSVGText.h:
* Source/WebCore/rendering/svg/SVGTextLayoutAlgorithm.cpp: Added.
* Source/WebCore/rendering/svg/SVGTextLayoutAlgorithm.h: Added.
* Source/WebCore/rendering/svg/SVGTextLayoutEngine.cpp:
(WebCore::SVGTextLayoutEngine::layoutTextOnLineOrPath):
* Source/WebCore/rendering/svg/SVGTextLayoutEngineBaseline.cpp:
(WebCore::SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBaseline const):
(WebCore::SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift const):
Take the style instead of the renderer so layout boxes can use it.
* Source/WebCore/rendering/svg/SVGTextLayoutEngineBaseline.h:
0 commit comments