Encodes each word separately instead of relying on Tw operator, which only supports character code 32, which isn't used by embedded fonts.
Still to do: proper unicode word breaking with support for non-space separated languages.
The following example adds text with three sections (part1, part2, part3) in different fonts and colors.
doc.font('Helvetica', 13)
.text(part1, 100, 300, { continued: yes, indent: 50 })
.fillColor('red')
.text(part2, { indent: 50, continued: yes })
.font('Times', 13)
.fillColor('green')
.text(part3)
Should solve a huge number of issues. The regular express based word matching from before was not good. It was overzealous and caused the most bugs of anything in the project. It also didn't work at all for languages like Chinese which don't have spaces between words.
The new wrapping algorithm supports all of this. It is a separate module at http://github.com/devongovett/linebreak.
When using a PDF standard font, the encoding is set to WinAnsiEncoding.
In addition, a encoding function is used to translate from UTF-8 to
WinAnsiEncoding.
@startY + options.height will actually = the full remainder of the page, by subrtacting out a line of text it just wrapped a line of text too early as the last line of text could never fit.
Because of the use of the construction "@x = x or @x" there was no way
to set x (or y) to 0, since 0 is falsy. Fix to use separate outer tests
and unconditional assignment.
Right now output returns a string to its callback, this means you can't just write it to a file or send it to a response as the default encoding (utf8) is incorrect. You have to manually specify binary. If instead of a string you return a binary buffer then you don't have to worry about this.
I also fixed the generation of the final string to not build the string with repeated concatenation which is O(n^2) and instead build up an array of strings then join them all at once which is O(n)
The path parser didn't handle numbers like "1e-4" correctly.
(I don't know what the SVG standard has to say about that formatting,
but Inkscape certainly does output them like that.)