Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save_png and save_svg produce different images #103

Closed
fajardogomez opened this issue Aug 2, 2023 · 1 comment
Closed

save_png and save_svg produce different images #103

fajardogomez opened this issue Aug 2, 2023 · 1 comment

Comments

@fajardogomez
Copy link

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
Copy link
Owner

cduck commented Aug 4, 2023

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.

@cduck cduck closed this as completed Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants