Skip to content

fix(textbox): rotated and typewriter text boxes from other editors keep their shape - #529

Merged
DutchSailor merged 1 commit into
mainfrom
fix/foreign-freetext
Oct 6, 2026
Merged

DutchSailor merged 1 commit into
mainfrom
fix/foreign-freetext

Conversation

@DutchSailor

Copy link
Copy Markdown
Collaborator

What happened

The same drawing (annotations made in another editor, page /Rotate 90) showed two text box problems:

  1. Rotated labels. Text boxes turned by 90 degrees (/Rotate 270 on the annotation, the rotation in the appearance /Matrix) were drawn wide and short with clipped text instead of tall and narrow. tekstvakMaat worked out width and height from the /Rect in PDF coordinates while the angle is a display angle; on a /Rotate 90 or 270 page those axes are swapped. Files saved by Open PDF Studio hid this, because their appearance has a single re that is read directly; this producer writes two.
  2. Typewriter text. Title-block fields are /IT /FreeTextTypewriter, which never wraps. The app wrapped them like ordinary text boxes. The producer makes the box exactly as wide as the text, so a measurement 0.005 pt wider broke a two-word name onto two lines over the next field (on a PC without the font, more fields broke or overflowed). Saving then wrote the wrap into the file and dropped /IT.

What this changes

  • js/pdf/loader/tekstvak-rotatie.js: the size comes from the box as displayed (rectVp), without rounding; an orientation check for the appearance rectangle, with guards (callouts, near 45 degrees, negative or far-off results).
  • Typewriter (/IT /FreeTextTypewriter, also the spelling FreeTextTypeWriter): noWrap in the model; the layout breaks only at hard line breaks; the editor uses white-space: pre; the canvas does not clip it.
  • Saver: writes /IT /FreeTextTypewriter back and widens /Rect and /BBox to the widest line as other viewers measure it (the larger of the canvas width and the substitute standard font), for left, centred and right alignment; non-standard font names map to a standard font instead of failing.
  • js/pdf/saver-test-hooks.mjs lets node tests run the real saver.js.

Unchanged

Text boxes saved by Open PDF Studio itself (including callouts and the /DS margin from 2026.39.2): six own variants on four page rotations save identically except /M, and load to identical models. Ordinary FreeText and callouts from other programs still wrap.

Verification

  • 31 new tests plus additions, each seen failing first; npm run test:unit 2629 passed, 0 failed; npx vite build and npm run typecheck green; the changed tests also pass with --no-experimental-strip-types.
  • Live check in a local build: the rotated labels are tall and narrow with the right reading direction, the typewriter field stays on one line.
  • Save round trip with the full verification set: identical to release 2026.39.2. Text rotation, save duplicates and rotation sweep (46/46) good; comparison sweep: the same flagged files as on main.
  • An adversarial review found six defects (ISO spelling, a crash on Helvetica-* font names, centred and right alignment past the box); all fixed test-first.

🤖 Generated with Claude Code

…ep their shape

- A text box turned by 90 degrees on a page with /Rotate 90 or 270 got
  its width and height swapped, because its size was worked out from
  the box in PDF coordinates while its angle is a screen angle. The
  size now comes from the box as it is displayed.
- Typewriter text (/IT /FreeTextTypewriter, also spelled
  FreeTextTypeWriter) never wraps, but it was wrapped like an ordinary
  text box and grew over the next field. It now breaks only at hard
  line breaks. Saving writes /IT back and widens the box to the text
  as other viewers measure it, for any alignment.
Text boxes saved by Open PDF Studio itself load and save as before.
@DutchSailor
DutchSailor merged commit 6d679d8 into main Oct 6, 2026
4 checks passed
DutchSailor added a commit that referenced this pull request Oct 6, 2026
@DutchSailor
DutchSailor deleted the fix/foreign-freetext branch October 6, 2026 06:38
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.

1 participant