From 6637dca8eb323b3955fca356948ca7dda1d66b96 Mon Sep 17 00:00:00 2001 From: Darius Kazemi Date: Wed, 19 Feb 2014 13:38:50 -0500 Subject: [PATCH] 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. --- lib/line_wrapper.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/line_wrapper.coffee b/lib/line_wrapper.coffee index 69fbaf6..b68488b 100644 --- a/lib/line_wrapper.coffee +++ b/lib/line_wrapper.coffee @@ -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