Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix precision rounding issues in LineWrapper #1595

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/line_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class LineWrapper extends EventEmitter {

canFit(word, w) {
if (word[word.length - 1] != SOFT_HYPHEN) {
return w <= this.spaceLeft;
return PDFNumber(w) <= PDFNumber(this.spaceLeft);
}
return w + this.wordWidth(HYPHEN) <= this.spaceLeft;
return PDFNumber(w + this.wordWidth(HYPHEN)) <= PDFNumber(this.spaceLeft);
}

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