Esempio n. 1
0
        public void SetFillStyle(SvgGraphicsElement graphicsElement)
        {
            var style = graphicsElement?.Style;

            _fillEvenOdd = style?.FillRule == SvgFillRule.EvenOdd;
            _fillColor   = graphicsElement != null && _pageViewport != null
                ? SvgPaintServerToDynamicPdfColorConverter.ConvertToColor(graphicsElement.CreateFillPaintServer(), _pageViewport, _pageHeight, graphicsElement, _spotColorOverride)
                : null;
        }
Esempio n. 2
0
        private void RenderShapeToCanvas(SvgGraphicsElement svgGraphicsElement, IPath path)
        {
            var matrix = CalulateUpdatedMatrix(svgGraphicsElement);

            var brush = svgGraphicsElement.CreateFillPaintServer()?.Accept(BrushGenerator <TPixel> .Instance);

            IBrush strokFill = null;
            IPath  outline   = null;

            if (svgGraphicsElement.StrokeWidth > 0)
            {
                strokFill = svgGraphicsElement.CreateStrokePaintServer()?.Accept(BrushGenerator <TPixel> .Instance);
                if (strokFill != null)
                {
                    var pattern = svgGraphicsElement.Style.StrokeDashArray.Value?.Select(X => X.Value).ToArray();
                    var joint   = svgGraphicsElement.Style.StrokeLineJoin.AsJointStyle();
                    var end     = svgGraphicsElement.Style.StrokeLineCap.AsEndCapStyle();
                    if (pattern == null || pattern.Length == 0)
                    {
                        outline = path.GenerateOutline(svgGraphicsElement.StrokeWidth, joint, end);
                    }
                    else
                    {
                        outline = path.GenerateOutline(svgGraphicsElement.StrokeWidth,
                                                       pattern,
                                                       false,
                                                       joint, end);
                    }
                }
            }

            var shapeOptions = new ShapeOptions {
                IntersectionRule = IntersectionRule.Nonzero
            };
            var shapeGraphicsOptions = new DrawingOptions()
            {
                ShapeOptions = shapeOptions
            };

            if (brush != null)
            {
                image.Fill(shapeGraphicsOptions, brush, path.Transform(matrix));
            }

            if (outline != null && strokFill != null)
            {
                image.Fill(shapeGraphicsOptions, strokFill, outline.Transform(matrix));
            }
        }