Drawing an SVG using Drawable - why doesn't this simple thing work?

Someone tell me why this doesn’t work? (x is non-null)

            String s{R"(<svg viewBox=\"0 0 10 12\" xmlns=\"http://www.w3.org/2000/svg\" fill-rule=\"evenodd\" clip-rule=\"evenodd\" stroke-linejoin=\"round\" stroke-miterlimit=\"2\"><circle cx=\"561.722\" cy=\"446.415\" r=\"2.553\" fill=\"#bfbfbf\" transform=\"translate(-609.04 -477.107) scale(1.08919)\"/><path d=\"M5.562.83a.83.83 0 00-1.66 0v8.42a.83.83 0 001.66 0V.83z\" fill=\"#ffffff\"/><circle cx=\"567\" cy=\"446\" r=\"1\" fill=\"#ffffff\" transform=\"translate(-558.713 -436.92)\"/></svg>)"};
            auto x = XmlDocument::parse(s);

            if (x)
            {
                auto drawable = Drawable::createFromSVG(*x);
                drawable->setTransformToFit(b, RectanglePlacement::centred);
                drawable->drawWithin(g, b, RectanglePlacement::centred, 1.0f);
            }

A few things that stand out for me:

  • the translation in the SVG itself - you might not want that, because you’ll probably end up fighting it to position it in your app.
  • stroke-miterlimit isn’t supported.
  • clip-rule isn’t supported
1 Like

Ta - I’ll have another play.

Still can’t get it to work! I just can’t make anything appear :slight_smile:

image

case dotted:
            {
                String s{R"(<svg fill-rule="evenodd" stroke-linejoin="round"><path d="M3.94 3.428V.563a.562.562 0 011.124 0v4.97A2.533 2.533 0 112.532 3c.52 0 1.005.158 1.407.427zm2.97 1.535a1.19 1.19 0 11-.001 2.378 1.19 1.19 0 010-2.378z" fill="#bfbfbf"/></svg>)"};
                auto x = XmlDocument::parse(s);

                if (x)
                {
                    auto drawable = Drawable::createFromSVG(*x);
                    drawable->setTransformToFit(b, RectanglePlacement::centred);
                    drawable->drawWithin(g, b, RectanglePlacement::centred, 1.0f);

                    g.setColour(Colours::hotpink);
                    g.drawRect(b);
                }
            }
            break;

Alright, solved it. drawWithin doesn’t work for me. Draw does…

You’re already using “transformToFit”, so drawWithin would transform it again, possibly making it really small. If you remove the “setTransformToFit” and then use “drawWithin” it would probably work just fine.

I’d reached the point of madness where i just kept adding code to avoid having to step into the draw call to figure out what was wrong :slight_smile: