Commit b6abd3cb authored by mrbean-bremen's avatar mrbean-bremen
Browse files

Add transform to bounds calculation in path based objects

see #281
parent f6622b55
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Xml;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace Svg namespace Svg
{ {
...@@ -13,7 +6,7 @@ namespace Svg ...@@ -13,7 +6,7 @@ namespace Svg
/// An SVG element to render circles to the document. /// An SVG element to render circles to the document.
/// </summary> /// </summary>
[SvgElement("circle")] [SvgElement("circle")]
public class SvgCircle : SvgVisualElement public class SvgCircle : SvgPathBasedElement
{ {
private GraphicsPath _path; private GraphicsPath _path;
...@@ -75,15 +68,6 @@ namespace Svg ...@@ -75,15 +68,6 @@ namespace Svg
} }
} }
/// <summary>
/// Gets the bounds of the circle.
/// </summary>
/// <value>The rectangular bounds of the circle.</value>
public override RectangleF Bounds
{
get { return this.Path(null).GetBounds(); }
}
/// <summary> /// <summary>
/// Gets the <see cref="GraphicsPath"/> representing this element. /// Gets the <see cref="GraphicsPath"/> representing this element.
/// </summary> /// </summary>
......
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Xml;
using System.ComponentModel;
namespace Svg namespace Svg
{ {
...@@ -12,7 +6,7 @@ namespace Svg ...@@ -12,7 +6,7 @@ namespace Svg
/// Represents and SVG ellipse element. /// Represents and SVG ellipse element.
/// </summary> /// </summary>
[SvgElement("ellipse")] [SvgElement("ellipse")]
public class SvgEllipse : SvgVisualElement public class SvgEllipse : SvgPathBasedElement
{ {
private SvgUnit _radiusX; private SvgUnit _radiusX;
private SvgUnit _radiusY; private SvgUnit _radiusY;
...@@ -80,15 +74,6 @@ namespace Svg ...@@ -80,15 +74,6 @@ namespace Svg
} }
} }
/// <summary>
/// Gets the bounds of the element.
/// </summary>
/// <value>The bounds.</value>
public override RectangleF Bounds
{
get { return this.Path(null).GetBounds(); }
}
/// <summary> /// <summary>
/// Gets the <see cref="GraphicsPath"/> for this element. /// Gets the <see cref="GraphicsPath"/> for this element.
/// </summary> /// </summary>
......
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using Svg.ExtensionMethods; using Svg.ExtensionMethods;
...@@ -12,7 +9,7 @@ namespace Svg ...@@ -12,7 +9,7 @@ namespace Svg
/// Represents and SVG line element. /// Represents and SVG line element.
/// </summary> /// </summary>
[SvgElement("line")] [SvgElement("line")]
public class SvgLine : SvgVisualElement public class SvgLine : SvgPathBasedElement
{ {
private SvgUnit _startX; private SvgUnit _startX;
private SvgUnit _startY; private SvgUnit _startY;
...@@ -186,11 +183,6 @@ namespace Svg ...@@ -186,11 +183,6 @@ namespace Svg
return result; return result;
} }
public override System.Drawing.RectangleF Bounds
{
get { return this.Path(null).GetBounds(); }
}
public override SvgElement DeepCopy() public override SvgElement DeepCopy()
{ {
return DeepCopy<SvgLine>(); return DeepCopy<SvgLine>();
......
using System.Drawing.Drawing2D;
namespace Svg
{
/// <summary>
/// Represents an element that is using a GraphicsPath as rendering base.
/// </summary>
public abstract class SvgPathBasedElement : SvgVisualElement
{
public override System.Drawing.RectangleF Bounds
{
get
{
var path = this.Path(null);
if (Transforms != null)
{
path = (GraphicsPath)path.Clone();
path.Transform(Transforms.GetMatrix());
}
return path.GetBounds();
}
}
}
}
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Diagnostics; using System.Diagnostics;
using Svg.ExtensionMethods; using Svg.ExtensionMethods;
using Svg.Pathing;
namespace Svg namespace Svg
{ {
...@@ -13,7 +9,7 @@ namespace Svg ...@@ -13,7 +9,7 @@ namespace Svg
/// SvgPolygon defines a closed shape consisting of a set of connected straight line segments. /// SvgPolygon defines a closed shape consisting of a set of connected straight line segments.
/// </summary> /// </summary>
[SvgElement("polygon")] [SvgElement("polygon")]
public class SvgPolygon : SvgVisualElement public class SvgPolygon : SvgPathBasedElement
{ {
private GraphicsPath _path; private GraphicsPath _path;
...@@ -136,12 +132,6 @@ namespace Svg ...@@ -136,12 +132,6 @@ namespace Svg
return result; return result;
} }
public override RectangleF Bounds
{
get { return this.Path(null).GetBounds(); }
}
public override SvgElement DeepCopy() public override SvgElement DeepCopy()
{ {
return DeepCopy<SvgPolygon>(); return DeepCopy<SvgPolygon>();
......
using System; using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using Svg.Transforms;
namespace Svg namespace Svg
{ {
...@@ -9,7 +8,7 @@ namespace Svg ...@@ -9,7 +8,7 @@ namespace Svg
/// Represents an SVG rectangle that could also have rounded edges. /// Represents an SVG rectangle that could also have rounded edges.
/// </summary> /// </summary>
[SvgElement("rect")] [SvgElement("rect")]
public class SvgRectangle : SvgVisualElement public class SvgRectangle : SvgPathBasedElement
{ {
private SvgUnit _cornerRadiusX; private SvgUnit _cornerRadiusX;
private SvgUnit _cornerRadiusY; private SvgUnit _cornerRadiusY;
...@@ -168,15 +167,6 @@ namespace Svg ...@@ -168,15 +167,6 @@ namespace Svg
} }
} }
/// <summary>
/// Gets the bounds of the element.
/// </summary>
/// <value>The bounds.</value>
public override RectangleF Bounds
{
get { return Path(null).GetBounds(); }
}
/// <summary> /// <summary>
/// Gets the <see cref="GraphicsPath"/> for this element. /// Gets the <see cref="GraphicsPath"/> for this element.
/// </summary> /// </summary>
......
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Basic Shapes\SvgImage.cs" /> <Compile Include="Basic Shapes\SvgImage.cs" />
<Compile Include="Basic Shapes\SvgPathBasedElement.cs" />
<Compile Include="Basic Shapes\SvgVisualElement.cs" /> <Compile Include="Basic Shapes\SvgVisualElement.cs" />
<Compile Include="Basic Shapes\SvgCircle.cs" /> <Compile Include="Basic Shapes\SvgCircle.cs" />
<Compile Include="Basic Shapes\SvgEllipse.cs" /> <Compile Include="Basic Shapes\SvgEllipse.cs" />
......
using System; using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Svg.Pathing; using Svg.Pathing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
namespace Svg namespace Svg
{ {
[SvgElement("glyph")] [SvgElement("glyph")]
public class SvgGlyph : SvgVisualElement public class SvgGlyph : SvgPathBasedElement
{ {
private GraphicsPath _path; private GraphicsPath _path;
...@@ -79,15 +76,6 @@ namespace Svg ...@@ -79,15 +76,6 @@ namespace Svg
return _path; return _path;
} }
/// <summary>
/// Gets the bounds of the element.
/// </summary>
/// <value>The bounds.</value>
public override System.Drawing.RectangleF Bounds
{
get { return this.Path(null).GetBounds(); }
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SvgGlyph"/> class. /// Initializes a new instance of the <see cref="SvgGlyph"/> class.
/// </summary> /// </summary>
......
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