[BUG] Drawing to SVG: stroke-linejoin not transferred to SVG

6 views
Skip to first unread message

Mikkel Pedersen

unread,
Nov 11, 2025, 7:20:23 AM (12 days ago) Nov 11
to reportlab-users
Hi all,

Version: 4.4.4.

When setting the stroke linejoin to 1 or 2 (round or bevel) in a Polygon, this information is not transferred when saving the Drawing as SVG. 

Here is a minimal example. Notice that the Polygon has strokeLineJoin=1.
from reportlab.graphics.shapes import Drawing, Polygon
from reportlab.lib.colors import Color
from reportlab.graphics import renderSVG

drawing = Drawing(500, 500)
polygon = Polygon(
    [10, 10, 250, 490, 490, 10],
    strokeWidth=5,
    fillColor=Color(0, 0, 0, 0),
    strokeLineJoin=1
)
drawing.add(polygon)

svg_data = drawing.asString('svg')
img_bytes = renderSVG.drawToString(drawing)
with open('output.svg', 'w') as f:
    f.write(img_bytes)

The output is shown below. Since I set the stroke linejoin to 1 (round) I would expect the linejoins to be round. Instead, the default 0 (miter) is used.
output.jpg

Digging into the saved SVG file I found that stroke-linejoin were nowhere to be found. In renderSVG.py I managed to find a solution that at least works for my example. Here are the changes:
Line 32: I added stroke-linejoin.
AREA_STYLES = 'stroke-width stroke-linecap stroke-linejoin stroke stroke-opacity fill fill-opacity stroke-dasharray stroke-dashoffset fill-rule id'.split()

Line 351: I changed stroke-linecap to stroke-linejoin. This is what convinced me that this is a bug. In the method setLineJoin(), it sets the stroke-linecap instead.
self.style['stroke-linejoin'] = vals[v]

Here is the output with these changes. As you can see the linejoins are now rounded.
output_edited.jpg

Here is a GitHub Gist of the modified renderSVG.py: https://gist.github.com/mikkelkp/5dd6a1a21dcffe7feb5d6e90578ef009

Regards,
Mikkel
Reply all
Reply to author
Forward
0 new messages