Add page composition: n-up, booklets, overlays and blanks - #2
Merged
Conversation
Pages that this package builds rather than borrows. A page is now borrowed, composed of other pages, or empty, and the three write out through the same path — which is what lets a laid-out sheet be laid out again, and a watermark later be just another tile. Each page placed inside another becomes a Form XObject whose own coordinates run from the origin to its effective size, so whatever places it need only scale and translate. A page's rotation is baked into that form's matrix exactly as a viewer would apply it, and a rotation of ninety or two hundred and seventy swaps which way round it is measured — so a sideways page laid out two-up takes the shape it will actually print in, not the shape its media box claims. The box used is the crop box where there is one, since that is what gets printed. NUp picks the grid rather than being told it: of every arrangement with at least n cells, the one whose cells come closest in shape to the pages going into them, with a small penalty for cells left over. Booklet reorders for saddle stitching — pages folded in half and stapled through the spine — padding to a multiple of four and laying two to a sheet. Overlay and Underlay draw one document over or under another, centred and scaled to fit. Generated content streams are compressed, which they have to be: they were decoded to get here and would otherwise go out several times the size they came in. Verified on the corpus rather than by assertion: for each of the 1 959 multi-page files, two-up produces the right number of sheets and every form drawn on them carries exactly the bytes of the page it stands for, blanks included. All 1 959 hold, and the 118 833-file checks of the earlier verbs still do. Exact 100% statement coverage over the package and the command, go vet clean, nine cross-compilation targets. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Pages that this package builds rather than borrows. A page is now borrowed,
composed of other pages, or empty, and the three write out through the same
path — which is what lets a laid-out sheet be laid out again, and a watermark
later be just another tile.
Each page placed inside another becomes a Form XObject whose own coordinates
run from the origin to its effective size, so whatever places it need only
scale and translate. A page's rotation is baked into that form's matrix
exactly as a viewer would apply it, and a rotation of ninety or two hundred and
seventy swaps which way round it is measured — so a sideways page laid out
two-up takes the shape it will actually print in, not the shape its media box
claims. The box used is the crop box where there is one, since that is what
gets printed.
NUp picks the grid rather than being told it: of every arrangement with at
least n cells, the one whose cells come closest in shape to the pages going
into them, with a small penalty for cells left over. Booklet reorders for
saddle stitching — pages folded in half and stapled through the spine — padding
to a multiple of four and laying two to a sheet. Overlay and Underlay draw one
document over or under another, centred and scaled to fit.
Generated content streams are compressed, which they have to be: they were
decoded to get here and would otherwise go out several times the size they came
in.
Verified on the corpus rather than by assertion: for each of the 1 959
multi-page files, two-up produces the right number of sheets and every form
drawn on them carries exactly the bytes of the page it stands for, blanks
included. All 1 959 hold, and the 118 833-file checks of the earlier verbs
still do.
Exact 100% statement coverage over the package and the command, go vet clean,
nine cross-compilation targets.