mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Actions: map Layer › New › Frame from Layers (#10723)
A Make of class `framedGroupSection` with `From` = a layer by name loads as `layer.new.frameFromLayers` on that layer. The recorded descriptor, session ids included, saves back byte for byte while the step still frames the same layer with the same name; native steps write the measured keys without the session ids. frameFromLayers sized the frame from the selected layers even when given a `layer`, while the grouping it runs takes in only that layer; the frame now fits the given layer.
This commit is contained in:
1 parent
d06ad73271
commit
d3fcccbe5e
8 files changed
+391
-2
No files matched your search
@@ -43,6 +43,7 @@ mod steps_direct_adjustments;
|
||||
mod steps_distort;
|
||||
mod steps_doc;
|
||||
mod steps_droplet;
|
||||
mod steps_frame_section;
|
||||
mod steps_gallery;
|
||||
mod steps_gradient;
|
||||
mod steps_image;
|
||||
@@ -193,5 +194,8 @@ mod selection_tests;
|
||||
#[cfg(test)]
|
||||
mod render_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod frame_section_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod recorded_tools_tests;
|
||||
@@ -855,6 +855,7 @@ pub(super) const EVENTS: &[Event] = &[
|
||||
"image.calculations",
|
||||
"type.convertToShape",
|
||||
"type.createWorkPath",
|
||||
super::steps_frame_section::COMMAND,
|
||||
"layer.new.layer",
|
||||
"layer.layerStyle.createLayer",
|
||||
"layer.new.group",
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
//! #10723: Layer › New › Frame from Layers, recorded as a Make of class `framedGroupSection`
|
||||
//! (`docs/atn.md`, "Recorded through the menus").
|
||||
|
||||
use super::*;
|
||||
use photocraft_doc::{Layer, LayerId};
|
||||
use photocraft_geom::Rect;
|
||||
|
||||
const FRAME: &str = "layer.new.frameFromLayers";
|
||||
const SOURCE: &str = "_atnFrameSectionDescriptor";
|
||||
|
||||
/// `From`: the layer `name`, by name.
|
||||
fn by_name(name: &str) -> D {
|
||||
D::Reference(vec![ReferenceItem::Name { class: class("Lyr "), name: UnicodeString::new_nul(name) }])
|
||||
}
|
||||
|
||||
/// The measured step, session ids included, built here independently of the converter.
|
||||
fn recorded(from: D, name: &str) -> Descriptor {
|
||||
Descriptor::new("null")
|
||||
.with("null", D::Reference(vec![ReferenceItem::Class(class("framedGroupSection"))]))
|
||||
.with("From", from)
|
||||
.with("layerSectionStart", D::Integer(4))
|
||||
.with("layerSectionEnd", D::Integer(5))
|
||||
.with("Nm ", D::Text(UnicodeString::new_nul(name)))
|
||||
}
|
||||
|
||||
/// `d` without the keys `drop`.
|
||||
fn without(mut d: Descriptor, drop: &[&str]) -> Descriptor {
|
||||
d.items.retain(|(k, _)| !drop.iter().any(|key| k.is(key)));
|
||||
d
|
||||
}
|
||||
|
||||
/// The step PhotoCraft writes: the measured keys without the session ids.
|
||||
fn canonical(from: D, name: Option<&str>) -> Descriptor {
|
||||
let d = without(recorded(from, name.unwrap_or("")), &["layerSectionStart", "layerSectionEnd"]);
|
||||
if name.is_some() { d } else { without(d, &["Nm "]) }
|
||||
}
|
||||
|
||||
/// The target layer, the `From` of a step recorded in PhotoCraft without a layer of its own.
|
||||
fn target_layer() -> D {
|
||||
D::Reference(vec![ReferenceItem::Enumerated { class: class("Lyr "), type_id: Id::new("Ordn"), value: Id::new("Trgt") }])
|
||||
}
|
||||
|
||||
/// Load the Make steps holding `ds` as action "A" through `actions.load`.
|
||||
fn load(ds: Vec<Descriptor>) -> (Session, Value) {
|
||||
let items = ds.into_iter().map(|d| AtnItem { event: AtnEvent::Code(*b"Mk "), dictionary: b"Make".to_vec(), descriptor: Some(d), ..Default::default() });
|
||||
let file = AtnFile {
|
||||
name: UnicodeString::new_nul("Frames"),
|
||||
actions: vec![AtnAction { name: UnicodeString::new_nul("A"), items: items.collect(), ..Default::default() }],
|
||||
..Default::default()
|
||||
};
|
||||
let mut s = Session::new();
|
||||
let r = s.execute("actions.load", json!({"data": photocraft_paint::tile::b64_encode(&atn::write(&file).unwrap())})).unwrap();
|
||||
(s, r)
|
||||
}
|
||||
|
||||
/// The descriptor of the first step of action "A" as `actions.save` writes it.
|
||||
fn saved(s: &mut Session) -> Option<Vec<u8>> {
|
||||
let r = s.execute("actions.save", json!({"action": "A"})).unwrap();
|
||||
assert_eq!(r["skipped"], json!([]), "{r}");
|
||||
let mut items = atn::parse(&photocraft_paint::tile::b64_decode(r["data"].as_str().unwrap()).unwrap()).unwrap().actions.remove(0).items;
|
||||
assert_eq!(items[0].event, AtnEvent::Code(*b"Mk "));
|
||||
items.remove(0).descriptor.as_ref().map(Descriptor::to_bytes)
|
||||
}
|
||||
|
||||
/// The descriptor a native Frame from Layers step with `p` saves as, if it saves.
|
||||
fn exported(p: &Value) -> Option<Descriptor> {
|
||||
export_item(FRAME, p, "S").and_then(|item| item.descriptor)
|
||||
}
|
||||
|
||||
/// A 100 × 80 document with "Photo" (pixels at (10, 15)–(40, 45)) under "Other" (pixels at
|
||||
/// (60, 5)–(90, 25)), "Other" selected.
|
||||
fn two_layers(s: &mut Session) -> (LayerId, LayerId) {
|
||||
s.execute("file.new", json!({"width": 100, "height": 80})).unwrap();
|
||||
let mut add = |name: &str, r: Rect| {
|
||||
s.edit(name, |doc, active| {
|
||||
let fmt = doc.pixel_format();
|
||||
let mut l = Layer::raster(name, fmt);
|
||||
l.surface_mut().unwrap().fill_rect(r, &photocraft_raster::from_rgba(&fmt, [1.0, 0.0, 0.0, 1.0]));
|
||||
let id = doc.insert_above(None, l);
|
||||
*active = Some(id);
|
||||
Ok(id)
|
||||
})
|
||||
.unwrap()
|
||||
};
|
||||
let photo = add("Photo", Rect::new(10, 15, 40, 45));
|
||||
let other = add("Other", Rect::new(60, 5, 90, 25));
|
||||
s.execute("layer.select", json!({"layer": other.0, "mode": "replace"})).unwrap();
|
||||
(photo, other)
|
||||
}
|
||||
|
||||
/// The frame layers named `name`, as (group id, frame `[x, y, w, h]`).
|
||||
fn frames(s: &Session, name: &str) -> Vec<(LayerId, [f64; 4])> {
|
||||
let doc = &s.active().unwrap().doc;
|
||||
doc.walk()
|
||||
.into_iter()
|
||||
.filter(|(_, _, l)| l.name == name)
|
||||
.filter_map(|(_, _, l)| l.frame.as_ref().map(|f| (l.id, [f.transform.m[4], f.transform.m[5], f.transform.m[0], f.transform.m[3]])))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Recorded steps load with the exact layer and name and save back byte for byte: the measured
|
||||
/// form, another key order, no session ids, no name, and the target-layer form.
|
||||
#[test]
|
||||
fn recorded_steps_load_and_save_back_unchanged() {
|
||||
let mut reordered = recorded(by_name("Photo"), "Frame 1");
|
||||
reordered.items.reverse();
|
||||
let cases = [
|
||||
(recorded(by_name("Photo"), "Frame 1"), json!({"layer": "Photo", "name": "Frame 1"})),
|
||||
(reordered, json!({"layer": "Photo", "name": "Frame 1"})),
|
||||
(without(recorded(by_name("Ébène"), "Cadre"), &["layerSectionStart", "layerSectionEnd"]), json!({"layer": "Ébène", "name": "Cadre"})),
|
||||
(without(recorded(by_name("Photo"), ""), &["Nm "]), json!({"layer": "Photo"})),
|
||||
(recorded(by_name("Photo"), ""), json!({"layer": "Photo", "name": ""})),
|
||||
(canonical(target_layer(), Some("Frame 1")), json!({"name": "Frame 1"})),
|
||||
];
|
||||
for (d, params) in cases {
|
||||
let (mut s, r) = load(vec![d.clone()]);
|
||||
assert_eq!(r["unsupported"], json!([]), "{r}");
|
||||
let (id, p) = &s.actions.list[0].steps[0];
|
||||
let mut p = p.clone();
|
||||
p.as_object_mut().unwrap().remove(SOURCE);
|
||||
assert_eq!((id.as_str(), &p), (FRAME, ¶ms));
|
||||
assert_eq!(saved(&mut s), Some(d.to_bytes()));
|
||||
}
|
||||
}
|
||||
|
||||
/// A loaded step frames the layer it names, not the selected one: the frame fits that layer's
|
||||
/// pixels, the other layer stays where it was, and one Undo takes the frame back.
|
||||
#[test]
|
||||
fn a_loaded_step_frames_the_named_layer_and_undoes() {
|
||||
let (mut s, _) = load(vec![recorded(by_name("Photo"), "Frame 1")]);
|
||||
let (photo, other) = two_layers(&mut s);
|
||||
let played = s.execute("actions.play", json!({"action": "A"})).unwrap();
|
||||
assert_eq!(played["ran"], 1, "{played}");
|
||||
assert_eq!(frames(&s, "Frame 1").into_iter().map(|f| f.1).collect::<Vec<_>>(), vec![[10.0, 15.0, 30.0, 30.0]]);
|
||||
let doc = &s.active().unwrap().doc;
|
||||
assert!(doc.layer(photo).is_none(), "Photo went into the frame");
|
||||
assert!(doc.layers.iter().any(|l| l.id == other), "Other stays a top-level layer");
|
||||
s.execute("history.undo", json!({})).unwrap();
|
||||
assert!(frames(&s, "Frame 1").is_empty());
|
||||
let doc = &s.active().unwrap().doc;
|
||||
assert!(doc.layers.iter().any(|l| l.id == photo) && doc.layers.iter().any(|l| l.id == other));
|
||||
}
|
||||
|
||||
/// Without a layer of its own the command still frames the selected layers.
|
||||
#[test]
|
||||
fn without_a_layer_the_selected_layers_are_framed() {
|
||||
let mut s = Session::new();
|
||||
let (photo, other) = two_layers(&mut s);
|
||||
s.execute(FRAME, json!({"name": "Frame 1"})).unwrap();
|
||||
assert_eq!(frames(&s, "Frame 1").into_iter().map(|f| f.1).collect::<Vec<_>>(), vec![[60.0, 5.0, 30.0, 20.0]]);
|
||||
let doc = &s.active().unwrap().doc;
|
||||
assert!(doc.layer(other).is_none() && doc.layers.iter().any(|l| l.id == photo));
|
||||
}
|
||||
|
||||
/// A step recorded in PhotoCraft writes the measured keys without the session ids: the layer by
|
||||
/// name (the target layer without one) and `Nm ` for a name that isn't blank. It loads back to
|
||||
/// the same settings.
|
||||
#[test]
|
||||
fn native_steps_save_the_measured_keys() {
|
||||
for (p, d, back) in [
|
||||
(json!({"layer": "Photo", "name": "Frame 1"}), canonical(by_name("Photo"), Some("Frame 1")), json!({"layer": "Photo", "name": "Frame 1"})),
|
||||
(json!({"layer": "Photo"}), canonical(by_name("Photo"), None), json!({"layer": "Photo"})),
|
||||
(json!({"name": "Frame 1"}), canonical(target_layer(), Some("Frame 1")), json!({"name": "Frame 1"})),
|
||||
(json!({"name": " ", "layer": null}), canonical(target_layer(), None), json!({})),
|
||||
(json!({}), canonical(target_layer(), None), json!({})),
|
||||
] {
|
||||
assert_eq!(exported(&p), Some(d.clone()), "{p}");
|
||||
let (s, _) = load(vec![d]);
|
||||
assert_eq!(s.actions.list[0].steps[0], (FRAME.to_string(), back), "{p}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A native step the event can't hold is refused: a layer by id or selector, a name that isn't
|
||||
/// text, or the group options the command passes on (colour, mode, opacity), which the step
|
||||
/// doesn't record.
|
||||
#[test]
|
||||
fn settings_the_event_cannot_hold_are_refused() {
|
||||
for p in [
|
||||
json!({"layer": 3}),
|
||||
json!({"layer": {"index": 2}}),
|
||||
json!({"layer": {"background": true}}),
|
||||
json!({"name": 4}),
|
||||
json!({"name": "Frame 1", "color": "red"}),
|
||||
json!({"mode": "multiply"}),
|
||||
json!({"opacity": 50}),
|
||||
json!({"name": "Frame 1", "width": 200}),
|
||||
] {
|
||||
assert!(exported(&p).is_none(), "{p}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Any other form keeps the reference step: no `From`, another `From`, a repeated or extra key,
|
||||
/// values of another type, or another `null`.
|
||||
#[test]
|
||||
fn other_forms_keep_the_photoshop_step() {
|
||||
let measured = recorded(by_name("Photo"), "Frame 1");
|
||||
let replaced = |key: &str, v: D| {
|
||||
let mut d = measured.clone();
|
||||
d.items.iter_mut().filter(|(k, _)| k.is(key)).for_each(|slot| slot.1 = v.clone());
|
||||
d
|
||||
};
|
||||
let forms = [
|
||||
without(measured.clone(), &["From"]),
|
||||
replaced("From", D::Reference(vec![ReferenceItem::Index { class: class("Lyr "), index: 2 }])),
|
||||
replaced("From", D::Reference(vec![ReferenceItem::Name { class: class("Chnl"), name: UnicodeString::new_nul("Photo") }])),
|
||||
replaced("From", D::Reference(vec![ReferenceItem::Enumerated { class: class("Lyr "), type_id: Id::new("Ordn"), value: Id::new("Al ") }])),
|
||||
replaced("From", D::Text(UnicodeString::new_nul("Photo"))),
|
||||
replaced("Nm ", D::Integer(1)),
|
||||
replaced("layerSectionEnd", D::Double(5.0)),
|
||||
replaced("null", D::Reference(vec![ReferenceItem::Class(class("frame"))])),
|
||||
measured.clone().with("Nm ", D::Text(UnicodeString::new_nul("Again"))),
|
||||
measured.clone().with("From", by_name("Other")),
|
||||
measured.clone().with("Wdth", D::UnitFloat { unit: PX, value: 200.0 }),
|
||||
];
|
||||
for d in forms {
|
||||
let (mut s, r) = load(vec![d.clone()]);
|
||||
assert_eq!(r["unsupported"].as_array().map(Vec::len), Some(1), "{d:?}");
|
||||
assert_eq!(s.actions.list[0].steps[0].0, PHOTOSHOP_STEP, "{d:?}");
|
||||
assert_eq!(saved(&mut s), Some(d.to_bytes()));
|
||||
}
|
||||
}
|
||||
|
||||
/// A loaded step whose layer or name was changed saves the new settings, not the stale
|
||||
/// recording; one whose recording is damaged still saves its settings.
|
||||
#[test]
|
||||
fn changed_or_damaged_steps_save_their_settings() {
|
||||
let (s, _) = load(vec![recorded(by_name("Photo"), "Frame 1")]);
|
||||
let mut p = s.actions.list[0].steps[0].1.clone();
|
||||
assert!(p.get(SOURCE).is_some(), "{p}");
|
||||
p["layer"] = json!("Other");
|
||||
assert_eq!(exported(&p), Some(canonical(by_name("Other"), Some("Frame 1"))));
|
||||
p["layer"] = json!("Photo");
|
||||
p["name"] = json!(" ");
|
||||
assert_eq!(exported(&p), Some(canonical(by_name("Photo"), None)));
|
||||
p["name"] = json!("Frame 1");
|
||||
p[SOURCE] = json!("not base64!");
|
||||
assert_eq!(exported(&p), Some(canonical(by_name("Photo"), Some("Frame 1"))));
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
//! Layer › New › Frame from Layers, recorded as a Make of class `framedGroupSection`, as
|
||||
//! `docs/atn.md` ("Recorded through the menus") measures it (#10723): `From` = the layer **by
|
||||
//! name**, `layerSectionStart`, `layerSectionEnd` (longs) and `Nm ` (text). The dialog's width
|
||||
//! and height are not in the step.
|
||||
//!
|
||||
//! `layerSectionStart` and `layerSectionEnd` are ids of the recording session, so they are not
|
||||
//! settings: a loaded step keeps them only inside its recorded descriptor.
|
||||
|
||||
use super::descriptors::{class_ref, desc, jstr, name_ref, target_ref, text};
|
||||
use super::fields::{Mapped, step};
|
||||
use super::{D, Descriptor, ReferenceItem, Value, json};
|
||||
|
||||
/// The native command the step plays as.
|
||||
pub(super) const COMMAND: &str = "layer.new.frameFromLayers";
|
||||
/// The recorded descriptor, kept when it differs from the one [`to`] would write (session ids,
|
||||
/// key order), so a load and save keeps the step unchanged.
|
||||
const SOURCE: &str = "_atnFrameSectionDescriptor";
|
||||
|
||||
/// The settings a step holds: the layer it frames (`None`: the selected layers) and the frame's
|
||||
/// name (`None`: no `Nm `, so the frame takes the command's default name).
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct Settings {
|
||||
layer: Option<String>,
|
||||
name: Option<String>,
|
||||
}
|
||||
|
||||
/// Text without the trailing NUL the format may carry.
|
||||
fn plain(t: &super::UnicodeString) -> Option<String> {
|
||||
String::from_utf16(t.0.strip_suffix(&[0]).unwrap_or(&t.0)).ok()
|
||||
}
|
||||
|
||||
/// `From`: a layer by name, or the target layer (`Lyr ` `Ordn.Trgt`), the form a step recorded
|
||||
/// in PhotoCraft without a layer of its own writes.
|
||||
fn source_layer(v: &D) -> Option<Option<String>> {
|
||||
let D::Reference(r) = v else { return None };
|
||||
match r.as_slice() {
|
||||
[ReferenceItem::Name { class, name }] if class.class_id.is("Lyr ") => Some(Some(plain(name)?)),
|
||||
[ReferenceItem::Enumerated { class, type_id, value }] if class.class_id.is("Lyr ") && type_id.is("Ordn") && value.is("Trgt") => Some(None),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The measured form only: `null` = class `framedGroupSection`, `From`, optional session ids
|
||||
/// (longs) and an optional `Nm `, each key at most once and nothing else.
|
||||
fn recorded(d: &Descriptor) -> Option<Settings> {
|
||||
const KEYS: [&str; 5] = ["null", "From", "layerSectionStart", "layerSectionEnd", "Nm "];
|
||||
let once = |key: &str| d.items.iter().filter(|(k, _)| k.is(key)).count() <= 1;
|
||||
if d.items.iter().any(|(k, _)| !KEYS.iter().any(|key| k.is(key))) || !KEYS.iter().all(|key| once(key)) {
|
||||
return None;
|
||||
}
|
||||
let section = matches!(d.get("null")?, D::Reference(r) if matches!(r.as_slice(), [ReferenceItem::Class(c)] if c.class_id.is("framedGroupSection")));
|
||||
if !section || ["layerSectionStart", "layerSectionEnd"].iter().any(|key| d.get(key).is_some_and(|v| !matches!(v, D::Integer(_)))) {
|
||||
return None;
|
||||
}
|
||||
let name = match d.get("Nm ") {
|
||||
None => None,
|
||||
Some(D::Text(t)) => Some(plain(t)?),
|
||||
Some(_) => return None,
|
||||
};
|
||||
Some(Settings { layer: source_layer(d.get("From")?)?, name })
|
||||
}
|
||||
|
||||
/// The descriptor a step recorded in PhotoCraft saves as: the measured keys without the session
|
||||
/// ids, `Nm ` only for a name of the step's own (not blank).
|
||||
fn canonical(settings: &Settings) -> Descriptor {
|
||||
let from = settings.layer.as_deref().map_or_else(|| target_ref("Lyr "), |layer| name_ref("Lyr ", layer));
|
||||
let d = desc("null").with("null", class_ref("framedGroupSection")).with("From", from);
|
||||
match &settings.name {
|
||||
Some(name) => d.with("Nm ", text(name)),
|
||||
None => d,
|
||||
}
|
||||
}
|
||||
|
||||
/// Map the measured form; any other stays a complete kept step.
|
||||
pub(super) fn from(d: &Descriptor) -> Mapped {
|
||||
let Some(settings) = recorded(d) else { return Mapped::Unsupported { harmless: false } };
|
||||
let mut p = json!({});
|
||||
if let Some(layer) = &settings.layer {
|
||||
p["layer"] = layer.as_str().into();
|
||||
}
|
||||
if let Some(name) = &settings.name {
|
||||
p["name"] = name.as_str().into();
|
||||
}
|
||||
if *d != canonical(&settings) {
|
||||
p[SOURCE] = photocraft_paint::tile::b64_encode(&d.to_bytes()).into();
|
||||
}
|
||||
step(COMMAND, p)
|
||||
}
|
||||
|
||||
/// A native step the event holds: the selected layers or a layer by name, and a name. A layer by
|
||||
/// id (meaningless in another document) and the group options the command passes on to the
|
||||
/// group it frames (colour, mode, opacity) refuse export: the step records none of them.
|
||||
fn native(p: &Value) -> Option<Settings> {
|
||||
let m = p.as_object()?;
|
||||
if m.keys().any(|key| !["layer", "name", SOURCE].contains(&key.as_str())) {
|
||||
return None;
|
||||
}
|
||||
let layer = match m.get("layer") {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(Value::String(layer)) => Some(layer.clone()),
|
||||
Some(_) => return None,
|
||||
};
|
||||
let name = match m.get("name") {
|
||||
None | Some(Value::Null) => None,
|
||||
// A blank name is no name to the command either.
|
||||
Some(Value::String(n)) => Some(n.clone()).filter(|n| !n.trim().is_empty()),
|
||||
Some(_) => return None,
|
||||
};
|
||||
Some(Settings { layer, name })
|
||||
}
|
||||
|
||||
/// Save the recorded descriptor while the step still frames the same layer with the same name,
|
||||
/// otherwise the canonical form of the step's settings.
|
||||
pub(super) fn to(p: &Value) -> Option<Descriptor> {
|
||||
let settings = native(p)?;
|
||||
let source = jstr(p, SOURCE)
|
||||
.and_then(photocraft_paint::tile::b64_decode)
|
||||
.and_then(|bytes| Descriptor::from_bytes(&bytes).ok())
|
||||
.filter(|d| recorded(d).is_some_and(|r| r.layer == settings.layer && r.name.filter(|n| !n.trim().is_empty()) == settings.name));
|
||||
Some(source.unwrap_or_else(|| canonical(&settings)))
|
||||
}
|
||||
@@ -552,6 +552,10 @@ pub(super) fn make_from(d: &Descriptor) -> Mapped {
|
||||
if let Some(mapped) = super::steps_layer_style::create_from_descriptor(d) {
|
||||
return mapped;
|
||||
}
|
||||
// Layer › New › Frame from Layers (#10723).
|
||||
if get_ref(d, "null").and_then(ref_class).as_deref() == Some("framedGroupSection") {
|
||||
return super::steps_frame_section::from(d);
|
||||
}
|
||||
if d.items == type_shape_descriptor().items {
|
||||
return none("type.convertToShape");
|
||||
}
|
||||
@@ -720,6 +724,9 @@ pub(super) fn make_to(id: &str, p: &Value) -> Option<Descriptor> {
|
||||
if id == super::steps_layer_style::CREATE {
|
||||
return super::steps_layer_style::style_to(id, p);
|
||||
}
|
||||
if id == super::steps_frame_section::COMMAND {
|
||||
return super::steps_frame_section::to(p);
|
||||
}
|
||||
if id == "type.convertToShape" {
|
||||
return p.as_object().filter(|p| p.is_empty()).map(|_| type_shape_descriptor());
|
||||
}
|
||||
|
||||
@@ -691,6 +691,7 @@ fn every_mapped_command_exports_and_imports_back() {
|
||||
"rotationAdaptation":"none","scale":true,"mirror":false,"output":"new"}),
|
||||
),
|
||||
("edit.fade", json!({"opacity":50,"mode":"Multiply"})),
|
||||
("layer.new.frameFromLayers", json!({"layer": "Photo", "name": "Frame 1"})),
|
||||
("layer.linkLayers", json!({})),
|
||||
("layer.smartObjects.stackMode.range", json!({})),
|
||||
("layer.smartObjects.stackMode.entropy", json!({})),
|
||||
|
||||
@@ -135,8 +135,11 @@ fn new_frame(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(result)
|
||||
}
|
||||
fn frame_from_layers(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// A `layer` of its own (a recorded step names its layer) is what the grouping below takes
|
||||
// in, so the frame fits that layer, not whatever is selected.
|
||||
let explicit = crate::commands::explicit_layer(s, p)?;
|
||||
let st = s.active().ok_or(EngineError::NoDocument)?;
|
||||
let ids = st.selected_layers();
|
||||
let ids = explicit.map_or_else(|| st.selected_layers(), |id| vec![id]);
|
||||
let bounds = ids
|
||||
.iter()
|
||||
.filter_map(|id| st.doc.layer(*id))
|
||||
|
||||
+15
-1
@@ -147,7 +147,7 @@ row; the action still adds only one Undo entry.
|
||||
| `CtTL` | cutToLayer | Layer Via Cut | `layer.new.layerViaCut` |
|
||||
| `LnsF` | lensFlare | Lens Flare | `filter.render.lensFlare` |
|
||||
| `Lvls` | levels | Levels | `image.adjustments.levels`, `image.autoTone`, `image.autoContrast` |
|
||||
| `Mk ` | make | Make | `image.calculations`, `layer.layerStyle.createLayer`, `layer.new.layer`, `layer.new.group`, `layer.groupLayers`, `layer.duplicate`, `layer.new.layerViaCopy`, `layer.new.layerViaCut`, `layer.newFillLayer.solidColor`, `layer.newFillLayer.pattern`, `layer.newFillLayer.gradient`, `layer.newAdjustmentLayer.levels`, `layer.newAdjustmentLayer.curves`, `layer.newAdjustmentLayer.hueSaturation`, `layer.newAdjustmentLayer.brightnessContrast`, `layer.newAdjustmentLayer.threshold`, `layer.newAdjustmentLayer.posterize`, `layer.newAdjustmentLayer.invert`, `layer.newAdjustmentLayer.colorBalance`, `layer.newAdjustmentLayer.vibrance`, `layer.newAdjustmentLayer.exposure`, `layer.newAdjustmentLayer.photoFilter`, `layer.newAdjustmentLayer.blackWhite`, `layer.newAdjustmentLayer.channelMixer`, `layer.newAdjustmentLayer.selectiveColor`, `layer.newAdjustmentLayer.gradientMap`, `layer.layerMask.revealAll`, `layer.layerMask.hideAll`, `layer.layerMask.revealSelection`, `layer.layerMask.hideSelection`, `file.new`, `file.newFromClipboard`, `history.newSnapshot`, `type.convertToShape`, `type.createWorkPath` |
|
||||
| `Mk ` | make | Make | `image.calculations`, `layer.layerStyle.createLayer`, `layer.new.layer`, `layer.new.group`, `layer.groupLayers`, `layer.new.frameFromLayers` (Layer › New › Frame from Layers), `layer.duplicate`, `layer.new.layerViaCopy`, `layer.new.layerViaCut`, `layer.newFillLayer.solidColor`, `layer.newFillLayer.pattern`, `layer.newFillLayer.gradient`, `layer.newAdjustmentLayer.levels`, `layer.newAdjustmentLayer.curves`, `layer.newAdjustmentLayer.hueSaturation`, `layer.newAdjustmentLayer.brightnessContrast`, `layer.newAdjustmentLayer.threshold`, `layer.newAdjustmentLayer.posterize`, `layer.newAdjustmentLayer.invert`, `layer.newAdjustmentLayer.colorBalance`, `layer.newAdjustmentLayer.vibrance`, `layer.newAdjustmentLayer.exposure`, `layer.newAdjustmentLayer.photoFilter`, `layer.newAdjustmentLayer.blackWhite`, `layer.newAdjustmentLayer.channelMixer`, `layer.newAdjustmentLayer.selectiveColor`, `layer.newAdjustmentLayer.gradientMap`, `layer.layerMask.revealAll`, `layer.layerMask.hideAll`, `layer.layerMask.revealSelection`, `layer.layerMask.hideSelection`, `file.new`, `file.newFromClipboard`, `history.newSnapshot`, `type.convertToShape`, `type.createWorkPath` |
|
||||
| (string ID only) | animationFramesFromLayers | Make Frames from Layers | |
|
||||
| (string ID only) | matchColor | Match Color | `image.adjustments.matchColor` |
|
||||
| `Mxm ` | maximum | Maximum | `filter.other.maximum` |
|
||||
@@ -272,6 +272,20 @@ options are refused on export. Playback uses the native command's preconditions
|
||||
and current state. Isolate Layers toggles the panel view; type defaults remain
|
||||
session settings; Record Measurements uses the current measurement configuration.
|
||||
|
||||
Layer › New › Frame from Layers is a Make with `null` = the class
|
||||
`framedGroupSection`, `From` = the layer by name and `Nm ` = the frame's name. It
|
||||
plays as `layer.new.frameFromLayers` on that layer, and the frame fits that
|
||||
layer's bounds whatever is selected. The dialog's width and height are not in the
|
||||
step. `layerSectionStart` and `layerSectionEnd` are ids of the recording session:
|
||||
a loaded step saves back its recorded descriptor, session ids included, while it
|
||||
still frames the same layer with the same name, and a step recorded in PhotoCraft
|
||||
writes `null`, `From` and `Nm ` (only for a name that isn't blank) without them. A
|
||||
native step without a layer of its own frames the selected layers and writes
|
||||
`From` = the target layer, a form the recordings don't show. Another `From`, a
|
||||
repeated or extra key, or a value of another type stays a kept step; a native step
|
||||
with a layer by id, or with the group options the command passes on (colour, mode,
|
||||
opacity), refuses export.
|
||||
|
||||
Link Layers plays as the toggle the reference application performs (played twice on the same
|
||||
layers it links, then unlinks them; see the measurements below). Unlink is explicit and
|
||||
idempotent: it keeps an already unlinked selection unlinked and clears singleton link groups.
|
||||
|
||||
Reference in new issue
Block a user