public SvgClipPathMaskWriterVisitor(PageWriter writer, SvgMatrix rootTransform, PdfSpotColor spotColorOverride)
 {
     _spotColorOverride = spotColorOverride;
     _writer            = writer ?? throw new ArgumentNullException(nameof(writer));
     _matrixStack.Push(SvgMatrix.Identity);
     PushMatrix(rootTransform);
 }
 public Visitor(VectorElementPdfPageViewport pageViewport, SvgGraphicsElement element, float pageHeight, PdfSpotColor spotColorOverride)
 {
     _spotColorOverride = spotColorOverride;
     _pageViewport      = pageViewport ?? throw new ArgumentNullException(nameof(pageViewport));
     _element           = element ?? throw new ArgumentNullException(nameof(element));
     _pageHeight        = pageHeight;
 }
Ejemplo n.º 3
0
 public static PdfColor ToPdfColor(this SvgColor color, PdfSpotColor spotColorOverride)
 {
     if (spotColorOverride != null)
     {
         return(spotColorOverride);
     }
     return(new PdfRgbColor(color.R, color.G, color.B));
 }
 private static GradientColorStop ConvertStop(SvgGradientPaintServerColorStop stop, PdfSpotColor spotColorOverride)
 {
     if (Math.Abs(stop.Opacity - 1) > float.Epsilon)
     {
         throw new NotSupportedException($"Gradient stop opacity is not supported, only supports value of 1 but got {stop.Opacity}");
     }
     return(new GradientColorStop(stop.Color.ToPdfColor(spotColorOverride), stop.Offset));
 }
            private static IReadOnlyCollection <GradientColorStop> ConvertStops(IEnumerable <SvgGradientPaintServerColorStop> stops, PdfSpotColor spotColorInk)
            {
                var result = stops.Select(s => ConvertStop(s, spotColorInk)).ToList();

                if (result.Count > 1)
                {
                    var lastStop = result[result.Count - 1];
                    if (lastStop.Offset < 1)
                    {
                        result.Add(new GradientColorStop(lastStop.Color, lastStop.Offset + 0.0001001f));
                    }
                }
                return(result);
            }
 public static Color ConvertToColor(SvgPaintServer paintServer, VectorElementPdfPageViewport pageViewport, float pageHeight, SvgGraphicsElement element, PdfSpotColor spotColorInk)
 => paintServer?.Accept(new Visitor(pageViewport, element, pageHeight, spotColorInk));
            private static bool CheckInvalidGradientPaintServer(SvgGradientPaintServer paintServer, PdfSpotColor spotColorInk, out Color color)
            {
                color = null;

                switch (paintServer.Stops.Count)
                {
                case 0:
                    return(true);

                case 1:
                    color = paintServer.Stops[0].Color.ToPdfColor(spotColorInk);
                    return(true);
                }

                return(false);
            }