public Location(PointF location, PathCommandType commandType, PathLocationInfo locationInfo, bool useRelativeCoordinates) : this() { locationCore = location; pathLocationInfoCore = locationInfo; useRelativeCoordinatesCore = useRelativeCoordinates; CommandType = commandType; }
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)); } }
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); }
public PathParser(string parseString) : base(parseString) { commands = new List <PathCommand>(); currentBearing = 0; lastTangent = 0; lastValue = Double2.Zero; lastControl = Double2.Zero; lastCommand = PathCommandType.None; Parse(); }
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) { ; }
// 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 EllipticalArcArgs(PathCommandType commandType) : base(commandType) { }
public HorizontalLineToArgs(PathCommandType commandType) : base(commandType) { }
public MoveToCommandArgs(PathCommandType commandType, Location[] locations) : base(commandType) { locationsCore = locations.ToList(); }
public MoveToCommandArgs(PathCommandType commandType) : base(commandType) { locationsCore = new List <Location>(); }
public PathCommandArgs(PathCommandType commandType) { commandTypeCore = commandType; }
public Location(PathCommandType commandType, PathLocationInfo locationInfo, bool useRelativeCoordinates) : this(PointF.Empty, commandType, locationInfo, useRelativeCoordinates) { }
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); } }
public MoveToCommandArgs(PathCommandType commandType) : base(commandType) { locationsCore = new List<Location>(); }
public MoveToCommandArgs(PathCommandType commandType, Location[] locations, PathLocationInfo pathLocationInfo) : base(commandType) { locationsCore = locations.ToList(); PathLocationInfo = pathLocationInfo; }
public VerticalLineToArgs(PathCommandType commandType) : base(commandType) { }
protected PathCommand(PathCommandType type) { this.Type = type; }
/// <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; }