Skip to content

Commit f90ef9e

Browse files
committed
Fix precision rounding issues in LineWrapper
1 parent 868e9be commit f90ef9e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/line_wrapper.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ class LineWrapper extends EventEmitter {
8686

8787
canFit(word, w) {
8888
if (word[word.length - 1] != SOFT_HYPHEN) {
89-
return w <= this.spaceLeft;
89+
return PDFNumber(w) <= PDFNumber(this.spaceLeft);
9090
}
91-
return w + this.wordWidth(HYPHEN) <= this.spaceLeft;
91+
return PDFNumber(w + this.wordWidth(HYPHEN)) <= PDFNumber(this.spaceLeft);
9292
}
9393

9494
eachWord(text, fn) {
@@ -119,7 +119,7 @@ class LineWrapper extends EventEmitter {
119119
while (word.length) {
120120
// fit as much of the word as possible into the space we have
121121
var l, mightGrow;
122-
if (w > this.spaceLeft) {
122+
if (PDFNumber(w) > PDFNumber(this.spaceLeft)) {
123123
// start our check at the end of our available space - this method is faster than a loop of each character and it resolves
124124
// an issue with long loops when processing massive words, such as a huge number of spaces
125125
l = Math.ceil(this.spaceLeft / (w / word.length));

0 commit comments

Comments
 (0)