SvgClosePathSegment.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. #pragma warning disable
  5. namespace Svg.Pathing
  6. {
  7. public sealed class SvgClosePathSegment : SvgPathSegment
  8. {
  9. public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath)
  10. {
  11. var pathData = graphicsPath.PathData;
  12. if (pathData.Points.Length > 0)
  13. {
  14. // Important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure.
  15. if (!pathData.Points[0].Equals(pathData.Points[pathData.Points.Length - 1]))
  16. {
  17. int i = pathData.Points.Length - 1;
  18. while (i >= 0 && pathData.Types[i] > 0) i--;
  19. if (i < 0) i = 0;
  20. graphicsPath.AddLine(pathData.Points[pathData.Points.Length - 1], pathData.Points[i]);
  21. }
  22. graphicsPath.CloseFigure();
  23. }
  24. }
  25. public override string ToString()
  26. {
  27. return "z";
  28. }
  29. }
  30. }
  31. #pragma warning restore