Ejemplo n.º 1
0
        //--------------------------------------------------------------------------------------------------

        internal static IEnumerable <SvgPathSegment> Create(string pathString, SvgConverter conv)
        {
            SvgPathSegment lastSegment  = null;
            SvgPathSegment firstSegment = null;
            int            next         = 0;

            while (next < pathString.Length)
            {
                int start = next;
                next = pathString.IndexOfAny(_PathCommands, start + 1);
                if (next == -1)
                {
                    next = pathString.Length;
                }

                IEnumerable <SvgPathSegment> newSegments = null;
                var commandString = pathString.Substring(start, next - start);
                switch (char.ToLower(commandString[0]))
                {
                case 'm':
                    newSegments = SvgPathSegMoveto.Create(lastSegment, commandString, conv);
                    break;

                case 'l':
                case 'h':
                case 'v':
                    newSegments = SvgPathSegLineto.Create(lastSegment, commandString, conv);
                    break;

                case 'c':
                case 's':
                    newSegments = SvgPathSegCurvetoCubic.Create(lastSegment, commandString, conv);
                    break;

                case 'q':
                case 't':
                    newSegments = SvgPathSegCurvetoQuadratic.Create(lastSegment, commandString, conv);
                    break;

                case 'a':
                    newSegments = SvgPathSegArc.Create(lastSegment, commandString, conv);
                    break;

                case 'z':
                    lastSegment = SvgPathSegClosePath.Create(firstSegment, lastSegment);
                    yield return(lastSegment);

                    firstSegment = null;
                    continue;
                }

                if (newSegments == null)
                {
                    continue;
                }

                foreach (var segment in newSegments)
                {
                    if (firstSegment == null)
                    {
                        firstSegment = segment;
                    }
                    lastSegment = segment;
                    yield return(segment);
                }
            }
        }