示例#1
0
        static void GetDimensionsPath(XPathNavigator node, double x, double y, ref double xMin, ref double yMin, ref double xMax, ref double yMax)
        {
            var  reader = new PathReader(node.GetAttribute("d", string.Empty));
            bool lastCommandRelative = false;

            while (reader.ReadNext())
            {
                if (reader.Command != '\0')
                {
                    lastCommandRelative = char.IsLower(reader.Command);
                }
                else
                {
                    if (lastCommandRelative)
                    {
                        x += reader.X;
                        y += reader.Y;
                    }
                    else
                    {
                        x = reader.X;
                        y = reader.Y;
                    }

                    if (xMin > x)
                    {
                        xMin = x;
                    }
                    if (yMin > y)
                    {
                        yMin = y;
                    }
                    if (xMax < x)
                    {
                        xMax = x;
                    }
                    if (yMax < y)
                    {
                        yMax = y;
                    }
                }
            }
        }
示例#2
0
        void TransformPathNode(XPathNavigator node, double dx, double dy)
        {
            var  reader = new PathReader(node.GetAttribute("d", string.Empty));
            bool lastCommandRelative = false;
            bool lastWasCommand      = true;
            var  sb = new StringBuilder();

            while (reader.ReadNext())
            {
                if (reader.Command != '\0')
                {
                    lastCommandRelative = char.IsLower(reader.Command);
                    sb.Append(reader.Command);
                    lastWasCommand = true;
                }
                else
                {
                    if (!lastWasCommand)
                    {
                        sb.Append(' ');
                    }

                    if (lastCommandRelative)
                    {
                        sb.Append(reader.X);
                        sb.Append(' ');
                        sb.Append(reader.Y);
                    }
                    else
                    {
                        sb.Append(reader.X + dx);
                        sb.Append(' ');
                        sb.Append(reader.Y + dy);
                    }
                    lastWasCommand = false;
                }
            }
            SetAttr(node, "d", sb.ToString());
        }