Ejemplo n.º 1
0
        public static string ToDefinitionString(this PathF path, float ppu = 1)
        {
            var writer = new StringWriter();

            for (var i = 0; i < path.OperationCount; i++)
            {
                var type   = path.GetSegmentType(i);
                var points = path.GetPointsForSegment(i);

                if (type == PathOperation.Move)
                {
                    writer.Write("M");
                    WritePoint(writer, points[0], ppu);
                }
                else if (type == PathOperation.Line)
                {
                    writer.Write(" L");
                    WritePoint(writer, points[0], ppu);
                }
                else if (type == PathOperation.Quad)
                {
                    writer.Write(" Q");
                    WritePoint(writer, points[0], ppu);
                    writer.Write(" ");
                    WritePoint(writer, points[1], ppu);
                }
                else if (type == PathOperation.Cubic)
                {
                    writer.Write(" C");
                    WritePoint(writer, points[0], ppu);
                    writer.Write(" ");
                    WritePoint(writer, points[1], ppu);
                    writer.Write(" ");
                    WritePoint(writer, points[2], ppu);
                }
                else if (type == PathOperation.Close)
                {
                    writer.Write(" Z ");
                }
            }

            return(writer.ToString());
        }
Ejemplo n.º 2
0
        private void ArcTo(bool isRelative)
        {
            var startPoint = _relativePoint ?? default;

            var rx = NextValue;
            var ry = NextValue;

            var r            = NextValue;
            var largeArcFlag = NextBoolValue;
            var sweepFlag    = NextBoolValue;
            var endPoint     = NewPoint(NextValue, NextValue, isRelative, false);

            var arcPath = new PathF(startPoint);

            arcPath.SVGArcTo(rx, ry, r, largeArcFlag, sweepFlag, endPoint.X, endPoint.Y, startPoint.X, startPoint.Y);

            for (int s = 0; s < arcPath.OperationCount; s++)
            {
                var segmentType     = arcPath.GetSegmentType(s);
                var pointsInSegment = arcPath.GetPointsForSegment(s);

                if (segmentType == PathOperation.Move)
                {
                    // do nothing
                }
                else if (segmentType == PathOperation.Line)
                {
                    _path.LineTo(pointsInSegment[0]);
                }
                else if (segmentType == PathOperation.Cubic)
                {
                    _path.CurveTo(pointsInSegment[0], pointsInSegment[1], pointsInSegment[2]);
                }
                else if (segmentType == PathOperation.Quad)
                {
                    _path.QuadTo(pointsInSegment[0], pointsInSegment[1]);
                }
            }

            _relativePoint = _path.LastPoint;
        }