yWorks / svg2pdf.js

A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
MIT License
655 stars 101 forks source link

Font-family not caught from root element #8

Closed henrikskar closed 6 years ago

henrikskar commented 7 years ago

Hi there yWorks,

It seems like font-family is not caught from the root element of the svg. In my use case there are no serif font-families, and svg2pdf seems to put it to a serif. Here's a demo for the issue: https://jsfiddle.net/henrikskar/mjpt2g7v/

Is there a way to fix this?

Thanks in advance for answers.

Best regards, Henrik Skar

yGuy commented 7 years ago

I guess this is because we are simply using jspdf's setFont method passing in the css definition for the font-family. I don't think jspdf can deal with the complex font you have in your example with all the fallbacks and such. You should improve the logic in our setTextProperties implementation or better in JSPDF's setFont/_getFont implementation, which is a very simple implementation that only recognizes a hand-full of hard-coded fonts.

HackbrettXXX commented 6 years ago

It should be fixed by this commits, I suppose: ffe406131bc690dea51f32b72066faf0b57baf0b 6dc2378bd8a4f7c7cdb9a1c9b196af2a09351e74

Additionally you might need to add the custom fonts you use (see readme), otherwise svg2pdf will fall back to Helvetica.

Feel free to reopen this issue if you think the bug is still there.