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]