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 },
{ '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
}
}
}
}
}
Loading…
Cancel
Save