Repository navigation
Conversation
The line wrapper scaled the width, indent and column gap by horizontalScaling, while widthOfString already returns scaled widths, so the scaling cancelled out: text wrapped at the same words as at 100% and ran past the right edge above 100% (or stopped short below it), and right and center alignment were off by the same factor. Justified spacing and the word spacing in decorations and boundsOfString were also computed at 100% and then scaled by Tz.
Member
|
Is there a code snippet that demonstrate the issue visually? |
Contributor
Author
|
Yes, this draws a 200pt-wide box and fills it at 50%, 100% and 150%, plus a right-aligned line at 120%: const PDFDocument = require('pdfkit');
const fs = require('fs');
const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('hscale.pdf'));
const text = 'The quick brown fox jumps over the lazy dog while the five boxing wizards jump quickly';
[50, 100, 150].forEach((horizontalScaling, i) => {
const y = 50 + i * 120;
doc.rect(50, y, 200, 100).stroke();
doc.text(text, 50, y, { width: 200, horizontalScaling });
});
doc.rect(50, 420, 200, 20).stroke();
doc.text('right aligned', 50, 420, { width: 200, align: 'right', horizontalScaling: 120 });
doc.end();On master the 150% text runs out of the box on every line and the 50% text only fills the left half, because each case breaks at the same words as 100%; the right-aligned line ends 40pt past the box. Rightmost glyph edges from
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix.
LineWrappermultiplieswidth,indentandcolumnGapbyhorizontalScaling / 100, butwidthOfString()already returns scaled widths, so the two cancel out. Text wraps at the same words as at 100%, overflows the box above 100% and leaves it part empty below, and right and center alignment are off by the same factor. Glyph boxes frompdftotext -bbox,width: 200at x 50 (right edge 250):horizontalScaling: 150, rightmost glyphhorizontalScaling: 50, lines'Hello big world',width: 400,align: 'right',horizontalScaling: 80, right marginhorizontalScaling: 120align: 'center',horizontalScaling: 120, left / right marginindent: 20,horizontalScaling: 120, first line starts atThe wrapper now keeps those three in page units; character and word spacing stay scaled, as Tz scales them.
align: 'justify'computed the gap in page units and then let Tz scale it again, so with only the wrapper fixed, justified lines ended at about 259 (120%) or 245 (80%) instead of 250. That gap is now divided by the scaling. The word spacing in the decoration width and inboundsOfString()is scaled as well; forwordSpacing: 6, horizontalScaling: 80the bounds width is now 72.60, the glyph width, instead of 75.00.With
horizontalScalingleft at 100 nothing changes. The new tests intests/unit/text.spec.jsfail on master (8 of them), and reverting either file or any one of the five scaled terms fails at least one.prettier --check,lintandnpm test(61 files, 538 tests) pass on Node 22; I did not run Node 20 or 24.Checklist:
Written with AI assistance (Claude); I have reviewed the change.