예제 #1
0
        void parse_poly(string[] attr, bool close_flag)
        {
            int    i;
            double x = 0.0;
            double y = 0.0;

            m_SVGPath.begin_path();
            for (i = 0; attr[i] != null; i += 2)
            {
                if (!parse_attr(attr[i], attr[i + 1]))
                {
                    if (string.Equals(attr[i], "points"))
                    {
                        m_SVGPathTokenizer.set_path_str(attr[i + 1]);
                        if (!m_SVGPathTokenizer.next())
                        {
                            throw new SVGException("parse_poly: Too few coordinates");
                        }
                        x = m_SVGPathTokenizer.last_number();
                        if (!m_SVGPathTokenizer.next())
                        {
                            throw new SVGException("parse_poly: Too few coordinates");
                        }
                        y = m_SVGPathTokenizer.last_number();
                        m_SVGPath.MoveTo(x, y);
                        while (m_SVGPathTokenizer.next())
                        {
                            x = m_SVGPathTokenizer.last_number();
                            if (!m_SVGPathTokenizer.next())
                            {
                                throw new SVGException("parse_poly: Odd number of coordinates");
                            }
                            y = m_SVGPathTokenizer.last_number();
                            m_SVGPath.LineTo(x, y);
                        }
                    }
                }
            }

            if (close_flag)
            {
                m_SVGPath.CloseSubPath();
            }

            m_SVGPath.end_path();
        }
예제 #2
0
        public void parse_path(SVGPathTokenizer tok)
        {
            while (tok.next())
            {
                double[] arg = new double[10];
                int      cmd = tok.last_command();
                int      i;
                switch (cmd)
                {
                case 'M':
                case 'm':
                    arg[0] = tok.last_number();
                    arg[1] = tok.next(cmd);
                    MoveTo(arg[0], arg[1], cmd == 'm');
                    break;

                case 'L':
                case 'l':
                    arg[0] = tok.last_number();
                    arg[1] = tok.next(cmd);
                    LineTo(arg[0], arg[1], cmd == 'l');
                    break;

                case 'V':
                case 'v':
                    vline_to(tok.last_number(), cmd == 'v');
                    break;

                case 'H':
                case 'h':
                    hline_to(tok.last_number(), cmd == 'h');
                    break;

                case 'Q':
                case 'q':
                    arg[0] = tok.last_number();
                    for (i = 1; i < 4; i++)
                    {
                        arg[i] = tok.next(cmd);
                    }
                    Curve3(arg[0], arg[1], arg[2], arg[3], cmd == 'q');
                    break;

                case 'T':
                case 't':
                    arg[0] = tok.last_number();
                    arg[1] = tok.next(cmd);
                    Curve3(arg[0], arg[1], cmd == 't');
                    break;

                case 'C':
                case 'c':
                    arg[0] = tok.last_number();
                    for (i = 1; i < 6; i++)
                    {
                        arg[i] = tok.next(cmd);
                    }
                    Curve4(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], cmd == 'c');
                    break;

                case 'S':
                case 's':
                    arg[0] = tok.last_number();
                    for (i = 1; i < 4; i++)
                    {
                        arg[i] = tok.next(cmd);
                    }
                    Curve4(arg[0], arg[1], arg[2], arg[3], cmd == 's');
                    break;

                case 'A':
                case 'a':
                    throw new SVGException("parse_path: Command A: NOT IMPLEMENTED YET");

                case 'Z':
                case 'z':
                    CloseSubPath();
                    break;

                default:
                {
                    throw new SVGException("parse_path: Invalid Command %c", cmd);
                }
                }
            }
        }