Skip to content

Commit

Permalink
Change SvgSymbol namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
H1Gdev committed Aug 15, 2019
1 parent 4914203 commit a0f2607
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 4 deletions.
112 changes: 109 additions & 3 deletions Source/Document Structure/SvgSymbol.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Svg.DocumentStructure
{
/// <summary>
/// An element used to group SVG shapes.
/// </summary>
[SvgElement("symbol")]
public class SvgSymbol : SvgVisualElement
{
/// <summary>
/// Gets or sets the viewport of the element.
/// </summary>
/// <value></value>
[SvgAttribute("viewBox")]
public SvgViewBox ViewBox
{
get { return GetAttribute<SvgViewBox>("viewBox", false); }
set { Attributes["viewBox"] = value; }
}

/// <summary>
/// Gets or sets the aspect of the viewport.
/// </summary>
/// <value></value>
[SvgAttribute("preserveAspectRatio")]
public SvgAspectRatio AspectRatio
{
get { return GetAttribute<SvgAspectRatio>("preserveAspectRatio", false); }
set { Attributes["preserveAspectRatio"] = value; }
}

/// <summary>
/// Gets the <see cref="System.Drawing.Drawing2D.GraphicsPath"/> for this element.
/// </summary>
/// <value></value>
public override System.Drawing.Drawing2D.GraphicsPath Path(ISvgRenderer renderer)
{
return GetPaths(this, renderer);
}

/// <summary>
/// Gets the bounds of the element.
/// </summary>
/// <value>The bounds.</value>
public override System.Drawing.RectangleF Bounds
{
get
{
var r = new RectangleF();
foreach (var c in this.Children)
{
if (c is SvgVisualElement)
{
// First it should check if rectangle is empty or it will return the wrong Bounds.
// This is because when the Rectangle is Empty, the Union method adds as if the first values where X=0, Y=0
if (r.IsEmpty)
{
r = ((SvgVisualElement)c).Bounds;
}
else
{
var childBounds = ((SvgVisualElement)c).Bounds;
if (!childBounds.IsEmpty)
{
r = RectangleF.Union(r, childBounds);
}
}
}
}

return TransformedBounds(r);
}
}

protected override bool Renderable { get { return false; } }

/// <summary>
/// Applies the required transforms to <see cref="ISvgRenderer"/>.
/// </summary>
/// <param name="renderer">The <see cref="ISvgRenderer"/> to be transformed.</param>
protected internal override bool PushTransforms(ISvgRenderer renderer)
{
if (!base.PushTransforms(renderer))
return false;
ViewBox.AddViewBoxTransform(AspectRatio, renderer, null);
return true;
}

// Only render if the parent is set to a Use element
protected override void Render(ISvgRenderer renderer)
{
if (_parent is SvgUse) base.Render(renderer);
}

public override SvgElement DeepCopy()
{
return DeepCopy<SvgSymbol>();
}

public override SvgElement DeepCopy<T>()
{
var newObj = base.DeepCopy<T>() as SvgSymbol;
if (this.Fill != null)
newObj.Fill = this.Fill.DeepCopy() as SvgPaintServer;
return newObj;
}
}
}

namespace Svg.Document_Structure
{
/// <summary>
/// An element used to group SVG shapes.
/// </summary>
[Obsolete("Use Svg.DocumentStructure.SvgSymbol.")]
[SvgElement("symbol")]
public class SvgSymbol : SvgVisualElement
{
Expand Down
3 changes: 2 additions & 1 deletion Source/SvgElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reflection;
using System.Text;
using System.Xml;
using Svg.DocumentStructure;
using Svg.Transforms;

namespace Svg
Expand Down Expand Up @@ -876,7 +877,7 @@ protected void AddPaths(SvgElement elem, GraphicsPath path)
// Skip to avoid double calculate Symbol element
// symbol element is only referenced by use element
// So here we need to skip when it is directly considered
if (child is Svg.Document_Structure.SvgSymbol)
if (child is SvgSymbol)
continue;

if (child is SvgVisualElement)
Expand Down

0 comments on commit a0f2607

Please sign in to comment.