SvgQuadraticCurveSegment.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Drawing;
  5. #pragma warning disable
  6. namespace Svg.Pathing
  7. {
  8. public sealed class SvgQuadraticCurveSegment : SvgPathSegment
  9. {
  10. private PointF _controlPoint;
  11. public PointF ControlPoint
  12. {
  13. get { return this._controlPoint; }
  14. set { this._controlPoint = value; }
  15. }
  16. private PointF FirstControlPoint
  17. {
  18. get
  19. {
  20. float x1 = Start.X + (this.ControlPoint.X - Start.X) * 2 / 3;
  21. float y1 = Start.Y + (this.ControlPoint.Y - Start.Y) * 2 / 3;
  22. return new PointF(x1, y1);
  23. }
  24. }
  25. private PointF SecondControlPoint
  26. {
  27. get
  28. {
  29. float x2 = this.ControlPoint.X + (this.End.X - this.ControlPoint.X) / 3;
  30. float y2 = this.ControlPoint.Y + (this.End.Y - this.ControlPoint.Y) / 3;
  31. return new PointF(x2, y2);
  32. }
  33. }
  34. public SvgQuadraticCurveSegment(PointF start, PointF controlPoint, PointF end)
  35. {
  36. this.Start = start;
  37. this._controlPoint = controlPoint;
  38. this.End = end;
  39. }
  40. public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath)
  41. {
  42. graphicsPath.AddBezier(this.Start, this.FirstControlPoint, this.SecondControlPoint, this.End);
  43. }
  44. public override string ToString()
  45. {
  46. return "Q" + this.ControlPoint.ToSvgString() + " " + this.End.ToSvgString();
  47. }
  48. }
  49. }
  50. #pragma warning restore