Ejemplo n.º 1
0
        /// <summary>
        /// Parses the Path-String
        /// </summary>
        /// <param name="path">the Path-String</param>
        private void Parse(string path)
        {
            PathCommandTokenizer tok = new PathCommandTokenizer(path);

            PathCommand.PathCommandType cmd = PathCommand.PathCommandType.Nothing;
            PathCommandToken[]          tmp;
            PathCommandToken            t;

            while ((t = tok.GetNextToken()) != null)
            {
                switch (t.Type)
                {
                case PathCommandSequenceToken.CommandMoveTo:
                    cmd = PathCommand.PathCommandType.MoveTo;
                    tmp = new PathCommandToken[] { tok.GetNextToken(), tok.GetNextToken() };
                    list.Add(new PathCommand(cmd, tmp));
                    break;

                case PathCommandSequenceToken.CommandLineTo:
                    cmd = PathCommand.PathCommandType.LineTo;
                    tmp = new PathCommandToken[] { tok.GetNextToken(), tok.GetNextToken() };
                    list.Add(new PathCommand(cmd, tmp));
                    break;

                case PathCommandSequenceToken.Number:
                case PathCommandSequenceToken.Formula:
                    tmp = new PathCommandToken[] { t, tok.GetNextToken() };
                    list.Add(new PathCommand(cmd, tmp));
                    break;

                case PathCommandSequenceToken.CommandClose:
                    cmd = PathCommand.PathCommandType.CloseLine;
                    list.Add(new PathCommand(cmd));
                    break;

                case PathCommandSequenceToken.CommandEnd:
                    cmd = PathCommand.PathCommandType.EndLine;
                    list.Add(new PathCommand(cmd));
                    break;
                }
            }
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Gets the next Token.
            /// </summary>
            /// <returns>the next token</returns>
            public PathCommandToken GetNextToken()
            {
                PathCommandToken ret = new PathCommandToken(PathCommandSequenceToken.Undefined, 0);
                int i;

                // we have reached the end of string
                if (pos >= eqn.Length)
                {
                    return(null);
                }

#if EXT_PARSER
                // we had to keep one token,
                // return it now
                if (carryForward != null)
                {
                    ret          = carryForward;
                    carryForward = null;
                    return(ret);
                }
#endif

                // get the next char
                switch (eqn[pos])
                {
                case '-':
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    for (i = pos; ((eqn[i] >= '0' && eqn[i] <= '9') || eqn[i] == '-') && (i < eqn.Length); i++)
                    {
                        ;
                    }
                    string str = eqn.Substring(pos, i - (pos));
                    int    tmp = (int)Convert.ToInt32(str);
                    ret = new PathCommandToken(PathCommandSequenceToken.Number, tmp);
                    pos = i;
                    break;

                case ',':
#if EXT_PARSER
                    // the extended parser for the shorter path strings
                    if (lookBack && !(lastToken == PathCommandSequenceToken.Number || lastToken == PathCommandSequenceToken.Forumla))
                    {
                        lookBack = false;
                        // insert an additional number zero (behind ',' 'm' 'l')
                        ret = new PathCommandToken(PathCommandSequenceToken.Number, 0);
                    }
                    else
                    {
                        pos++;
                        lastToken    = PathCommandSequenceToken.Separator;
                        carryForward = GetNextToken();
                        if (carryForward.Type == PathCommandSequenceToken.Number || carryForward.Type == PathCommandSequenceToken.Forumla)
                        {
                            ret          = carryForward;
                            carryForward = null;
                        }
                        else
                        {
                            // insert an additional number zero and keep carryForward (before 'm' 'l' 'e' 'x')
                            ret = new PathCommandToken(PathCommandSequenceToken.Number, 0);
                        }
                    }
                    lastToken = ret.Type;
                    break;
#endif
                case ' ':
                case '\t':
                    pos++;
                    ret = GetNextToken();

                    break;

                case 'm':
                    ret = new PathCommandToken(PathCommandSequenceToken.CommandMoveTo, 0);
                    pos++;
                    break;

                case 'l':
                    ret = new PathCommandToken(PathCommandSequenceToken.CommandLineTo, 0);
                    pos++;
                    break;

                case 'x':
                    ret = new PathCommandToken(PathCommandSequenceToken.CommandClose, 0);
                    pos++;
                    break;

                case 'e':
                    ret = new PathCommandToken(PathCommandSequenceToken.CommandEnd, 0);
                    pos++;
                    break;

                case '@':
                    pos++;
                    for (i = pos; (eqn[i] >= '0' && eqn[i] <= '9') && (i < eqn.Length); i++)
                    {
                        ;
                    }
                    ret = new PathCommandToken(PathCommandSequenceToken.Formula, Convert.ToInt32(eqn.Substring(pos, i - (pos))));
                    pos = i;
                    break;

                default:
                    break;
                }
                return(ret);
            }