Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fix bundlers and file tracers packing the ESM copies of the standard font metrics instead of the CommonJS ones the Node build actually loads, which left `Cannot find module` errors for every standard font at runtime, by resolving the internal `#standard-fonts/*` mapping to a single file under all conditions
- Fix `doc.file()` throwing when the same in-memory attachment is embedded twice under one name, because the creation and modified dates the deduplication check compares are absent for sources that are not read from disk
- Fix `doc.text()` throwing `unsupported number: NaN` when `lineBreak: false` is combined with `underline`, `strike`, `link` or `goTo`, because the rendered width was computed from the line wrapper's measurements, which are never produced when wrapping is disabled

### [v0.20.1] - 2026-08-23

Expand Down
10 changes: 8 additions & 2 deletions lib/mixins/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,15 @@ export default {
}

// calculate the actual rendered width of the string after word and character spacing
// the wrapper supplies textWidth and wordCount; measure them directly when it did not run
const measuredWidth =
options.textWidth ??
this.widthOfString(text, options) - characterSpacing * (text.length - 1);
const measuredWordCount =
options.wordCount ?? (text.trim() ? text.trim().split(/\s+/).length : 0);
const renderedWidth =
options.textWidth +
wordSpacing * (options.wordCount - 1) +
measuredWidth +
wordSpacing * (measuredWordCount - 1) +
characterSpacing * (text.length - 1);

// create link annotations if the link option is given
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@ Q

expect(docData).toContainText({ text: 'text with null x' });
});

test.each([
['underline', { underline: true }],
['strike', { strike: true }],
['link', { link: 'http://example.com/' }],
['goTo', { goTo: 'anchor' }],
])('with lineBreak false and %s', (_name, extraOptions) => {
const docData = logData(document);

document.text('no line break', 50, 50, {
lineBreak: false,
...extraOptions,
});
document.end();

expect(docData).toContainText({ text: 'no line break' });
});
});

describe('text with structure parent links', () => {
Expand Down
Loading