Ejemplo n.º 1
0
        public static GraphicsPath CreatePath(SvgPolylineElement element)
        {
            GraphicsPath gp = new GraphicsPath();

            ISvgPointList list = element.AnimatedPoints;
            ulong nElems = list.NumberOfItems;

            PointF[] points = new PointF[nElems];

            for (uint i = 0; i < nElems; i++)
            {
                points[i] = new PointF((float)list.GetItem(i).X, (float)list.GetItem(i).Y);
            }

            gp.AddLines(points);

            string fillRule = element.GetPropertyValue("fill-rule");
            if (fillRule == "evenodd")
                gp.FillMode = FillMode.Alternate;
            else
                gp.FillMode = FillMode.Winding;

            return gp;
        }
Ejemplo n.º 2
0
        public static Geometry CreateGeometry(SvgPolylineElement element)
        {
            ISvgPointList list = element.AnimatedPoints;
            ulong nElems = list.NumberOfItems;
            if (nElems == 0)
            {
                return null;
            }

            PointCollection points = new PointCollection((int)nElems);

            for (uint i = 0; i < nElems; i++)
            {
                ISvgPoint point = list.GetItem(i);
                points.Add(new Point(Math.Round(point.X, 4), Math.Round(point.Y, 4)));
            }
            PolyLineSegment polyline = new PolyLineSegment();
            polyline.Points = points;

            PathFigure polylineFigure = new PathFigure();
            polylineFigure.StartPoint = points[0];
            polylineFigure.IsClosed = false;
            polylineFigure.IsFilled = true;

            polylineFigure.Segments.Add(polyline);

            PathGeometry geometry = new PathGeometry();

            string fillRule = element.GetPropertyValue("fill-rule");
            string clipRule = element.GetAttribute("clip-rule");
            if (!String.IsNullOrEmpty(clipRule) &&
                String.Equals(clipRule, "evenodd") || String.Equals(clipRule, "nonzero"))
            {
                fillRule = clipRule;
            }
            if (fillRule == "evenodd")
                geometry.FillRule = FillRule.EvenOdd;
            else if (fillRule == "nonzero")
                geometry.FillRule = FillRule.Nonzero;

            geometry.Figures.Add(polylineFigure);

            return geometry;
        }