Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix center-aligned character spacing #301

Merged
merged 1 commit into from
Sep 11, 2014
Merged

Conversation

ef4
Copy link
Contributor

@ef4 ef4 commented Sep 11, 2014

Center-aligned text fails to take into account the character spacing. The fix just requires renaming @charSpacing so that the widthOfString function in mixins/text will see it.

Here is a minimal sample document that demonstrates the issue:

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

function test(charSpacing) {
  doc.rect(150, doc.y, 150, 30).stroke('#000');
  doc.x = 150;
  doc.y += 10;
  doc.text("Testing", {width: 150, align: 'center', characterSpacing: charSpacing});
  doc.moveDown();
}

test();
test(3);
doc.end();

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

devongovett added a commit that referenced this pull request Sep 11, 2014
Fix center-aligned character spacing
@devongovett devongovett merged commit 33920c3 into foliojs:master Sep 11, 2014
@ef4 ef4 deleted the center-spacing branch September 12, 2014 19:10
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants