SvgGlyph.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System.Linq;
  2. using Svg.Pathing;
  3. using System.Drawing.Drawing2D;
  4. #pragma warning disable
  5. namespace Svg
  6. {
  7. [SvgElement("glyph")]
  8. public class SvgGlyph : SvgPathBasedElement
  9. {
  10. private GraphicsPath _path;
  11. /// <summary>
  12. /// Gets or sets a <see cref="SvgPathSegmentList"/> of path data.
  13. /// </summary>
  14. [SvgAttribute("d", true)]
  15. public SvgPathSegmentList PathData
  16. {
  17. get { return this.Attributes.GetAttribute<SvgPathSegmentList>("d"); }
  18. set { this.Attributes["d"] = value; }
  19. }
  20. [SvgAttribute("glyph-name", true)]
  21. public virtual string GlyphName
  22. {
  23. get { return this.Attributes["glyph-name"] as string; }
  24. set { this.Attributes["glyph-name"] = value; }
  25. }
  26. [SvgAttribute("horiz-adv-x", true)]
  27. public float HorizAdvX
  28. {
  29. get { return (this.Attributes["horiz-adv-x"] == null ? this.Parents.OfType<SvgFont>().First().HorizAdvX : (float)this.Attributes["horiz-adv-x"]); }
  30. set { this.Attributes["horiz-adv-x"] = value; }
  31. }
  32. [SvgAttribute("unicode", true)]
  33. public string Unicode
  34. {
  35. get { return this.Attributes["unicode"] as string; }
  36. set { this.Attributes["unicode"] = value; }
  37. }
  38. [SvgAttribute("vert-adv-y", true)]
  39. public float VertAdvY
  40. {
  41. get { return (this.Attributes["vert-adv-y"] == null ? this.Parents.OfType<SvgFont>().First().VertAdvY : (float)this.Attributes["vert-adv-y"]); }
  42. set { this.Attributes["vert-adv-y"] = value; }
  43. }
  44. [SvgAttribute("vert-origin-x", true)]
  45. public float VertOriginX
  46. {
  47. get { return (this.Attributes["vert-origin-x"] == null ? this.Parents.OfType<SvgFont>().First().VertOriginX : (float)this.Attributes["vert-origin-x"]); }
  48. set { this.Attributes["vert-origin-x"] = value; }
  49. }
  50. [SvgAttribute("vert-origin-y", true)]
  51. public float VertOriginY
  52. {
  53. get { return (this.Attributes["vert-origin-y"] == null ? this.Parents.OfType<SvgFont>().First().VertOriginY : (float)this.Attributes["vert-origin-y"]); }
  54. set { this.Attributes["vert-origin-y"] = value; }
  55. }
  56. /// <summary>
  57. /// Gets the <see cref="GraphicsPath"/> for this element.
  58. /// </summary>
  59. public override GraphicsPath Path(ISvgRenderer renderer)
  60. {
  61. if (this._path == null || this.IsPathDirty)
  62. {
  63. _path = new GraphicsPath();
  64. foreach (SvgPathSegment segment in this.PathData)
  65. {
  66. segment.AddToPath(_path);
  67. }
  68. this.IsPathDirty = false;
  69. }
  70. return _path;
  71. }
  72. /// <summary>
  73. /// Initializes a new instance of the <see cref="SvgGlyph"/> class.
  74. /// </summary>
  75. public SvgGlyph()
  76. {
  77. var pathData = new SvgPathSegmentList();
  78. this.Attributes["d"] = pathData;
  79. }
  80. public override SvgElement DeepCopy()
  81. {
  82. return DeepCopy<SvgGlyph>();
  83. }
  84. public override SvgElement DeepCopy<T>()
  85. {
  86. var newObj = base.DeepCopy<T>() as SvgGlyph;
  87. foreach (var pathData in this.PathData)
  88. newObj.PathData.Add(pathData.Clone());
  89. return newObj;
  90. }
  91. }
  92. }
  93. #pragma warning restore