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;
 }
예제 #2
0
        public override void Draw(PageWriter writer)
        {
            var svg = SvgDocument.RootElement;

            if (svg == null)
            {
                return;
            }

            var svgWidth  = svg.ViewBox?.Width ?? (svg.Width ?? 0);
            var svgHeight = svg.ViewBox?.Height ?? (svg.Height ?? Height);   // as per spec height defaults to 100%

            if (svgWidth <= 0 || svgHeight <= 0)
            {
                return;
            }

            var viewport      = new VectorElementPdfPageViewport(svgWidth, svgHeight, X, Y, Width, Height, ContentHorizontalAlignment, ContentVerticalAlignment);
            var pagePlacement = viewport.PagePlacement;
            var container     = new TransformationGroup(pagePlacement.X, pagePlacement.Y, Width, Height)
            {
                ScaleX = viewport.ScaleX,
                ScaleY = viewport.ScaleY
            };

            var pageHeight = writer.Page.Dimensions.Height;

            container.Add(svg.Accept(new SvgElementToDynamicPdfElementConverter(svg, viewport, pageHeight, SpotColorOveride)));
            container.Draw(writer);
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of <see cref="SvgPathSegToDynamicPdfPathsConverter"/> using the specified <see cref="graphicsElement"/>
 /// for the styling properties of the resulting paths
 /// </summary>
 public SvgPathSegToDynamicPdfPathsConverter(SvgGraphicsElement graphicsElement, VectorElementPdfPageViewport pageViewport, float pageHeight, PdfSpotColor spotColorOverride)
 {
     _spotColorOverride = spotColorOverride;
     _pageViewport      = pageViewport;
     _pageHeight        = pageHeight;
     SetFillStyle(graphicsElement);
     SetStrokeStyle(graphicsElement);
 }
예제 #4
0
 public SvgElementToDynamicPdfElementConverter(SvgSvgElement rootSvgElement, VectorElementPdfPageViewport pageViewport, float pageHeight, PdfSpotColor spotColorOverride)
 {
     _spotColorOverride = spotColorOverride;
     _rootSvgElement    = rootSvgElement ?? throw new ArgumentNullException(nameof(rootSvgElement));
     _pageViewport      = pageViewport ?? throw new ArgumentNullException(nameof(pageViewport));
     _pageHeight        = pageHeight;
     _matrixStack.Push(SvgMatrix.Identity);
 }
 public static Color ConvertToColor(SvgPaintServer paintServer, VectorElementPdfPageViewport pageViewport, float pageHeight, SvgGraphicsElement element, PdfSpotColor spotColorInk)
 => paintServer?.Accept(new Visitor(pageViewport, element, pageHeight, spotColorInk));