From 4fc492d2ca6a889c6f9bfc302e0833ed41e10d90 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 17 Oct 2026 16:40:40 +0200 Subject: [PATCH] Actions: an imported Crop step in a unit other than pixels is not applied as pixels (#7084) Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/atn_cmds.rs | 8 +++++++- crates/engine/src/atn_cmds/tests.rs | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rs index ebeda48687..96b39d8eba 100644 --- a/crates/engine/src/atn_cmds.rs +++ b/crates/engine/src/atn_cmds.rs @@ -2344,7 +2344,13 @@ fn image_size_to(_: &str, p: &Value) -> Option { fn crop_from(d: &Descriptor) -> Mapped { let mut p = Map::new(); if let Some(t) = get_obj(d, "To ") { - let (Some(top), Some(left), Some(bottom), Some(right)) = (get_num(t, "Top "), get_num(t, "Left"), get_num(t, "Btom"), get_num(t, "Rght")) else { + // Pixels only, like Canvas Size: a side in percent or points needs the document's size + // or resolution and must not be played as pixels. + let side = |k: &str| match t.get(k) { + Some(D::UnitFloat { unit: PX, value }) if value.is_finite() => Some(*value), + _ => None, + }; + let (Some(top), Some(left), Some(bottom), Some(right)) = (side("Top "), side("Left"), side("Btom"), side("Rght")) else { return Mapped::Unsupported { harmless: false }; }; p.insert("x".into(), left.round().into()); diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs index 871300372c..45e4962bd3 100644 --- a/crates/engine/src/atn_cmds/tests.rs +++ b/crates/engine/src/atn_cmds/tests.rs @@ -479,6 +479,20 @@ fn unsupported_shapes_become_photoshop_steps_not_errors() { assert!(imp.actions[0].disabled.is_empty(), "steps with a document effect stay on so playback reports them"); } +#[test] +fn crop_sides_in_other_units_are_refused_not_played_as_pixels() { + let rect = |unit: [u8; 4]| { + let side = |v: f64| D::UnitFloat { unit, value: v }; + desc("null") + .with("To ", D::Descriptor(desc("Rctn").with("Top ", side(10.0)).with("Left", side(10.0)).with("Btom", side(90.0)).with("Rght", side(90.0)))) + }; + for unit in [PCT, *b"#Rlt"] { + assert!(matches!(crop_from(&rect(unit)), Mapped::Unsupported { harmless: false }), "{}", String::from_utf8_lossy(&unit)); + } + let Mapped::Steps(steps) = crop_from(&rect(PX)) else { panic!("a crop in pixels maps") }; + assert_eq!(steps, [("image.crop".to_string(), json!({"x": 10.0, "y": 10.0, "width": 80.0, "height": 80.0}))]); +} + #[test] fn step_commands_and_bad_params_fail_gracefully() { let mut s = Session::new();