mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Fix for SVG view box parsing. Improved introjucer SVG viewer to show the image's content inside the view-box as defined in the file.
This commit is contained in:
parent
d633ee5d31
commit
8e7fbe9976
2 changed files with 27 additions and 12 deletions
|
|
@ -32,8 +32,7 @@
|
|||
class ItemPreviewComponent : public Component
|
||||
{
|
||||
public:
|
||||
ItemPreviewComponent (const File& f)
|
||||
: file (f)
|
||||
ItemPreviewComponent (const File& f) : file (f)
|
||||
{
|
||||
setOpaque (true);
|
||||
tryToLoadImage();
|
||||
|
|
@ -45,17 +44,28 @@ public:
|
|||
|
||||
if (drawable != nullptr)
|
||||
{
|
||||
Rectangle<int> area = RectanglePlacement (RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize)
|
||||
.appliedTo (drawable->getBounds(), Rectangle<int> (4, 22, getWidth() - 8, getHeight() - 26));
|
||||
Rectangle<float> contentBounds (drawable->getDrawableBounds());
|
||||
|
||||
if (DrawableComposite* dc = dynamic_cast<DrawableComposite*> (drawable.get()))
|
||||
{
|
||||
Rectangle<float> r (dc->getContentArea().resolve (nullptr));
|
||||
|
||||
if (! r.isEmpty())
|
||||
contentBounds = r;
|
||||
}
|
||||
|
||||
Rectangle<float> area = RectanglePlacement (RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize)
|
||||
.appliedTo (contentBounds, Rectangle<float> (4.0f, 22.0f, getWidth() - 8.0f, getHeight() - 26.0f));
|
||||
|
||||
Path p;
|
||||
p.addRectangle (area);
|
||||
DropShadow (Colours::black.withAlpha (0.5f), 6, Point<int> (0, 1)).drawForPath (g, p);
|
||||
|
||||
g.fillCheckerBoard (area, 24, 24, Colour (0xffffffff), Colour (0xffeeeeee));
|
||||
g.fillCheckerBoard (area.getSmallestIntegerContainer(), 24, 24,
|
||||
Colour (0xffffffff), Colour (0xffeeeeee));
|
||||
|
||||
g.setOpacity (1.0f);
|
||||
drawable->drawWithin (g, area.toFloat(), RectanglePlacement::stretchToFit, 1.0f);
|
||||
drawable->draw (g, 1.0f, RectanglePlacement (RectanglePlacement::stretchToFit)
|
||||
.getTransformToFit (contentBounds, area.toFloat()));
|
||||
}
|
||||
|
||||
g.setFont (Font (14.0f, Font::bold));
|
||||
|
|
@ -75,7 +85,7 @@ private:
|
|||
drawable = nullptr;
|
||||
|
||||
{
|
||||
ScopedPointer <InputStream> input (file.createInputStream());
|
||||
ScopedPointer<InputStream> input (file.createInputStream());
|
||||
|
||||
if (input != nullptr)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,13 +69,15 @@ public:
|
|||
if (newState.width <= 0) newState.width = 100;
|
||||
if (newState.height <= 0) newState.height = 100;
|
||||
|
||||
Point<float> viewboxXY;
|
||||
|
||||
if (xml->hasAttribute ("viewBox"))
|
||||
{
|
||||
const String viewBoxAtt (xml->getStringAttribute ("viewBox"));
|
||||
String::CharPointerType viewParams (viewBoxAtt.getCharPointer());
|
||||
Point<float> vxy, vwh;
|
||||
Point<float> vwh;
|
||||
|
||||
if (parseCoords (viewParams, vxy, true)
|
||||
if (parseCoords (viewParams, viewboxXY, true)
|
||||
&& parseCoords (viewParams, vwh, true)
|
||||
&& vwh.x > 0
|
||||
&& vwh.y > 0)
|
||||
|
|
@ -105,7 +107,7 @@ public:
|
|||
}
|
||||
|
||||
newState.transform = RectanglePlacement (placementFlags)
|
||||
.getTransformToFit (Rectangle<float> (vxy.x, vxy.y, vwh.x, vwh.y),
|
||||
.getTransformToFit (Rectangle<float> (viewboxXY.x, viewboxXY.y, vwh.x, vwh.y),
|
||||
Rectangle<float> (newState.width, newState.height))
|
||||
.followedBy (newState.transform);
|
||||
}
|
||||
|
|
@ -118,7 +120,10 @@ public:
|
|||
|
||||
newState.parseSubElements (xml, *drawable);
|
||||
|
||||
drawable->setContentArea (RelativeRectangle (Rectangle<float> (newState.viewBoxW, newState.viewBoxH)));
|
||||
drawable->setContentArea (RelativeRectangle (RelativeCoordinate (viewboxXY.x),
|
||||
RelativeCoordinate (viewboxXY.x + newState.viewBoxW),
|
||||
RelativeCoordinate (viewboxXY.y),
|
||||
RelativeCoordinate (viewboxXY.y + newState.viewBoxH)));
|
||||
drawable->resetBoundingBoxToContentArea();
|
||||
|
||||
return drawable;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue