Browse Source

Path properly parse Arc implemented - issue #354

pull/356/head
donandren 10 years ago
parent
commit
05da19937f
  1. 39
      src/Perspex.SceneGraph/Media/PathMarkupParser.cs

39
src/Perspex.SceneGraph/Media/PathMarkupParser.cs

@ -28,6 +28,8 @@ namespace Perspex.Media
{ 'v', Command.VerticalLineRelative }, { 'v', Command.VerticalLineRelative },
{ 'C', Command.CubicBezierCurve }, { 'C', Command.CubicBezierCurve },
{ 'c', Command.CubicBezierCurveRelative }, { 'c', Command.CubicBezierCurveRelative },
{ 'A', Command.Arc },
{ 'a', Command.Arc },
{ 'Z', Command.Close }, { 'Z', Command.Close },
{ 'z', Command.Close }, { 'z', Command.Close },
}; };
@ -64,6 +66,7 @@ namespace Perspex.Media
VerticalLineRelative, VerticalLineRelative,
CubicBezierCurve, CubicBezierCurve,
CubicBezierCurveRelative, CubicBezierCurveRelative,
Arc,
Close, Close,
Eof, Eof,
} }
@ -98,8 +101,8 @@ namespace Perspex.Media
_context.EndFigure(false); _context.EndFigure(false);
} }
point = command == Command.Move ? point = command == Command.Move ?
ReadPoint(reader) : ReadPoint(reader) :
ReadRelativePoint(reader, point); ReadRelativePoint(reader, point);
_context.BeginFigure(point, true); _context.BeginFigure(point, true);
@ -144,6 +147,22 @@ namespace Perspex.Media
_context.CubicBezierTo(point1, point2, point); _context.CubicBezierTo(point1, point2, point);
break; 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: case Command.Close:
_context.EndFigure(true); _context.EndFigure(true);
@ -244,6 +263,20 @@ namespace Perspex.Media
return new Point(x, y); 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) private static Point ReadRelativePoint(StringReader reader, Point lastPoint)
{ {
ReadWhitespace(reader); ReadWhitespace(reader);
@ -302,4 +335,4 @@ namespace Perspex.Media
} }
} }
} }
} }
Loading…
Cancel
Save