using System; using System.Collections.Generic; using System.Linq; using System.Text; using Svg.Pathing; using System.Drawing.Drawing2D; namespace Svg { [SvgElement("glyph")] public class SvgGlyph : SvgVisualElement { private GraphicsPath _path; /// /// Gets or sets a of path data. /// [SvgAttribute("d", true)] public SvgPathSegmentList PathData { get { return this.Attributes.GetAttribute("d"); } set { this.Attributes["d"] = value; } } [SvgAttribute("glyph-name", true)] public virtual string GlyphName { get { return this.Attributes["glyph-name"] as string; } set { this.Attributes["glyph-name"] = value; } } [SvgAttribute("horiz-adv-x", true)] public float HorizAdvX { get { return (this.Attributes["horiz-adv-x"] == null ? this.Parents.OfType().First().HorizAdvX : (float)this.Attributes["horiz-adv-x"]); } set { this.Attributes["horiz-adv-x"] = value; } } [SvgAttribute("unicode", true)] public string Unicode { get { return this.Attributes["unicode"] as string; } set { this.Attributes["unicode"] = value; } } [SvgAttribute("vert-adv-y", true)] public float VertAdvY { get { return (this.Attributes["vert-adv-y"] == null ? this.Parents.OfType().First().VertAdvY : (float)this.Attributes["vert-adv-y"]); } set { this.Attributes["vert-adv-y"] = value; } } [SvgAttribute("vert-origin-x", true)] public float VertOriginX { get { return (this.Attributes["vert-origin-x"] == null ? this.Parents.OfType().First().VertOriginX : (float)this.Attributes["vert-origin-x"]); } set { this.Attributes["vert-origin-x"] = value; } } [SvgAttribute("vert-origin-y", true)] public float VertOriginY { get { return (this.Attributes["vert-origin-y"] == null ? this.Parents.OfType().First().VertOriginY : (float)this.Attributes["vert-origin-y"]); } set { this.Attributes["vert-origin-y"] = value; } } /// /// Gets the for this element. /// public override GraphicsPath Path(ISvgRenderer renderer) { if (this._path == null || this.IsPathDirty) { _path = new GraphicsPath(); foreach (SvgPathSegment segment in this.PathData) { segment.AddToPath(_path); } this.IsPathDirty = false; } return _path; } /// /// Gets or sets a value to determine if anti-aliasing should occur when the element is being rendered. /// protected override bool RequiresSmoothRendering { get { return true; } } /// /// Gets the bounds of the element. /// /// The bounds. public override System.Drawing.RectangleF Bounds { get { return this.Path(null).GetBounds(); } } /// /// Initializes a new instance of the class. /// public SvgGlyph() { var pathData = new SvgPathSegmentList(); this.Attributes["d"] = pathData; } public override SvgElement DeepCopy() { return DeepCopy(); } public override SvgElement DeepCopy() { var newObj = base.DeepCopy() as SvgGlyph; foreach (var pathData in this.PathData) newObj.PathData.Add(pathData.Clone()); return newObj; } } }