Beispiel #1
0
        public override string ToString()
        {
            PathSeg prev    = null;
            var     builder = new System.Text.StringBuilder();

            foreach (PathSeg seg in _path)
            {
                if (prev == null || (prev.Type != seg.Type || prev.Abs != seg.Abs))
                {
                    builder.Append(seg.Char).Append(" ");
                }
                foreach (float d in seg.Data)
                {
                    builder.Append(d.ToString(CultureInfo.InvariantCulture)).Append(" ");
                }
                prev = seg;
            }
            return(builder.ToString());
        }
Beispiel #2
0
        public override string ToString()
        {
            PathSeg pathSeg = null;
            string  text    = "";

            foreach (PathSeg pathSeg2 in this._path)
            {
                if (pathSeg == null || pathSeg.Type != pathSeg2.Type || pathSeg.Abs != pathSeg2.Abs)
                {
                    text += pathSeg2.Char;
                    text += " ";
                }
                float[] data = pathSeg2.Data;
                for (int i = 0; i < data.Length; i++)
                {
                    text += data[i].ToString();
                    text += " ";
                }
                pathSeg = pathSeg2;
            }
            return(text);
        }
Beispiel #3
0
        public override string ToString()
        {
            PathSeg prev = null;
            string  s    = "";

            foreach (PathSeg seg in _path)
            {
                if (prev == null || (prev.Type != seg.Type || prev.Abs != seg.Abs))
                {
                    s += seg.Char;
                    s += " ";
                }

                foreach (float d in seg.Data)
                {
                    s += d.ToString();
                    s += " ";
                }

                prev = seg;
            }

            return(s);
        }
Beispiel #4
0
        /// <summary>
        /// The parsing of the path is not completely perfect yet.  You can only have one space between path elements.
        /// </summary>
        /// <param name="s"></param>
        public void FromString(string s)
        {
            string[] sa = s.Split(new char[] { ' ', ',', '\t', '\r', '\n' });

            PathSeg ps;
            int datasize = 0;
            SvgPathSegType pt = SvgPathSegType.SVG_SEGTYPE_UNKNOWN;
            bool abs = false;
            int i = 0;
            char segTypeChar;
            _path = new ArrayList();

            while (i < sa.Length) {
                if (sa[i] == "") {
                    i += 1;
                    continue;
                }

                //check for a segment-type character

                if (char.IsLetter(sa[i][0])) {
                    segTypeChar = sa[i][0];

                    if (segTypeChar == 'M' || segTypeChar == 'm') {
                        pt = SvgPathSegType.SVG_SEGTYPE_MOVETO;
                        abs = (segTypeChar == 'M');
                        datasize = 2;
                    } else if (segTypeChar == 'Z' || segTypeChar == 'z') {
                        pt = SvgPathSegType.SVG_SEGTYPE_CLOSEPATH;
                        datasize = 0;
                    } else if (segTypeChar == 'L' || segTypeChar == 'l') {
                        pt = SvgPathSegType.SVG_SEGTYPE_LINETO;
                        abs = (segTypeChar == 'L');
                        datasize = 2;
                    } else if (segTypeChar == 'H' || segTypeChar == 'h') {
                        pt = SvgPathSegType.SVG_SEGTYPE_HLINETO;
                        abs = (segTypeChar == 'H');
                        datasize = 1;
                    } else if (segTypeChar == 'V' || segTypeChar == 'v') {
                        pt = SvgPathSegType.SVG_SEGTYPE_VLINETO;
                        abs = (segTypeChar == 'V');
                        datasize = 1;
                    } else if (segTypeChar == 'C' || segTypeChar == 'c') {
                        pt = SvgPathSegType.SVG_SEGTYPE_CURVETO;
                        abs = (segTypeChar == 'C');
                        datasize = 6;
                    } else if (segTypeChar == 'S' || segTypeChar == 's') {
                        pt = SvgPathSegType.SVG_SEGTYPE_SMOOTHCURVETO;
                        abs = (segTypeChar == 'S');
                        datasize = 4;
                    } else if (segTypeChar == 'Q' || segTypeChar == 'q') {
                        pt = SvgPathSegType.SVG_SEGTYPE_BEZIERTO;
                        abs = (segTypeChar == 'Q');
                        datasize = 4;
                    } else if (segTypeChar == 'T' || segTypeChar == 't') {
                        pt = SvgPathSegType.SVG_SEGTYPE_SMOOTHBEZIERTO;
                        abs = (segTypeChar == 'T');
                        datasize = 2;
                    } else if (segTypeChar == 'A' || segTypeChar == 'a') {
                        pt = SvgPathSegType.SVG_SEGTYPE_ARCTO;
                        abs = (segTypeChar == 'A');
                        datasize = 7;
                    } else {
                        throw new SvgException("Invalid SvgPath", s);
                    }

                    //strip off type character
                    sa[i] = sa[i].Substring(1);

                    if (sa[i] == "")
                        i += 1;
                }

                if (pt == SvgPathSegType.SVG_SEGTYPE_UNKNOWN)
                    throw new SvgException("Invalid SvgPath", s);

                float[] arr = new float[datasize];

                for (int j = 0; j < datasize; ++j) {
                    arr[j] = float.Parse(sa[i + j]);
                }

                ps = new PathSeg(pt, abs, arr);

                _path.Add(ps);

                i += datasize;
            }
        }
Beispiel #5
0
        /// <summary>
        /// The parsing of the path is not completely perfect yet.  You can only have one space between path elements.
        /// </summary>
        /// <param name="s"></param>
        public void FromString(string s)
        {
            var sa = s.Split(new char[] { ' ', ',', '\t', '\r', '\n' });

            PathSeg ps;
            var     datasize = 0;
            var     pt       = SvgPathSegType.SVG_SEGTYPE_UNKNOWN;
            var     abs      = false;
            var     i        = 0;
            char    segTypeChar;

            _path = new ArrayList();

            while (i < sa.Length)
            {
                if (sa[i] == "")
                {
                    i += 1;
                    continue;
                }

                //check for a segment-type character

                if (char.IsLetter(sa[i][0]))
                {
                    segTypeChar = sa[i][0];

                    if (segTypeChar == 'M' || segTypeChar == 'm')
                    {
                        pt       = SvgPathSegType.SVG_SEGTYPE_MOVETO;
                        abs      = (segTypeChar == 'M');
                        datasize = 2;
                    }
                    else if (segTypeChar == 'Z' || segTypeChar == 'z')
                    {
                        pt       = SvgPathSegType.SVG_SEGTYPE_CLOSEPATH;
                        datasize = 0;
                    }
                    else if (segTypeChar == 'L' || segTypeChar == 'l')
                    {
                        pt       = SvgPathSegType.SVG_SEGTYPE_LINETO;
                        abs      = (segTypeChar == 'L');
                        datasize = 2;
                    }
                    else if (segTypeChar == 'H' || segTypeChar == 'h')
                    {
                        pt       = SvgPathSegType.SVG_SEGTYPE_HLINETO;
                        abs      = (segTypeChar == 'H');
                        datasize = 1;
                    }
                    else if (segTypeChar == 'V' || segTypeChar == 'v')
                    {
                        pt       = SvgPathSegType.SVG_SEGTYPE_VLINETO;
                        abs      = (segTypeChar == 'V');
                        datasize = 1;
                    }
                    else if (segTypeChar == 'C' || segTypeChar == 'c')
                    {
                        pt       = SvgPathSegType.SVG_SEGTYPE_CURVETO;
                        abs      = (segTypeChar == 'C');
                        datasize = 6;
                    }
                    else if (segTypeChar == 'S' || segTypeChar == 's')
                    {
                        pt       = SvgPathSegType.SVG_SEGTYPE_SMOOTHCURVETO;
                        abs      = (segTypeChar == 'S');
                        datasize = 4;
                    }
                    else if (segTypeChar == 'Q' || segTypeChar == 'q')
                    {
                        pt       = SvgPathSegType.SVG_SEGTYPE_BEZIERTO;
                        abs      = (segTypeChar == 'Q');
                        datasize = 4;
                    }
                    else if (segTypeChar == 'T' || segTypeChar == 't')
                    {
                        pt       = SvgPathSegType.SVG_SEGTYPE_SMOOTHBEZIERTO;
                        abs      = (segTypeChar == 'T');
                        datasize = 2;
                    }
                    else if (segTypeChar == 'A' || segTypeChar == 'a')
                    {
                        pt       = SvgPathSegType.SVG_SEGTYPE_ARCTO;
                        abs      = (segTypeChar == 'A');
                        datasize = 7;
                    }
                    else
                    {
                        throw new SvgException("Invalid SvgPath", s);
                    }

                    //strip off type character
                    sa[i] = sa[i].Substring(1);

                    if (sa[i] == "")
                    {
                        i += 1;
                    }
                }

                if (pt == SvgPathSegType.SVG_SEGTYPE_UNKNOWN)
                {
                    throw new SvgException("Invalid SvgPath", s);
                }

                var arr = new float[datasize];

                for (int j = 0; j < datasize; ++j)
                {
                    arr[j] = float.Parse(sa[i + j], CultureInfo.InvariantCulture);
                }

                ps = new PathSeg(pt, abs, arr);

                _path.Add(ps);

                i += datasize;
            }
        }
Beispiel #6
0
        public void FromString(string s)
        {
            string[] array = s.Split(new char[]
            {
                ' ',
                ',',
                '\t',
                '\r',
                '\n'
            });
            int            num            = 0;
            SvgPathSegType svgPathSegType = SvgPathSegType.SVG_SEGTYPE_UNKNOWN;
            bool           a = false;
            int            i = 0;

            this._path = new ArrayList();
            while (i < array.Length)
            {
                if (array[i] == "")
                {
                    i++;
                }
                else
                {
                    if (char.IsLetter(array[i][0]))
                    {
                        char c = array[i][0];
                        if (c == 'M' || c == 'm')
                        {
                            svgPathSegType = SvgPathSegType.SVG_SEGTYPE_MOVETO;
                            a   = (c == 'M');
                            num = 2;
                        }
                        else if (c == 'Z' || c == 'z')
                        {
                            svgPathSegType = SvgPathSegType.SVG_SEGTYPE_CLOSEPATH;
                            num            = 0;
                        }
                        else if (c == 'L' || c == 'l')
                        {
                            svgPathSegType = SvgPathSegType.SVG_SEGTYPE_LINETO;
                            a   = (c == 'L');
                            num = 2;
                        }
                        else if (c == 'H' || c == 'h')
                        {
                            svgPathSegType = SvgPathSegType.SVG_SEGTYPE_HLINETO;
                            a   = (c == 'H');
                            num = 1;
                        }
                        else if (c == 'V' || c == 'v')
                        {
                            svgPathSegType = SvgPathSegType.SVG_SEGTYPE_VLINETO;
                            a   = (c == 'V');
                            num = 1;
                        }
                        else if (c == 'C' || c == 'c')
                        {
                            svgPathSegType = SvgPathSegType.SVG_SEGTYPE_CURVETO;
                            a   = (c == 'C');
                            num = 6;
                        }
                        else if (c == 'S' || c == 's')
                        {
                            svgPathSegType = SvgPathSegType.SVG_SEGTYPE_SMOOTHCURVETO;
                            a   = (c == 'S');
                            num = 4;
                        }
                        else if (c == 'Q' || c == 'q')
                        {
                            svgPathSegType = SvgPathSegType.SVG_SEGTYPE_BEZIERTO;
                            a   = (c == 'Q');
                            num = 4;
                        }
                        else if (c == 'T' || c == 't')
                        {
                            svgPathSegType = SvgPathSegType.SVG_SEGTYPE_SMOOTHBEZIERTO;
                            a   = (c == 'T');
                            num = 2;
                        }
                        else
                        {
                            if (c != 'A' && c != 'a')
                            {
                                throw new SvgException("Invalid SvgPath", s);
                            }
                            svgPathSegType = SvgPathSegType.SVG_SEGTYPE_ARCTO;
                            a   = (c == 'A');
                            num = 7;
                        }
                        array[i] = array[i].Substring(1);
                        if (array[i] == "")
                        {
                            i++;
                        }
                    }
                    if (svgPathSegType == SvgPathSegType.SVG_SEGTYPE_UNKNOWN)
                    {
                        throw new SvgException("Invalid SvgPath", s);
                    }
                    float[] array2 = new float[num];
                    for (int j = 0; j < num; j++)
                    {
                        array2[j] = float.Parse(array[i + j], CultureInfo.InvariantCulture);
                    }
                    PathSeg value = new PathSeg(svgPathSegType, a, array2);
                    this._path.Add(value);
                    i += num;
                }
            }
        }