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

Rendering non-ASCII charcaters fails #63

Closed
jensfinnas opened this issue Sep 27, 2016 · 3 comments
Closed

Rendering non-ASCII charcaters fails #63

jensfinnas opened this issue Sep 27, 2016 · 3 comments

Comments

@jensfinnas
Copy link

Trying to PNG this SVG:

<svg xmlns="http://www.w3.org/2000/svg"><g><text x="50" y="50" font-size="15">åäö</text></g></svg>

...gets me this:

skarmavbild 2016-09-27 kl 21 24 14

@domenic
Copy link
Owner

domenic commented Oct 1, 2016

Confirmed this does not happen in Edge, Chrome, or Firefox despite there being no encoding declaration. So assuming I can repro with svg2png, it's our bug...

@losnikitos
Copy link
Contributor

Hi! Looks like the problem happens when phantomjs parses Base64-encoded SVG from stdin with atob (see lib/converter.js). So the HTML passed to phantom for rendering has wrong characters.

I'm not sure, what is the best way to solve it. As a workaround, I can suggest replacing all non-ASCII characters to their appropriate HTML codes in your SVG:

svg = svg.replace(/[\u0080-\u024F]/g, v => '&#' + v.charCodeAt() + ';')

worked for me.

@domenic
Copy link
Owner

domenic commented Oct 26, 2016

@losnikitos thanks for the diagnosis! It sounds like this is something svg2png should fix for people, e.g. by using a better base64 encoder/decoder. Now that I understand the issue better I can hopefully fix it soon, or maybe someone can send a pull request.

domenic pushed a commit that referenced this issue Nov 6, 2016
Closes #63, by sending the data to PhantomJS as UTF-8 instead of as base64.
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

3 participants