From ac8cdf071defffff436b5c04bbc5778dfbe5e584 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 18:00:12 -0800 Subject: [PATCH] Preflight: measure a distorted image's resolution as Image Info does Production Preflight measured a distorted image's effective resolution from its transform alone, so an image enlarged by Perspective Distort or Free Distort could pass the minimum. It now measures it at its middle, with the placement Image Info reports. --- crates/engine/src/cmd/preflight.rs | 4 +++- crates/engine/tests/preflight.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/preflight.rs b/crates/engine/src/cmd/preflight.rs index ebfaf5deeb..a564b29335 100644 --- a/crates/engine/src/cmd/preflight.rs +++ b/crates/engine/src/cmd/preflight.rs @@ -89,11 +89,13 @@ fn check(s: &mut Session, p: &Value) -> Result { continue; }; let bounds = doc.node(source).and_then(|n| vectorcraft_render::painted_bounds(&doc, n)); + // A distorted image is measured at its middle, as Link Info measures it. + let xf = doc.node(source).and_then(vectorcraft_doc::image_quad::nearest_affine).unwrap_or(im.xf); let ppi = context .pages .iter() .filter(|(area, _)| bounds.is_some_and(|b| area.intersect(b).area() > 0.0)) - .map(|(_, to_page)| super::place::effective_ppi(*to_page * im.xf)) + .map(|(_, to_page)| super::place::effective_ppi(*to_page * xf)) .reduce(|[a, b], [c, d]| [a.min(c), b.min(d)]); let Some(ppi) = ppi else { resolution_unchecked += 1; diff --git a/crates/engine/tests/preflight.rs b/crates/engine/tests/preflight.rs index 08b7cf153b..e656596d71 100644 --- a/crates/engine/tests/preflight.rs +++ b/crates/engine/tests/preflight.rs @@ -112,6 +112,26 @@ fn preflight_resolution_follows_placed_size_and_both_axes() { assert!(codes(&screen).is_empty(), "{screen}"); } +/// A distorted image's resolution is measured at its middle, as Image Info measures it. +#[test] +fn preflight_resolution_of_a_distorted_image_is_image_infos() { + let dir = Folder::new("preflight-resolution-distorted"); + let path = dir.file("picture.png"); + std::fs::write(&path, png(100, 100, [200, 50, 10])).unwrap(); + let mut s = new(); + let id = s.execute("file.place", &json!({ "path": path, "link": false, "at": [200, 200] })).unwrap()["ids"][0].clone(); + s.execute("select.set", &json!({ "ids": [id] })).unwrap(); + s.execute("object.setBounds", &json!({ "width": 24, "height": 24 })).unwrap(); + assert!(codes(&s.execute("document.preflight", &json!({ "minPpi": 200 })).unwrap()).is_empty()); + // The top stays 24 pt wide; the bottom is 120 pt wide. + s.execute("object.distort", &json!({ "corners": [[188, 188], [212, 188], [260, 212], [140, 212]] })).unwrap(); + assert!(s.doc().unwrap().doc.node(NodeId(id.as_u64().unwrap())).unwrap().is_distorted_image()); + let info = s.execute("image.info", &json!({ "id": id })).unwrap(); + let r = s.execute("document.preflight", &json!({ "minPpi": 200 })).unwrap(); + let f = r["findings"].as_array().unwrap().iter().find(|f| f["code"] == "lowResolution").expect("a low resolution finding"); + assert_eq!(f["effectivePpi"], info["ppi"], "{info}"); +} + #[test] fn preflight_resolution_accepts_the_exact_threshold_but_rejects_a_real_shortfall() { let dir = Folder::new("preflight-resolution-boundary");