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

Avoid unnecessarily breaking inside words when using continued #308

Merged
merged 1 commit into from
Sep 15, 2014

Conversation

ef4
Copy link
Contributor

@ef4 ef4 commented Sep 12, 2014

continued is implemented by temporarily shortening the lineWidth, which can cause the linewrapper to break inside words when that's not really necessary.

`continued` is implemented by temporarily shortening the lineWidth,
which can cause the linewrapper to break inside words when that's not
really necessary.
@devongovett
Copy link
Member

Do you have an example where this is a problem? Wouldn't we want the word to be broken at the maximum width of the line, which in the case of continued or indent, is at the shortened lineWidth? Not sure I follow the logic here.

@ef4
Copy link
Contributor Author

ef4 commented Sep 15, 2014

Here's an example:

var fs = require('fs');
var PDFDocument = require('pdfkit');
var doc = new PDFDocument();
var stream = doc.pipe(fs.createWriteStream('./out.pdf'));
var width = 307;

doc.text("Mississippi in Mississippi in Mississippi in Mississippi ", {continued: true, width: width});
doc.text("in Mississippi ");
doc.end();¯

stream.on('finish', function() {
  process.exit(0);
});

There's no reason to break the word here, because it fits on the next line. This is why we should only break words if they're longer than the true line width, not the temporarily shortened line width.

@devongovett
Copy link
Member

Makes sense, thanks!

devongovett added a commit that referenced this pull request Sep 15, 2014
Avoid unnecessarily breaking inside words when using `continued`
@devongovett devongovett merged commit b36c548 into foliojs:master Sep 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants