Drawable & DrawableComposite show only a small part of the SVG



All I want to do is display an SVG in a certain part of my GUI.  I took at look at the Juce Demo and am trying some similar code:


        StringArray iconNames;

        OwnedArray<Drawable> iconsFromZipFile;


        // If we've not already done so, load all the images from the zip file..

        MemoryInputStream iconsFileStream (BinaryData::PulseWidthIcon_svg_zip, BinaryData::PulseWidthIcon_svg_zipSize, false);

        ZipFile icons (&iconsFileStream, false);


        for (int i = 0; i < icons.getNumEntries(); ++i)


            ScopedPointer<InputStream> svgFileStream (icons.createStreamForEntry (i));


            for (int i = 0; i < icons.getNumEntries(); ++i)


                ScopedPointer<InputStream> svgFileStream (icons.createStreamForEntry (i));


                if (svgFileStream != 0)


                    iconNames.add (icons.getEntry(i)->filename);

                    iconsFromZipFile.add (Drawable::createFromImageDataStream (*svgFileStream));





        DrawableComposite* image = dynamic_cast <DrawableComposite*> (iconsFromZipFile [iconNames.indexOf ("PulseWidthIcon.svg")]->createCopy());


        //Drawable* image = iconsFromZipFile [iconNames.indexOf ("PulseWidthIcon.svg")]->createCopy();




        image->setBounds (9, 6, 10, 10);

Both dymanic casting the Drawable to a DrawableComposite (as shown above) or no casting and using Drawable, (commented out above) show only a small part of the SVG.  

If I omit setBounds then they both show the whole SVG but way too big.

Interestingly, DrawableImage fails to display anything, either with or without setBounds.

I guess I should set the 'Bounding Box' or 'Content Area' but I'm not sure how.

Can anybody tell me how I can display the entire SVG, in the bounds (9, 6, 10, 10)?

Thanks in advance






Drawable::drawWithin? DrawableComposite::resetBoundingBoxToContentArea() ?

Hi Jules,

Thanks for replying.  

So I'm going with the DrawableComposite and I have your Juce Demo 'edit-find' svg as an example.  I must be doing something very wrong since resetBoundingBoxToContentArea() doesn't work for me.

Here's the code:

//A first SVG, displayed correctly:        

DrawableComposite* image = dynamic_cast <DrawableComposite*> (iconsFromZipFile [iconNames.indexOf ("edit-find.svg")]->createCopy());


image->setBounds (9, 200, 60, 60);

//A second SVG that SHOULD look the same but smaller:

DrawableComposite* imageOfDesiredSize = dynamic_cast <DrawableComposite*> (iconsFromZipFile [iconNames.indexOf ("edit-find.svg")]->createCopy());


imageOfDesiredSize->setBounds (100, 200, 25, 25);

imageOfDesiredSize->resetBoundingBoxToContentArea(); // is this wrong???!!!

I have setup a simple display of the issue since I'm sure I didn't explain properly.  I would like my SVG to be, say, 25x25 but it doesn't shrink.  I just see, with this example, the top left portion of the edit-find icon, I want the WHOLE thing!!

Here is picture that illustrates the problem:


Please help!





Have a look at the SVGDemo class in the juce demo codebase. That shows how to position them.

ok Jules. Thanks.  I'll check that out later