mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Actions: an imported Crop step in a unit other than pixels is not applied as pixels (#7084)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
5f65579ecb
commit
4fc492d2ca
2 files changed
+21
-1
No files matched your search
@@ -2344,7 +2344,13 @@ fn image_size_to(_: &str, p: &Value) -> Option<Descriptor> {
|
||||
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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user