From 05da19937f259dd3151fa3cb49b685bc2cab150d Mon Sep 17 00:00:00 2001 From: donandren Date: Wed, 9 Dec 2015 20:34:15 +0200 Subject: [PATCH] Path properly parse Arc implemented - issue #354 --- .../Media/PathMarkupParser.cs | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Perspex.SceneGraph/Media/PathMarkupParser.cs b/src/Perspex.SceneGraph/Media/PathMarkupParser.cs index 0caa53dc7c..17539c924b 100644 --- a/src/Perspex.SceneGraph/Media/PathMarkupParser.cs +++ b/src/Perspex.SceneGraph/Media/PathMarkupParser.cs @@ -28,6 +28,8 @@ namespace Perspex.Media { 'v', Command.VerticalLineRelative }, { 'C', Command.CubicBezierCurve }, { 'c', Command.CubicBezierCurveRelative }, + { 'A', Command.Arc }, + { 'a', Command.Arc }, { 'Z', Command.Close }, { 'z', Command.Close }, }; @@ -64,6 +66,7 @@ namespace Perspex.Media VerticalLineRelative, CubicBezierCurve, CubicBezierCurveRelative, + Arc, Close, Eof, } @@ -98,8 +101,8 @@ namespace Perspex.Media _context.EndFigure(false); } - point = command == Command.Move ? - ReadPoint(reader) : + point = command == Command.Move ? + ReadPoint(reader) : ReadRelativePoint(reader, point); _context.BeginFigure(point, true); @@ -144,6 +147,22 @@ namespace Perspex.Media _context.CubicBezierTo(point1, point2, point); break; } + case Command.Arc: + { + //example: A10,10 0 0,0 10,20 + //format - size rotationAngle isLargeArcFlag sweepDirectionFlag endPoint + Size size = ReadSize(reader); + ReadSeparator(reader); + double rotationAngle = ReadDouble(reader); + ReadSeparator(reader); + bool isLargeArc = ReadBool(reader); + ReadSeparator(reader); + SweepDirection sweepDirection = ReadBool(reader) ? SweepDirection.Clockwise : SweepDirection.CounterClockwise; + point = ReadPoint(reader); + + _context.ArcTo(point, size, rotationAngle, isLargeArc, sweepDirection); + break; + } case Command.Close: _context.EndFigure(true); @@ -244,6 +263,20 @@ namespace Perspex.Media return new Point(x, y); } + private static Size ReadSize(StringReader reader) + { + ReadWhitespace(reader); + double x = ReadDouble(reader); + ReadSeparator(reader); + double y = ReadDouble(reader); + return new Size(x, y); + } + + private static bool ReadBool(StringReader reader) + { + return ReadDouble(reader) != 0; + } + private static Point ReadRelativePoint(StringReader reader, Point lastPoint) { ReadWhitespace(reader); @@ -302,4 +335,4 @@ namespace Perspex.Media } } } -} +} \ No newline at end of file