MrJoy / UnitySVG

SVG renderer for Unity3D.
Other
272 stars 52 forks source link

Parsing Path Input #8

Closed CDBridger closed 6 years ago

CDBridger commented 6 years ago

I'm fairly new to working with SVG's so feel free to correct me, but for parsing the path input, specifically for the characters l or L, I believe you can have multiple inputs to string points together, e.g ldx1,dy1 dx2,dy2 dx3,dy3 but this library doesn't appear to have support for that.

Would it be difficult to add this functionality?

here is an example svg im trying to render into unity :

<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" width="95" height="67.75" viewBox="21 18.5 190 135.5"><path d="M25,50 l150,0 0,100 -150,0 z" stroke-width="4" stroke="black" fill="rgb(255,128,128)" fill-opacity="1" ></path><path d="M25,50 L175,150 M25,150 L175,50" stroke-width="4" stroke="black" fill="black" ></path><g transform="translate(0,0)" stroke-width="4" stroke="black" fill="none" ><circle cx="100" cy="30" r="7.5" fill="black" ></circle><circle cx="70" cy="30" r="7.5" fill="black" ></circle><circle cx="130" cy="30" r="7.5" fill="black" ></circle></g><text x="185" y="60" text-anchor="start" font-size="35" font-family="Arial" font-weight="bold" fill="black" >J</text></svg>

Expected :

examplesvg

Rendered :

rendered

MrJoy commented 6 years ago

This project is pretty much DOA, unfortunately. I'm not sure if multiple points to the line-to operator is something added in SVG 1.2, or if the library UnitySVG is based on simply had an omission, but if you really need this, and you really need UnitySVG*, then you might be able to wedge some code into the parsing code to do this yourself.

The relevant place in the code is here:

https://github.com/MrJoy/UnitySVG/blob/master/Assets/UnitySVG/Implementation/SVG/DOM/Paths/SVGPathElement.cs#L51

You'll need some sort of lookahead mechanism here, most likely... Not sure how I'd handle this off the top of my head, but seems like it should be a fairly straightforward enhancement. (Famous last words, I know...)