mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
- steps_layer.rs select_from/select_to: #10753's layer references by name, index and ordinal (recorded_layer_target / recorded_layer_ref) together with #10702's property references and the zero document offset it refuses; the line merge had interleaved the two functions. - layer_params.rs explicit_layer: #10753's group-end arm had lost its closing brace next to #10702's Background arm. - events.rs event_for: the batch's lookup (by code, else by non-empty name, legacy codes) kept; #10628 renamed IntW/Dstr to intersectWith/distribute, and the run-time names the reference application reports (interfaceWhite, distort) still load through NAME_ALIASES (test extended). - Vibrance: one event, saved as the string event `vibrance` (#10702, from #8659) with the `vibrance` class main writes (#8534); `Vbrn` still loads. #10702's round-trip test expects that class now (the top-level class does not change what the reference application plays). - #10702's tests build AtnFile with the `encoding` field main added (#8327). All engine tests pass. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
5d6041c1cd
commit
d97a1c2efa
7 files changed
+29
-25
No files matched your search
@@ -38,9 +38,9 @@ mod steps_image;
|
||||
mod steps_layer;
|
||||
mod steps_make;
|
||||
|
||||
mod steps_selection;
|
||||
mod steps_other;
|
||||
mod steps_render;
|
||||
mod steps_selection;
|
||||
mod tables;
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -489,8 +489,9 @@ pub(super) const EVENTS: &[Event] = &[
|
||||
adjustment_event!("Pstr", "Pstr", "posterize", "Posterize"),
|
||||
adjustment_event!("Invr", "Invr", "invert", "Invert"),
|
||||
adjustment_event!("ClrB", "ClrB", "colorBalance", "Color Balance"),
|
||||
adjustment_event!("Vbrn", "vibrance", "vibrance", "Vibrance"),
|
||||
adjustment_event!("", "Vbrn", "vibrance", "Vibrance"),
|
||||
// Written as the string event the reference application runs, with the `vibrance` class it
|
||||
// records; the old `Vbrn` code still loads through LEGACY_CODES.
|
||||
adjustment_event!("", "vibrance", "vibrance", "Vibrance"),
|
||||
adjustment_event!("Exps", "Exps", "exposure", "Exposure"),
|
||||
// Photoshop runs Photo Filter by name only: `PhtF` is the class, not an event (#8301).
|
||||
adjustment_event!("", "PhtF", "photoFilter", "Photo Filter"),
|
||||
@@ -851,6 +852,10 @@ const LEGACY_CODES: &[(&str, &str)] = &[
|
||||
("GdMp", "gradientMapEvent"),
|
||||
];
|
||||
|
||||
/// Older string names a step can carry for an event that is listed under another name: the
|
||||
/// reference application reports `IntW` and `Dstr` as `interfaceWhite` and `distort` at run time.
|
||||
const NAME_ALIASES: &[(&str, &str)] = &[("interfaceWhite", "intersectWith"), ("distort", "distribute")];
|
||||
|
||||
pub(super) fn event_for(item: &AtnEvent) -> Option<&'static Event> {
|
||||
let id = item.id();
|
||||
let by_name = |name: &str| EVENTS.iter().find(|e| !e.name.is_empty() && e.name == name);
|
||||
@@ -859,13 +864,8 @@ pub(super) fn event_for(item: &AtnEvent) -> Option<&'static Event> {
|
||||
.iter()
|
||||
.find(|e| !e.code.is_empty() && e.code.trim_end() == id.trim_end())
|
||||
.or_else(|| LEGACY_CODES.iter().find(|(code, _)| *code == id).and_then(|(_, name)| by_name(name))),
|
||||
AtnEvent::Name(_) => by_name(&id),
|
||||
AtnEvent::Name(_) => by_name(&id).or_else(|| NAME_ALIASES.iter().find(|(old, _)| *old == id).and_then(|(_, name)| by_name(name))),
|
||||
}
|
||||
let find = |id: &str| EVENTS.iter().find(|e| (!e.code.is_empty() && e.code.trim_end() == id.trim_end()) || (!e.name.is_empty() && e.name == id));
|
||||
find(&id).or_else(|| match item {
|
||||
AtnEvent::Code(_) => LEGACY_CODES.iter().find(|(code, _)| *code == id).and_then(|(_, name)| find(name)),
|
||||
AtnEvent::Name(_) => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// The event `id` exports as: the first event listing it whose converter accepts the params
|
||||
|
||||
@@ -193,6 +193,9 @@ fn group_f_string_ids_map_like_their_codes() {
|
||||
("IntW", "intersectWith", rectangle([30.0, 30.0, 120.0, 120.0], false)),
|
||||
("Dstr", "distribute", desc("null").with("null", target_ref("Lyr ")).with("Usng", enm("ADSt", "AdLf"))),
|
||||
("MrgL", "mergeLayers", desc("null")),
|
||||
// The run-time names the reference application reports for IntW and Dstr.
|
||||
("IntW", "interfaceWhite", rectangle([30.0, 30.0, 120.0, 120.0], false)),
|
||||
("Dstr", "distort", desc("null").with("null", target_ref("Lyr ")).with("Usng", enm("ADSt", "AdLf"))),
|
||||
] {
|
||||
let by_code = import(&file(AtnEvent::Code(id.as_bytes().try_into().unwrap()), d.clone())).unwrap();
|
||||
let by_name = import(&file(AtnEvent::name(name), d)).unwrap();
|
||||
|
||||
@@ -10,19 +10,13 @@ use super::tables::{FILL_CONTENTS, INTERPOLATION, MENU_ITEMS, STROKE_LOCATION, b
|
||||
use super::{D, Descriptor, Id, Map, ReferenceItem, UnicodeString, Value, json};
|
||||
|
||||
/// Import recorded targets while retaining stack and opening-order references for playback.
|
||||
/// Resolve a recorded selection while retaining layer names, Background properties and modifiers.
|
||||
pub(super) fn select_from(d: &Descriptor) -> Mapped {
|
||||
let Some(r) = get_ref(d, "null") else { return Mapped::Unsupported { harmless: false } };
|
||||
match (ref_class(r).as_deref(), target(r)) {
|
||||
(Some("Lyr"), Target::Name(_) | Target::Index(_) | Target::Ordinal(_)) => {
|
||||
let Some(params) = recorded_layer_target(r) else { return Mapped::Unsupported { harmless: false } };
|
||||
let mut p = Value::Object(params);
|
||||
/// Resolve a recorded selection while retaining layer names, Background properties and modifiers.
|
||||
pub(super) fn select_from(d: &Descriptor) -> Mapped {
|
||||
let Some(r) = get_ref(d, "null") else { return Mapped::Unsupported { harmless: false } };
|
||||
match (ref_class(r).as_deref(), target(r)) {
|
||||
(Some("Lyr"), Target::Name(_) | Target::Property(_)) => {
|
||||
let Some(p) = layer_target(r) else { return Mapped::Unsupported { harmless: false } };
|
||||
let mut p = Value::Object(p);
|
||||
match get_enum(d, "selectionModifier").as_deref() {
|
||||
Some("addToSelection") => p["mode"] = json!("add"),
|
||||
Some("removeFromSelection") => p["mode"] = json!("remove"),
|
||||
@@ -32,6 +26,11 @@ pub(super) fn select_from(d: &Descriptor) -> Mapped {
|
||||
}
|
||||
step("layer.select", p)
|
||||
}
|
||||
// A Cmd-click recorded on a layer property (e.g. the Background, #10702).
|
||||
(Some("Lyr"), Target::Property(_)) => {
|
||||
let Some(p) = layer_target(r) else { return Mapped::Unsupported { harmless: false } };
|
||||
step("layer.select", Value::Object(p))
|
||||
}
|
||||
// The Channels panel: the active layer's mask, or back to the composite (`RGB`, `CMYK`…).
|
||||
(Some("Chnl"), Target::Ordinal(o)) => match o.as_str() {
|
||||
"Msk" => step("channel.target", json!({"channel": "mask"})),
|
||||
@@ -51,9 +50,8 @@ pub(super) fn select_from(d: &Descriptor) -> Mapped {
|
||||
},
|
||||
// Switching to another open document: its offset from the active one, -1 for the previous
|
||||
// opened document and 1 for the next, independently of dragged tabs (#7103).
|
||||
(Some("Dcmn"), Target::Offset(o)) => step("document.activate", json!({"offset": o})),
|
||||
(Some("Dcmn"), Target::Index(index)) if r.len() == 1 => step("document.activate", json!({"document": {"index": index}})),
|
||||
(Some("Dcmn"), Target::Offset(o)) if o != 0 => step("document.activate", json!({"offset": o})),
|
||||
(Some("Dcmn"), Target::Index(index)) if r.len() == 1 => step("document.activate", json!({"document": {"index": index}})),
|
||||
_ => Mapped::Unsupported { harmless: false },
|
||||
}
|
||||
}
|
||||
@@ -72,11 +70,7 @@ pub(super) fn select_to(id: &str, p: &Value) -> Option<Descriptor> {
|
||||
name_ref("Lyr ", name.as_str()?)
|
||||
} else {
|
||||
p.get("layer").filter(|v| !v.is_null())?;
|
||||
recorded_layer_ref(p)?
|
||||
let reference = match jstr(p, "name") {
|
||||
Some(name) => name_ref("Lyr ", name),
|
||||
None if p.get("layer").is_some_and(|v| !v.is_null()) => layer_ref(p)?,
|
||||
None => return None,
|
||||
recorded_layer_ref(p).or_else(|| layer_ref(p))?
|
||||
};
|
||||
let mut d = desc("null").with("null", reference);
|
||||
match jstr(p, "mode") {
|
||||
@@ -115,7 +109,7 @@ pub(super) fn select_to(id: &str, p: &Value) -> Option<Descriptor> {
|
||||
// A native numeric document selects a tab; the typed index above selects opening order.
|
||||
"document.activate" if p.get("document").is_none_or(Value::is_null) => {
|
||||
let offset = i32::try_from(p.get("offset")?.as_i64()?).ok()?;
|
||||
// Photoshop rejects zero, though the native command permits that no-op.
|
||||
// The reference application rejects zero, though the native command permits that no-op.
|
||||
if offset == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ pub(crate) fn explicit_layer(s: &Session, p: &Value) -> Result<Option<LayerId>>
|
||||
// A group end is no layer: fail rather than fall back to the selection.
|
||||
Some(v @ Value::Object(fields)) if fields.contains_key("index") || fields.contains_key("ordinal") => {
|
||||
super::recorded_layer(s, v)?.map(Some).ok_or_else(|| EngineError::Other("a group end is not a layer".into()))
|
||||
}
|
||||
Some(Value::Object(selector)) if selector.len() == 1 && selector.get("background") == Some(&Value::Bool(true)) => {
|
||||
let d = s.active().ok_or(EngineError::NoDocument)?;
|
||||
d.doc.background().map(|l| Some(l.id)).ok_or_else(|| EngineError::Other("the document has no Background layer".into()))
|
||||
|
||||
@@ -487,6 +487,7 @@ fn recorded(event: AtnEvent, d: Descriptor) -> Action {
|
||||
..Default::default()
|
||||
}],
|
||||
warnings: vec![],
|
||||
encoding: None,
|
||||
})
|
||||
.unwrap();
|
||||
atn_cmds::import(&bytes).unwrap().actions.remove(0)
|
||||
@@ -527,7 +528,11 @@ fn recorded_vibrance_uses_the_string_event_and_keeps_legacy_playback() {
|
||||
assert_eq!(action.steps, vec![("image.adjustments.vibrance".into(), json!({"vibrance":47,"saturation":-19}))]);
|
||||
let written = saved(&action);
|
||||
assert_eq!(written.event, AtnEvent::name("vibrance"), "Vibrance must save by its string event");
|
||||
assert_eq!(written.descriptor, Some(d.clone()));
|
||||
// Saved with the `vibrance` class the reference application records (#8534); the
|
||||
// top-level class does not change what it plays.
|
||||
let mut want = d.clone();
|
||||
want.class_id = Descriptor::new("vibrance").class_id;
|
||||
assert_eq!(written.descriptor, Some(want));
|
||||
let create = || {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width":4,"height":3,"depth":depth})).unwrap();
|
||||
|
||||
@@ -20,6 +20,7 @@ fn recorded(event: &str, descriptor: Option<Descriptor>) -> Vec<u8> {
|
||||
..Default::default()
|
||||
}],
|
||||
warnings: vec![],
|
||||
encoding: None,
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user