yWorks / jsPDF

JavaScript PDF generation to work with SVG
MIT License
56 stars 23 forks source link

issue with utf-8 characters #6

Closed poplevente closed 6 years ago

poplevente commented 7 years ago

Hi, i'm having issues with some utf-8 characters For example text : őőŐŐűűááŐÚÜÖ is shown like QQQPPqqááPÚÜÖ

http://jsbin.com/rilace/edit?html,js,output

These characters aren't supported?

yGuy commented 7 years ago

No, they are not - this is a long standing issue with the underlying original implementation by MrRio. There are projects, which try to fix this: https://github.com/sphilee/jsPDF-CustomFonts-support Fonts and font-mapping is still a big issue with that libray: https://stackoverflow.com/a/22356398/351836

We are thinking about merging the CustomFonts code into our fork. But this still needs a lot of work.

poplevente commented 7 years ago

ok, thanks.

for now as the fastest solution I'm flattening all letters that are not extended ascii, with the ones without the diacritics. of course i know i have not too much text, so it's not taking me back in performance.

`function isASCII(text, extended) { return (extended ? /^[\x00-\xFF]$/ : /^[\x00-\x7F]$/).test(text); }

function escapeTextforPdf(text) { for(var i=0;i<text.length;++i) { if(!isASCII(text[i], true)) { text = text.replace(RegExp(text[i], "g"), text[i].normalize('NFD').replace(/[\u0300-\u036f]/g, "")); } } return text; }

escapeTextforPdf(text);`

yGuy commented 6 years ago

I think this should be fixed, now that we have support for custom fonts, wouldn't you agree @HackbrettXXX ?

Uzlopak commented 6 years ago

Note to myself to check if I can implement this into jsPDF

HackbrettXXX commented 6 years ago

I just tested it and it works both with our recent changes and on the current master (assuming you embed a font that supports these characters).

poplevente commented 6 years ago

Great work guys!