Skip to content

ipptransform: transform annotations for scaled and N-up pages - #223

Open
cyberph3onix wants to merge 1 commit into
OpenPrinting:masterfrom
cyberph3onix:ipptransform-annots
Open

cyberph3onix wants to merge 1 commit into
OpenPrinting:masterfrom
cyberph3onix:ipptransform-annots

Conversation

@cyberph3onix

Copy link
Copy Markdown

Fixes #71.

Problem

  • Scaled 1-up: the input page's Annots array was copied unchanged, so annotation rectangles kept their original coordinates while the page content was scaled and centered on the output media. Each annotation's /P also pulled the input page and its content streams into the output.
  • N-up: annotations were not copied at all.

Changes

  • Moved the cell transform calculation out of copy_page() into get_cell_matrix().
  • Added copy_annots(), which creates a new annotation dictionary for each input annotation:
    • maps Rect and QuadPoints through the cell matrix (plus the back side transform for duplex) and clips them to the layout cell,
    • scales Border and BS widths and dash patterns (ISO 32000 12.5.2 / 12.5.4),
    • drops /P, /IRT, /Parent and /Popup, and skips Popup annotations.
  • Both the scaled 1-up and N-up paths now use it. The array is built before pdfio_start_page() since PDFio writes the page dictionary there, and it is reset for each copy so collated copies don't pile up duplicate annotations.
  • The unscaled fast path (pdfioPageCopy) is unchanged.

Testing

I used a 2-page Letter PDF where each page has a filled box and a Link annotation covering exactly that box (one with a dashed /Border, one with a /BS dictionary). For each output I rendered it with mutool draw and checked that the pixels just inside each Rect are the box color and the ones just outside are not:

Case Before After
A4, print-scaling=fit Rect not transformed ✅
number-up=2 (rotated cells) no annotations ✅
number-up=4 no annotations ✅
Letter, no scaling (fast path) ✅ ✅ (unchanged)
Duplex back side, -s rotated / -s flipped — ✅
copies=3, collated — ✅ one set per page
Text note + reply (/IRT), scaled 1-up 4 page objects for 2 pages (orphaned input page copies via /P) ✅ 2 page objects, no extra annotation copies

Border example, 2-up (scale 0.63): /Border [1 1 2 [3 2]] → [.63 .63 1.26 [1.89 1.26]], /BS /W 4 /D [6 3] → /W 2.52 /D [3.78 1.89].

tools/run-tests.sh passes (202 tests, 0 failed).

Known limitations

  • Widget annotations keep their appearance, but /Parent (the field) and the document AcroForm aren't copied, so fields are no longer interactive. That should be fine for print output.
  • In rotated N-up cells, appearance streams are fitted to the new Rect but not rotated (/AP /Matrix isn't changed).
  • Existing behavior, not changed here: the cell matrix doesn't account for a non-zero CropBox origin. Annotations still line up with the content since they use the same matrix.

…penPrinting#71)

The scaled 1-up path copied Annots without transforming Rect, so
annotations were misplaced when a page was scaled to the media, and
the N-up path dropped annotations entirely.

Add copy_annots(), which applies the cell matrix (and back side
transform) to Rect and QuadPoints, scales Border/BS widths and dash
arrays, and drops the P, IRT, Parent and Popup references.  Use it
for both the scaled 1-up and N-up paths.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ipptransform: Copy and update Annots objects from page dictionaries

1 participant