public override void Initialize(MandalaElement sourceElement, Random random) { // Convert source to correct type ME_Stripe source = (ME_Stripe)sourceElement; Colour = new SvgColourServer(Color.FromArgb(random.Next(256), random.Next(256), random.Next(256))); }
internal static XPen Stroke2XPen(SvgPaintServer stroke, SvgUnit strokeWidth, SvgStrokeLineCap strokeLineCap, SvgStrokeLineJoin strokeLineJoin) { var pen = stroke is SvgColourServer stroke1 ? new XPen(Color2XColor(stroke1), strokeWidth.Value) : new XPen(XColors.Black, strokeWidth.Value); switch (strokeLineCap) { case SvgStrokeLineCap.Inherit: pen.LineCap = XLineCap.Flat; break; case SvgStrokeLineCap.Butt: break; case SvgStrokeLineCap.Round: pen.LineCap = XLineCap.Round; break; case SvgStrokeLineCap.Square: pen.LineCap = XLineCap.Square; break; default: throw new ArgumentOutOfRangeException(); } switch (strokeLineJoin) { case SvgStrokeLineJoin.Inherit: break; case SvgStrokeLineJoin.Miter: pen.LineJoin = XLineJoin.Miter; break; case SvgStrokeLineJoin.Round: pen.LineJoin = XLineJoin.Round; break; case SvgStrokeLineJoin.Bevel: pen.LineJoin = XLineJoin.Bevel; break; default: throw new ArgumentOutOfRangeException(nameof(strokeLineJoin), strokeLineJoin, null); } return(pen); }
private void recolorSVGDoc(IEnumerable <SvgElement> nodes, SvgPaintServer colorServer) { foreach (var node in nodes) { if (node.Fill != SvgPaintServer.None) { node.Fill = colorServer; } if (node.Color != SvgPaintServer.None) { node.Color = colorServer; } if (node.Stroke != SvgPaintServer.None) { node.Stroke = colorServer; } recolorSVGDoc(node.Descendants(), colorServer); } }
public virtual void DefaultVisit(SvgPaintServer paintServer) { // nop }
public override Color DefaultVisit(SvgPaintServer paintServer) => throw new NotSupportedException($"SVG paint server '{paintServer?.GetType().Name}' is not supported");
public static Color ConvertToColor(SvgPaintServer paintServer, VectorElementPdfPageViewport pageViewport, float pageHeight, SvgGraphicsElement element, PdfSpotColor spotColorInk) => paintServer?.Accept(new Visitor(pageViewport, element, pageHeight, spotColorInk));
internal static XBrush Fill2XBrush(SvgPaintServer fill) { return(fill is SvgColourServer fill1 ? new XSolidBrush(Color2XColor(fill1)) : XBrushes.Black); }
internal static XPen Stroke2XPen(SvgPaintServer stroke, SvgUnit strokeWidth) { var pen = stroke is SvgColourServer stroke1 ? new XPen(Color2XColor(stroke1), strokeWidth.Value) : new XPen(XColors.Black, strokeWidth.Value); return(pen); }
public SvgImageLoader(Color color) { svgPaintServer = new SvgColourServer(color); }
public IPaintServer GetFromSvg(SvgPaintServer server, SvgElement element, out bool userSpaceOnUse, out DoubleMatrix transform) { transform = DoubleMatrix.Identity; server = SvgDeferredPaintServer.TryGet <SvgPaintServer>(server, element); userSpaceOnUse = false; // Go through each paint server type if (server is SvgColourServer clr) { // A color paint server that has alpha = 0 is equal to no paint server if (clr.Colour.A == 0) { return(new NoPaintServer()); } return(new SolidPaintServer(Convert(clr.Colour))); } // For all those, see if they are already cached else if (paintServerCache.ContainsKey(server.ID)) { userSpaceOnUse = userSpaceOnUseCache[server.ID]; transform = transformCache[server.ID]; return(paintServerCache[server.ID]); } // Linear gradient else if (server is SvgGradientServer grad) { GradientPaintServer paintServer; if (server is SvgLinearGradientServer lgrad) { paintServer = new LinearGradientPaintServer(lgrad.X1, lgrad.Y1, lgrad.X2, lgrad.Y2, SpreadMethodFrom(grad.SpreadMethod)); } else if (server is SvgRadialGradientServer rgrad) { paintServer = new RadialGradientPaintServer(rgrad.CenterX, rgrad.CenterY, rgrad.Radius, rgrad.FocalX, rgrad.FocalY, rgrad.FocalRadius, SpreadMethodFrom(rgrad.SpreadMethod)); } else { throw new Exception("Gradient server that is neither linear or radial???"); } foreach (var stop in grad.Stops) { paintServer.AddStop(stop.Offset, Convert(stop.GetColor(element))); } paintServerCache.Add(grad.ID, (IPaintServer)paintServer); userSpaceOnUse = userSpaceOnUseCache[server.ID] = grad.GradientUnits == SvgCoordinateUnits.UserSpaceOnUse; transform = transformCache[server.ID] = grad.GradientTransform?.GetMatrix().ToDoubleMatrix() ?? DoubleMatrix.Identity; return((IPaintServer)paintServer); } return(new NoPaintServer()); GradientSpreadMethod SpreadMethodFrom(SvgGradientSpreadMethod method) { switch (method) { case SvgGradientSpreadMethod.Reflect: return(GradientSpreadMethod.Reflect); case SvgGradientSpreadMethod.Repeat: return(GradientSpreadMethod.Repeat); default: return(GradientSpreadMethod.Pad); } } }