Пример #1
0
        public static SVGPath Parse(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(new SVGPath());
            }
            if (path.StartsWith("path://"))
            {
                path = path.Substring(7);
            }
            path = path.Replace(' ', ',');
            var mc      = s_PathRegex.Matches(path);
            var svgPath = new SVGPath();

            foreach (var m in mc)
            {
                var key = m.ToString();
                if (key.Equals("Z") || key.Equals("z"))
                {
                    var seg = new SVGPathSeg(SVGPathSegType.Z);
                    seg.raw      = key;
                    seg.relative = key.Equals("z");
                    svgPath.AddSegment(seg);
                }
                else
                {
                    var        type = s_PathValueRegex.Match(key).Groups[1].ToString().ToCharArray() [0];
                    var        mc3  = s_PathValueRegex2.Matches(key);
                    SVGPathSeg seg  = null;
                    switch (type)
                    {
                    case 'M':
                    case 'm':
                        seg          = new SVGPathSeg(SVGPathSegType.M);
                        seg.relative = type == 'm';
                        break;

                    case 'L':
                    case 'l':
                        seg          = new SVGPathSeg(SVGPathSegType.L);
                        seg.relative = type == 'l';
                        break;

                    case 'H':
                    case 'h':
                        seg          = new SVGPathSeg(SVGPathSegType.H);
                        seg.relative = type == 'h';
                        break;

                    case 'V':
                    case 'v':
                        seg          = new SVGPathSeg(SVGPathSegType.V);
                        seg.relative = type == 'v';
                        break;

                    case 'C':
                    case 'c':
                        seg          = new SVGPathSeg(SVGPathSegType.C);
                        seg.relative = type == 'c';
                        break;

                    case 'S':
                    case 's':
                        seg          = new SVGPathSeg(SVGPathSegType.S);
                        seg.relative = type == 's';
                        break;

                    case 'Q':
                    case 'q':
                        seg          = new SVGPathSeg(SVGPathSegType.Q);
                        seg.relative = type == 'q';
                        break;

                    case 'T':
                    case 't':
                        seg          = new SVGPathSeg(SVGPathSegType.T);
                        seg.relative = type == 't';
                        break;

                    case 'A':
                    case 'a':
                        seg          = new SVGPathSeg(SVGPathSegType.A);
                        seg.relative = type == 'a';
                        break;
                    }
                    if (seg != null)
                    {
                        seg.raw = key;
                        foreach (var m3 in mc3)
                        {
                            // if (type == 'c' || type == 'C')
                            //Debug.LogError("\tmc3:" + type + "," + m3.ToString());
                            float p;
                            if (float.TryParse(m3.ToString(), out p))
                            {
                                seg.parameters.Add(p);
                            }
                        }
                        svgPath.AddSegment(seg);
                    }
                }
            }
            // Debug.LogError(path);
            // foreach (var cmd in svgPath.commands)
            // {
            //     Debug.LogError(cmd.raw);
            // }
            return(svgPath);
        }
Пример #2
0
 public void AddSegment(SVGPathSeg seg)
 {
     segs.Add(seg);
 }