mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
Gradients: paint.setStroke refuses a dithered gradient when "swatch" is null
Review follow-up (CodeRabbit): the refusal skipped any request carrying a `swatch` key, so `"swatch": null` with a dithered gradient got through. Only a named swatch (a gradient swatch keeps its own dither) is exempt now. The dither test sends `"swatch": null`; it fails without the change.
This commit is contained in:
committed by
bflatastic
parent
a7ee168efe
commit
e20c330bd3
@@ -403,8 +403,9 @@ fn set_paint(s: &mut Session, p: &Value, fill: bool) -> Result<Value> {
|
||||
}
|
||||
check_keep_model(p, cmd)?;
|
||||
let paint = paint_from(s, p)?.ok_or_else(|| bad(cmd, "give color, none, swatch or gradient"))?;
|
||||
// As `paint.editGradient`: a `dither` given applies to gradient fills only.
|
||||
if !fill && matches!(&paint, Paint::Gradient(g) if g.gradient.dither) && p.get("swatch").is_none() {
|
||||
// As `paint.editGradient`: a `dither` given applies to gradient fills only. A gradient swatch
|
||||
// (named) keeps its own dither; `"swatch": null` names none.
|
||||
if !fill && matches!(&paint, Paint::Gradient(g) if g.gradient.dither) && p.get("swatch").and_then(Value::as_str).is_none() {
|
||||
return Err(bad(cmd, "`dither` applies to gradient fills (paint.setFill)"));
|
||||
}
|
||||
apply_paint(s, p, paint, fill)
|
||||
|
||||
@@ -441,6 +441,7 @@ fn dither_is_a_fill_gradient_option_that_saves_and_loads() {
|
||||
let before = node(&s, id).appearance.clone();
|
||||
assert!(s.execute("paint.editGradient", &json!({"dither": true, "stroke": true})).is_err());
|
||||
assert!(s.execute("paint.setStroke", &json!({"gradient": {"dither": true}})).is_err());
|
||||
assert!(s.execute("paint.setStroke", &json!({"swatch": null, "gradient": {"dither": true}})).is_err(), "a null swatch names none");
|
||||
assert!(s.execute("paint.editGradient", &json!({"dither": "yes"})).is_err());
|
||||
assert!(s.execute("paint.setFill", &json!({"gradient": {"dither": 1}})).is_err());
|
||||
assert_eq!(node(&s, id).appearance, before);
|
||||
|
||||
Reference in New Issue
Block a user