|
Gin
|
SVG parsing and rendering helpers built on NanoSVG. More...
Enumerations | |
| enum class | Engine { nanosvg , juce } |
| Rendering backend. More... | |
Functions | |
| juce::Image | renderToImage (const juce::String &svgText, int width, int height, Engine engine=Engine::juce) |
| Renders svgText into a width x height ARGB image with a transparent background. | |
| juce::Image | renderToImage (const juce::String &svgText, int width, int height, juce::Colour backgroundColour, Engine engine=Engine::juce) |
| As above, but fills the image with backgroundColour before drawing. | |
| juce::Path | renderToPath (const juce::String &svgText) |
| Returns all visible shapes flattened into a single juce::Path in the SVG's own coordinate space. | |
| juce::Path | renderToPath (const juce::String &svgText, juce::Rectangle< float > targetBounds, juce::RectanglePlacement placement=juce::RectanglePlacement::centred) |
| Returns the SVG as a juce::Path fitted into targetBounds. | |
| void | render (const juce::String &svgText, juce::Graphics &g, juce::Rectangle< float > targetBounds, Engine engine=Engine::juce) |
| Draws svgText into targetBounds on the given Graphics context. | |
SVG parsing and rendering helpers built on NanoSVG.
Why use these instead of JUCE's built-in SVG support? These helpers honour the source SVG's view box (width/height) when fitting into a target rectangle, preserving aspect ratio. JUCE's Drawable::createFromSVG and Path::createPathFromString collapse shapes into the path's own bounding box, which loses the view box and distorts artwork that has padding or off-centre content.
|
strong |
| juce::Image SVG::renderToImage | ( | const juce::String & | svgText, |
| int | width, | ||
| int | height, | ||
| Engine | engine = Engine::juce |
||
| ) |
Renders svgText into a width x height ARGB image with a transparent background.
The SVG is scaled uniformly to fit and centred — its view box aspect ratio is preserved.
| juce::Image SVG::renderToImage | ( | const juce::String & | svgText, |
| int | width, | ||
| int | height, | ||
| juce::Colour | backgroundColour, | ||
| Engine | engine = Engine::juce |
||
| ) |
As above, but fills the image with backgroundColour before drawing.
| juce::Path SVG::renderToPath | ( | const juce::String & | svgText | ) |
Returns all visible shapes flattened into a single juce::Path in the SVG's own coordinate space.
Note: the resulting path's bounding box is the union of its shapes, NOT the SVG view box, so transforming it directly will not preserve the view box — use the targetBounds overload below if you need that.
| juce::Path SVG::renderToPath | ( | const juce::String & | svgText, |
| juce::Rectangle< float > | targetBounds, | ||
| juce::RectanglePlacement | placement = juce::RectanglePlacement::centred |
||
| ) |
Returns the SVG as a juce::Path fitted into targetBounds.
Unlike the single-argument overload, this version uses the view box for the fit, so padding and off-centre content are preserved.
| void SVG::render | ( | const juce::String & | svgText, |
| juce::Graphics & | g, | ||
| juce::Rectangle< float > | targetBounds, | ||
| Engine | engine = Engine::juce |
||
| ) |
Draws svgText into targetBounds on the given Graphics context.
The view box is preserved via a centred uniform scale.