Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge PR #6389: Print: Functions › Bleed (corner crop marks on the trim line)

aiongg029e97951f67
diff --cc crates/engine/src/print_cmds.rs
index 9b264f061,29de3e57f..a7ddb98ad
--- a/crates/engine/src/print_cmds.rs
+++ b/crates/engine/src/print_cmds.rs
@@@ -642,7 -465,7 +676,7 @@@ fn render_and_spool(doc: &Document, p:
sent = true;
}
Ok(
- json!({"pdf": pdf_path, "bytes": pdf_len, "paper": [pw, ph], "imageRect": [x, y, w, h], "emulsionDown": emulsion_down, "scale": scale * 100.0, "copies": copies, "command": command, "sent": sent, "spooler": spool, "backend": backend, "color": color}),
- json!({"pdf": pdf_path, "bytes": pdf.len(), "paper": [pw, ph], "imageRect": [x, y, w, h], "emulsionDown": emulsion_down, "bleed": marks.bleed / 72.0, "scale": scale * 100.0, "copies": copies, "command": command, "sent": sent, "spooler": spool, "color": color}),
++ json!({"pdf": pdf_path, "bytes": pdf_len, "paper": [pw, ph], "imageRect": [x, y, w, h], "emulsionDown": emulsion_down, "bleed": marks.bleed / 72.0, "scale": scale * 100.0, "copies": copies, "command": command, "sent": sent, "spooler": spool, "backend": backend, "color": color}),
)
}
@@@ -1098,7 -784,7 +1132,7 @@@ pub fn specs() -> Vec<CommandSpec>
CommandSpec { id: $id, label: $label, menu: $menu, shortcut: $sc, params: $params, enabled: $enabled, journal: true, run: $run }
};
}
- const PRINT_PARAMS: &str = r##"{"printerSettings":hex? (Windows driver settings),"printer":name? (default printer),"copies":1..999=1,"paper":"letter|legal|tabloid|a3|a4|a5|4x6|5x7"|[w,h] pt="letter","orientation":"portrait|landscape"="portrait","center":bool=true,"top":in?,"left":in?,"scale":%=100,"scaleToFit":bool=false,"colorHandling":"printerManages|photocraftManages|noColorManagement"="printerManages","printerProfile":profile? (photocraftManages),"intent":"perceptual|relative|saturation|absolute"="relative","bpc":bool=true,"cornerCropMarks":bool,"centerCropMarks":bool,"registrationMarks":bool,"description":bool,"labels":bool,"emulsionDown":bool=false (mirror the page left to right, for sublimation and other transfer printing),"output":pdf path? (print to PDF; then "send" defaults to false),"send":bool?,"printServer":"host[:port]|socket path"? (default: the system's CUPS; a named server is always printed to over IPP),"dryRun":bool=false (render the PDF, report the backend command, don't spool; write a PDF only at an explicit output path)} → {pdf:path|null (null without explicit output), imageRect, command:diagnostic array|null, sent, spooler:where the job went|null, backend:"lp|windows|ipp|portal"|null}"##;
- const PRINT_PARAMS: &str = r##"{"printerSettings":hex? (Windows driver settings),"printer":name? (default printer),"copies":1..999=1,"paper":"letter|legal|tabloid|a3|a4|a5|4x6|5x7"|[w,h] pt="letter","orientation":"portrait|landscape"="portrait","center":bool=true,"top":in?,"left":in?,"scale":%=100,"scaleToFit":bool=false,"colorHandling":"printerManages|photocraftManages|noColorManagement"="printerManages","printerProfile":profile? (photocraftManages),"intent":"perceptual|relative|saturation|absolute"="relative","bpc":bool=true,"cornerCropMarks":bool,"centerCropMarks":bool,"registrationMarks":bool,"bleed":in=0 (Functions › Bleed: corner crop marks this far inside the image edge, on the trim line),"description":bool,"labels":bool,"emulsionDown":bool=false (mirror the page left to right, for sublimation and other transfer printing),"output":pdf path? (print to PDF; then "send" defaults to false),"send":bool?,"dryRun":bool=false (render the PDF, report the backend command, don't spool; write a PDF only at an explicit output path)} → {pdf:path|null (null without explicit output), imageRect, command:diagnostic array|null, sent}"##;
++ const PRINT_PARAMS: &str = r##"{"printerSettings":hex? (Windows driver settings),"printer":name? (default printer),"copies":1..999=1,"paper":"letter|legal|tabloid|a3|a4|a5|4x6|5x7"|[w,h] pt="letter","orientation":"portrait|landscape"="portrait","center":bool=true,"top":in?,"left":in?,"scale":%=100,"scaleToFit":bool=false,"colorHandling":"printerManages|photocraftManages|noColorManagement"="printerManages","printerProfile":profile? (photocraftManages),"intent":"perceptual|relative|saturation|absolute"="relative","bpc":bool=true,"cornerCropMarks":bool,"centerCropMarks":bool,"registrationMarks":bool,"bleed":in=0 (Functions › Bleed: corner crop marks this far inside the image edge, on the trim line),"description":bool,"labels":bool,"emulsionDown":bool=false (mirror the page left to right, for sublimation and other transfer printing),"output":pdf path? (print to PDF; then "send" defaults to false),"send":bool?,"printServer":"host[:port]|socket path"? (default: the system's CUPS; a named server is always printed to over IPP),"dryRun":bool=false (render the PDF, report the backend command, don't spool; write a PDF only at an explicit output path)} → {pdf:path|null (null without explicit output), imageRect, command:diagnostic array|null, sent, spooler:where the job went|null, backend:"lp|windows|ipp|portal"|null}"##;
vec![
spec!("file.print", "Print…", &["File"], Some("Cmd+P"), PRINT_PARAMS, native_doc, print),
diff --cc crates/engine/src/print_cmds/tests.rs
index 38567ffb6,f3d1fc3fe..e0c5c8d55
--- a/crates/engine/src/print_cmds/tests.rs
+++ b/crates/engine/src/print_cmds/tests.rs
@@@ -557,315 -435,73 +557,386 @@@ fn printers_lists_the_spooler_destinati
}
}
+/// Spooling tests run in a child process: `disable_printing` is process-wide and a test above
+/// sets it, and CI sets `PHOTOCRAFT_NO_PRINT` for the whole shell. True in the child, which runs
+/// the test body; the parent starts the child and checks that it passed.
+fn in_child(test: &str, envs: &[(&str, &str)]) -> bool {
+ const CHILD: &str = "PHOTOCRAFT_TEST_PRINT_CHILD";
+ if std::env::var_os(CHILD).is_some() {
+ return true;
+ }
+ let mut cmd = std::process::Command::new(std::env::current_exe().unwrap());
+ cmd.args(["--exact", test, "--nocapture"]).env(CHILD, "1").env_remove("PHOTOCRAFT_NO_PRINT");
+ for (k, v) in envs {
+ cmd.env(k, v);
+ }
+ // Bounded: a child stuck in a printer dialog or a driver must not hang the suite.
+ let mut child = cmd.stdout(std::process::Stdio::piped()).stderr(std::process::Stdio::piped()).spawn().unwrap();
+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(120);
+ let status = loop {
+ if let Some(status) = child.try_wait().unwrap() {
+ break Some(status);
+ }
+ if std::time::Instant::now() > deadline {
+ let _ = child.kill();
+ break None;
+ }
+ std::thread::sleep(std::time::Duration::from_millis(50));
+ };
+ let out = child.wait_with_output().unwrap();
+ assert!(
+ status.is_some_and(|s| s.success()),
+ "{}\nstdout: {}\nstderr: {}",
+ if status.is_none() { "the child did not finish within 120 s and was killed" } else { "the child failed" },
+ String::from_utf8_lossy(&out.stdout),
+ String::from_utf8_lossy(&out.stderr)
+ );
+ false
+}
+
+/// A spooler that keeps every job it gets.
+fn recording_spooler(preferred: bool, seen: &std::sync::Arc<std::sync::Mutex<Vec<PrintJob>>>) -> Spooler {
+ let seen = std::sync::Arc::clone(seen);
+ Spooler {
+ name: "test",
+ preferred,
+ run: std::sync::Arc::new(move |job: &PrintJob| {
+ seen.lock().unwrap().push(job.clone());
+ Ok("queued".into())
+ }),
+ }
+}
+
+#[test]
+fn a_preferred_app_spooler_takes_the_job() {
+ if !in_child("print_cmds::tests::a_preferred_app_spooler_takes_the_job", &[]) {
+ return;
+ }
+ let seen = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));
+ let mut s = session("rgb", 8);
+ s.print_spooler = Some(recording_spooler(true, &seen));
+ let r = s.execute("file.print", json!({"copies": 2, "paper": "a4", "orientation": "landscape"})).unwrap();
+ assert_eq!((r["sent"].as_bool(), r["backend"].as_str(), r["spooler"].as_str()), (Some(true), Some("test"), Some("queued")));
+ assert!(r["pdf"].is_null(), "{r}");
+ let jobs = seen.lock().unwrap();
+ let job = &jobs[0];
+ assert!(job.pdf.starts_with(b"%PDF-1.4"));
+ assert_eq!((job.copies, job.title.as_str(), job.printer.as_deref(), job.landscape), (2, "Print Me.psd", None, true));
+ assert!((job.paper.0 - 841.89).abs() < 0.01 && (job.paper.1 - 595.28).abs() < 0.01);
+ drop(jobs);
+ // A named print server asks for the IPP route, preferred spooler or not.
+ let e = s.execute("file.print", json!({"printServer": "127.0.0.1:1"})).unwrap_err().to_string();
+ assert!(e.contains("no print server at 127.0.0.1:1") || e.contains("not available on Windows"), "{e}");
+ assert_eq!(seen.lock().unwrap().len(), 1);
+ // "output" keeps the file and does not spool unless asked.
+ let out = format!("{}/out.pdf", tmp("output"));
+ let r = s.execute("file.print", json!({"output": out})).unwrap();
+ assert_eq!((r["sent"].as_bool(), r["pdf"].as_str()), (Some(false), Some(out.as_str())));
+ assert!(std::path::Path::new(&out).exists());
+}
+
+#[cfg(not(target_os = "windows"))]
+mod cups {
+ use super::*;
+ use photocraft_ipp::{
+ Attribute, OP_CUPS_GET_CLASSES, OP_CUPS_GET_DEFAULT, OP_CUPS_GET_PRINTERS, OP_PRINT_JOB, Printer, Request, TAG_JOB_GROUP, TAG_NAME, TAG_PRINTER_GROUP,
+ };
+ use std::io::{BufRead, BufReader, Read, Write};
+ use std::sync::mpsc;
+
+ fn printer(name: &str, is_default: bool) -> Printer {
+ Printer { name: name.into(), info: String::new(), state: 3, accepting_jobs: true, is_default, is_class: false }
+ }
+
+ #[test]
+ fn the_printer_is_the_requested_one_else_the_default_else_the_only_one() {
+ let two = [printer("Office", false), printer("Lab", true)];
+ assert_eq!(resolve_printer(None, Some("Lab"), &two).ok(), Some("Lab".into()));
+ assert_eq!(resolve_printer(Some("office"), Some("Lab"), &two).ok(), Some("Office".into()));
+ assert_eq!(resolve_printer(None, None, &two[..1]).ok(), Some("Office".into()));
+ match resolve_printer(None, None, &two) {
+ Err(SpoolError::Failed(e)) => assert!(e.contains("no default printer") && e.contains("Office, Lab"), "{e}"),
+ _ => panic!("several printers and no default must fail"),
+ }
+ match resolve_printer(Some("Nope"), Some("Lab"), &two) {
+ Err(SpoolError::Failed(e)) => assert!(e.contains("`Nope`") && e.contains("Office, Lab"), "{e}"),
+ _ => panic!("an unknown printer must fail"),
+ }
+ match resolve_printer(None, None, &[]) {
+ Err(SpoolError::NoRoute(e)) => assert!(e.contains("no printer is set up"), "{e}"),
+ _ => panic!("no printers is no route"),
+ }
+ // A printer asked for by name on a server without any is a failure, not a missing route.
+ match resolve_printer(Some("Office"), None, &[]) {
+ Err(SpoolError::Failed(e)) => assert!(e.contains("`Office`") && e.contains("none"), "{e}"),
+ _ => panic!("a named printer never falls through"),
+ }
+ // A stale default that the server no longer lists falls through to the only printer.
+ assert_eq!(resolve_printer(None, Some("Gone"), &two[..1]).ok(), Some("Office".into()));
+ }
+
+ /// What the fake received per request: op, attributes, document.
+ type Seen = (u16, Vec<Attribute>, Vec<u8>);
+
+ /// A fake CUPS on a TCP port: lists `printers` and `classes`, names `default`, accepts jobs
+ /// as id 42. Answers for as long as the test process lives.
+ fn fake_cups(printers: &'static [&'static str], classes: &'static [&'static str], default: Option<&'static str>) -> (String, mpsc::Receiver<Seen>) {
+ let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
+ let server = format!("127.0.0.1:{}", listener.local_addr().unwrap().port());
+ let (tx, rx) = mpsc::channel();
+ std::thread::spawn(move || {
+ for stream in listener.incoming() {
+ let Ok(stream) = stream else { break };
+ let mut reader = BufReader::new(stream);
+ let (mut first, mut line, mut len) = (String::new(), String::new(), 0usize);
+ loop {
+ line.clear();
+ if reader.read_line(&mut line).unwrap_or(0) == 0 || line == "\r\n" {
+ break;
+ }
+ if first.is_empty() {
+ first = line.clone();
+ }
+ if let Some(v) = line.to_ascii_lowercase().strip_prefix("content-length:") {
+ len = v.trim().parse().unwrap();
+ }
+ }
+ if first.is_empty() {
+ continue; // a reachability probe
+ }
+ let mut body = vec![0u8; len];
+ reader.read_exact(&mut body).unwrap();
+ let (op, attrs, doc) = photocraft_ipp::parse_request(&body).unwrap();
+ let list = |names: &[&str]| {
+ if names.is_empty() {
+ return Request::new(0x0406, 1).end();
+ }
+ let mut r = Request::new(0, 1);
+ for p in names {
+ r.group(TAG_PRINTER_GROUP);
+ r.attr(TAG_NAME, "printer-name", p.as_bytes());
+ }
+ r.end()
+ };
+ let reply = match op {
+ OP_CUPS_GET_PRINTERS => list(printers),
+ OP_CUPS_GET_CLASSES => list(classes),
+ OP_CUPS_GET_DEFAULT => match default {
+ Some(d) => {
+ let mut r = Request::new(0, 1);
+ r.group(TAG_PRINTER_GROUP);
+ r.attr(TAG_NAME, "printer-name", d.as_bytes());
+ r.end()
+ }
+ None => Request::new(0x0406, 1).end(),
+ },
+ OP_PRINT_JOB => {
+ let mut r = Request::new(0, 1);
+ r.group(TAG_JOB_GROUP);
+ r.integer("job-id", 42);
+ r.end()
+ }
+ _ => Request::new(0x0501, 1).end(),
+ };
+ let _ = tx.send((op, attrs, doc));
+ let mut out = reader.into_inner();
+ let _ = out.write_all(format!("HTTP/1.1 200 OK\r\nContent-Type: application/ipp\r\nContent-Length: {}\r\n\r\n", reply.len()).as_bytes());
+ let _ = out.write_all(&reply);
+ let _ = out.flush();
+ }
+ });
+ (server, rx)
+ }
+
+ #[test]
+ fn a_named_server_is_printed_to_over_ipp() {
+ if !in_child("print_cmds::tests::cups::a_named_server_is_printed_to_over_ipp", &[]) {
+ return;
+ }
+ let (server, rx) = fake_cups(&["Office"], &["Lab"], Some("Lab"));
+ let mut s = session("rgb", 8);
+ let r = s.execute("file.print", json!({"printServer": server, "copies": 3})).unwrap();
+ assert_eq!((r["sent"].as_bool(), r["backend"].as_str(), r["spooler"].as_str()), (Some(true), Some("ipp"), Some("job 42 on Lab")));
+ assert!(r["pdf"].is_null());
+ let job = std::iter::from_fn(|| rx.try_recv().ok()).find(|(op, _, _)| *op == OP_PRINT_JOB).expect("a Print-Job request");
+ let attr = |name: &str| job.1.iter().find(|a| a.name == name).unwrap_or_else(|| panic!("{name}"));
+ assert!(attr("printer-uri").text().ends_with("/classes/Lab"), "{}", attr("printer-uri").text());
+ assert_eq!(
+ (attr("copies").int(), attr("job-name").text().as_str(), attr("document-format").text().as_str()),
+ (Some(3), "Print Me.psd", "application/pdf")
+ );
+ assert!(job.2.starts_with(b"%PDF-1.4"));
+ // The requested printer, in any case; an unknown one names the choices.
+ let r = s.execute("file.print", json!({"printServer": server, "printer": "office"})).unwrap();
+ assert_eq!(r["spooler"], "job 42 on Office");
+ let job = std::iter::from_fn(|| rx.try_recv().ok()).filter(|(op, _, _)| *op == OP_PRINT_JOB).last().expect("the second Print-Job");
+ assert!(job.1.iter().any(|a| a.name == "printer-uri" && a.text().ends_with("/printers/Office")));
+ let e = s.execute("file.print", json!({"printServer": server, "printer": "Nope"})).unwrap_err().to_string();
+ assert!(e.contains("`Nope`") && e.contains("Office, Lab"), "{e}");
+ // Printers can be listed.
+ let r = s.execute("file.printers", json!({"printServer": server})).unwrap();
+ let names: Vec<&str> = r["printers"].as_array().unwrap().iter().map(|p| p["name"].as_str().unwrap()).collect();
+ assert_eq!((names, r["default"].as_str()), (vec!["Office", "Lab"], Some("Lab")));
+ assert_eq!(
+ (r["printers"][1]["default"].as_bool(), r["printers"][1]["class"].as_bool(), r["printers"][0]["class"].as_bool()),
+ (Some(true), Some(true), Some(false))
+ );
+ }
+
+ #[test]
+ fn without_a_printer_the_app_spooler_takes_over() {
+ if !in_child("print_cmds::tests::cups::without_a_printer_the_app_spooler_takes_over", &[]) {
+ return;
+ }
+ let (server, _rx) = fake_cups(&[], &[], None);
+ let mut s = session("gray", 8);
+ let e = s.execute("file.print", json!({"printServer": server})).unwrap_err().to_string();
+ assert!(e.contains("no printer is set up"), "{e}");
+ // Asking for a printer by name never falls through to another route.
+ let e = s.execute("file.print", json!({"printServer": server, "printer": "Office"})).unwrap_err().to_string();
+ assert!(e.contains("`Office`"), "{e}");
+ let seen = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));
+ s.print_spooler = Some(recording_spooler(false, &seen));
+ let r = s.execute("file.print", json!({"printServer": server})).unwrap();
+ assert_eq!((r["backend"].as_str(), r["spooler"].as_str()), (Some("test"), Some("queued")));
+ assert_eq!(seen.lock().unwrap().len(), 1);
+ // An unreachable named server is a failure, not a missing route.
+ let e = s.execute("file.print", json!({"printServer": "127.0.0.1:1"})).unwrap_err().to_string();
+ assert!(e.contains("no print server at"), "{e}");
+ let r = s.execute("file.printers", json!({"printServer": "127.0.0.1:1"})).unwrap();
+ assert!(r["printers"].as_array().unwrap().is_empty() && r["note"].as_str().unwrap().contains("no print server"));
+ }
+
+ /// The Flatpak case: no `lp` on the path, so the job goes to the system's CUPS over IPP
+ /// (`CUPS_SERVER` names it here), and with no print server at all to the app's spooler.
+ /// Runs in a child process, since the path is process-wide.
+ #[test]
+ fn without_lp_the_job_goes_over_ipp_then_to_the_app_spooler() {
+ const CHILD: &str = "PHOTOCRAFT_TEST_PRINT_NO_LP";
+ if std::env::var_os(CHILD).is_some() {
+ let mut s = session("rgb", 8);
+ let r = s.execute("file.print", json!({"copies": 2})).unwrap();
+ assert_eq!((r["sent"].as_bool(), r["backend"].as_str(), r["spooler"].as_str()), (Some(true), Some("ipp"), Some("job 42 on Office")));
+ let seen = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));
+ s.print_spooler = Some(recording_spooler(false, &seen));
+ // The IPP route first, then the app's spooler only when there is no server.
+ let r = s.execute("file.print", json!({})).unwrap();
+ assert_eq!(r["backend"], "ipp");
+ assert!(seen.lock().unwrap().is_empty());
+ // (CUPS_SERVER is read per job; an unreachable one is no route.)
+ let r = s.execute("file.print", json!({"printServer": "127.0.0.1:1"})).unwrap_err().to_string();
+ assert!(r.contains("no print server at"), "{r}");
+ println!("child ok");
+ return;
+ }
+ let (server, rx) = fake_cups(&["Office"], &[], Some("Office"));
+ let no_lp = tempfile::tempdir().unwrap();
+ let out = std::process::Command::new(std::env::current_exe().unwrap())
+ .args(["--exact", "print_cmds::tests::cups::without_lp_the_job_goes_over_ipp_then_to_the_app_spooler", "--nocapture"])
+ .env(CHILD, "1")
+ .env("PATH", no_lp.path())
+ .env("CUPS_SERVER", &server)
+ .env_remove("PHOTOCRAFT_NO_PRINT")
+ .output()
+ .unwrap();
+ let (stdout, stderr) = (String::from_utf8_lossy(&out.stdout), String::from_utf8_lossy(&out.stderr));
+ assert!(out.status.success() && stdout.contains("child ok"), "stdout: {stdout}\nstderr: {stderr}");
+ let jobs = std::iter::from_fn(|| rx.try_recv().ok()).filter(|(op, _, _)| *op == OP_PRINT_JOB).count();
+ assert_eq!(jobs, 2, "both prints reached the fake CUPS");
+ }
+}
+
+#[cfg(target_os = "windows")]
+#[test]
+fn windows_pdf_component_is_detected_by_loading_its_dll() {
+ // #5884: a Windows image without a loadable Windows.Data.Pdf.dll reports an error instead of
+ // aborting at the delay-load stub.
+ let dir = tempfile::tempdir().unwrap();
+ let dll = windows_pdf_dll(dir.path());
+ assert!(!windows_pdf_loads(&dll));
+ // Present but not loadable counts as missing.
+ std::fs::create_dir(dir.path().join("System32")).unwrap();
+ std::fs::write(&dll, b"MZ").unwrap();
+ assert!(!windows_pdf_loads(&dll));
+ let root = std::env::var_os("SystemRoot").unwrap();
+ // The real DLL may be missing or unloadable on a stripped image; the check follows the loader.
+ let system = windows_pdf_dll(std::path::Path::new(&root));
+ assert_eq!(require_windows_pdf().is_ok(), windows_pdf_loads(&system));
+}
+
+#[cfg(not(target_os = "windows"))]
+#[test]
+fn the_windows_pdf_check_is_a_no_op_elsewhere() {
+ assert!(require_windows_pdf().is_ok());
+}
++
+ /// A dry-run print to `name`.pdf with `extra` params; returns the result and the PDF content stream.
+ fn print_with(s: &mut Session, dir: &str, name: &str, extra: Value) -> (Value, Vec<u8>) {
+ let mut p = json!({"output": format!("{dir}/{name}.pdf"), "dryRun": true, "paper": "a4", "center": false, "left": 1.0, "top": 1.0});
+ for (k, v) in extra.as_object().unwrap() {
+ p[k] = v.clone();
+ }
+ let r = s.execute("file.print", p).unwrap();
+ let pdf = std::fs::read(r["pdf"].as_str().unwrap()).unwrap();
+ (r, pdf)
+ }
+
+ #[test]
+ fn zero_bleed_prints_exactly_as_before() {
+ let mut s = session("rgb", 8);
+ let dir = tmp("bleed-zero");
+ let (plain, a) = print_with(&mut s, &dir, "plain", json!({"cornerCropMarks": true}));
+ let (zero, b) = print_with(&mut s, &dir, "zero", json!({"cornerCropMarks": true, "bleed": 0.0}));
+ assert_eq!(a, b, "bleed 0 must not change a single byte");
+ assert_eq!(plain["bleed"], 0.0);
+ assert_eq!(zero["bleed"], 0.0);
+ let _ = std::fs::remove_dir_all(&dir);
+ }
+
+ #[test]
+ fn bleed_puts_corner_crop_marks_on_the_trim_line_outside_the_image() {
+ let mut s = session("rgb", 8);
+ let dir = tmp("bleed");
+ let (r, pdf) = print_with(&mut s, &dir, "bleed", json!({"cornerCropMarks": true, "centerCropMarks": true, "bleed": 0.125}));
+ assert_eq!(r["bleed"], 0.125);
+ let rect: Vec<f64> = r["imageRect"].as_array().unwrap().iter().map(|v| v.as_f64().unwrap()).collect();
+ let (x, y, w, h) = (rect[0], rect[1], rect[2], rect[3]);
+ let c = pdf_content(&pdf);
+ // Bottom-left corner (PDF is bottom-up): the horizontal mark runs left from 6 pt outside the
+ // image, 9 pt (0.125 in) above the image's bottom edge; the vertical one 9 pt right of its left edge.
+ assert!(c.contains(&format!("{:.2} {:.2} m {:.2} {:.2} l S", x - 6.0, y + 9.0, x - 24.0, y + 9.0)), "{c}");
+ assert!(c.contains(&format!("{:.2} {:.2} m {:.2} {:.2} l S", x + 9.0, y - 6.0, x + 9.0, y - 24.0)), "{c}");
+ // Top-right corner, mirrored.
+ assert!(c.contains(&format!("{:.2} {:.2} m {:.2} {:.2} l S", x + w + 6.0, y + h - 9.0, x + w + 24.0, y + h - 9.0)), "{c}");
+ assert!(c.contains(&format!("{:.2} {:.2} m {:.2} {:.2} l S", x + w - 9.0, y + h + 6.0, x + w - 9.0, y + h + 24.0)), "{c}");
+ // Centre crop marks are on the midlines, which a symmetric bleed does not move.
+ assert!(c.contains(&format!("{:.2} {:.2} m {:.2} {:.2} l S", x + w / 2.0, y - 6.0, x + w / 2.0, y - 24.0)), "{c}");
+ // Print One Copy repeats the last print, bleed included.
+ let again = s.execute("file.printOneCopy", json!({"output": format!("{dir}/again.pdf"), "dryRun": true})).unwrap();
+ assert_eq!(again["bleed"], 0.125);
+ // The image box itself is unchanged: bleed moves marks, not pixels.
+ let (plain, _) = print_with(&mut s, &dir, "plain", json!({"cornerCropMarks": true}));
+ assert_eq!(plain["imageRect"], r["imageRect"]);
+ let _ = std::fs::remove_dir_all(&dir);
+ }
+
+ #[test]
+ fn bleed_without_corner_crop_marks_changes_nothing() {
+ let mut s = session("rgb", 8);
+ let dir = tmp("bleed-nomarks");
+ let (_, a) = print_with(&mut s, &dir, "plain", json!({"registrationMarks": true}));
+ let (r, b) = print_with(&mut s, &dir, "bleed", json!({"registrationMarks": true, "bleed": 0.1}));
+ assert_eq!(a, b);
+ assert_eq!(r["bleed"], 0.0);
+ let _ = std::fs::remove_dir_all(&dir);
+ }
+
+ #[test]
+ fn bad_bleed_is_an_error_not_a_panic() {
+ let mut s = session("rgb", 8);
+ // The test document prints 300 × 150 pt, so 1.05 in (75.6 pt) leaves no trim box.
+ for bleed in [json!(-0.1), json!("0.1"), json!(true), json!([0.1]), json!(1.05), json!(1e308)] {
+ let r = s.execute("file.print", json!({"dryRun": true, "send": false, "output": "", "cornerCropMarks": true, "bleed": bleed}));
+ assert!(matches!(r, Err(EngineError::BadParams { .. })), "bleed {bleed}: {r:?}");
+ }
+ }
diff --cc docs/target-app-parity.md
index a2581c4b4,98948d070..4c06ff651
--- a/docs/target-app-parity.md
+++ b/docs/target-app-parity.md
@@@ -1,6 -1,6 +1,6 @@@
# PhotoCraft vs Adobe Photoshop: target-app parity
- > **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-18 · **Change:** minor (Content-Aware Move live preview for every selection size, TOOL-213-4 done, #6680; retouching evidence: Pattern Stamp and Background Eraser draw live, only the Mixer Brush is left of TOOL-213-7; fill and adjustment layers copy and paste whole, UI-217-23 partial, #2344; shape layers take Density and Feather, TOOL-214-12 done, #5846; on-canvas corner radius widgets, TOOL-214-12; `.atn` import maps 112 events; Free Transform H/V skew fields; stale rows corrected against `main` and the scorecard, estimates unchanged; Photoshop Actions `.atn` load and save; 2026-10-10: Tilt-Shift measurements added; earlier the same day: major, full re-measure against Photoshop 2026 27.11.0; merged `parity-estimate.md` and the roadmap's honest assessment; stale missing-tool rows corrected: Color Replacement and Red Eye are live toolbar tools, Frame landed; percentages unchanged) · **Target:** Adobe Photoshop 2026
-> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-15 · **Change:** minor (Print › Functions › Bleed through `file.print`; on-canvas corner radius widgets, TOOL-214-12; `.atn` import maps 112 events; Free Transform H/V skew fields; stale rows corrected against `main` and the scorecard, estimates unchanged; Photoshop Actions `.atn` load and save; 2026-10-10: Tilt-Shift measurements added; earlier the same day: major, full re-measure against Photoshop 2026 27.11.0; merged `parity-estimate.md` and the roadmap's honest assessment; stale missing-tool rows corrected: Color Replacement and Red Eye are live toolbar tools, Frame landed; percentages unchanged) · **Target:** Adobe Photoshop 2026
++> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-18 · **Change:** minor (Content-Aware Move live preview for every selection size, TOOL-213-4 done, #6680; retouching evidence: Pattern Stamp and Background Eraser draw live, only the Mixer Brush is left of TOOL-213-7; fill and adjustment layers copy and paste whole, UI-217-23 partial, #2344; shape layers take Density and Feather, TOOL-214-12 done, #5846; Print › Functions › Bleed through `file.print`; on-canvas corner radius widgets, TOOL-214-12; `.atn` import maps 112 events; Free Transform H/V skew fields; stale rows corrected against `main` and the scorecard, estimates unchanged; Photoshop Actions `.atn` load and save; 2026-10-10: Tilt-Shift measurements added; earlier the same day: major, full re-measure against Photoshop 2026 27.11.0; merged `parity-estimate.md` and the roadmap's honest assessment; stale missing-tool rows corrected: Color Replacement and Red Eye are live toolbar tools, Frame landed; percentages unchanged) · **Target:** Adobe Photoshop 2026
The authoritative answer to "how close is PhotoCraft to Photoshop, and how much work is left". The
one-page summary is [`ROADMAP.md`](../ROADMAP.md); the ranked work list is [`gaps.md`](gaps.md);
@@@ -565,9 -565,7 +565,10 @@@ See [method, raw measurements and repro
| Date | Change | Summary |
|---|---|---|
+| 2026-10-18 | minor | Layers: with no selection, Copy takes fill and adjustment layers whole and Paste recreates them (#2344); UI-217-23 stays partial; percentages unchanged |
+| 2026-10-16 | minor | Content-Aware Move: live result preview for every selection the command takes (TOOL-213-4 done, #6680); percentages unchanged |
+| 2026-10-15 | minor | Vector shapes: shape layers take Density and Feather (Properties › Masks), PSD and .pcraft round trip; TOOL-214-12 done (#5846); estimates unchanged |
+ | 2026-10-15 | minor | Print: Functions › Bleed (`file.print` / `file.printOneCopy` `bleed`, corner crop marks on the trim line, PDF and Windows paths); the Print dialog field is still missing; percentages unchanged |
| 2026-10-13 | minor | Vector shapes: on-canvas corner radius widgets on live rectangles (TOOL-214-12); estimates unchanged |
| 2026-10-13 | minor | Stale "missing tool" rows corrected against main: Color Replacement (`paint.colorReplacement`), Red Eye (`paint.redEye`) and Add/Delete Anchor Point (the Pen flyout) are live toolbar tools and Frame landed, so Art History Brush is the only tool still missing; percentages unchanged |
| 2026-10-12 | minor | Free Transform options bar H/V skew fields; percentages unchanged |