mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 10:30:03 +00:00
Color: an opacity alone refuses a span other than "object"
paint.setFill and paint.setStroke given only `opacity` now check `span` as they do with a paint: "selection" asks for a gradient, and an unknown value is an error, instead of the opacity going through unchecked.
This commit is contained in:
@@ -560,10 +560,8 @@ pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool)
|
||||
fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity: Option<f32>, fill: bool) -> Result<Value> {
|
||||
let cmd = if fill { "paint.setFill" } else { "paint.setStroke" };
|
||||
let focus = switch_or(p, "focus", true, cmd)?;
|
||||
let span = match &paint {
|
||||
Some(paint) => spans_targets(p, paint).map_err(|e| bad(cmd, e))?,
|
||||
None => false,
|
||||
};
|
||||
// An opacity alone places no gradient, so `span` may only be "object" with it.
|
||||
let span = spans_targets(p, paint.as_ref().unwrap_or(&Paint::None)).map_err(|e| bad(cmd, e))?;
|
||||
// Characters selected with the Type tool take the paint, not the whole type object (#1063).
|
||||
if p.get("ids").is_none()
|
||||
&& p.get("id").is_none()
|
||||
|
||||
@@ -156,6 +156,15 @@ fn errors_leave_the_document_and_defaults_alone() {
|
||||
}
|
||||
let e = s.execute("paint.setFill", &json!({})).unwrap_err();
|
||||
assert!(e.to_string().contains("give color, none, swatch, gradient or opacity"), "{e}");
|
||||
// An opacity alone places no gradient across the selection.
|
||||
let doc = s.doc().unwrap().doc.clone();
|
||||
for (span, says) in [(json!("selection"), "give `gradient`"), (json!("all"), "span must be \"object\" or \"selection\"")] {
|
||||
let e = s.execute("paint.setFill", &json!({"opacity": 40, "span": span})).unwrap_err();
|
||||
assert!(e.to_string().contains(says), "{span}: {e}");
|
||||
}
|
||||
assert_eq!(*s.doc().unwrap().doc, *doc);
|
||||
s.execute("paint.setFill", &json!({"opacity": 40, "span": "object"})).unwrap();
|
||||
assert!((fill_opacity(&s, id) - 0.4).abs() < 1e-6);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
let doc = s.doc().unwrap().doc.clone();
|
||||
for p in [json!({"opacity": 40}), json!({"color": "#ff0000", "opacity": 40})] {
|
||||
|
||||
Reference in New Issue
Block a user