Browse Source

make PathGeometry.ToString work properly

Andrey Kunchev 6 years ago
parent
commit
9283fd4049

+ 5 - 0
src/Avalonia.Visuals/Media/ArcSegment.cs

@@ -1,6 +1,8 @@
 // Copyright (c) The Avalonia Project. All rights reserved.
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
+using System.Globalization;
+
 namespace Avalonia.Media
 {
     public sealed class ArcSegment : PathSegment
@@ -99,5 +101,8 @@ namespace Avalonia.Media
         {
             ctx.ArcTo(Point, Size, RotationAngle, IsLargeArc, SweepDirection);
         }
+
+        public override string ToString()
+            => $"A {Size} {RotationAngle.ToString(CultureInfo.InvariantCulture)} {(IsLargeArc ? 1 : 0)} {(int)SweepDirection} {Point}";
     }
 }

+ 3 - 0
src/Avalonia.Visuals/Media/BezierSegment .cs

@@ -61,5 +61,8 @@ namespace Avalonia.Media
         {
             ctx.CubicBezierTo(Point1, Point2, Point3);
         }
+
+        public override string ToString()
+            => $"C {Point1} {Point2} {Point3}";
     }
 }

+ 3 - 0
src/Avalonia.Visuals/Media/LineSegment.cs

@@ -27,5 +27,8 @@ namespace Avalonia.Media
         {
             ctx.LineTo(Point);
         }
+
+        public override string ToString()
+            => $"L {Point}";
     }
 }

+ 3 - 0
src/Avalonia.Visuals/Media/PathFigure.cs

@@ -98,5 +98,8 @@ namespace Avalonia.Media
         }
 
         private PathSegments _segments;
+
+        public override string ToString()
+            => $"M {StartPoint} {string.Join(" ", _segments)}{(IsClosed ? "Z" : "")}";
     }
 }

+ 4 - 0
src/Avalonia.Visuals/Media/PathGeometry.cs

@@ -112,5 +112,9 @@ namespace Avalonia.Media
                 () => InvalidateGeometry());
             _figuresPropertiesObserver = figures?.TrackItemPropertyChanged(_ => InvalidateGeometry());
         }
+
+
+        public override string ToString()
+            => $"{(FillRule != FillRule.EvenOdd ? "F1 " : "")}{(string.Join(" ", Figures))}";
     }
 }

+ 3 - 0
src/Avalonia.Visuals/Media/QuadraticBezierSegment .cs

@@ -42,5 +42,8 @@ namespace Avalonia.Media
         {
             ctx.QuadraticBezierTo(Point1, Point2);
         }
+
+        public override string ToString()
+            => $"Q {Point1} {Point2}";
     }
 }