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);
        }
Пример #2
0
        public 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.IsNullOrWhiteSpace(clipRule) &&
                string.Equals(clipRule, "evenodd") || string.Equals(clipRule, CssConstants.ValNonzero))
            {
                fillRule = clipRule;
            }
            if (fillRule == "evenodd")
            {
                geometry.FillRule = FillRule.EvenOdd;
            }
            else if (fillRule == CssConstants.ValNonzero)
            {
                geometry.FillRule = FillRule.Nonzero;
            }

            geometry.Figures.Add(polylineFigure);

            return(geometry);
        }