Ejemplo n.º 1
0
 public Token(TokenType type, double value, PathCommandType commandType, bool commandIsAbsolute)
 {
     Type              = type;
     Value             = value;
     CommandType       = commandType;
     CommandIsAbsolute = commandIsAbsolute;
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
            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);
            }
Ejemplo n.º 5
0
 public PathCommand(PathCommandType type, bool absolute)
 {
     Type     = type;
     Absolute = absolute;
 }
Ejemplo n.º 6
0
 public PathCommandParser(string input)
 {
     Input        = input;
     CommandTypes = PathCommandType.GetAll();
 }