Skip to content

Commit

Permalink
REGRESSION (r238524): SVG textPath cannot be rendered when <text> ele…
Browse files Browse the repository at this point in the history
…ment is referred by <use> element

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

Reviewed by Myles C. Maxfield.

The bug was caused by targetElementFromIRIString looking for a matching element in the use element's
UA shadow tree instead of the outer tree which defined the content of use element's shadow tree.

Fixed the bug by looking for the matching element in the tree that contains the use element instead.

* LayoutTests/svg/dom/use-element-reference-within-use-shadow-tree-expected.html: Added.
* LayoutTests/svg/dom/use-element-reference-within-use-shadow-tree.html: Added.
* Source/WebCore/svg/SVGURIReference.cpp:
(WebCore::SVGURIReference::targetElementFromIRIString): Fixed the bug.

Canonical link: https://commits.webkit.org/252547@main
  • Loading branch information
rniwa committed Jul 17, 2022
1 parent f76c9aa commit 72c9014
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
@@ -0,0 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 500 500" >
<path id="MyPath" d="M 100 100 C 100 100 400 100 400 100" fill="none" stroke="green"/>
<text id="MyText" font-size="20" fill="green">
<textPath xlink:href="#MyPath">
PASS
</textPath>
</text>
</svg>
@@ -0,0 +1,16 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 500 500" >
<defs>
<g id="g">
<defs>
<path id="path" d="M 100 100 C 100 100 400 100 400 100" />
</defs>
<text id="text" font-size="20" fill="green" >
<textPath xlink:href="#path">
PASS
</textPath>
</text>
</g>
</defs>
<use xlink:href="#path" fill="none" stroke="green"/>
<use xlink:href="#g"/>
</svg>
7 changes: 6 additions & 1 deletion Source/WebCore/svg/SVGURIReference.cpp
Expand Up @@ -25,8 +25,9 @@
#include "Document.h"
#include "Element.h"
#include "SVGElement.h"
#include <wtf/URL.h>
#include "SVGUseElement.h"
#include "XLinkNames.h"
#include <wtf/URL.h>

namespace WebCore {

Expand Down Expand Up @@ -101,6 +102,10 @@ auto SVGURIReference::targetElementFromIRIString(const String& iri, const TreeSc
if (isExternalURIReference(iri, document))
return { nullptr, WTFMove(id) };

RefPtr shadowHost = treeScope.rootNode().shadowHost();
if (is<SVGUseElement>(shadowHost))
return { shadowHost->treeScope().getElementById(id), WTFMove(id) };

return { treeScope.getElementById(id), WTFMove(id) };
}

Expand Down

0 comments on commit 72c9014

Please sign in to comment.