Fix for drawing strokes properly

Nov 18, 2011 at 10:10 AM

Hi there,

I tried to use this rendering engine, but I noticed that it incorrectly renders strokes with line joins and line caps set to non-default values (e.g. round ones). 

So I created a bit of a fix for that. Please consider it for inclusion (but notice that it only addresses the situation where the caps and joins are defined to be round).

The fix is in SvgVisualElements.cs, starting from line 121 and looks like this

protected internal virtual void RenderStroke(SvgRenderer renderer) {           

	if (this.Stroke != null) {               
		float strokeWidth = this.StrokeWidth.ToDeviceValue(this);               
		using (var pen = new Pen(this.Stroke.GetBrush(this, this.StrokeOpacity), strokeWidth)) {                   

			if (StrokeLineCap == SvgStrokeLineCap.Round) {                       
				pen.StartCap = LineCap.Round;                       
				pen.EndCap = LineCap.Round;                   
			}                   

			if (StrokeLineJoin == SvgStrokeLineJoin.Round) {                       
				pen.LineJoin = LineJoin.Round;                   
			}
                    	if (this.StrokeDashArray != null && this.StrokeDashArray.Count > 0) {                       
				/* divide by stroke width - GDI behaviour that I don't quite understand yet.*/                       
				pen.DashPattern = this.StrokeDashArray.ConvertAll(u => u.Value / ((strokeWidth <= 0) ? 1 : strokeWidth)).ToArray();                   
			}
                    	renderer.DrawPath(pen, this.Path);               
		}           
	}       
}

Fix is boldened and in red

 

Best Regards

kalamon