Contact Sheet II: a size of 0 converts as the 8 x 10 the command reads

The command reads a width or height of 0 as 8 x 10 in the units it is given, but switching Units converted 0 to 0, so the sheet changed size. The switch now converts the size the command would make.
This commit is contained in:
rmsff committed 2026-11-27 16:03:04 +03:00
1 parent 06bb3bf741
commit 8073c120a5
2 files changed
+16 -1

No files matched your search

@@ -183,6 +183,19 @@ fn width_and_height_refuse_a_value_their_rows_cannot_hold() {
});
}
/// A size of 0 is the command's 8 x 10 in the units shown, so switching the units shows that size, not 0.
#[test]
fn switching_units_converts_a_zero_size_as_the_command_reads_it() {
crate::i18n::with_language(crate::i18n::Lang::EN, || {
let (mut h, id) = opened();
pick_unit(&mut h, id, "inches");
set(&mut h, id, "width", json!(0.0));
pick_unit(&mut h, id, "cm");
assert!((num(&h, id, "width") - 20.32).abs() < 1e-6, "width: {}", num(&h, id, "width"));
assert!((num(&h, id, "height") - 25.4).abs() < 1e-6, "height: {}", num(&h, id, "height"));
});
}
/// Picks `unit` in the Units list, as the list's pick does.
fn pick_unit(h: &mut H, id: DialogId, unit: &str) {
set(h, id, "units", json!(unit));
@@ -80,7 +80,9 @@ pub(crate) fn follow_units(fields: &mut DialogFields) {
let ppi = fields.number("resolution").unwrap_or(300.0);
let (from, to) = (unit_of(&shown), unit_of(&units));
for (key, default) in [("width", 8.0), ("height", 10.0)] {
let v = to.from_px(from.to_px(fields.number(key).unwrap_or(default), ppi, 0.0, 72.0), ppi, 0.0, 72.0);
// The command reads no size or 0 as 8 x 10 in the units it is given, so that is the size to convert.
let shown = fields.number(key).filter(|v| v.is_finite() && *v > 0.0).unwrap_or(default);
let v = to.from_px(from.to_px(shown, ppi, 0.0, 72.0), ppi, 0.0, 72.0);
// Kept unrounded (the field shows two decimals): a small pixel size at a high resolution would round to
// 0 in, which the command reads as no size. Pixels are whole.
fields.set(key, if to == Unit::Pixels { v.round() } else { v });