protected static IEnumerable <PathSegment> GetPathSegments(string attributeValue)
        {
            IList <IPathCommand> stack = null;
            var          bounds        = new XyRect();
            var          cursor        = new PxPoint(0, 0);
            var          start         = new PxPoint(0, 0);
            IPathCommand previous      = null;

            foreach (var command in GetCommands(attributeValue))
            {
                var c = CreateSegment(cursor, previous, start, command.Key, command.Value);
                previous = c;

                if (command.Key == 'M' || command.Key == 'm')
                {
                    if (stack != null)
                    {
                        //If we get here, we have an existing path that has not been closed.
                        // We add a dummy closepath
                        stack.Add(new ClosePathCommand(cursor, start, false));
                        yield return(new PathSegment(stack, bounds, false));
                    }

                    stack  = new List <IPathCommand>();
                    bounds = new XyRect();
                    start  = c.NextPoint;
                    stack.Add(c);
                }
                else if (command.Key == 'Z' || command.Key == 'z')
                {
                    if (stack != null)
                    {
                        stack.Add(c);
                        yield return(new PathSegment(stack, bounds, true));
                    }

                    stack  = null;
                    bounds = new XyRect();
                }
                else
                {
                    stack?.Add(c);
                }

                cursor = c.NextPoint;
                bounds.AddPoint(cursor);
            }

            if (stack != null)
            {
                //If we get here, we have an existing path that has not been closed.
                // We add a dummy closepath
                stack.Add(new ClosePathCommand(cursor, start, false));
                yield return(new PathSegment(stack, bounds, false));
            }
        }
        protected override bool TryCreate(string attributeValue, out Path path)
        {
            var bounds   = new XyRect();
            var segments = new List <PathSegment>();

            foreach (var ps in GetPathSegments(attributeValue))
            {
                segments.Add(ps);
                bounds = bounds.Add(ps.Bounds);
            }
            path = new Path(segments.ToArray(), bounds);
            return(true);
        }
        public static bool TryParse(string value, out Path path)
        {
            var bounds   = new XyRect();
            var segments = new List <PathSegment>();

            foreach (var ps in GetPathSegments(value))
            {
                segments.Add(ps);
                bounds = bounds.Add(ps.Bounds);
            }
            path = new Path(segments.ToArray(), bounds);
            return(true);
        }