Correcting for edge case in line wrapping

If you look at the flow of the `eachWord` function, you'll notice that we add the word to the buffer if the width of the word `w` is less than the space available.

There's an edge case where `linebreaker` says that a line break is required on a word (because of a manual break: `theword\n`) and the width of the word being considered is greater than `spaceLeft`. In the current pdfkit, if this is the case:

 * we do not append the word to the buffer
 * we emit the line
 * we break and move on to the next line, starting with a clean line

This omits the word entirely.

This commit makes it so that we only break the line and start with a clean line if we already had the space to write the line to the buffer. Otherwise, we append the word to the buffer and go to a new line.
This commit is contained in:
Darius Kazemi 2014-02-19 13:38:50 -05:00
parent 5a530712c3
commit 6637dca8eb

View File

@ -165,7 +165,7 @@ class LineWrapper extends EventEmitter
return no
# reset the space left and buffer
if bk.required
if bk.required and w <= @spaceLeft
@spaceLeft = @lineWidth
buffer = ''
textWidth = 0