From f06ecfaceb75a2bc2f0abe139acd82d5dcd7f357 Mon Sep 17 00:00:00 2001 From: Higgs32584 Date: Wed, 18 Nov 2026 08:24:06 -0500 Subject: [PATCH] #816: print test draws the cell picture through set_picture The image-budget test inserted the cell picture into `cell_pictures` directly. The cell had no value, so `draw_block` skipped it, and only the floating picture was measured. The test now uses `Sheet::set_picture` and checks the cell picture's draws separately: one per page. --- crates/engine/src/cmd/print/tests.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/print/tests.rs b/crates/engine/src/cmd/print/tests.rs index 80926ae0e3..f6d90f70c1 100644 --- a/crates/engine/src/cmd/print/tests.rs +++ b/crates/engine/src/cmd/print/tests.rs @@ -814,7 +814,8 @@ fn picture_copies_across_pages_stay_within_the_image_budget() { mime: "image/png".into(), alt: String::new(), }); - sh.cell_pictures.insert(CellRef::new(0, 2), std::sync::Arc::new(CellPicture { data: png, mime: "image/png".into(), alt: String::new() })); + // `set_picture` gives C1 the cell value `draw_block` needs to reach the picture at all. + sh.set_picture(CellRef::new(0, 2), std::sync::Arc::new(CellPicture { data: png, mime: "image/png".into(), alt: String::new() })); let d = s.doc().unwrap(); let lays = layouts(&d.wb, &PrintOptions::from_params(&json!({}), "file.exportPdf").unwrap()); @@ -824,7 +825,12 @@ fn picture_copies_across_pages_stay_within_the_image_budget() { // Identical copies are written to the file once, so the draws are what to count. let draws = |pdf: &[u8]| String::from_utf8_lossy(pdf).matches(" Do Q").count(); let full_draws = draws(&full); - assert!(full_draws >= pages - 1, "{full_draws} picture draws on {pages} pages"); + // The cell picture, on its own: the same render without it draws one picture fewer per page. + let mut floating_only = (*d.wb).clone(); + floating_only.sheet_mut(0).unwrap().cell_pictures.clear(); + let floating_draws = draws(&render_pdf(&floating_only, &lays, "t", "").unwrap().bytes); + assert!(floating_draws >= pages - 1, "{floating_draws} floating picture draws on {pages} pages"); + assert_eq!(full_draws - floating_draws, pages, "the title-row cell picture draws once on each of {pages} pages"); // 64×64 RGB is 12,288 bytes: a 64 KiB budget holds a handful of page copies, not one per page. let budget = 64 * 1024;