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

Mismatch between view in notebook and Inkscape #101

Open
PanZWarzywniaka opened this issue Jul 12, 2023 · 3 comments
Open

Mismatch between view in notebook and Inkscape #101

PanZWarzywniaka opened this issue Jul 12, 2023 · 3 comments

Comments

@PanZWarzywniaka
Copy link

Hi,

This simple code, produces image in notebook as expected:
image

But when I open that in Inkscape there is a big mismatch nad text is not hanging any more.

image

Drawsvg: v2.1.1
Python: 3.11

Any idea how to fix that?

@cduck
Copy link
Owner

cduck commented Jul 13, 2023

Thanks for reporting this issue with how text is displayed. Unfortunately, the dominant-baseline attribute might be poorly supported by Inkscape (related bug, discussion). Drawsvg is generating the requested SVG but Inkscape is rendering it incorrectly. Interestingly, I see also this when I view it in Firefox (with the Mac Firefox default font_family='Helvetica'):
Screenshot 2023-07-12 at 22 14 28

More evidence that the dominant-baseline is not well supported while selecting the text in Inkscape:
Screenshot 2023-07-12 at 22 41 37


I've found the most reliable and portable way to align text in an SVG is by specifying the font with font-family (so different viewers don't pick different default fonts) and manually offsetting the y-position. Avoid using dominant-baseline or other advanced attributes. For example:

dw.Text('HELLO', 25, 100, 100+(25*0.8), font_family='Arial', ...)

where 0.8 depends on your font. Either measure this or use some font inspection tool to determine the appropriate value.

@PanZWarzywniaka
Copy link
Author

Thank you for your reply,

If that's the case maybe it should be mentioned in the 'Quick Reference'
that use of dominant-baseline is not well supported and discouraged.

I'll create PR to change the docs.

@cduck
Copy link
Owner

cduck commented Jul 14, 2023

Please do. Your issue really exemplified this.

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