Commit 52b7d326 authored by mrbean-bremen's avatar mrbean-bremen
Browse files

Correctly handle embedded SVG fragments without viewbox

- calculate svg element bounds considering child svg fragments
- consider svg fragment offset in bounds / dimensions
- do not create view box if none is defined
- fixes #244
parent 2f426fa3
...@@ -211,7 +211,34 @@ namespace Svg ...@@ -211,7 +211,34 @@ namespace Svg
{ {
get 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 ...@@ -244,13 +271,12 @@ namespace Svg
else else
{ {
bounds = this.Bounds; //do just one call to the recursive bounds property 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) if (isWidthperc)
{ {
w = (bounds.Width) * (Width.Value * 0.01f); w = (bounds.Width + bounds.X) * (Width.Value * 0.01f);
} }
else else
{ {
...@@ -258,7 +284,7 @@ namespace Svg ...@@ -258,7 +284,7 @@ namespace Svg
} }
if (isHeightperc) if (isHeightperc)
{ {
h = (bounds.Height) * (Height.Value * 0.01f); h = (bounds.Height + bounds.Y) * (Height.Value * 0.01f);
} }
else 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