# Need a fair amount of help with SVGs

**URL:** <https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117>\
**Category:** Audio Plugins\
**Created:** [October 8, 2020, 8:01pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117 "2020-10-08T20:01:59Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wiznat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/wiznat/32/11103_2.png) [@Wiznat](https://forum.juce.com/u/Wiznat)\
**Post date:** [October 8, 2020, 8:01pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/1 "2020-10-08T20:01:59Z")

</div>

Hello hello,  
First, most of my questions aren’t too code related but more about working with SVGs them self. Im working on incorporating SVG images into my gui at the moment, and the first big issue Im having is that my SVG exported out of Illustrator is not loading correctly into JUCE. When I preview the SVG through the just the mac preview it looks fine, but when I load it into JUCE, gradients are missing, outlines are gone, text is messed up, etc… I assume this has to do with how my Illustrator file is setup and exported rather than an issue of JUCE. Could anyone explain is there something in particular I need to make sure my SVG is exporting correctly?

My second question is how efficient are SVGs? So I had most of my Gui set up with png versions before, and my cpu while running the plugin was never peaking past ~25%. When I loaded in my very broken SVG version of my background, turning a dial peaks my cpu usage at almost 80%. I assume something must be very wrong here, because I can’t imagine SVG drawing would cause that much of a difference, but hopefully someone can help me out.

---

<div class="post-metadata">

**Author:** ![kamedin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kamedin/32/11711_2.png) [@kamedin](https://forum.juce.com/u/kamedin)\
**Post date:** [October 8, 2020, 11:32pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/2 "2020-10-08T23:32:02Z")

</div>

The SVG implementation in Juce is not complete -I don’t know of all missing parts, but gradients are one of them. Also it’s better to convert all text to paths before importing. As for efficiency, they’re realized as paths, so complex shapes increase the workload. Of course you shouldn’t convert them in paint() -they should be available somewhere as Drawables or Paths. I always optimize them before importing -there are [some sites](https://vecta.io/nano) that do it for you.

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [October 9, 2020, 12:15am UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/3 "2020-10-09T00:15:19Z")

</div>

Gradients work just fine.

---

<div class="post-metadata">

**Author:** ![Wiznat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/wiznat/32/11103_2.png) [@Wiznat](https://forum.juce.com/u/Wiznat)\
**Post date:** [October 9, 2020, 12:33am UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/4 "2020-10-09T00:33:51Z")

</div>

I managed to get some of the gradients working properly by adjusting their groupings in Illustrator, but I haven’t quite figured out why it decides to draw them properly for some and not for others, guess just trial and error for now. And one of the big issues I figured out was that there was a png hiding around in my background layer, which did not play friendly with JUCE, so taking that out helped some as well.

And in regards to drawing them, I believe I’m doing it correctly.  
I created a unique\_ptr,  
Assigned the ptr in the editor constructor with Drawable::createFromImageData(x\_svg, x\_svgSize),  
addAndMakeVisibly(\*drawable).  
So definitely not doing anything directly in the paint function.  
I think some of the bog down might be coming from causing to many repaints since all the components lay on top of the background SVG, but idk maybe that assumption is incorrect.

---

<div class="post-metadata">

**Author:** ![kamedin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kamedin/32/11711_2.png) [@kamedin](https://forum.juce.com/u/kamedin)\
**Post date:** [October 9, 2020, 6:08am UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/5 "2020-10-09T06:08:09Z")

</div>

At least all the alpha gradients I’ve tried have been read as solids.

> [@Wiznat](#):
>
> I think some of the bog down might be coming from causing to many repaints since all the components lay on top of the background SVG, but idk maybe that assumption is incorrect.

Every repaint of something not opaque above the background will cause it to repaint too. Try `setBufferedToImage (true)` on the background -this avoids calling paint() for indirect repaints.

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [October 9, 2020, 5:55pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/6 "2020-10-09T17:55:59Z")

</div>

> [@kamedin](#):
>
> At least all the alpha gradients I’ve tried have been read as solids.

Hasn’t this been fixed recently? Or maybe I’m thinking our own fork?

---

<div class="post-metadata">

**Author:** ![kamedin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kamedin/32/11711_2.png) [@kamedin](https://forum.juce.com/u/kamedin)\
**Post date:** [October 9, 2020, 7:06pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/7 "2020-10-09T19:06:09Z")

</div>

You’re right, just checked and it works. It seems to have been added in April. Nice!

---

<div class="post-metadata">

**Author:** ![Wiznat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/wiznat/32/11103_2.png) [@Wiznat](https://forum.juce.com/u/Wiznat)\
**Post date:** [October 10, 2020, 10:04pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/8 "2020-10-10T22:04:08Z")

</div>

Bro thank you so much, just that one line brought down my cpu usage 30% lmao

---

<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:** [October 11, 2020, 10:40am UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/9 "2020-10-11T10:40:39Z")

</div>

When having problems with JUCE’s support of SVG files, I recommend also trying [`svg-simplify`](https://github.com/yairchu/svg-simplify), a tool that improves svg files compatibility which I made specifically for using svg files in JUCE projects.

---

<div class="post-metadata">

**Author:** ![Wiznat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/wiznat/32/11103_2.png) [@Wiznat](https://forum.juce.com/u/Wiznat)\
**Post date:** [November 2, 2020, 8:21pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/10 "2020-11-02T20:21:31Z")

</div>

Hey, I just got around to installing this, however I don’t understand is there an executable that I then bring the SVG into and it gives me a simplified version? Or does it work some other way. I see the unix executable in the .local/bin but opening it just gives me

 ![Screen Shot 2020-11-02 at 12.17.16 PM](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/7/75874ee246d0f8e780f3bb07bf0037f031d1b667.png)

---

<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:** [November 2, 2020, 8:37pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/11 "2020-11-02T20:37:37Z")

</div>

yes it would simplify the svg file you specify in-place (and hopefully I remembered to save the previous in a backup file). if there’s another way you’d like it to work you can file an issue and I think I’ll be responsive 🙂

---

<div class="post-metadata">

**Author:** ![Wiznat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/wiznat/32/11103_2.png) [@Wiznat](https://forum.juce.com/u/Wiznat)\
**Post date:** [November 2, 2020, 8:57pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/12 "2020-11-02T20:57:34Z")

</div>

Oh no worries Im sure it works fine lol, just more or less my lack of understanding lol. I guess thats more my question how do I use the program. The only executable I see after installing is the one in the local/bin but nothing seems to happen/ I cant do anything more after running it. My screenshot above is what I get from running the executable.

---

<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:** [November 2, 2020, 9:06pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/13 "2020-11-02T21:06:15Z")

</div>

yeah so just give it the path to your svg and it will “simplify” it 🙂

---

<div class="post-metadata">

**Author:** ![Wiznat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/wiznat/32/11103_2.png) [@Wiznat](https://forum.juce.com/u/Wiznat)\
**Post date:** [November 2, 2020, 10:06pm UTC](https://forum.juce.com/t/need-a-fair-amount-of-help-with-svgs/42117/14 "2020-11-02T22:06:35Z")

</div>

Ah okay got it, thanks for the quick replies !
