PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Print: marks need room in the printable area only when fitting (#7782)
jlange0e67ff8e4f7e
diff --git a/crates/engine/src/print_cmds.rs b/crates/engine/src/print_cmds.rsindex af06fd2e9..019dd7330 100644--- a/crates/engine/src/print_cmds.rs+++ b/crates/engine/src/print_cmds.rs@@ -526,13 +526,15 @@ pub fn layout(doc: &Document, p: &Value, cmd: &str) -> Result<PrintLayout> {// borderless paper); marks keep their inset inside it. Without one (CUPS, PDF), the paper// minus a fixed margin.let emulsion_down = p.get("emulsionDown").and_then(Value::as_bool).unwrap_or(false);+ let fit = p.get("scaleToFit").and_then(Value::as_bool).unwrap_or(false);let fit_box = match printable(p, (pw, ph), cmd)? {Some((x, y, w, h)) => {// Emulsion Down mirrors the page as it prints: fit the mirror of the printable area,// so the printed image lands inside the real one.let x = if emulsion_down { pw - x - w } else { x };let inset = if has_marks { 36.0 } else { 0.0 };- if !(w > 2.0 * inset && h > 2.0 * inset) {+ // Only Scale to Fit Media needs room for the marks; a manual scale is the user's.+ if fit && !(w > 2.0 * inset && h > 2.0 * inset) {return Err(bad(cmd, "the printable area is too small for crop and registration marks"));}(x + inset, y + inset, w - 2.0 * inset, h - 2.0 * inset)@@ -542,7 +544,6 @@ pub fn layout(doc: &Document, p: &Value, cmd: &str) -> Result<PrintLayout> {(margin, margin, pw - 2.0 * margin, ph - 2.0 * margin)}};- let fit = p.get("scaleToFit").and_then(Value::as_bool).unwrap_or(false);let scale = if fit { (fit_box.2 / iw).min(fit_box.3 / ih) } else { p.get("scale").and_then(Value::as_f64).filter(|v| *v > 0.0).unwrap_or(100.0) / 100.0 };let (w, h) = (iw * scale, ih * scale);let center = p.get("center").and_then(Value::as_bool).unwrap_or(true);diff --git a/crates/engine/src/print_cmds/tests.rs b/crates/engine/src/print_cmds/tests.rsindex 0a41a2247..8093547c2 100644--- a/crates/engine/src/print_cmds/tests.rs+++ b/crates/engine/src/print_cmds/tests.rs@@ -860,3 +860,21 @@ fn a_print_uses_the_printable_area_but_does_not_remember_it() {let last = last_print(&s).unwrap();assert!(last.get("printable").is_none() && last["scaleToFit"] == true, "{last}");}++#[test]+fn a_rejected_printable_area_fails_the_print_and_changes_nothing() {+ let mut s = Session::new();+ s.execute("file.new", json!({"width": 500, "height": 1000, "resolution": 72})).unwrap();+ s.execute("file.print", json!({"paper": "a3", "scale": 50, "dryRun": true})).unwrap();+ let before = (last_print(&s), s.prefs.get().dialogs.get(REMEMBERED).cloned(), s.active().unwrap().doc.clone());+ for printable in [json!([2000, 0, 100, 100]), json!([0, "oops", 0, 842.29, 1191.14])] {+ let r = s.execute("file.print", json!({"paper": "a3", "scaleToFit": true, "printable": printable, "dryRun": true}));+ assert!(r.is_err(), "{printable}: {r:?}");+ }+ assert!(before == (last_print(&s), s.prefs.get().dialogs.get(REMEMBERED).cloned(), s.active().unwrap().doc.clone()));+ // Marks need room only to fit: a small manual scale in a 60 pt-wide area prints.+ let r = s.execute("file.print", json!({"paper": "a3", "scale": 5, "printable": [0, 0, 60, 1191.14], "cornerCropMarks": true, "dryRun": true}));+ assert!(r.is_ok(), "{r:?}");+ let r = s.execute("file.print", json!({"paper": "a3", "scaleToFit": true, "printable": [0, 0, 60, 1191.14], "cornerCropMarks": true, "dryRun": true}));+ assert!(r.is_err(), "{r:?}");+}