How to get path(s) from an SVG?

Maybe a stupid question, but is there a way in JUCE to get a path from an SVG containing a single path?

And is there a way to extract more than one path from an SVG that contains multiple paths? Thanks.

I found the SVG Path Converter in the Projucer, and I was able to extract a path from an SVG. So I guess there is no way to do it on-the-fly in code; you have to manually prepare it ahead of time?

To get a Drawable from an SVG, use Drawable::createFromSVG(). You need to have read the SVG as an XmlElement (parseXML() will do it from a String). To get a single path from an SVG path, use Drawable::parseSVGPath(). It must be an actual path, like “M10 0L0 10h20zM5 10h10v10H5z”, not the whole SVG containing it.

Thanks, but I’m not quite following that. Let’s say I have a Drawable that is created in the way you say, i.e.:

    static std::unique_ptr<Drawable> createDrawableFromSVG (const char* data)
    {
        auto xml = parseXML (data);
        jassert (xml != nullptr);
        return Drawable::createFromSVG (*xml);
    }

How then do I get the path out of that Drawable?

getOutlineAsPath?

https://docs.juce.com/master/classDrawable.html#ace2082bc995b8e035079b71b32c1460f

1 Like

Thank you, that does seem to work for my use case!