Skip to content

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

Fill layers: document the functions and tests the PR adds or changes

abc2cb0e8840f1571e
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index e036bf821..b3b8e823c 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -406,6 +406,7 @@ pub(crate) fn mask_new_layer(doc: &Document, l: &mut Layer, p: &Value, cmd: &str
pub(crate) const NEW_LAYER_PATH: &str =
r##""path":"work"|saved path name|{…path}? (the active path: becomes the vector mask; else the selection is the layer mask, or white with no selection)"##;
+/// Add an adjustment layer above the active one; it takes the mask `mask_new_layer` builds from `p` (a path, the selection, or the default white mask).
fn new_adjustment(s: &mut Session, adj: Adjustment, p: &Value, cmd: &str) -> Result<Value> {
let label = format!("New {} Layer", adj.label());
let name = adj.label().to_string();
@@ -419,6 +420,7 @@ fn new_adjustment(s: &mut Session, adj: Adjustment, p: &Value, cmd: &str) -> Res
Ok(json!({ "layer": id.0 }))
}
+/// Apply `adj` in place to the targeted layer mask, the targeted alpha channel or Quick Mask, or else the active layer's pixels, as one history step named `label`.
fn destructive_adjust(s: &mut Session, label: &str, adj: Adjustment, p: &Value) -> Result<Value> {
if is_mask_target(p) {
// The targeted layer mask (#780): ⌘I inverts it, as in Photoshop.
diff --git a/crates/engine/src/layer_multi_cmds.rs b/crates/engine/src/layer_multi_cmds.rs
index 1ea70ecb2..e7c3a626e 100644
--- a/crates/engine/src/layer_multi_cmds.rs
+++ b/crates/engine/src/layer_multi_cmds.rs
@@ -2970,6 +2970,7 @@ mod layers_panel_parity_tests {
assert!(s.active().unwrap().fx_collapsed.contains(&target));
}
+ /// New Solid Color and Gradient fill layers get the default mask only while Use Default Masks on Fill Layers is on.
#[test]
fn fill_layers_respect_use_default_masks_option() {
let (mut s, _) = new_session();
diff --git a/crates/engine/src/pattern_cmds.rs b/crates/engine/src/pattern_cmds.rs
index 87ae0322f..c81d4145a 100644
--- a/crates/engine/src/pattern_cmds.rs
+++ b/crates/engine/src/pattern_cmds.rs
@@ -328,6 +328,7 @@ pub(crate) fn insert_fill_layer(
Ok(id)
}
+/// `layer.newFillLayer.pattern`: a Pattern Fill layer above the active one, masked as the Layers panel's Use Default Masks on Fill Layers option says.
fn new_fill_layer(s: &mut Session, p: &Value) -> Result<Value> {
let pat = resolve_param(s, "layer.newFillLayer.pattern", p)?;
let default_mask = crate::commands::layer_panel_option(s, "useDefaultMasksOnFillLayers", true);
@@ -335,6 +336,7 @@ fn new_fill_layer(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({"layer": id.0, "pattern": pat.id}))
}
+/// `brush.texturePattern`: use a pattern as the brush texture, converted to grey as the luminance of its composite over white.
fn brush_texture(s: &mut Session, p: &Value) -> Result<Value> {
let pat = resolve_param(s, "brush.texturePattern", p)?;
let n = pat.is_paintable().then(|| usize::try_from(pat.pixel_count()).ok()).flatten();
diff --git a/crates/engine/src/pattern_fill_cmds.rs b/crates/engine/src/pattern_fill_cmds.rs
index 0ecf09f37..82fd02faa 100644
--- a/crates/engine/src/pattern_fill_cmds.rs
+++ b/crates/engine/src/pattern_fill_cmds.rs
@@ -132,6 +132,7 @@ pub fn preview(s: &Session, cmd: &str, p: &Value) -> Result<Document> {
Ok(doc)
}
+/// Register `layer.fill.pattern.set` (the Pattern Fill dialog's command), journaled like any other edit.
pub fn specs() -> Vec<CommandSpec> {
vec![CommandSpec {
id: SET,
@@ -217,6 +218,7 @@ mod tests {
assert!(preview(&s, "edit.fill", &json!({})).is_err());
}
+ /// At 8, 16 and 32 bits the Pattern Fill preview and the committed layer carry the default mask only while the option is on, and creating one is one undoable step.
#[test]
fn create_preview_and_commit_honor_default_masks_option() {
for depth in [8, 16, 32] {
@@ -249,6 +251,7 @@ mod tests {
}
}
+ /// Malformed or out-of-range params, and missing layers or patterns, are errors in both the command and its preview, never panics.
#[test]
fn bad_params_and_targets_are_errors_not_panics() {
let (mut s, id) = session(8);
diff --git a/crates/ui-egui/src/layers_panel_ui.rs b/crates/ui-egui/src/layers_panel_ui.rs
index 8d29c0de5..a90291662 100644
--- a/crates/ui-egui/src/layers_panel_ui.rs
+++ b/crates/ui-egui/src/layers_panel_ui.rs
@@ -382,6 +382,7 @@ mod tests {
assert!(restored.layers_panel_dialog.is_none());
}
+ /// With the option off a new fill layer has no mask and the mask is not targeted; with it on the new layer's mask is targeted.
#[test]
fn disabling_default_fill_masks_never_targets_an_absent_mask() {
let mut session = photocraft_engine::Session::new();