Skip to content

Conversation

@ljluestc
Copy link

Closes #417

Description

Implements support for the path attribute of the SVG <textPath> element, as specified in SVG2 TextPathElementPathAttribute. This allows <textPath> to define a path directly (e.g., path="M10,20 L100,100") instead of requiring an xlink:href to a <path> element.

Changes

  • Added path: Option<PathData> field to usvg::TextPath in crates/usvg/src/text.rs.
  • Updated TextPath::from_xml to parse the path attribute using parser.parse_path_data.
  • Modified process_text to use the path attribute’s PathData if present, falling back to xlink:href.
  • Ensured parse_path_data in crates/usvg/src/path.rs converts the path attribute string to PathData.

Testing

  • Manually tested with test_textpath.svg:
    <svg xmlns="http://www.w3.org/2000/svg" width="600" height="200">
        <text font-size="24" fill="blue">
            <textPath path="M10,100 Q50,50 100,100" startOffset="0">Text on Path</textPath>
        </text>
        <text font-size="24" fill="red" y="150">
            <textPath xlink:href="#path1" startOffset="0">Text on Ref Path</textPath>
        </text>
        <path id="path1" d="M10,150 Q50,100 100,150" fill="none" stroke="black"/>
    </svg>

@RazrFalcon
Copy link
Collaborator

That's a very strange patch. All you have to do is modify the parser to handle inline paths and not just xlink:href. But you do way too many other things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support the path property of textPath

2 participants