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

Using default fonts #6

Open
mitar opened this issue Nov 14, 2016 · 7 comments
Open

Using default fonts #6

mitar opened this issue Nov 14, 2016 · 7 comments

Comments

@mitar
Copy link

mitar commented Nov 14, 2016

It seems default fonts canvas 1 is using are pretty limited and do not really match those available in the browsers, even on the same system. So SVG rendered in the browser is different from a PNG rendered with this library it SVG contains text.

@fuzhenn
Copy link
Owner

fuzhenn commented Nov 15, 2016

node-canvas's parsing of font-familyis stricter than in browser: in node-canvas, font-family needs to be double quoted.
e.g.
bold 12px/20px arial,sans-serif is OK in browser, but with node-canvas it has to be
bold 12px/20px "arial,sans-serif"

You may give a try.

@fuzhenn
Copy link
Owner

fuzhenn commented Nov 15, 2016

In my experience, node-canvas's font rendering is always different from browser. I guess it's caused by cairo, the 2d graphics lib used by node-canvas.

@mitar
Copy link
Author

mitar commented Nov 15, 2016

Hm, I am using: font-family="Helvetica, Arial, Lucida Grande, sans-serif". So what I think it would be interesting if node-canvas 2.0 registerFont would be passed through so that I can register additional fonts. (Once this package will be using 2.0.)

@fuzhenn
Copy link
Owner

fuzhenn commented Nov 15, 2016

I have made a quick check of canvg's source codes, and found the font style is not double quoted in canvg.

I have fixed it here : fuzhenn/canvg@623676a

You can update your canvg and make another try.

@mitar
Copy link
Author

mitar commented Nov 15, 2016

Hm, I tried it but in my particular case I do not see a difference. It might that Helvetica is simply not available through Cairo?

@fuzhenn
Copy link
Owner

fuzhenn commented Nov 15, 2016

Yeah, i guess, Helvetica font is a system-dependent one. I have tested some other fonts (on Windows), and they are all correctly rendered.

And I'll update node-canvas to 2.0 once it's stable and released, maybe it can fix it.

@lookatitude
Copy link

I had the same problem on a project runing on AWS lambda, se solution was:
1 - add the fonts to your OS - in our case we used a layer to load the fonts into the aws image.
2 - before calling svg2img register your fonts in Canvas:
const Canvas = require('canvas') Canvas.registerFont('/var/task/fonts/Archivo-Regular.ttf', {family: 'Archivo'});

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