From 557a6be962f5a546c6498913ce1c6da3d718b07e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 22:33:51 -0800 Subject: [PATCH] Document Info: an image placed at a very small size keeps its resolution The test for a transform that leaves an image no area compares the determinant with the product of the two pixel axes' lengths instead of a fixed 1e-12, so a placement at 1e-7 pt per pixel still reports its resolution. The package report test expects the new Linked Images row with the format and resolution. --- crates/engine/src/cmd/docinfo.rs | 17 +++++++++++++++-- crates/engine/src/tests/package.rs | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/docinfo.rs b/crates/engine/src/cmd/docinfo.rs index 3fa7cce615..f58eb97e41 100644 --- a/crates/engine/src/cmd/docinfo.rs +++ b/crates/engine/src/cmd/docinfo.rs @@ -209,8 +209,10 @@ impl ImageRow { // A distorted image is measured at its middle, as `image.info` measures it. let xf = vectorcraft_doc::image_quad::nearest_affine(n).unwrap_or(im.xf); let ppi = super::place::effective_ppi(xf); - // A transform that lays both pixel axes on one line leaves the image no area. - let has_area = xf.determinant().abs() > 1e-12; + // A transform that lays both pixel axes on one line leaves the image no area. The + // determinant is compared with the product of the two axes' lengths, at any scale. + let [xx, xy, yx, yy, ..] = xf.as_coeffs(); + let has_area = xf.determinant().abs() > 1e-9 * xx.hypot(xy) * yx.hypot(yy); let embedded = im.link.is_none(); let memory = || u64::from(im.width).checked_mul(u64::from(im.height))?.checked_mul(4); Self { @@ -2469,6 +2471,17 @@ mod tests { assert_eq!(rows(&selected, "linkedImages"), [linked[2].clone()]); } + /// An image placed at a very small size still has an area, so its row gives a resolution. + #[test] + fn a_tiny_placement_still_gives_a_resolution() { + let mut s = Session::new(); + images_in(&mut s, &[("a", "image/png", Some("/art/huge.png"), 100_000, 100_000, Affine::scale(1e-7))]); + let i = s.execute("document.info", &json!({})).unwrap(); + let ppi = i["imageObjects"][0]["effectivePpi"].as_array().map(|v| v.iter().map(|v| v.as_f64().unwrap_or(0.0)).collect::>()); + let ppi = ppi.unwrap_or_default(); + assert!(ppi.len() == 2 && ppi.iter().all(|v| (v / 7.2e8 - 1.0).abs() < 1e-9), "{}", i["imageObjects"][0]); + } + /// A number of bytes reads in B below 1 KiB, else in KiB, MiB or GiB to a tenth, and a /// resolution to a tenth without a trailing `.0`. #[test] diff --git a/crates/engine/src/tests/package.rs b/crates/engine/src/tests/package.rs index f146e39941..e39fe2885f 100644 --- a/crates/engine/src/tests/package.rs +++ b/crates/engine/src/tests/package.rs @@ -792,7 +792,7 @@ fn the_document_info_report_has_every_category() { assert!(text.contains(&format!("\n{h}\n")), "{h}: {text}"); } assert!(text.contains("Images: 3") && text.contains("Source Sans 3 Regular: built in; embedding allowed"), "{text}"); - assert!(text.contains("red.png: 600 × 300 px — ") && text.contains("Color Mode: RGB") && text.contains("\nSwatches: "), "{text}"); + assert!(text.contains("red.png: PNG; 600 × 300 px; 72 ppi — ") && text.contains("Color Mode: RGB") && text.contains("\nSwatches: "), "{text}"); let fonts = run(&mut s, "document.info", json!({"format": "text", "category": "fonts"}))["text"].as_str().unwrap().to_string(); assert!(fonts.contains("FONTS") && !fonts.contains("OBJECTS"), "{fonts}"); let i = run(&mut s, "document.info", json!({"category": "linkedImages"})); @@ -802,7 +802,7 @@ fn the_document_info_report_has_every_category() { // embedded one with no file. let linked: Vec = i["imageObjects"].as_array().unwrap().iter().filter(|o| o["linked"] == true).cloned().collect(); for (o, r) in linked.iter().zip(i["sections"][0]["rows"].as_array().unwrap()) { - let shown = format!("{} × {} px — {}", o["width"], o["height"], o["file"].as_str().unwrap()); + let shown = format!("PNG; {} × {} px; 72 ppi — {}", o["width"], o["height"], o["file"].as_str().unwrap()); assert_eq!((&o["name"], shown.as_str()), (&r[0], r[1].as_str().unwrap())); } assert_eq!(linked.len(), 2);