Skip to content

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

Layer Style: a new Stroke is 1 px inside black, as in Photoshop (#7765)

David Mann41fb9f986c78
diff --git a/crates/engine/src/layer_style.rs b/crates/engine/src/layer_style.rs
index 8933f838b..8b8103a17 100644
--- a/crates/engine/src/layer_style.rs
+++ b/crates/engine/src/layer_style.rs
@@ -91,7 +91,7 @@ pub fn effect_defaults(kind: &str) -> Value {
"innerGlow" => {
json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "source": "edge", "choke": 0, "size": 5, "contour": "Linear", "antiAlias": false, "noise": 0})
}
- "stroke" => json!({"size": 3, "position": "outside", "blend": "Normal", "opacity": 100, "color": "#000000"}),
+ "stroke" => json!({"size": 1, "position": "inside", "blend": "Normal", "opacity": 100, "color": "#000000"}),
"colorOverlay" => json!({"blend": "Normal", "color": "#ff0000", "opacity": 100}),
"gradientOverlay" => {
json!({"blend": "Normal", "opacity": 100, "from": "#000000", "to": "#ffffff", "reverse": false, "style": "linear", "angle": 90, "scale": 100})
@@ -507,9 +507,9 @@ fn fresh_effect(kind: &str) -> Option<Effect> {
"innerGlow" => Effect::InnerGlow(glow()),
"stroke" => Effect::Stroke(StrokeFx {
common: FxCommon::new(BlendMode::Normal, 1.0),
- size: 3.0,
- position: StrokePosition::Outside,
- paint: FxPaint::Color(Color::rgb(1.0, 0.0, 0.0)),
+ size: 1.0,
+ position: StrokePosition::Inside,
+ paint: FxPaint::Color(Color::BLACK),
}),
"colorOverlay" => Effect::ColorOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), color: Color::rgb(1.0, 0.0, 0.0) },
"gradientOverlay" => Effect::GradientOverlay { common: FxCommon::new(BlendMode::Normal, 1.0), gradient: Gradient::default(), dither: false },
@@ -1012,7 +1012,7 @@ pub fn specs() -> Vec<CommandSpec> {
style_cmd!(
"stroke",
"Stroke…",
- r##"{"size":px=3,"position":"outside|inside|center","color":"#rrggbb","from":"#rrggbb","to":"#rrggbb","method":"classic|perceptual|linear|smooth"?,"smoothness":0..100=100,"style":str,"angle":deg,"opacity":0..100,"blend":str,"add":bool}"##
+ r##"{"size":px=1,"position":"inside|outside|center","color":"#rrggbb","from":"#rrggbb","to":"#rrggbb","method":"classic|perceptual|linear|smooth"?,"smoothness":0..100=100,"style":str,"angle":deg,"opacity":0..100,"blend":str,"add":bool}"##
),
style_cmd!("colorOverlay", "Color Overlay…", r##"{"color":"#rrggbb","opacity":0..100=100,"blend":str,"add":bool}"##),
style_cmd!(
@@ -1518,7 +1518,7 @@ mod tests {
// Factory default first: Reset without a saved default gives the factory set.
let r = s.execute("layer.layerStyle.defaultFor", json!({"kind": "stroke"})).unwrap();
assert_eq!(r["user"], json!(false));
- assert_eq!(r["params"]["size"], json!(3));
+ assert_eq!(r["params"]["size"], json!(1));
s.execute(
"layer.layerStyle.makeDefault",
json!({"kind": "stroke", "params": {"size": 9, "position": "inside", "blend": "Normal", "opacity": 100, "color": "#000000"}}),
@@ -1533,6 +1533,22 @@ mod tests {
assert!(s.execute("layer.layerStyle.defaultFor", json!({"kind": "nope"})).is_err());
}
+ /// #7765: a stroke built without params was red, while the dialog's factory default was
+ /// black. Both now give Photoshop's Reset to Default: 1 px, inside, Normal, 100 %, black.
+ #[test]
+ fn fresh_effects_match_the_dialog_factory_defaults() {
+ for kind in
+ ["dropShadow", "innerShadow", "outerGlow", "innerGlow", "stroke", "colorOverlay", "gradientOverlay", "patternOverlay", "satin", "bevelEmboss"]
+ {
+ let bare = effect_from_params(kind, &json!({})).unwrap();
+ let dialog = effect_from_params(kind, &effect_defaults(kind)).unwrap();
+ assert_eq!(bare, dialog, "{kind}");
+ }
+ let Some(Effect::Stroke(st)) = effect_from_params("stroke", &json!({})) else { panic!("no stroke") };
+ assert_eq!((st.size, st.position, st.common.blend, st.common.opacity), (1.0, StrokePosition::Inside, BlendMode::Normal, 1.0));
+ assert_eq!(st.paint, FxPaint::Color(Color::BLACK));
+ }
+
#[test]
fn layer_style_defaults_persist_with_presets() {
let mut s = session();
diff --git a/crates/engine/src/pattern_cmds.rs b/crates/engine/src/pattern_cmds.rs
index 0cb9052ce..dc3cc380f 100644
--- a/crates/engine/src/pattern_cmds.rs
+++ b/crates/engine/src/pattern_cmds.rs
@@ -557,7 +557,7 @@ mod tests {
s.execute("edit.fill", json!({"color": "#0000ff"})).unwrap();
s.execute("select.deselect", json!({})).unwrap();
s.execute("layer.layerStyle.patternOverlay", json!({"pattern": "Diagonal Lines"})).unwrap();
- s.execute("layer.layerStyle.stroke", json!({"size": 3, "color": "#00ff00", "add": true})).unwrap();
+ s.execute("layer.layerStyle.stroke", json!({"size": 3, "position": "outside", "color": "#00ff00", "add": true})).unwrap();
let out = pixel(&s, 8, 15);
assert!(out[1] > 0.9 && out[0] < 0.1, "stroke outside: {out:?}");
}