Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(actions): accept Photoshop blend mode stringIDs

justinjohn0306926b1bf9f7eb
diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rs
index afba79302..45aa76368 100644
--- a/crates/engine/src/atn_cmds.rs
+++ b/crates/engine/src/atn_cmds.rs
@@ -303,33 +303,51 @@ fn path_value(text: &str) -> D {
/// Photoshop's `BlnM` enumeration ↔ PhotoCraft's blend mode labels.
const BLEND_MODES: &[(&str, &str)] = &[
("Nrml", "Normal"),
+ ("normal", "Normal"),
("Dslv", "Dissolve"),
+ ("dissolve", "Dissolve"),
("Drkn", "Darken"),
+ ("darken", "Darken"),
("Mltp", "Multiply"),
+ ("multiply", "Multiply"),
("CBrn", "Color Burn"),
+ ("colorBurn", "Color Burn"),
("linearBurn", "Linear Burn"),
("darkerColor", "Darker Color"),
("Lghn", "Lighten"),
+ ("lighten", "Lighten"),
("Scrn", "Screen"),
+ ("screen", "Screen"),
("CDdg", "Color Dodge"),
+ ("colorDodge", "Color Dodge"),
("linearDodge", "Linear Dodge (Add)"),
("lighterColor", "Lighter Color"),
("Ovrl", "Overlay"),
+ ("overlay", "Overlay"),
("SftL", "Soft Light"),
+ ("softLight", "Soft Light"),
("HrdL", "Hard Light"),
+ ("hardLight", "Hard Light"),
("vividLight", "Vivid Light"),
("linearLight", "Linear Light"),
("pinLight", "Pin Light"),
("hardMix", "Hard Mix"),
("Dfrn", "Difference"),
+ ("difference", "Difference"),
("Xclu", "Exclusion"),
+ ("exclusion", "Exclusion"),
("blendSubtraction", "Subtract"),
("blendDivide", "Divide"),
("H", "Hue"),
+ ("hue", "Hue"),
("Strt", "Saturation"),
+ ("saturation", "Saturation"),
("Clr", "Color"),
+ ("color", "Color"),
("Lmns", "Luminosity"),
+ ("luminosity", "Luminosity"),
("PsTh", "Pass Through"),
+ ("passThrough", "Pass Through"),
];
fn blend_label(ps: &str) -> Option<&'static str> {
diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs
index bbec1def4..9954f85fe 100644
--- a/crates/engine/src/atn_cmds/tests.rs
+++ b/crates/engine/src/atn_cmds/tests.rs
@@ -3,6 +3,33 @@ use photocraft_psd::atn::{AtnAction, AtnEvent, AtnFile, AtnItem};
use photocraft_psd::descriptor::{Descriptor, Id, ReferenceItem, UnicodeString, Value as D};
use serde_json::json;
+#[test]
+fn blend_modes_accept_photoshop_string_ids_and_export_canonical_char_ids() {
+ for (string_id, char_id, label) in [
+ ("normal", "Nrml", "Normal"),
+ ("dissolve", "Dslv", "Dissolve"),
+ ("darken", "Drkn", "Darken"),
+ ("multiply", "Mltp", "Multiply"),
+ ("colorBurn", "CBrn", "Color Burn"),
+ ("lighten", "Lghn", "Lighten"),
+ ("screen", "Scrn", "Screen"),
+ ("colorDodge", "CDdg", "Color Dodge"),
+ ("overlay", "Ovrl", "Overlay"),
+ ("softLight", "SftL", "Soft Light"),
+ ("hardLight", "HrdL", "Hard Light"),
+ ("difference", "Dfrn", "Difference"),
+ ("exclusion", "Xclu", "Exclusion"),
+ ("hue", "H", "Hue"),
+ ("saturation", "Strt", "Saturation"),
+ ("color", "Clr", "Color"),
+ ("luminosity", "Lmns", "Luminosity"),
+ ("passThrough", "PsTh", "Pass Through"),
+ ] {
+ assert_eq!(blend_label(string_id), Some(label), "{string_id}");
+ assert_eq!(blend_ps(label), Some(char_id), "{label} remains serialized canonically");
+ }
+}
+
fn item(event: &str, label: &str, d: Option<Descriptor>) -> AtnItem {
let event = match event.as_bytes() {
[a, b, c, dd] => AtnEvent::Code([*a, *b, *c, *dd]),