I’m pretty new to Juce and I’d like to know the best way to preserve the empty space in an SVG Drawable’s SVG viewport/viewBox when attempting to scale it.
I’m using a JUCE git checkout from Aug 18 2012 on Linux if that matters.
I’m basically trying to reproduce the pretty chess diagrams in the Wikipedia chess article http://en.wikipedia.org/wiki/Chess, using Wikimedia’s SVG pieces at http://commons.wikimedia.org/wiki/Category:SVG_chess_pieces – but specifically the pieces with no background square (so that I can customize the square if desired)
When I use Drawable::createFromSVG() to create these pieces, and then try Drawable::setTransformToFit() on them with a custom square component, the piece is scaled and translated so that its bottom and top touch the edges of the custom component. This makes it look too big, especially the pawns.
The current kludge/workaround I’m using is to patch JUCE’s juce_SVGparser.cpp:parseSVGElement(), by changing
drawable->setContentArea(RelativeRectangle(Rectangle<float>(0.0, 0.0, newState.viewBoxW, newState.viewBoxH)));
And then in my custom square component, which owns the ScopedPointer piece, instead of scaling the piece by doing
/* doesn't work because piece's getDrawableBounds() returns the bounds of the visible part of the piece, not the entire viewport. getBounds(), getHeight(), and getWidth() fail in similar fashion */
I do something like:
DrawableComposite *dc = dynamic_cast<DrawableComposite *>(piece.get());
if (dc != nullptr)
Which gives me what I want:
Is there a nicer way to do this? Particularly one where I don’t have to maintain a private (and probably wrong) patch to the JUCE source, and don’t have to change the SVG pieces I’m using?
Thanks for any help, --buck
(and feel free to ignore the weird fill on the knights, that’s some unrelated issue I’ll try to track down better before I inquire about it)