mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-22 10:23:16 +01:00
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.
This commit is contained in:
1 parent
fb0a82b095
commit
ac8cdf071d
2 files changed
+23
-1
No files matched your search
@@ -89,11 +89,13 @@ fn check(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user