From a941d706c33011bce35fa6eaf55ba96e8bca30ef Mon Sep 17 00:00:00 2001 From: eliets2 Date: Fri, 6 Nov 2026 13:31:38 +0200 Subject: [PATCH] Picture Package and Custom Package pages can print cut guides at each cell's corners (#3843) * Picture Package and Custom Package pages can print cut guides at each cell's corners Picture Package and Custom Package pages can print cut guides at each cell's corners Picture Package and Custom Package pages can print cut guides at each cell's corners Test: picture_package_and_custom_package_pages_can_print_cut_guide failed before the change and passes after. * Print: Cut Guides in the package preview, page panel in its own function, tests follow the guides Co-Authored-By: Claude Opus 5.5 * Print: Cut Guides sit at each cell's corners, outside any border Co-Authored-By: Claude Opus 5.5 * Print: shorten the scroll position comment to what the code does Co-Authored-By: Claude Opus 5.5 * Print: back to one scroll position for the settings column Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: eliets2 <287273517+eliets2@users.noreply.github.com> Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- crates/engine/src/print/compose.rs | 14 ++++-- crates/engine/src/print/compose/tests.rs | 10 +++- crates/ui-egui/src/dialogs/print_view.rs | 58 ++++++++++++++---------- crates/ui-egui/src/tests/print.rs | 34 +++++++++++++- 4 files changed, 85 insertions(+), 31 deletions(-) diff --git a/crates/engine/src/print/compose.rs b/crates/engine/src/print/compose.rs index 16c683a84a..a45df4e7a2 100644 --- a/crates/engine/src/print/compose.rs +++ b/crates/engine/src/print/compose.rs @@ -98,7 +98,7 @@ pub struct PageStyle { pub page_numbers: bool, /// The print settings (sharpening, profile, resolution) at the bottom left of each page. pub page_info: bool, - /// Marks at the corners of each photo to cut along. + /// Marks at the corners of each photo to cut along (the packages' Cut Guides reuse this). pub crop_marks: bool, } @@ -116,7 +116,8 @@ pub fn rec2020_from_srgb8(c: [u8; 3]) -> [u16; 3] { } /// Whether a layout style prints the Page Options (page numbers, page info, crop marks): -/// Lightroom offers them for Single Image and Contact Sheet; its packages have Cut Guides instead. +/// Lightroom offers them for Single Image and Contact Sheet. Its packages have Cut Guides +/// instead, which print whatever this says ([`PageStyle::crop_marks`]). pub fn has_page_options(style: Style) -> bool { !style.is_package() } @@ -452,6 +453,8 @@ struct Marks { crop: Option<(usize, usize, usize)>, numbers: bool, info: Option, + /// Marks go at each cell's corners (a package's Cut Guides, outside any border), not the photo's. + around_cells: bool, ink: [u16; 3], text_px: f32, /// The printable area: the text sits in the margin below it, aligned with its sides. @@ -464,9 +467,10 @@ impl Marks { let page = &settings.page; let px = |inches: f64| (inches * ppi).round() as usize; Marks { - crop: (on && page.crop_marks).then(|| (px(CROP_MARK_IN), px(CROP_MARK_GAP_IN), px(CROP_MARK_PT / 72.0).max(1))), + crop: page.crop_marks.then(|| (px(CROP_MARK_IN), px(CROP_MARK_GAP_IN), px(CROP_MARK_PT / 72.0).max(1))), numbers: on && page.page_numbers, info: (on && page.page_info).then(|| page_info_text(settings)), + around_cells: !on, ink: rec2020_from_srgb8(mark_ink(page.background)), text_px: (PAGE_TEXT_PT / 72.0 * ppi) as f32, area: settings.layout.printable().ok().and_then(|a| px_rect(&a, ppi, pw, ph)), @@ -609,7 +613,9 @@ impl Prepared { } }; let photo = &cache.get(at).ok_or("render cache lost an entry")?.1; - placed.push(draw_cell(&mut page, photo, item.cell, &self.style).map_err(|e| format!("{}: {e}", item.name))?); + let cell = item.cell; + let drawn = draw_cell(&mut page, photo, cell, &self.style).map_err(|e| format!("{}: {e}", item.name))?; + placed.push(if self.marks.around_cells { cell } else { drawn }); } self.marks.draw(&mut page, &placed, index + 1); out.push(PageRaster { width: w as u32, height: h as u32, ppi: self.ppi, rgb: page.rgb }); diff --git a/crates/engine/src/print/compose/tests.rs b/crates/engine/src/print/compose/tests.rs index f1e979cc0a..830d3f0764 100644 --- a/crates/engine/src/print/compose/tests.rs +++ b/crates/engine/src/print/compose/tests.rs @@ -373,13 +373,19 @@ fn page_numbers_and_info_print_in_the_bottom_margin() { for p in &info { assert!(inked(p, left.0, left.1, 550, 600) > 10, "the print settings line"); } - // the packages have no Page Options in Lightroom: nothing is drawn - let all = PageStyle { page_numbers: true, page_info: true, crop_marks: true, ..Default::default() }; + // the packages have no page numbers or page info in Lightroom: nothing is drawn + let all = PageStyle { page_numbers: true, page_info: true, ..Default::default() }; let package = page_options_pages(&mut s, Style::PicturePackage, all); assert_eq!(package.len(), 2); for p in &package { assert_eq!(inked(p, 0, 400, 550, 600) + inked(p, 0, 400, 0, 50), 0); } + // their Cut Guides are the crop marks, at each photo's corners + let guides = page_options_pages(&mut s, Style::PicturePackage, PageStyle { crop_marks: true, ..Default::default() }); + assert_eq!(guides.len(), 2); + for (g, p) in guides.iter().zip(&package) { + assert!(inked(g, 0, 400, 0, 600) > inked(p, 0, 400, 0, 600), "the guides add ink"); + } } #[test] diff --git a/crates/ui-egui/src/dialogs/print_view.rs b/crates/ui-egui/src/dialogs/print_view.rs index 3161aa96f7..fda115e6c1 100644 --- a/crates/ui-egui/src/dialogs/print_view.rs +++ b/crates/ui-egui/src/dialogs/print_view.rs @@ -286,6 +286,32 @@ fn image_section(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens, st: &PrintSet }); } +/// The Page panel: the background, and the Page Options or, on a package, Cut Guides. +fn page_section(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens, st: &PrintSettings) { + let ctx = ui.ctx().clone(); + heading(ui, t, "Page"); + row(ui, t, "Background", |ui| { + if let Some(c) = colour(ui, "printBackground", st.page.background) { + patch(app, &ctx, json!({"page": {"background": c}})); + } + }); + if compose::has_page_options(st.layout.style) { + ui.label(egui::RichText::new(crate::i18n::tr("Page Options")).color(t.text_label)); + let p = &st.page; + for (id, label, on, key) in [ + ("printPageNumbers", "Page Numbers", p.page_numbers, "pageNumbers"), + ("printPageInfo", "Page Info", p.page_info, "pageInfo"), + ("printCropMarks", "Crop Marks", p.crop_marks, "cropMarks"), + ] { + if let Some(v) = check(ui, id, label, on) { + patch(app, &ctx, json!({"page": {(key): v}})); + } + } + } else if let Some(v) = check(ui, "printCropMarks", "Cut Guides", st.page.crop_marks) { + patch(app, &ctx, json!({"page": {"cropMarks": v}})); + } +} + fn settings(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens, pu: &mut PrintUi, st: &PrintSettings, photos: usize) { let ctx = ui.ctx().clone(); let l = &st.layout; @@ -461,25 +487,7 @@ fn settings(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens, pu: &mut PrintUi, }); } - heading(ui, t, "Page"); - row(ui, t, "Background", |ui| { - if let Some(c) = colour(ui, "printBackground", st.page.background) { - patch(app, &ctx, json!({"page": {"background": c}})); - } - }); - if compose::has_page_options(l.style) { - ui.label(egui::RichText::new(crate::i18n::tr("Page Options")).color(t.text_label)); - let p = &st.page; - for (id, label, on, key) in [ - ("printPageNumbers", "Page Numbers", p.page_numbers, "pageNumbers"), - ("printPageInfo", "Page Info", p.page_info, "pageInfo"), - ("printCropMarks", "Crop Marks", p.crop_marks, "cropMarks"), - ] { - if let Some(v) = check(ui, id, label, on) { - patch(app, &ctx, json!({"page": {(key): v}})); - } - } - } + page_section(app, ui, t, st); heading(ui, t, "Print Job"); row(ui, t, "Resolution", |ui| { @@ -720,10 +728,12 @@ fn package_cells( let ctx = ui.ctx().clone(); let first = ids.first().copied(); let cells: Vec = st.layout.cells_on_page(pu.page as u32).cloned().collect(); + let mut shown = Vec::new(); for c in &cells { let photo = if st.layout.style == Style::CustomPackage { c.photo.map(PhotoId).or(first) } else { first }; let rect = sheet.rect(&c.rect); paint_cell(app, painter, t, st, rect, photo, sheet, &c.rect); + shown.push(rect); let resp = ui.interact(rect, egui::Id::unique(("print-cell", c.id)), Sense::click_and_drag()); register(ui, format!("print:cell:{}", c.id), rect); if resp.clicked() || resp.drag_started() { @@ -760,6 +770,7 @@ fn package_cells( } }); } + page_options(painter, st, sheet, &shown, pu.page + 1); // the selected cell's outline and resize handle go over everything let Some(sel) = pu.selected.and_then(|s| cells.iter().find(|c| c.id == s)) else { return }; let rect = sheet.rect(&sel.rect); @@ -925,11 +936,9 @@ fn paint_cell( /// The Page Options as the print draws them ([`compose`]): crop marks at the corners of each /// photo, the page number at the bottom right and the print settings at the bottom left. -/// Packages draw none of them, as the print doesn't ([`compose::has_page_options`]). +/// Packages draw only the crop marks, as their Cut Guides at each cell's corners +/// ([`compose::has_page_options`]). fn page_options(painter: &egui::Painter, st: &PrintSettings, sheet: &Sheet, photos: &[Rect], number: usize) { - if !compose::has_page_options(st.layout.style) { - return; - } let p = &st.page; let ink = compose::mark_ink(p.background); let ink = Color32::from_rgb(ink[0], ink[1], ink[2]); @@ -946,6 +955,9 @@ fn page_options(painter: &egui::Painter, st: &PrintSettings, sheet: &Sheet, phot } } let Ok(area) = st.layout.printable() else { return }; + if !compose::has_page_options(st.layout.style) { + return; + } let area = sheet.rect(&area); let font = egui::FontId::proportional((compose::PAGE_TEXT_PT as f32 / 72.0 * sheet.scale).max(4.0)); let y = (area.bottom() + sheet.page.bottom()) / 2.0; diff --git a/crates/ui-egui/src/tests/print.rs b/crates/ui-egui/src/tests/print.rs index 68f3d328d0..7a6c380e4f 100644 --- a/crates/ui-egui/src/tests/print.rs +++ b/crates/ui-egui/src/tests/print.rs @@ -454,7 +454,37 @@ fn page_options_checkboxes_set_the_page_and_hide_for_packages() { scroll(&mut h, 600.0); click(&mut h, "button:printStyle-1"); assert!(has(&h, "check:printCropMarks"), "a contact sheet has Page Options"); - // Lightroom's packages have no Page Options + // Lightroom's packages have no page numbers or page info (they have Cut Guides, tested below) click(&mut h, "button:printStyle-2"); - assert!(!has(&h, "check:printPageNumbers") && !has(&h, "check:printCropMarks")); + assert!(!has(&h, "check:printPageNumbers") && !has(&h, "check:printPageInfo")); +} + +#[test] +fn picture_package_and_custom_package_pages_can_print_cut_guide() { + let mut h = demo(Services::default()); + open_print(&mut h); + let scroll = |h: &mut Headless, dy: f32| { + // The pointer position from the last widget interaction stays over the settings column, + // so scrolling keeps working even after combo:printPaper is out of view. + for _ in 0..4 { + h.request("ui.scroll", json!({"dy": dy}), T); + h.settle(T); + } + }; + // picture package (style 2) and custom package (style 3) both offer Cut Guides, not the + // Page Options: only crop marks, reusing page.cropMarks, labelled for packages + for style in ["button:printStyle-2", "button:printStyle-3"] { + click(&mut h, style); + scroll(&mut h, -600.0); + assert!(has(&h, "check:printCropMarks"), "{style}: a package has Cut Guides"); + assert!(!has(&h, "check:printPageNumbers") && !has(&h, "check:printPageInfo"), "{style}: packages have no page numbers or page info"); + assert!(h.painted_text().iter().any(|t| t == "Cut Guides"), "{style}: the checkbox is labelled Cut Guides: {:?}", h.painted_text()); + assert!(!h.painted_text().iter().any(|t| t == "Crop Marks"), "{style}: packages do not label it Crop Marks: {:?}", h.painted_text()); + assert!(!h.app.session.print.page.crop_marks); + click(&mut h, "check:printCropMarks"); + assert!(h.app.session.print.page.crop_marks, "{style}: Cut Guides sets crop_marks"); + click(&mut h, "check:printCropMarks"); + assert!(!h.app.session.print.page.crop_marks, "{style}: the reuse keeps reading page.cropMarks"); + scroll(&mut h, 600.0); + } }