Commit 2a4bc179 authored by Tebjan Halm's avatar Tebjan Halm Committed by GitHub
Browse files

Merge pull request #293 from mrbean-bremen/svg-bounds

Correctly handle embedded SVG fragments without viewbox
parents f9181931 52b7d326
......@@ -211,7 +211,34 @@ namespace Svg
{
get
{
return this.Path.GetBounds();
var bounds = new RectangleF();
foreach (var child in this.Children)
{
RectangleF childBounds = new RectangleF();
if (child is SvgFragment)
{
childBounds = ((SvgFragment)child).Bounds;
childBounds.Offset(((SvgFragment)child).X, ((SvgFragment)child).Y);
}
else if (child is SvgVisualElement)
{
childBounds = ((SvgVisualElement)child).Bounds;
}
if (!childBounds.IsEmpty)
{
if (bounds.IsEmpty)
{
bounds = childBounds;
}
else
{
bounds = RectangleF.Union(bounds, childBounds);
}
}
}
return bounds;
}
}
......@@ -244,13 +271,12 @@ namespace Svg
else
{
bounds = this.Bounds; //do just one call to the recursive bounds property
this.ViewBox = new SvgViewBox(bounds.X, bounds.Y, bounds.Width, bounds.Height);
}
}
if (isWidthperc)
{
w = (bounds.Width) * (Width.Value * 0.01f);
w = (bounds.Width + bounds.X) * (Width.Value * 0.01f);
}
else
{
......@@ -258,7 +284,7 @@ namespace Svg
}
if (isHeightperc)
{
h = (bounds.Height) * (Height.Value * 0.01f);
h = (bounds.Height + bounds.Y) * (Height.Value * 0.01f);
}
else
{
......
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<svg id="svg1" x="30" viewBox="0 0 100 100">
<rect id="rect1" x="10" y="10" height="100" width="100"
style="stroke:#ff0000; fill: #0000ff"/>
</svg>
<svg id="svg1" x="200" y="20" viewBox="0 0 100 100">
<rect id="rect2" x="10" y="10" height="100" width="100"
style="stroke:#009900; fill: #00cc00"/>
</svg>
</svg>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment