ajstarks / svgo

Go Language Library for SVG generation
Other
2.14k stars 169 forks source link

How to add attributes to textpath instead of the parent text node #74

Open marcuswu opened 2 weeks ago

marcuswu commented 2 weeks ago

Code like this:

draw.Textpath("Some text here", "#topArc", `text-anchor="middle"`, `startOffset="50%"`, `font-size="25"`, `font-family='Salma Pro'`, `fill="black"`)

Results in this xml:

<text xmlns="http://www.w3.org/2000/svg" text-anchor="middle" startOffset="50%" font-size="25px" font-family="Salma Pro" fill="black">
  <textPath xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#topArc">Some text here</textPath>
</text>

I want the text-anchor and startOffset fields to be on the <textPath> tag instead of the <text> tag. How would I make that happen? Is there a way to define the two tags separately?

marcuswu commented 2 weeks ago

Looking at the code it seems that it does not support this right now. I'll think about how this could be implemented. I might submit a PR.

I did find a hacky way of working around it for now similar to an SQL injection. I inject attributes via the path id field:

draw.Textpath("Some text here", "#topArc\" text-anchor=\"middle\" startOffset=\"50%", `font-size="25"`, `font-family='Salma Pro'`, `fill="black"`)
marcuswu commented 2 weeks ago

@ajstarks I know you have been focused on other libraries / projects (and I considered using one of them instead, but it doesn't cover all of my needs right now. Mainly text along a path), but I would love to have your opinion on the changes I proposed in the above PR.