foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.86k stars 1.15k forks source link

Text wrapper not properly working with soft hyphens #457

Open Janneman84 opened 8 years ago

Janneman84 commented 8 years ago

The linebreak logic doesn't seem to be designed to handle soft hyphens. These are characters that indicate where a word may be split in order to prevent a big gap as the end of a line.

http://www.fileformat.info/info/unicode/char/ad/index.htm

In my language composed words are written as one, so "computer screen" becomes "computerscreen". You understand that words can get potentially very long, like "computers­creen­size­measurement­accuracy­category" or something. I put some soft hyphens in this word so it breaks if it doesn't fit on one line so you probably see a dash now, try resizing the text field.

Typing soft hyphens is annoying because you can't usually see them, so it's advised to use unicode, like in JS you can type "I have a very big computer\u00ADscreen."

so Instead of this: I have a very big computerscreen.

you get: I have a very big computer- screen.

Long story short: in PDFKit all soft hyphen characters are typed as a dash and not just the one at the end of a line. It probably takes a bit of puzzling to get the sizing algorithms working correctly.

Is this something someone would like to look a little more in to?

sampov2 commented 8 years ago

This is an issue for me as well. I'd love to see a solution for this in upcoming versions!