# Alternative SVG parser/rasterizer?

**URL:** <https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663>\
**Category:** General JUCE discussion\
**Created:** [September 8, 2020, 10:23pm UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663 "2020-09-08T22:23:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [September 8, 2020, 10:23pm UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/1 "2020-09-08T22:23:30Z")

</div>

I got a new UI design for a plug in that has been designed with Adobe XD. It looks great and my designer exported the various parts of it as SVGs. The SVGs look great in the web browser as well. But rendered with JUCE they are full of all kinds of flaws and especially most shadows are not rendered correctly, some shapes are not where there are expected to be – seems like the SVGs exported by XD are full of things the JUCE parser has not implemented.

I planed to create a purely vector graphics based freely resizable user interface. However, with the way the JUCE SVG parser interprets the SVGs this is simply not possible. Before reverting my plans and moving back to a raster based user interface, I wonder if there are any suitable third party libraries that allow rasterizing my SVGs correctly without artifacts at runtime? A quick search revealed Skia but that seems like a massive dependency 😬

Maybe somebody else faced a similar problem before as well?

Or, as another option, if the JUCE team wants to extend its SVG capabilities I’d be happy to supply the failing SVGs to them 😉 But I’m not sure if there are any plans like that?

---

<div class="post-metadata">

**Author:** ![olilarkin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/olilarkin/32/7142_2.png) [@olilarkin](https://forum.juce.com/u/olilarkin)\
**Post date:** [September 8, 2020, 11:15pm UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/2 "2020-09-08T23:15:42Z")

</div>

this [rust library](https://github.com/RazrFalcon/resvg) is the best thing i have found, which uses skia to render.

you can build a static lib with c bindings, and rasterize into a juce image

---

<div class="post-metadata">

**Author:** ![connorreviere](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/connorreviere/32/4890_2.png) [@connorreviere](https://forum.juce.com/u/connorreviere)\
**Post date:** [September 9, 2020, 12:51am UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/3 "2020-09-09T00:51:30Z")

</div>

I haven’t tried any third-party SVG libraries, but occasionally when JUCE is having issues with Adobe SVGs I’ve had success by opening the files in Inkscape and resaving them. It’s very hit or miss, but it might be worth trying.

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [September 9, 2020, 6:38am UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/4 "2020-09-09T06:38:04Z")

</div>

Thanks @olilarkin, that sounds promising!  
I have zero rust experience, but if all I need is compiling the C library from it, I guess I‘ll manage that 😉

> [@olilarkin](#):
>
> you can build a static lib with c bindings, and rasterize into a juce image

So I can build a static library with it that uses skia but has no runtime dependencies to skia as a shared library?

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [September 9, 2020, 6:48am UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/5 "2020-09-09T06:48:21Z")

</div>

> [@connorreviere](#):
>
> I’ve had success by opening the files in Inkscape and resaving them

Will try that as well! Interesting enough, former UI Designs from the same designer which he created with Illustrator instead of XD worked better, so it’s probably really some formating think or so. But it still seems that some kinds of shadows are simply not supported at all from the JUCE side

---

<div class="post-metadata">

**Author:** ![ttg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ttg/32/14456_2.png) [@ttg](https://forum.juce.com/u/ttg)\
**Post date:** [September 9, 2020, 6:57am UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/6 "2020-09-09T06:57:19Z")

</div>

The best thing is actually mitigate the SVGs themselves or actually fix juce 🙂

Here some things I have logged internally for us (we work around them by modifying the SVGs).

- SVG alpha for `<image>` isn’t preserved. (usually your Illustrator/Adobe export would have a base64 image with alpha that JUCE ignore). \<- shadow rendered too harsh ?

- SVG styles (css) classes are being overwrite instead of appended.  
eg:

```auto
.class-1 { blah }

.class 1,
.class-2 { grrr }

```

So SVG wants `.class2` to have { blah grrr } but instead it’ll just have grrr.

Last,  
This is a useful utility made by @yairadix that designed to help some issues on the SVG side.

> **[yairchu/svg-simplify](https://github.com/yairchu/svg-simplify)**
>
> A tool to simplify SVG files to use more basic features - yairchu/svg-simplify

Again,  
best would actually be to fix JUCE renderer.

btw,  
advantage of JUCE renderer vs suggested binding:

- smaller binary footprint
- ‘some’ optimization. since the SVG calls will be translated to graphic ones. on OpenGL for example, some would benefit from being shaders. (some at least…)

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [September 9, 2020, 11:47am UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/7 "2020-09-09T11:47:36Z")

</div>

Thank you for that detailed response. To be honest, I have nearly no knowledge of SVG internals, so the details shared above seem quite cryptic for me at the moment 😉

I’ll definetively try out svg-simplify, thank you for that link. However I’m not sure if learning SVG internals is the most straigtforward way for me to get this working? If all automated tools like svg-simplify and re-exporting from inkskape don’t help, I feel more confident and safe with adding a third party dependency with all its downsides than learning to read SVGs (and maybe coming to the conclusion that there are still problems issues with the JUCE renderer)

---

<div class="post-metadata">

**Author:** ![yairadix](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yairadix/32/1114_2.png) [@yairadix](https://forum.juce.com/u/yairadix)\
**Post date:** [September 9, 2020, 12:35pm UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/8 "2020-09-09T12:35:41Z")

</div>

Note that if you do end up investigating and finding which missing functionality in JUCE’s SVG implementation you need, reporting it might be better in the long term. At least you won’t find yourself needing to fix two libraries 😉

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [September 9, 2020, 12:38pm UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/9 "2020-09-09T12:38:04Z")

</div>

Totally agree with that. At the moment I’m indeed looking for a quick solution as the planned release is not too far away and this is a real blocker, but in the long term I might investigate whats wrong in the JUCE implementation and of course share my findings!

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [September 13, 2020, 9:25pm UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/10 "2020-09-13T21:25:59Z")

</div>

Update:

Trying to simplify the SVGs failed 😐

So I had a closer look at resvg. Built a quick JUCE wrapper around it:

> **[JanosGit/Resvg4JUCE](https://github.com/JanosGit/Resvg4JUCE)**
>
> A JUCE module that wraps the resvg SVG rendering library in a JUCE compatible interface - JanosGit/Resvg4JUCE

I modified the Cargo build script to output a static library, as I’m not interested in installing dynamic library dependencies with my plugin if possible. On Mac this works quite well, while the static lib is quite large, the binary size stays reasonably small and all works smooth. And especially my SVG assets finaly look like they should 😍

However on Windows I’ve run into more trouble with that. Seems that the rust compiler will always output a library compiled again the non-debug DLL runtime (like compiling with /MD) which leads to linker errors if the application/plugin itself is built with any other option. But I didn’t find any information on how to change that. @olilarkin As you suggested the library, did you already use it successfully on Windows and if so, how did you get this working? 😃 I have to admit that I feel quite more at home on Mac OS and as I said I’ve got no rust know-how, so this might be something quite simple 😉

---

<div class="post-metadata">

**Author:** ![olilarkin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/olilarkin/32/7142_2.png) [@olilarkin](https://forum.juce.com/u/olilarkin)\
**Post date:** [September 13, 2020, 9:51pm UTC](https://forum.juce.com/t/alternative-svg-parser-rasterizer/41663/11 "2020-09-13T21:51:30Z")

</div>

I also had trouble with that [https://github.com/RazrFalcon/resvg/issues/201](https://github.com/RazrFalcon/resvg/issues/201)

If you can build a dll you should be able to link that whatever (but dlls are not much fun with plugins)
