cduck/drawsvg

save_png and save_svg produce different images

Closed this issue · 1 comments

I noticed differences in the outputs from saving the same drawing as either an svg or png file. In png format, the text positions and decorations don't behave as expected. For example, the following code

import drawsvg as dw
d = dw.Drawing(50, 50, origin='center')
r = dw.Rectangle(-20, -15, 40, 30, stroke='black', stroke_width=2)
t = dw.Text('1', x=0, y=0, font_size = 20, text_anchor='middle', dominant_baseline='middle', text_decoration='overline', fill='blue')
d.append(r)
d.append(t)
d.save_svg('test.svg')
d.save_png('test.png')

produces this svg graphic:
test

and a png graphic that has offset the text position and ignores the overline decoration:
test

I don't know if this is a feature or a bug (maybe some things can't be adapted to png?), but the behavior I expected was that the png image would be no different from what I'd obtain using a png export in Inkscape.

cduck commented

Thanks for sharing this issue. The PNG output is generated using the CairoSVG library which mostly supports the SVG 1.1 specification but it appears that text_decoration is an SVG 2 feature.

Ideally the PNG would match your browser's display of the SVG, but unfortunately each rendering engine supports a different subset of the SVG specification. For now, I would suggest using an alternative tool to convert the SVG to a PNG if you need to use advanced text features.

I'm going to close this as a duplicate of #102. Please reply there with further comments about rendering differences and rendering backends.