mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 03:29:58 +00:00
Shape Builder: a fill or stroke object that is not a paint is an error
A fill or stroke such as {"swatch": 123} gave no paint, so shapeBuilder.copyRegion and shapeBuilder.merge used the current paint. Both commands now report it as a bad fill or stroke.
This commit is contained in:
@@ -279,7 +279,8 @@ fn paint_param(s: &Session, p: &Value, key: &str, cmd: &str) -> Result<Option<Pa
|
||||
match p.get(key) {
|
||||
None | Some(Value::Null) => Ok(None),
|
||||
Some(v @ Value::Object(o)) if o.contains_key("color") || o.contains_key("swatch") || o.contains_key("gradient") || o.contains_key("none") => {
|
||||
paint_from(s, v)
|
||||
// A paint key whose value is not a paint, such as `{"swatch": 123}`, gives no paint.
|
||||
paint_from(s, v)?.map(Some).ok_or_else(|| bad(cmd, format!("bad {key} {v}")))
|
||||
}
|
||||
Some(v) => color_value(v).map(|c| Some(Paint::solid(super::paint::new_color(s, p, c)))).ok_or_else(|| bad(cmd, format!("bad {key} {v}"))),
|
||||
}
|
||||
|
||||
@@ -453,6 +453,12 @@ fn fill_area_outside_every_area_changes_nothing() {
|
||||
for p in [json!({}), json!({"point": [50]}), json!({"point": [50, 70], "fill": "nope"}), json!({"point": [50, 70], "stroke": 3})] {
|
||||
assert!(s.execute("shapeBuilder.copyRegion", &p).is_err(), "{p}");
|
||||
}
|
||||
for paint in [json!({"swatch": 123}), json!({"color": 5}), json!({"color": "nope"})] {
|
||||
for key in ["fill", "stroke"] {
|
||||
let p = json!({"point": [50, 70], key: paint});
|
||||
assert!(s.execute("shapeBuilder.copyRegion", &p).is_err(), "{p}");
|
||||
}
|
||||
}
|
||||
assert!(s.execute("shapeBuilder.copyRegion", &json!({"point": [50, 70], "ids": [999_999]})).is_err());
|
||||
assert_eq!((undo_len(&s), stack(&s)), (undo, kids));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user