SvgTextPath.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Diagnostics;
  8. #pragma warning disable
  9. namespace Svg
  10. {
  11. /// <summary>
  12. /// The <see cref="SvgText"/> element defines a graphics element consisting of text.
  13. /// </summary>
  14. [SvgElement("textPath")]
  15. public class SvgTextPath : SvgTextBase
  16. {
  17. private Uri _referencedPath;
  18. public override SvgUnitCollection Dx
  19. {
  20. get { return null; }
  21. set { /* do nothing */ }
  22. }
  23. [SvgAttribute("startOffset")]
  24. public virtual SvgUnit StartOffset
  25. {
  26. get { return (_dx.Count < 1 ? SvgUnit.None : _dx[0]); }
  27. set
  28. {
  29. if (_dx.Count < 1)
  30. {
  31. _dx.Add(value);
  32. }
  33. else
  34. {
  35. _dx[0] = value;
  36. }
  37. }
  38. }
  39. [SvgAttribute("method")]
  40. public virtual SvgTextPathMethod Method
  41. {
  42. get { return (this.Attributes["method"] == null ? SvgTextPathMethod.Align : (SvgTextPathMethod)this.Attributes["method"]); }
  43. set { this.Attributes["method"] = value; }
  44. }
  45. [SvgAttribute("spacing")]
  46. public virtual SvgTextPathSpacing Spacing
  47. {
  48. get { return (this.Attributes["spacing"] == null ? SvgTextPathSpacing.Exact : (SvgTextPathSpacing)this.Attributes["spacing"]); }
  49. set { this.Attributes["spacing"] = value; }
  50. }
  51. [SvgAttribute("href", SvgAttributeAttribute.XLinkNamespace)]
  52. public virtual Uri ReferencedPath
  53. {
  54. get { return this._referencedPath; }
  55. set { this._referencedPath = value; }
  56. }
  57. protected override GraphicsPath GetBaselinePath(ISvgRenderer renderer)
  58. {
  59. var path = this.OwnerDocument.IdManager.GetElementById(this.ReferencedPath) as SvgVisualElement;
  60. if (path == null) return null;
  61. var pathData = (GraphicsPath)path.Path(renderer).Clone();
  62. if (path.Transforms.Count > 0)
  63. {
  64. Matrix transformMatrix = new Matrix(1, 0, 0, 1, 0, 0);
  65. foreach (var transformation in path.Transforms)
  66. {
  67. transformMatrix.Multiply(transformation.Matrix);
  68. }
  69. pathData.Transform(transformMatrix);
  70. }
  71. return pathData;
  72. }
  73. protected override float GetAuthorPathLength()
  74. {
  75. var path = this.OwnerDocument.IdManager.GetElementById(this.ReferencedPath) as SvgPath;
  76. if (path == null) return 0;
  77. return path.PathLength;
  78. }
  79. public override SvgElement DeepCopy()
  80. {
  81. return base.DeepCopy<SvgTextPath>();
  82. }
  83. }
  84. }
  85. #pragma warning restore