From 000daef5a6eb27dea31e8d9425d322b402e9bb0c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 1 Nov 2026 09:17:08 -0800 Subject: [PATCH] Print: the page boxes of a Copies per Sheet page hold only the copies on the paper When the placement moved some copies off the paper, each of those copies counted as the whole page, so the TrimBox and BleedBox became the paper. They now hold the copies that print, and the whole page only when no copy is on it. --- crates/pdf/src/print/layout.rs | 16 +++++++++++----- crates/pdf/src/tests/print.rs | 3 +++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/pdf/src/print/layout.rs b/crates/pdf/src/print/layout.rs index 9002ceb80..3d404abab 100644 --- a/crates/pdf/src/print/layout.rs +++ b/crates/pdf/src/print/layout.rs @@ -246,12 +246,14 @@ pub(crate) fn layout(doc: &Document, set: &PrintSettings, warnings: &mut Vec 0.0 { (t, b) } else { (page, page) } + (t.area() > 0.0).then_some((t, b)) }; + let boxes = |view: Affine, trim: Rect| visible(view, trim).unwrap_or((page, page)); let base = |view, window, place, area, trim, (page_trim, page_bleed), tile, copies| Layout { artboard, tile, @@ -305,8 +307,12 @@ pub(crate) fn layout(doc: &Document, set: &PrintSettings, warnings: &mut Vec = grid.map_or_else(Vec::new, |(cols, rows)| { (0..rows).flat_map(|j| (0..cols).map(move |i| Vec2::new(i as f64 * step.0, j as f64 * step.1))).collect() }); - let page_boxes = - copies.iter().map(|m| boxes(turn, trim + *m)).reduce(|a, b| (a.0.union(b.0), a.1.union(b.1))).unwrap_or_else(|| boxes(turn, trim)); + // The boxes hold the copies on the page; copies off it are left out. + let page_boxes = copies + .iter() + .filter_map(|m| visible(turn, trim + *m)) + .reduce(|a, b| (a.0.union(b.0), a.1.union(b.1))) + .unwrap_or_else(|| boxes(turn, trim)); pages.push(base(turn, None, place_at(trim), bleed_box, trim, page_boxes, None, copies)); continue; } diff --git a/crates/pdf/src/tests/print.rs b/crates/pdf/src/tests/print.rs index 694430ad6..daf2bab07 100644 --- a/crates/pdf/src/tests/print.rs +++ b/crates/pdf/src/tests/print.rs @@ -246,6 +246,9 @@ fn copies_per_sheet_fill_the_page_in_a_grid() { // The placement places the grid, inside the margin. let pv = preview(&d, &settings(json!({"copiesPerSheet": true, "margin": 9, "placement": {"origin": "topLeft"}}))).unwrap(); assert_eq!(corners(&pv), grid(&[9.0, 153.0, 297.0, 441.0], &[9.0, 261.0, 513.0])); + // Moved 400 pt right, two columns leave the paper: the TrimBox holds the copies still on it. + let pv = preview(&d, &settings(json!({"copiesPerSheet": true, "placement": {"origin": "topLeft", "x": 400}}))).unwrap(); + assert_eq!(pv.sheets[0].trim, [400.0, 0.0, 612.0, 756.0]); } #[test]