示例#1
0
 public Location(PointF location, PathCommandType commandType, PathLocationInfo locationInfo, bool useRelativeCoordinates) : this()
 {
     locationCore               = location;
     pathLocationInfoCore       = locationInfo;
     useRelativeCoordinatesCore = useRelativeCoordinates;
     CommandType = commandType;
 }
示例#2
0
        static PathCommandArgs CreateInstance(PathCommandType commandType)
        {
            switch (commandType)
            {
            case PathCommandType.MoveTo: return(new MoveToCommandArgs(commandType));

            case PathCommandType.LineTo: return(new MoveToCommandArgs(commandType));

            case PathCommandType.HorizontalLineTo: return(new HorizontalLineToArgs(commandType));

            case PathCommandType.VerticalLineTo: return(new VerticalLineToArgs(commandType));

            case PathCommandType.CurveTo: return(new MoveToCommandArgs(commandType));

            case PathCommandType.SmoothCurveTo: return(new MoveToCommandArgs(commandType));

            case PathCommandType.QuadraticCurveTo: return(new MoveToCommandArgs(commandType));

            case PathCommandType.SmoothQuadraticCurveTo: return(new MoveToCommandArgs(commandType));

            case PathCommandType.EllipticalArc: return(new EllipticalArcArgs(commandType));

            default: return(new PathCommandArgs(commandType));
            }
        }
示例#3
0
        public static PathCommandArgs Parse(PathCommandType commandType, string sequence, PathLocationInfo pathLocationInfo = null)
        {
            PathCommandArgs commandArgs = CreateInstance(commandType);

            commandArgs.PathLocationInfo       = pathLocationInfo;
            commandArgs.UseRelativeCoordinates = Char.IsLower(sequence.First());
            commandArgs.ParseCore(sequence.Substring(1), pathLocationInfo);
            return(commandArgs);
        }
示例#4
0
        public PathParser(string parseString) : base(parseString)
        {
            commands       = new List <PathCommand>();
            currentBearing = 0;
            lastTangent    = 0;

            lastValue   = Double2.Zero;
            lastControl = Double2.Zero;
            lastCommand = PathCommandType.None;

            Parse();
        }
示例#5
0
 public static PathCommandArgs Parse(PathCommandType commandType, string sequence, PathLocationInfo pathLocationInfo = null) {
     PathCommandArgs commandArgs = CreateInstance(commandType);
     commandArgs.PathLocationInfo = pathLocationInfo;
     commandArgs.UseRelativeCoordinates = Char.IsLower(sequence.First());
     commandArgs.ParseCore(sequence.Substring(1), pathLocationInfo);
     return commandArgs;
 }
 /// <summary>
 /// Creates a new PathCommand without Parameters
 /// </summary>
 /// <param name="Cmd">the PathComandType</param>
 public PathCommand(PathCommandType Cmd)
     : this(Cmd, null)
 {
     ;
 }
示例#7
0
        // Main parse loop
        void Parse()
        {
            // Use an exception to break out the loop
            try
            {
                bool isfirst = true;

                while (true)
                {
                    // Pick the command list
                    var cmd = ParseCommand(out var relative);

                    // First command MUST be a moveto
                    if (isfirst && cmd != 'M')
                    {
                        throw new ParserException($"First path command MUST be a moveto! Error at position {index}.");
                    }

                    // Moveto command
                    if (cmd == 'M')
                    {
                        bool first   = true;
                        bool onlyone = true;

                        foreach (var vs in DelimitedPositionTuple(1))
                        {
                            onlyone = first;

                            var lpos = lastValue;
                            var pos  = ProcessRelative(vs[0], relative);
                            commands.Add(first ? PathCommand.MoveTo(pos) : PathCommand.LineTo(pos));
                            lastControl = pos;
                            lastTangent = first ? 0 : lpos.AngleFacing(pos);

                            first = false;
                        }

                        lastCommand = onlyone ? PathCommandType.MoveTo : PathCommandType.LineTo;
                    }
                    // Lineto command
                    else if (cmd == 'L')
                    {
                        foreach (var vs in DelimitedPositionTuple(1))
                        {
                            var lpos = lastValue;
                            var pos  = ProcessRelative(vs[0], relative);
                            commands.Add(PathCommand.LineTo(pos));
                            lastTangent = lpos.AngleFacing(pos);
                            lastControl = pos;
                        }

                        lastCommand = PathCommandType.LineTo;
                    }
                    // Horizontal lineto command
                    else if (cmd == 'H')
                    {
                        foreach (var h in DelimitedSequence())
                        {
                            var lpos = lastValue;
                            var v    = relative ? 0 : lpos.Y;
                            var pos  = ProcessRelative(new Double2(h, v), relative);
                            commands.Add(PathCommand.LineTo(pos));
                            lastTangent = lpos.AngleFacing(pos);
                            lastControl = pos;
                        }

                        lastCommand = PathCommandType.LineTo;
                    }
                    // Vertical lineto command
                    else if (cmd == 'V')
                    {
                        foreach (var v in DelimitedSequence())
                        {
                            var lpos = lastValue;
                            var h    = relative ? 0 : lpos.X;
                            var pos  = ProcessRelative(new Double2(h, v), relative);
                            commands.Add(PathCommand.LineTo(pos));
                            lastTangent = lpos.AngleFacing(pos);
                            lastControl = pos;
                        }

                        lastCommand = PathCommandType.LineTo;
                    }
                    // Quadratic bezier command
                    else if (cmd == 'Q')
                    {
                        foreach (var vs in DelimitedPositionTuple(2))
                        {
                            var ctl = ProcessRelative(vs[0], relative, false);
                            var pos = ProcessRelative(vs[1], relative);
                            commands.Add(PathCommand.QuadraticCurveTo(ctl, pos));
                            lastTangent = ctl.AngleFacing(pos);
                            lastControl = ctl;
                        }

                        lastCommand = PathCommandType.QuadraticCurveTo;
                    }
                    // Smooth quadratic bezier command
                    else if (cmd == 'T')
                    {
                        foreach (var vs in DelimitedPositionTuple(1))
                        {
                            var lpos = lastValue;
                            var lctl = lastCommand == PathCommandType.QuadraticCurveTo ? lastControl : lastValue;
                            var ctl  = 2 * lpos - lctl;
                            var pos  = ProcessRelative(vs[0], relative);
                            commands.Add(PathCommand.QuadraticCurveTo(ctl, pos));
                            lastTangent = ctl.AngleFacing(pos);
                        }

                        lastCommand = PathCommandType.QuadraticCurveTo;
                    }
                    // Cubic bezier command
                    else if (cmd == 'C')
                    {
                        foreach (var vs in DelimitedPositionTuple(3))
                        {
                            var ctl  = ProcessRelative(vs[0], relative, false);
                            var ctl2 = ProcessRelative(vs[1], relative, false);
                            var pos  = ProcessRelative(vs[2], relative);
                            commands.Add(PathCommand.CubicCurveTo(ctl, ctl2, pos));
                            lastTangent = ctl2.AngleFacing(pos);
                            lastControl = ctl2;
                        }

                        lastCommand = PathCommandType.CubicCurveTo;
                    }
                    // Smooth cubic bezier command
                    else if (cmd == 'S')
                    {
                        foreach (var vs in DelimitedPositionTuple(2))
                        {
                            var lpos = lastValue;
                            var lctl = lastCommand == PathCommandType.CubicCurveTo ? lastControl : lastValue;
                            var ctl  = 2 * lpos - lctl;
                            var ctl2 = ProcessRelative(vs[0], relative, false);
                            var pos  = ProcessRelative(vs[1], relative);
                            commands.Add(PathCommand.CubicCurveTo(ctl, ctl2, pos));
                            lastTangent = ctl.AngleFacing(pos);
                            lastControl = ctl2;
                        }

                        lastCommand = PathCommandType.CubicCurveTo;
                    }
                    // Arc command
                    else if (cmd == 'A')
                    {
                        double ThrowF() => throw new ParserException($"Invalid parameter passed to arc command at position {index}.");
                        bool ThrowB() => ThrowF() == 0;

                        // Pick parameters
                        while (true)
                        {
                            // If there isn't a next double, end the command
                            var next = ParseDouble();
                            if (!next.HasValue)
                            {
                                break;
                            }

                            // Pick the doubles and flags in order
                            var rx = next.Value;
                            SkipWhitespaceAndDelimiters();
                            var ry = ParseDouble() ?? ThrowF();
                            SkipWhitespaceAndDelimiters();
                            var rAngle = ParseDouble() ?? ThrowF();
                            SkipWhitespaceAndDelimiters();
                            var largeArc = ParseFlag() ?? ThrowB();
                            SkipWhitespaceAndDelimiters();
                            var sweep = ParseFlag() ?? ThrowB();

                            Double2 target;
                            // Check if the target isn't a premature closepath
                            next = ParseDouble();
                            SkipWhitespaceAndDelimiters();
                            if (!next.HasValue)
                            {
                                if (parseString[index] == 'z' || parseString[index] == 'Z')
                                {
                                    target = new Double2(double.NaN, double.NaN);
                                }
                                else
                                {
                                    ThrowF();
                                }
                            }

                            // Assign the target
                            target.X = next.Value;
                            target.Y = ParseDouble() ?? ThrowF();

                            // Adjust for relative
                            rAngle = (rAngle.ToRadians() + (relative ? currentBearing : 0)).WrapAngle();
                            target = ProcessRelative(target, relative);

                            // Add the command
                            commands.Add(PathCommand.ArcTo(new Double2(rx, ry), rAngle, largeArc, sweep, target));
                        }
                    }
                    // Bearing command
                    else if (cmd == 'B')
                    {
                        if (!relative)
                        {
                            currentBearing = DelimitedSequence().Last().ToRadians();
                        }
                        else
                        {
                            currentBearing += DelimitedSequence().Sum().ToRadians();
                        }

                        lastCommand = PathCommandType.None;
                    }
                    // Complete closepath command
                    else if (cmd == 'Z')
                    {
                        commands.Add(PathCommand.ClosePath());
                        lastCommand = PathCommandType.ClosePath;
                    }
                    // Unknown command
                    else
                    {
                        throw new ParserException($"Unrecognized command at position {index-1}.");
                    }

                    isfirst = false;
                }
            }
            catch (EndParseException)
            {
                // The expression says it
            }
        }
 public Location(PointF location, PathCommandType commandType, PathLocationInfo locationInfo, bool useRelativeCoordinates) : this() {
     locationCore = location;
     pathLocationInfoCore = locationInfo;
     useRelativeCoordinatesCore = useRelativeCoordinates;
     CommandType = commandType;
 }
示例#9
0
 public EllipticalArcArgs(PathCommandType commandType) : base(commandType) { }
示例#10
0
 public HorizontalLineToArgs(PathCommandType commandType) : base(commandType) { }
示例#11
0
 public MoveToCommandArgs(PathCommandType commandType, Location[] locations) : base(commandType) {
     locationsCore = locations.ToList();
 }
示例#12
0
 public MoveToCommandArgs(PathCommandType commandType) : base(commandType)
 {
     locationsCore = new List <Location>();
 }
示例#13
0
 public PathCommandArgs(PathCommandType commandType)
 {
     commandTypeCore = commandType;
 }
示例#14
0
 public Location(PathCommandType commandType, PathLocationInfo locationInfo, bool useRelativeCoordinates) : this(PointF.Empty, commandType, locationInfo, useRelativeCoordinates)
 {
 }
示例#15
0
 static PathCommandArgs CreateInstance(PathCommandType commandType) {
     switch(commandType) {
         case PathCommandType.MoveTo: return new MoveToCommandArgs(commandType);
         case PathCommandType.LineTo: return new MoveToCommandArgs(commandType);
         case PathCommandType.HorizontalLineTo: return new HorizontalLineToArgs(commandType);
         case PathCommandType.VerticalLineTo: return new VerticalLineToArgs(commandType);
         case PathCommandType.CurveTo: return new MoveToCommandArgs(commandType);
         case PathCommandType.SmoothCurveTo: return new MoveToCommandArgs(commandType);
         case PathCommandType.QuadraticCurveTo: return new MoveToCommandArgs(commandType);
         case PathCommandType.SmoothQuadraticCurveTo: return new MoveToCommandArgs(commandType);
         case PathCommandType.EllipticalArc: return new EllipticalArcArgs(commandType);
         default: return new PathCommandArgs(commandType);
     }
 }
示例#16
0
 public MoveToCommandArgs(PathCommandType commandType) : base(commandType) {
     locationsCore = new List<Location>();
 }
示例#17
0
 public MoveToCommandArgs(PathCommandType commandType, Location[] locations) : base(commandType)
 {
     locationsCore = locations.ToList();
 }
示例#18
0
 public MoveToCommandArgs(PathCommandType commandType, Location[] locations, PathLocationInfo pathLocationInfo) : base(commandType) {
     locationsCore = locations.ToList();
     PathLocationInfo = pathLocationInfo;
 }
示例#19
0
 public MoveToCommandArgs(PathCommandType commandType, Location[] locations, PathLocationInfo pathLocationInfo) : base(commandType)
 {
     locationsCore    = locations.ToList();
     PathLocationInfo = pathLocationInfo;
 }
示例#20
0
 public VerticalLineToArgs(PathCommandType commandType) : base(commandType) { }
示例#21
0
 public HorizontalLineToArgs(PathCommandType commandType) : base(commandType)
 {
 }
示例#22
0
 protected PathCommand(PathCommandType type)
 {
     this.Type = type;
 }
示例#23
0
 public VerticalLineToArgs(PathCommandType commandType) : base(commandType)
 {
 }
 public Location(PathCommandType commandType, PathLocationInfo locationInfo, bool useRelativeCoordinates) : this(PointF.Empty, commandType, locationInfo, useRelativeCoordinates) {
 }
示例#25
0
 public EllipticalArcArgs(PathCommandType commandType) : base(commandType)
 {
 }
示例#26
0
 public PathCommandArgs(PathCommandType commandType) {
     commandTypeCore = commandType;
 }
示例#27
0
 /// <summary>
 /// Creates a new PahtCommand with Parameters
 /// </summary>
 /// <param name="Cmd">the PathCommandType</param>
 /// <param name="Param">the Array of PathCommandToken</param>
 public PathCommand(PathCommandType Cmd, PathCommandToken[] Param)
 {
     cmd   = Cmd;
     param = Param;
 }