public Token(TokenType type, double value, PathCommandType commandType, bool commandIsAbsolute) { Type = type; Value = value; CommandType = commandType; CommandIsAbsolute = commandIsAbsolute; }
private Token CreateToken(List <char> chars, TokenType tokenType) { if (tokenType == TokenType.Command) { PathCommandType commandType = null; if (chars.Count != 1 || (commandType = CommandTypes.SingleOrDefault(n => char.ToLower(n.Character) == char.ToLower(chars[0]))) == null) { ThrowFormatException(); } return(new Token(TokenType.Command, 0, commandType, char.IsUpper(chars[0]))); } if (tokenType == TokenType.Seperator) { return(new Token(TokenType.Seperator, 0, null, false)); } if (tokenType == TokenType.Value) { double value; if (!double.TryParse(new string(chars.ToArray()), out value)) { ThrowFormatException(); } return(new Token(TokenType.Value, value, null, false)); } ThrowFormatException(); return(null); }
static PathCommandType() { LineTo = new PathCommandType('L', 2, typeof(LineCommand)); MoveTo = new PathCommandType('M', 2, typeof(MoveCommand)); HorizontalLineTo = new PathCommandType('H', 1, typeof(HorizontalLineCommand)); VerticalLineTo = new PathCommandType('V', 1, typeof(VerticalLineCommand)); ClosePath = new PathCommandType('Z', 0, typeof(ClosePathCommand)); CircleTo = new PathCommandType('C', 6, typeof(CircleCommand)); SmoothCircleTo = new PathCommandType('S', 4, typeof(SmoothCircleCommand)); QuadricCurve = new PathCommandType('Q', 4, typeof(QuadricCurveCommand)); SmoothQuadricCurve = new PathCommandType('T', 2, typeof(SmoothQuadricCurveCommand)); Arc = new PathCommandType('A', 7, typeof(ArcCommand)); MoveTo.ImplicitNextType = LineTo; }
private PathCommand CreateCommand(PathCommandType type, List <double> values, bool absolute) { if (values.Count < type.ParameterCount) { ThrowFormatException(); } var commandType = type.CommandType; var constructor = commandType.GetConstructors().FirstOrDefault(); var parameterTypes = constructor.GetParameters(); var parameters = new object[parameterTypes.Length]; for (int i = 0; i < parameters.Length; i++) { object value; if (parameterTypes[i].Name == "absolute") { value = absolute; } else if (parameterTypes[i].ParameterType.Name == "Boolean") { value = values[i] == 1; } else { value = values[i]; } parameters[i] = value; } var command = (PathCommand)constructor.Invoke(parameters); if (values.Count > type.ParameterCount) { if (type.ImplicitNextType == null) { ThrowFormatException(); } var next = CreateCommand(type.ImplicitNextType, values.Skip(type.ParameterCount).ToList(), absolute); command.AppendNext(next); } return(command); }
public PathCommand(PathCommandType type, bool absolute) { Type = type; Absolute = absolute; }
public PathCommandParser(string input) { Input = input; CommandTypes = PathCommandType.GetAll(); }