// THIS FILE IS PART OF SVG PROJECT
// THE SVG PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MS-PL License.
// COPYRIGHT (C) svg-net. ALL RIGHTS RESERVED.
// GITHUB: https://github.com/svg-net/SVG
using System.Drawing;
namespace AntdUI.Svg.Document_Structure
{
///
/// An element used to group SVG shapes.
///
public class SvgSymbol : SvgVisualElement
{
public override string ClassName { get => "symbol"; }
///
/// Gets or sets the viewport of the element.
///
///
[SvgAttribute("viewBox")]
public SvgViewBox ViewBox
{
get { return Attributes.GetAttribute("viewBox"); }
set { Attributes["viewBox"] = value; }
}
///
/// Gets or sets the aspect of the viewport.
///
///
[SvgAttribute("preserveAspectRatio")]
public SvgAspectRatio AspectRatio
{
get { return Attributes.GetAttribute("preserveAspectRatio"); }
set { Attributes["preserveAspectRatio"] = value; }
}
///
/// Gets the for this element.
///
///
public override System.Drawing.Drawing2D.GraphicsPath Path(ISvgRenderer renderer)
{
return GetPaths(this, renderer);
}
///
/// Gets the bounds of the element.
///
/// The bounds.
public override RectangleF Bounds
{
get
{
var r = new RectangleF();
foreach (var c in 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; } }
///
/// Applies the required transforms to .
///
/// The to be transformed.
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);
}
}
}