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)); } }
public void SetStrokeStyle(SvgGraphicsElement graphicsElement) { var style = graphicsElement?.Style; _strokeColor = graphicsElement != null && _pageViewport != null ? SvgPaintServerToDynamicPdfColorConverter.ConvertToColor(graphicsElement.CreateStrokePaintServer(), _pageViewport, _pageHeight, graphicsElement, _spotColorOverride) : null; _strokeWidth = _strokeColor != null ? graphicsElement?.StrokeWidth ?? 0 : 0; _lineJoin = style?.StrokeLineJoin.ConvertToDynamicPdf() ?? LineJoin.Miter; _miterLimit = style?.StrokeMiterLimit ?? 1f; _lineCap = style?.StrokeLineCap.ConvertToDynamicPdf() ?? LineCap.Butt; _strokeStyle = LineStyle.Solid; var dashArray = style?.StrokeDashArray.Value; if (dashArray?.Length > 0) { var dashValues = dashArray.Select(i => i.Value).ToArray(); _strokeStyle = new LineStyle(dashValues, style.StrokeDashOffset.Value.Value); } }