mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 02:22:14 +00:00
Paint: an opacity alone counts only the targets that took it
paint.setFill and paint.setStroke with only `opacity` reported every selected target in `objects`, including type and objects without the fill or stroke row, which the opacity leaves alone. They now count only the targets whose row or mesh points took the opacity.
This commit is contained in:
@@ -702,8 +702,8 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
|
||||
// The type objects whose characters took the paint (no row targeted): only those change what a graph's labels keep
|
||||
// for their characters; a row edit is kept with the label's rows.
|
||||
let characters = std::cell::RefCell::new(Vec::new());
|
||||
// Whether a target took the opacity, and whether one would have given it to its characters.
|
||||
let (took_opacity, characters_skipped) = (std::cell::Cell::new(false), std::cell::Cell::new(false));
|
||||
// The targets that took the opacity, and whether one would have given it to its characters.
|
||||
let (took_opacity, characters_skipped) = (std::cell::RefCell::new(std::collections::BTreeSet::new()), std::cell::Cell::new(false));
|
||||
let paint_one = |n: &mut Node, index: Option<usize>, paint: &Paint| -> Result<()> {
|
||||
if index.is_none() && matches!(n.kind, NodeKind::Text(_)) {
|
||||
characters.borrow_mut().push(n.id);
|
||||
@@ -779,7 +779,7 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
|
||||
for i in points {
|
||||
if let Some(q) = m.points.get_mut(*i) {
|
||||
q.opacity = o;
|
||||
took_opacity.set(true);
|
||||
took_opacity.borrow_mut().insert(n.id);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -788,7 +788,7 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
|
||||
if fill { n.appearance.fill_at_mut(index).map(|f| &mut f.opacity) } else { n.appearance.stroke_at_mut(index).map(|s| &mut s.opacity) };
|
||||
if let Some(item) = item {
|
||||
*item = o;
|
||||
took_opacity.set(true);
|
||||
took_opacity.borrow_mut().insert(n.id);
|
||||
}
|
||||
};
|
||||
// The objects counted: with a design's art, those with a row equal to the art's.
|
||||
@@ -811,7 +811,7 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
|
||||
},
|
||||
|before, d, changed| {
|
||||
// An opacity that no target took is an error, which also takes back the paint given with it.
|
||||
if opacity.is_some() && !took_opacity.get() {
|
||||
if opacity.is_some() && took_opacity.borrow().is_empty() {
|
||||
if characters_skipped.get() {
|
||||
return Err(characters_have_no_opacity(cmd));
|
||||
}
|
||||
@@ -844,7 +844,9 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
|
||||
paint_new_art(s, paint, fill);
|
||||
s.remember_paint(paint);
|
||||
}
|
||||
Ok(json!({"objects": ids.iter().collect::<std::collections::BTreeSet<_>>().len()}))
|
||||
// An opacity alone counts only the targets that took it.
|
||||
let objects = if paint.is_none() { took_opacity.borrow().len() } else { ids.iter().collect::<std::collections::BTreeSet<_>>().len() };
|
||||
Ok(json!({"objects": objects}))
|
||||
}
|
||||
|
||||
/// The instance whose object is selected with Direct Selection, and that object's path
|
||||
|
||||
@@ -298,7 +298,8 @@ fn type_beside_other_art_is_left_alone() {
|
||||
};
|
||||
let before = (node(&s, t), runs(&s));
|
||||
select(&mut s, &[r, t]);
|
||||
s.execute("paint.setFill", &json!({"opacity": 40})).unwrap();
|
||||
let out = s.execute("paint.setFill", &json!({"opacity": 40})).unwrap();
|
||||
assert_eq!(out["objects"], 1, "only the rectangle took the opacity");
|
||||
assert!((fill_opacity(&s, r) - 0.4).abs() < 1e-6);
|
||||
assert_eq!((node(&s, t), runs(&s)), before);
|
||||
select(&mut s, &[t]);
|
||||
@@ -348,7 +349,8 @@ fn an_opacity_no_target_takes_is_an_error() {
|
||||
s.execute("paint.setFill", &json!({"opacity": 70})).unwrap();
|
||||
select(&mut s, &[a, b]);
|
||||
assert_eq!(proxies(&mut s)["fillOpacity"], 70.0, "the first selected object with a fill item answers");
|
||||
s.execute("paint.setFill", &json!({"opacity": 20})).unwrap();
|
||||
let out = s.execute("paint.setFill", &json!({"opacity": 20})).unwrap();
|
||||
assert_eq!(out["objects"], 1, "the object without a fill item is not counted");
|
||||
assert!((fill_opacity(&s, b) - 0.2).abs() < 1e-6);
|
||||
assert!(node(&s, a).appearance.fill().is_none());
|
||||
}
|
||||
|
||||
+1
-1
@@ -841,7 +841,7 @@ its kind (`paint.proxies`) and the Gradient tool's annotator then show that row.
|
||||
`inspect_document` reports it as `paint.appearanceItem`. `paint.setFill` and `paint.setStroke` also take `opacity`
|
||||
(0 to 100, a percentage as in `transparency.set`), which sets the opacity of the fill or stroke row they paint, with
|
||||
or without a new paint, as one undo step. An opacity that no target takes is an error and also leaves the paint
|
||||
undone. `paint.proxies` answers it as `fillOpacity` and `strokeOpacity`, from the first selected object that has
|
||||
undone. Without a new paint, `objects` counts only the targets that took the opacity. `paint.proxies` answers it as `fillOpacity` and `strokeOpacity`, from the first selected object that has
|
||||
that row (a selected path of a compound path answers with its compound path's row, which the commands edit). It answers null with nothing selected, for an object selected in a symbol instance, while the Type tool
|
||||
has characters selected, and when only type characters (which have no opacity of their own) or objects without that
|
||||
row are selected. Live effects take the same `item` to apply to one fill or
|
||||
|
||||
Reference in New Issue
Block a user