diff --git a/crates/engine/src/cmd/printadvanced.rs b/crates/engine/src/cmd/printadvanced.rs index c5927f3bfd..a678e43d4c 100644 --- a/crates/engine/src/cmd/printadvanced.rs +++ b/crates/engine/src/cmd/printadvanced.rs @@ -80,10 +80,11 @@ fn drop_guides(nodes: &mut Vec>) { } /// The resolution Print as Bitmap renders `doc` at with `set` (ppi): `advanced.bitmapResolution`, -/// or the document's raster effects resolution when that is 0. +/// or the document's raster effects resolution when that is 0 (72 ppi when the stored value isn't a +/// number). fn bitmap_ppi(doc: &Document, set: &PrintSettings) -> f64 { let asked = set.advanced.bitmap_resolution; - if asked > 0.0 { asked } else { doc.raster_effects_ppi } + if asked > 0.0 { asked } else { doc.raster_ppi() } } /// The pixels per document point Print as Bitmap renders `area` at so that it prints at `ppi` on diff --git a/crates/engine/src/tests/printadvanced.rs b/crates/engine/src/tests/printadvanced.rs index 7d1a0e6e2e..f7d9238e05 100644 --- a/crates/engine/src/tests/printadvanced.rs +++ b/crates/engine/src/tests/printadvanced.rs @@ -152,6 +152,31 @@ fn print_as_bitmap_prints_all_of_a_long_artboard() { assert!(b.x0 <= 0.0 && b.x1 >= 9000.0, "the image covers the artboard: {b:?}"); } +/// A raster effects resolution that isn't a number prints at the resolution the document reads it +/// as (72 ppi), not as an empty page. +#[test] +fn print_as_bitmap_of_a_resolution_that_is_not_a_number_prints_at_72_ppi() { + let (s, _) = session(); + let saved = s.prefs.flattener_presets.clone(); + let set = settings(json!({"advanced": {"printAsBitmap": true}})); + let widths = |ppi: f64| { + let mut d = doc(&s).clone(); + d.raster_effects_ppi = ppi; + let bitmap = crate::cmd::printadvanced::prepare("file.print", &d, &set, &saved, false).unwrap().unwrap(); + let mut widths = vec![]; + bitmap.walk(|n| { + if let NodeKind::Image(im) = &n.kind { + widths.push(im.width); + } + }); + widths + }; + let at_72 = widths(72.0); + assert_eq!(at_72.len(), 1, "{at_72:?}"); + assert_eq!(widths(f64::NAN), at_72); + assert!(widths(144.0)[0] > at_72[0], "the resolution decides the image's size"); +} + /// The images `file.print` prints with `settings`: their pixel sizes and their places on the page /// in the print-ready PDF (read back), their pixel sizes in the PostScript file (its image /// dictionaries, each size once), and the warnings of both.