Skip to content

Worker 07, round 76 — local handoff - #1801

Open
2836048681 wants to merge 1 commit into
Hopding:masterfrom
2836048681:fix/1590-preserve-empty-lines
Open

2836048681 wants to merge 1 commit into
Hopding:masterfrom
2836048681:fix/1590-preserve-empty-lines

Conversation

@2836048681

Copy link
Copy Markdown
  • Repository: Hopding/pdf-lib (8,690 stars when screened).
  • Issue: BUG: breakTextIntoLines removes empty lines in multiline text #1590
  • Checkout: /home/hatch/workspace/pr-factory/work/w07-r76/repo (shallow clone of master).
  • Base: 93dd36e85aa659a3bca09867d2d8fac172501fbe.
  • Branch: fix/1590-preserve-empty-lines.
  • Local commit: fbe18e6e8dc46b4db0a4093e0c0acaf4d973701c.
  • Commit identity: Codex <codex@localhost>; the supervisor may replace it before submission.
  • Screening: 21 eligible candidate issues assessed in shortlist.md; raw unauthenticated GitHub API curl responses in screening/.
  • Status: local fix and tests complete; ready for supervisor code review, with the upstream browser/manual integration checks explicitly unverified below.
  • No remote writes or GitHub authentication used.

What?

Fixes #1590.

Preserve leading, consecutive, and trailing empty lines when drawText() is given maxWidth. Empty input also produces the same single empty line as the existing unwrapped path.

For first\n\nsecond\n, the wrapped path now produces ['first', '', 'second', ''] instead of ['first', 'second'].

Why?

Setting maxWidth currently removes vertical spacing explicitly included in the input, even when the text is short enough that no width-based wrapping occurs. The same text drawn without maxWidth retains those empty lines.

How?

Always append the current line at an explicit line break and at the end of the input. Ignore zero-length regex matches, and only flush for width overflow when the current line contains text. These two guards preserve the handling of words wider than maxWidth without creating extra blank lines around them.

The production change is three lines in src/utils/strings.ts. Tests cover empty input, leading/consecutive/trailing newlines, word wrapping, overlong words, and the actual Tj/T* operators emitted by PDFPage.drawText() with and without maxWidth.

Testing?

On Node.js 24.22.1 with the checked-in dependency versions:

  • yarn test — 65 suites, 627 tests passed.
  • yarn typecheck — passed.
  • node node_modules/tslint/bin/tslint --project tsconfig.json — passed.
  • node node_modules/tslint/bin/tslint --project tests/tsconfig.json — passed.
  • node node_modules/prettier/bin-prettier.js --check src/utils/strings.ts tests/utils/strings.spec.ts tests/api/PDFPage.spec.ts — passed.
  • git diff --check — passed.

Before the production fix, the updated two-file Jest regression run failed 9 tests, with 11 passing. The complete suite passes with the fix.

Additional local checks (scripts/logs in evidence/):

  • 10 focused string cases and 4,095 generated LF/CR string cases match the unwrapped path after the fix. The unchanged source passes only 2/10 focused cases and 690/4,095 generated cases.
  • Save/reload checks on Node.js 16.20.2, Node.js 24.22.1, and Deno 2.9.6 each pass four cases: new/existing documents, with/without maxWidth. Each reload verifies the persisted text and line-advance operators.
  • CommonJS, ES modules, and the UMD bundle build successfully with TypeScript 3.9.5 and isolated ttypescript 1.5.15. Repository dependency files were not changed.

Build qualification: the checked-in ttypescript 1.5.10 fails on both tested Node versions with Cannot set property constructor ... which has only a getter. Importing that unchanged build dependency alone reproduces the failure before any project source is read. The isolated build tool above is a validation workaround, not a dependency change in this PR.

Browser qualification: launching the provided Chromium binary failed before page creation because the environment requires a Hatch WebGL domain policy. No browser pass is claimed. The interactive apps/ integration suite and the upstream manual multi-viewer matrix were not run.

New Dependencies?

No. Tooling used for local validation is outside the repository. package.json and yarn.lock are unchanged.

Screenshots

A rendered comparison is saved at evidence/comparison.png, with the original wrapped behavior, the existing unwrapped behavior, and the fixed wrapped behavior side by side. The fixed spacing matches the unwrapped control. The companion comparison.pdf was rendered with Poppler and the image was inspected. The submitter can attach the PNG to the PR.

Suggested Reading?

No. The recommended PDF-specification sections were not read for this string-wrapping change. Existing content-stream generation is unchanged and is checked through operator assertions and PDF save/reload tests.

Anything Else?

No GitHub push, PR, issue comment, or claim was made. Public API screening found no competing fix for #1590, and the issue is unassigned. The repository has a maintenance backlog; no review/merge timing is assumed.

Checklist

  • I read CONTRIBUTING.md.
  • I read MAINTAINERSHIP.md#pull-requests.
  • I added/updated unit tests for my changes.
  • I added/updated integration tests for my changes (public API operator test; additional local save/reload checks).
  • I ran the repository's interactive integration test applications. Focused automated save/reload checks passed instead.
  • I tested my changes in Node, Deno, and the browser. Node and Deno passed; browser startup was blocked by the environment.
  • I viewed documents in Adobe Acrobat, Foxit Reader, Firefox, and Chrome. Poppler rendering was inspected; this manual matrix remains unverified.
  • I added/updated doc comments for public APIs. No API or signature was added; this fixes existing behavior.
  • My changes work for new and existing PDF files, verified by save/reload checks.
  • I ran the linters on my changes.

Handoff path limitation

The sandbox rejected the requested parent/global output locations as outside the writable round directory. The complete draft, ledger entry, branch metadata, and patch are saved here and in ready/pdf-lib-1590/. evidence/handoff-paths.json records the exact failures. A supervisor with write access must copy/append these local handoff files to the requested destinations.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: breakTextIntoLines removes empty lines in multiline text

1 participant