public static GraphicsPath CreatePath(SvgPolygonElement 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.AddPolygon(points); string fillRule = element.GetPropertyValue("fill-rule"); if (fillRule == "evenodd") { gp.FillMode = FillMode.Alternate; } else { gp.FillMode = FillMode.Winding; } return(gp); }
public Geometry CreateGeometry(SvgPolygonElement element) { ISvgPointList list = element.AnimatedPoints; ulong nElems = list.NumberOfItems; if (nElems < 3) { 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 = true; 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); }
public override void HandleAttributeChange(XmlAttribute attribute) { if (attribute.NamespaceURI.Length == 0) { switch (attribute.LocalName) { case "points": points = null; Invalidate(); return; case "marker-start": case "marker-mid": case "marker-end": // Color.attrib, Paint.attrib case "color": case "fill": case "fill-rule": case "stroke": case "stroke-dasharray": case "stroke-dashoffset": case "stroke-linecap": case "stroke-linejoin": case "stroke-miterlimit": case "stroke-width": // Opacity.attrib case "opacity": case "stroke-opacity": case "fill-opacity": // Graphics.attrib case "display": case "image-rendering": case "shape-rendering": case "text-rendering": case "visibility": Invalidate(); break; case "transform": Invalidate(); break; } base.HandleAttributeChange(attribute); } }
public void Visit(ISvgPolygonElement element) { ISvgPointList list = element.AnimatedPoints; ulong nElems = list.NumberOfItems; SvgPolygonElement pe = element as SvgPolygonElement; if (nElems == 0 || pe == null) { return; } 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 = true; polylineFigure.IsFilled = true; polylineFigure.Segments.Add(polyline); PathGeometry geometry = new PathGeometry(); FillRule fillRule; if (TryGetFillRule(pe, out fillRule)) { geometry.FillRule = fillRule; } geometry.Figures.Add(polylineFigure); var shape = WrapGeometry(geometry, element); DisplayShape(shape, element); }
public GraphicsPath GetGraphicsPath() { if (gp == null) { gp = new GraphicsPath(); ISvgPointList list = 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); } if (this is SvgPolygonElement) { gp.AddPolygon(points); } else { gp.AddLines(points); } string fillRule = GetPropertyValue("fill-rule"); if (fillRule == "evenodd") { gp.FillMode = FillMode.Alternate; } else { gp.FillMode = FillMode.Winding; } } return(gp); }