diff --git a/crates/engine/src/cmd/atn_cmds/descriptors.rs b/crates/engine/src/cmd/atn_cmds/descriptors.rs index 9e9835218b..3e1dcd7a24 100644 --- a/crates/engine/src/cmd/atn_cmds/descriptors.rs +++ b/crates/engine/src/cmd/atn_cmds/descriptors.rs @@ -20,13 +20,17 @@ pub(super) fn get_num(d: &Descriptor, k: &str) -> Option { d.get(k).and_then(num) } -pub(super) fn get_bool(d: &Descriptor, k: &str) -> Option { - match d.get(k) { - Some(D::Boolean(b)) => Some(*b), +pub(super) fn boolean(v: &D) -> Option { + match v { + D::Boolean(b) => Some(*b), _ => None, } } +pub(super) fn get_bool(d: &Descriptor, k: &str) -> Option { + d.get(k).and_then(boolean) +} + pub(super) fn get_text(d: &Descriptor, k: &str) -> Option { match d.get(k) { Some(D::Text(t)) => Some(t.to_string_lossy()), @@ -35,13 +39,17 @@ pub(super) fn get_text(d: &Descriptor, k: &str) -> Option { } /// An enumerated value's id, trailing spaces removed (`Ordn.Trgt` → `"Trgt"`). -pub(super) fn get_enum(d: &Descriptor, k: &str) -> Option { - match d.get(k) { - Some(D::Enumerated { value, .. }) => Some(trimmed(value)), +pub(super) fn enumerated(v: &D) -> Option { + match v { + D::Enumerated { value, .. } => Some(trimmed(value)), _ => None, } } +pub(super) fn get_enum(d: &Descriptor, k: &str) -> Option { + d.get(k).and_then(enumerated) +} + pub(super) fn get_obj<'a>(d: &'a Descriptor, k: &str) -> Option<&'a Descriptor> { match d.get(k) { Some(D::Descriptor(o) | D::GlobalObject(o)) => Some(o), diff --git a/crates/engine/src/cmd/atn_cmds/steps_image.rs b/crates/engine/src/cmd/atn_cmds/steps_image.rs index 2a318f2fb6..c5bfb6c220 100644 --- a/crates/engine/src/cmd/atn_cmds/steps_image.rs +++ b/crates/engine/src/cmd/atn_cmds/steps_image.rs @@ -1,5 +1,5 @@ use super::descriptors::{ - PX, Target, ang, class, code, desc, enm, get_bool, get_enum, get_num, get_obj, get_ref, jbool, jnum, jstr, layer_ref, layer_target, long, pct, px, + PX, Target, ang, boolean, class, code, desc, enm, get_bool, get_enum, get_num, get_obj, get_ref, jbool, jnum, jstr, layer_ref, layer_target, long, pct, px, ref_class, target, trimmed, }; use super::events::pixel_target; @@ -461,6 +461,16 @@ fn only_keys(d: &Descriptor, keys: &[&str]) -> bool { d.items.iter().all(|(k, _)| keys.contains(&trimmed(k).as_str())) } +/// The step's `key` read by `read` (its space padding ignored, as `only_keys` admits it), +/// `default` when the step leaves it out, `None` when it holds a value `read` can't take: that +/// is still the step's setting, so the step is kept rather than played with the default. +fn setting(d: &Descriptor, key: &str, read: impl Fn(&D) -> Option, default: T) -> Option { + match d.items.iter().find(|(k, _)| trimmed(k) == key.trim_end()) { + Some((_, v)) => read(v), + None => Some(default), + } +} + /// Whether `p` sets nothing but `allowed` (a `null` counts as unset). fn sets_only(p: &Value, allowed: &[&str]) -> bool { p.as_object().is_none_or(|m| m.iter().all(|(k, v)| v.is_null() || allowed.contains(&k.as_str()))) @@ -480,10 +490,10 @@ pub(super) fn bare_to(_: &str, p: &Value) -> Option { /// Select Sky (`selectSky`): `sampleAllLayers` only, false when the step leaves it out /// (the command's own default is true). pub(super) fn select_sky_from(d: &Descriptor) -> Mapped { - if !only_keys(d, &["sampleAllLayers"]) { - return Mapped::Unsupported { harmless: false }; + match setting(d, "sampleAllLayers", boolean, false) { + Some(all) if only_keys(d, &["sampleAllLayers"]) => step("select.sky", json!({"sampleAllLayers": all})), + _ => Mapped::Unsupported { harmless: false }, } - step("select.sky", json!({"sampleAllLayers": get_bool(d, "sampleAllLayers").unwrap_or(false)})) } /// The event has no mode, threshold or softness: only their replay values survive. diff --git a/crates/engine/src/cmd/atn_cmds/tests.rs b/crates/engine/src/cmd/atn_cmds/tests.rs index bb277c9f00..c3712da42e 100644 --- a/crates/engine/src/cmd/atn_cmds/tests.rs +++ b/crates/engine/src/cmd/atn_cmds/tests.rs @@ -3278,3 +3278,17 @@ fn newer_feature_steps_that_cannot_be_written_are_refused() { } assert!(export_item("select.sky", &json!({"mode": "replace", "threshold": 50, "softness": 50}), "S").is_some()); } + +/// A recorded setting of the wrong type is the step's own setting, not a missing one: the +/// mapper must not play it with a default but keep the Photoshop step (#10610). +fn kept_when_wrong_typed(name: &str, settings: &[(&str, D)]) { + for (key, v) in settings { + let m = newer(name, desc("null").with(key, v.clone())); + assert!(matches!(m, Mapped::Unsupported { harmless: false }), "{name} with {key:?} = {v:?} was mapped"); + } +} + +#[test] +fn select_sky_with_a_wrong_typed_setting_is_kept() { + kept_when_wrong_typed("selectSky", &[("sampleAllLayers", D::Integer(1)), ("sampleAllLayers", text("true"))]); +}