Live Paint: the Eyedropper, overprint, proxies and contents edits follow the whole-group rule

Follows #8685. The Eyedropper (appearance.copyFrom) onto a whole
selected Live Paint group, or reversed onto a clicked one, wrote the
picked appearance to every face, every edge and the hidden source
paths. It now gives the fill attributes to the faces and the stroke
attributes to the edges, and the source paths keep their paint. A
whole-appearance pick gives each face every picked fill row and each
edge every picked stroke row, and their other rows keep their order.
With append, the faces and edges take the picked rows but not the
picked object effects. A whole group picked up as the source gives
its first face's fills with its first edge's strokes above them, and
the group's own opacity, blend mode and effects.

Appearance edits with target "contents" also reached the source paths
and the parts of the other kind. The source paths are now left out of
a Live Paint group's contents. appearance.addFill adds a fill to the
faces only, and appearance.addStroke adds a stroke to the edges only.
A fill or stroke edit of the contents with an item (stroke.set,
paint.invert, paint.complement, gradient edits and
object.setOverprint) goes to the parts of its kind. Overprint Fill
and Overprint Stroke on a whole group also go to the faces and the
edges.

The Fill proxy and the Stroke panel showed a face's or edge's own
paint when it was selected before its group. A part selected with its
group, or with a group that holds its Live Paint group, now counts
with the group, whatever the selection order.

Docs: docs/mcp.md, params text, docs/target-app-parity.md.
This commit is contained in:
dotCooCoo
2026-11-19 10:15:49 -08:00
parent 2bc41aeb86
commit e0ae990abc
10 changed files with 499 additions and 59 deletions
+148 -22
View File
@@ -29,6 +29,7 @@ use vectorcraft_color::{BlendMode, Paint};
use vectorcraft_doc::appearance::SharedStack;
use vectorcraft_doc::{Appearance, AppearanceItem, CharStyle, Document, FillLayer, Node, NodeKind, ParaStyle, StrokeLayer};
use vectorcraft_geom::Rect;
use vectorcraft_tools::builder::{edges, faces, is_live_paint};
use super::edit::{outermost, roots_of, selected_roots};
use super::opacitymask::percent;
@@ -48,7 +49,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Add New Fill",
["Window", "Appearance"],
Some("Cmd+/"),
"{ids?|id?, target?: \"object\"|\"contents\"} add a fill on top of each selected object's own stack, on an image right below its Contents row, with its top fill's paint (type without one: its characters' fill; else the default fill). With a fill row active (appearance.setActiveItem), no `ids`, no `id` and no `target: \"contents\"`, the new fill takes that row's paint, goes right above it, and becomes the active row; appearance.duplicateItem copies a whole row. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, what the edit changes, and the row it adds when that row becomes the line's topmost visible row of its kind)",
"{ids?|id?, target?: \"object\"|\"contents\"} add a fill on top of each selected object's own stack, on an image right below its Contents row, with its top fill's paint (type without one: its characters' fill; else the default fill). In the contents of a Live Paint group the fill goes on its faces only, and its hidden source paths, like every contents edit, are left as they are. With a fill row active (appearance.setActiveItem), no `ids`, no `id` and no `target: \"contents\"`, the new fill takes that row's paint, goes right above it, and becomes the active row; appearance.duplicateItem copies a whole row. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, what the edit changes, and the row it adds when that row becomes the line's topmost visible row of its kind)",
has_doc,
|s, p| add_item(s, p, true)
),
@@ -57,7 +58,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Add New Stroke",
["Window", "Appearance"],
Some("Cmd+Alt+/"),
"{ids?|id?, target?} add a stroke on top of each selected object's own stack, on an image right below its Contents row, with its top stroke's paint (else the default stroke) and that stroke's weight when it has paint, at least 1 pt. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, what the edit changes, and the row it adds when that row becomes the line's topmost visible row of its kind)",
"{ids?|id?, target?} add a stroke on top of each selected object's own stack, on an image right below its Contents row, with its top stroke's paint (else the default stroke) and that stroke's weight when it has paint, at least 1 pt. In the contents of a Live Paint group the stroke goes on its edges only, and its hidden source paths are left as they are. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, what the edit changes, and the row it adds when that row becomes the line's topmost visible row of its kind)",
has_doc,
|s, p| add_item(s, p, false)
),
@@ -129,7 +130,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Eyedropper",
[],
None,
"{source: id, ids?, pickUp?, apply? (trees as eyedropper.setOptions, merged over the Eyedropper Options for this call), reverse?: bool, append?: bool, defaultsOnly?: bool} copy the attributes both picked up and applied (by default the whole appearance stack, opacity and blend mode, and from type to type the character and paragraph attributes using effective character dimensions while preserving target transforms) from `source` to ids (default: highlighted characters while editing type, after Select All in a frame of threaded text the text of the story's frames, leaving out `source`, otherwise the object selection; highlighted characters reject enabled non-neutral object transparency), the fill, stroke and weight also to the paint defaults; `defaultsOnly` updates only paint defaults and cannot be combined with ids, reverse or append; `reverse` (Alt-click) copies from the first selected object (or ids) onto `source` instead, or with nothing selected what the Eyedropper picked up last (a click without Alt); `append` (Shift+Alt-click) adds the source's fills, strokes and effects on top of each target's stack; placed gradients land at the same place relative to each target's bounds (defaults: fitted to new art); with an object of a dynamic symbol instance selected by Direct Selection and no ids, reverse, append or defaultsOnly, that object takes the source's fill and stroke (solid, none, gradient or pattern) for this instance only, as the Eyedropper Options allow, and a source that is not a path, compound path or type, or options that pick up neither color, are refused. On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke and the object's opacity and blend mode (exceptions, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, the graph stores, for every label of its kind, the character attributes the pick gives all of its text, its object opacity and blend mode when transparency is applied, and with `append` its topmost visible fill and stroke rows of the kinds it adds; on a graph's axis line, tick mark or radar ring, its topmost visible fill and stroke rows, and when transparency is applied its object opacity and blend mode, for every line of its kind (a pick of some attributes without `append`: what it changes, and the paint, stroke weight and row transparency it applies to the topmost visible rows; with `append`: only the kinds of row it adds) → {ids}",
"{source: id, ids?, pickUp?, apply? (trees as eyedropper.setOptions, merged over the Eyedropper Options for this call), reverse?: bool, append?: bool, defaultsOnly?: bool} copy the attributes both picked up and applied (by default the whole appearance stack, opacity and blend mode, and from type to type the character and paragraph attributes using effective character dimensions while preserving target transforms) from `source` to ids (default: highlighted characters while editing type, after Select All in a frame of threaded text the text of the story's frames, leaving out `source`, otherwise the object selection; highlighted characters reject enabled non-neutral object transparency), the fill, stroke and weight also to the paint defaults; `defaultsOnly` updates only paint defaults and cannot be combined with ids, reverse or append; `reverse` (Alt-click) copies from the first selected object (or ids) onto `source` instead, or with nothing selected what the Eyedropper picked up last (a click without Alt); `append` (Shift+Alt-click) adds the source's fills, strokes and effects on top of each target's stack; a whole Live Paint group (selected, in ids, or `source` with `reverse`) takes the fill attributes on its faces and the stroke attributes on its edges (a whole-appearance pick: every fill row on each face and every stroke row on each edge, which keep their rows of the other kind and their effects; `append` adds the source's rows but not its object effects to them), and its hidden source paths keep their paint; a whole Live Paint group picked up (`source`, or selected first with `reverse`) gives its first face's fills with its first edge's strokes above them and the group's own opacity, blend mode and effects; placed gradients land at the same place relative to each target's bounds (defaults: fitted to new art); with an object of a dynamic symbol instance selected by Direct Selection and no ids, reverse, append or defaultsOnly, that object takes the source's fill and stroke (solid, none, gradient or pattern) for this instance only, as the Eyedropper Options allow, and a source that is not a path, compound path or type, or options that pick up neither color, are refused. On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke and the object's opacity and blend mode (exceptions, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, the graph stores, for every label of its kind, the character attributes the pick gives all of its text, its object opacity and blend mode when transparency is applied, and with `append` its topmost visible fill and stroke rows of the kinds it adds; on a graph's axis line, tick mark or radar ring, its topmost visible fill and stroke rows, and when transparency is applied its object opacity and blend mode, for every line of its kind (a pick of some attributes without `append`: what it changes, and the paint, stroke weight and row transparency it applies to the topmost visible rows; with `append`: only the kinds of row it adds) → {ids}",
has_doc,
copy_from
),
@@ -280,7 +281,8 @@ impl ItemTarget {
/// [`ItemTarget::targets`] of a fill (`fill`) or a stroke edit: on the topmost fill or stroke, a
/// Live Paint group stands for its faces in a fill edit and for its edges in a stroke edit
/// ([`super::paint::live_paint_parts_skipped`]).
/// ([`super::paint::live_paint_parts_skipped`]); an item edit with `target: "contents"` leaves out
/// the parts of the other kind the same way ([`contents_skipped`]).
pub(crate) fn targets_for(self, s: &Session, p: &Value, fill: bool) -> Result<Vec<NodeId>> {
Ok(self.targets_and_skipped(s, p, fill)?.0)
}
@@ -290,13 +292,15 @@ impl ItemTarget {
/// to new art.
pub(crate) fn targets_and_skipped(self, s: &Session, p: &Value, fill: bool) -> Result<(Vec<NodeId>, bool)> {
let mut ids = self.targets(s, p)?;
let mut skipped_any = false;
if self == ItemTarget::Top {
let skipped = super::paint::live_paint_parts_skipped(&s.doc()?.doc, &super::targets(s, p)?, fill);
let before = ids.len();
ids.retain(|id| !skipped.contains(id));
skipped_any = ids.len() != before;
}
// An item edit of the contents of a Live Paint group goes to its parts of the edited kind too.
let skipped = if self == ItemTarget::Top {
super::paint::live_paint_parts_skipped(&s.doc()?.doc, &super::targets(s, p)?, fill)
} else {
contents_skipped(s, p, fill)?
};
let before = ids.len();
ids.retain(|id| !skipped.contains(id));
let skipped_any = ids.len() != before;
Ok((ids, skipped_any))
}
@@ -491,15 +495,37 @@ pub(crate) fn subject_roots(s: &Session) -> Result<Vec<NodeId>> {
/// Objects whose own appearance stack a command edits: `ids`/`id` (layers too; an id inside
/// another given one is dropped), else the [`subject_roots`]; with `target: "contents"` the painted
/// objects inside the groups and layers among them ([`leaf_targets`]).
/// objects inside the groups and layers among them ([`leaf_targets`]), without the hidden source paths
/// of Live Paint groups.
pub(crate) fn appearance_targets(s: &Session, p: &Value) -> Result<Vec<NodeId>> {
let roots = if p.get("ids").is_none() && p.get("id").is_none() {
subject_roots(s)?
let roots = appearance_roots(s, p)?;
if !targets_contents(p)? {
return Ok(roots);
}
let (_, _, hidden) = super::paint::live_paint_split(&s.doc()?.doc, &roots);
let mut ids = leaf_targets(s, &roots)?;
ids.retain(|id| !hidden.contains(id));
Ok(ids)
}
/// The objects [`appearance_targets`] starts from: `ids`/`id`, else the [`subject_roots`].
fn appearance_roots(s: &Session, p: &Value) -> Result<Vec<NodeId>> {
if p.get("ids").is_none() && p.get("id").is_none() {
subject_roots(s)
} else {
let d = &s.doc()?.doc;
outermost(d, targets(s, p)?.into_iter().filter(|id| d.node(*id).is_some()).collect())
};
if targets_contents(p)? { leaf_targets(s, &roots) } else { Ok(roots) }
Ok(outermost(d, targets(s, p)?.into_iter().filter(|id| d.node(*id).is_some()).collect()))
}
}
/// The parts of the Live Paint groups whose contents `p` targets (`target: "contents"`) that a fill
/// (`fill`) or stroke edit of those contents leaves as they are: their edges or faces. Empty without
/// `target: "contents"`.
pub(crate) fn contents_skipped(s: &Session, p: &Value, fill: bool) -> Result<HashSet<NodeId>> {
if !targets_contents(p)? {
return Ok(HashSet::new());
}
Ok(super::paint::live_paint_parts_skipped(&s.doc()?.doc, &appearance_roots(s, p)?, fill))
}
/// The refusal of an appearance edit whose targets are all the art of graph designs drawn in graph series.
@@ -897,7 +923,17 @@ fn set_active_item(s: &mut Session, p: &Value) -> Result<Value> {
}
fn add_item(s: &mut Session, p: &Value, fill: bool) -> Result<Value> {
let ids = require_targets(s, p, if fill { "appearance.addFill" } else { "appearance.addStroke" })?;
let cmd = if fill { "appearance.addFill" } else { "appearance.addStroke" };
let mut ids = require_targets(s, p, cmd)?;
// In the contents of a Live Paint group, a new fill goes on its faces and a new stroke on its edges;
// with no part of that kind, nothing changes.
let skipped = contents_skipped(s, p, fill)?;
if !skipped.is_empty() {
ids.retain(|id| !skipped.contains(id));
if ids.is_empty() {
return ok();
}
}
let defaults = s.paint.clone();
// The panel's active Fill row, when the new fill goes on the selection: the new fill takes that
// row's paint, right above it in each target that has it (others take their top fill's paint).
@@ -1779,7 +1815,13 @@ fn copy_from(s: &mut Session, p: &Value) -> Result<Value> {
// Reversed, the first selected object's attributes go onto the clicked object; with nothing
// selected, what the Eyedropper picked up last does (#4382).
let (source, mut targets) = if reverse {
let source = match leaf_targets(s, &selected)?.into_iter().next() {
// A Live Paint group selected first is picked up as a whole ([`live_paint_look`]); its hidden source paths are
// not what it draws.
let d = &s.doc()?.doc;
let group = selected.first().copied().filter(|id| d.node(*id).and_then(live_paint_look).is_some());
let (_, _, hidden) = super::paint::live_paint_split(d, &selected);
let first = leaf_targets(s, &selected)?.into_iter().find(|id| !hidden.contains(id));
let source = match group.or(first) {
Some(first) => Some(first),
None if s.eyedropper_sample.is_some() => None,
None => return Err(bad(C, "select the object to copy from")),
@@ -1788,10 +1830,38 @@ fn copy_from(s: &mut Session, p: &Value) -> Result<Value> {
} else {
(Some(clicked), leaf_targets(s, &selected)?)
};
targets.retain(|id| Some(*id) != source);
// A whole Live Paint group takes the fill attributes on its faces and the stroke attributes on its edges, and its
// hidden source paths keep their paint.
let roots = if reverse { vec![clicked] } else { selected };
let (faces, edges, hidden) = super::paint::live_paint_split(&s.doc()?.doc, &roots);
// Some(true) for a face, Some(false) for an edge.
let part_of = |id: &NodeId| {
if faces.contains(id) {
Some(true)
} else if edges.contains(id) {
Some(false)
} else {
None
}
};
let attrs_for = |id: &NodeId| {
let mut a = attrs;
match part_of(id) {
Some(true) => a.appearance.stroke = StrokeAttrs::NONE,
Some(false) => a.appearance.fill = FillAttrs::NONE,
None => {}
}
a
};
// A pick of the whole appearance gives a face every fill row and an edge every stroke row.
let whole = attrs.appearance.fill == FillAttrs::ALL && attrs.appearance.stroke == StrokeAttrs::ALL;
targets.retain(|id| Some(*id) != source && !hidden.contains(id));
let mut targets = without_design_art(&s.doc()?.doc, targets, C)?;
let node = match source {
Some(id) => Arc::new(s.doc()?.doc.node(id).ok_or(EngineError::NoNode(id))?.clone()),
Some(id) => {
let n = s.doc()?.doc.node(id).ok_or(EngineError::NoNode(id))?;
Arc::new(live_paint_look(n).unwrap_or_else(|| n.clone()))
}
None => s.eyedropper_sample.clone().ok_or_else(|| bad(C, "select the object to copy from"))?,
};
let picked = Picked::of(&node);
@@ -1919,7 +1989,17 @@ fn copy_from(s: &mut Session, p: &Value) -> Result<Value> {
super::overprint::edit_counted(s, "Eyedropper", |d| {
for id in &targets {
if let Some(n) = d.node_mut(*id) {
picked.apply(n, &attrs, append, characters.get(id));
match part_of(id) {
Some(fill) if whole && !append => picked.apply_rows(n, &attrs, fill),
// `append` does not add the picked object effects to a face or edge, as a whole pick keeps the part's
// own; a row's effects go with the row.
Some(_) => {
let effects = n.appearance.effects.len();
picked.apply(n, &attrs_for(id), append, characters.get(id));
n.appearance.effects.truncate(effects);
}
None => picked.apply(n, &attrs_for(id), append, characters.get(id)),
}
}
}
check_text_bounds(d)?;
@@ -2170,6 +2250,52 @@ impl Picked {
}
super::object::snap_if_aligned(n);
}
/// A whole pick ([`Self::apply`] with every fill and stroke attribute) onto a Live Paint face
/// (`fill`) or edge: the face's fills (the edge's strokes) become the picked ones, and its rows of
/// the other kind and its effects stay as they are.
fn apply_rows(&self, n: &mut Node, a: &EyedropperAttrs, fill: bool) {
if a.appearance.transparency {
n.opacity = self.opacity;
n.blend = self.blend;
}
let taken: Vec<AppearanceItem> = self.placed(n.geometric_bounds()).items.into_iter().filter(|it| it.is_fill() == fill).collect();
// The picked rows go where the part's first row of that kind was, the other rows keep their order; without
// such a row, fills go to the bottom and strokes to the top.
let items = &n.appearance.items;
let at = items.iter().position(|it| it.is_fill() == fill);
let at = at.map_or(if fill { 0 } else { items.iter().filter(|it| it.is_fill() != fill).count() }, |i| {
items.iter().take(i).filter(|it| it.is_fill() != fill).count()
});
let mut kept: Vec<AppearanceItem> = items.iter().filter(|it| it.is_fill() != fill).cloned().collect();
kept.splice(at..at, taken);
n.appearance.items = kept;
super::object::snap_if_aligned(n);
}
}
/// What the Eyedropper picks up from a whole Live Paint group `n`: its first face (else its first edge) with that
/// face's fills and the first edge's strokes above them, their gradients placed as on those parts, and the group's
/// own opacity, blend mode and effects. None for any other object, and for a group with no face and no edge.
fn live_paint_look(n: &Node) -> Option<Node> {
if !is_live_paint(n) {
return None;
}
let (face, edge) = (faces(n).first().copied(), edges(n).first().copied());
let mut look = (**face.or(edge)?).clone();
let rows = |part: Option<&Arc<Node>>, fill: bool| -> Vec<AppearanceItem> {
part.map(|p| p.appearance.items.iter().filter(|it| it.is_fill() == fill).cloned().collect()).unwrap_or_default()
};
// The edge's stroke gradients, placed relative to the look's bounds as they are to the edge's.
let mut strokes = Appearance { items: rows(edge, false), ..Default::default() };
if let (Some(from), Some(to)) = (edge.and_then(|e| e.geometric_bounds()), look.geometric_bounds()) {
strokes.rebase_gradients(from, to);
}
look.appearance.items = rows(face, true).into_iter().chain(strokes.items).collect();
look.appearance.effects = n.appearance.effects.clone();
look.opacity = n.opacity;
look.blend = n.blend;
Some(look)
}
/// The focal (topmost) fill and stroke attributes `a` of `from` onto `to`. Taking a colour creates
+1 -1
View File
@@ -787,7 +787,7 @@ fn set_gradient_geom(s: &mut Session, p: &Value) -> Result<Value> {
let skipped = super::paint::live_paint_parts_skipped(&s.doc()?.doc, &roots, !stroke);
leaf_targets(s, &roots)?.into_iter().filter(|id| !skipped.contains(id)).collect()
}
_ => item.targets(s, p)?,
_ => item.targets_for(s, p, !stroke)?,
};
if targets.is_empty() {
return Err(EngineError::Other("nothing selected".into()));
+2 -2
View File
@@ -21,7 +21,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Overprint",
[],
None,
"{fill?: bool, stroke?: bool, item?: appearance item index|null, ids?|id?, target?: \"object\"|\"contents\"} make fills and/or strokes overprint (Overprint Preview, Separations Preview) or knock out: item's, else every fill or stroke of the painted objects (groups: their contents; type: its characters too). Without item and ids, the Appearance panel's active item stands in when it is of that kind → {changed: objects}",
"{fill?: bool, stroke?: bool, item?: appearance item index|null, ids?|id?, target?: \"object\"|\"contents\"} make fills and/or strokes overprint (Overprint Preview, Separations Preview) or knock out: item's, else every fill or stroke of the painted objects (groups: their contents; type: its characters too). Without item and ids, the Appearance panel's active item stands in when it is of that kind. A whole Live Paint group (also its contents with `item`) takes the fill flags on its faces and the stroke flags on its edges, and its hidden source paths keep theirs → {changed: objects}",
has_doc,
set_overprint
),
@@ -135,7 +135,7 @@ fn aims(s: &Session, p: &Value, cmd: &str, kinds: impl IntoIterator<Item = bool>
.into_iter()
.map(|fill| {
let it = item.of_kind(s, fill);
let ids = it.targets(s, p)?;
let ids = it.targets_for(s, p, fill)?;
let ids = if edit { super::appearance::drop_design_art_rows(s, ids, it, fill, cmd)? } else { ids };
Ok((fill, it, ids))
})
+39 -14
View File
@@ -215,12 +215,15 @@ impl Session {
}
let first = st.doc.node(*st.selection.subjects().first()?)?;
let item = self.appearance_item();
// Only an active Appearance row is shown here: it is a row of the first selected object.
if first.appearance.item_of_kind(item, !stroke).is_some() {
return Some((Cow::Borrowed(first), item));
}
// A Live Paint group without faces (or edges) shows the next selected object's paint; any other
// object without a painted object shows the defaults for new art.
for id in st.selection.subjects() {
// object without a painted object shows the defaults for new art. A face or edge selected with
// its Live Paint group counts with the group, wherever it is in the selection.
let covered = live_paint_covered(&st.doc, st.selection.subjects());
for id in st.selection.subjects().iter().filter(|id| !covered.contains(*id)) {
let Some(n) = st.doc.node(*id) else { continue };
let mut nodes = vec![];
painted(n, true, stroke, &mut nodes);
@@ -272,14 +275,6 @@ fn same_in_proxy(a: &Paint, b: &Paint) -> bool {
}
}
/// The ids of the faces and edges of `n` when it is a Live Paint group, else none.
pub(crate) fn live_paint_parts(n: &Node) -> Vec<NodeId> {
if !is_live_paint(n) {
return vec![];
}
faces(n).into_iter().chain(edges(n)).map(|part| part.id).collect()
}
/// The objects whose paints the proxies show for a selected `n`, the ones the paint commands
/// change ([`leaf_targets`]): groups and layers stand for their contents (and so do blends and
/// other containers inside them), a compound path for its parts. A Live Paint group stands for its
@@ -330,8 +325,9 @@ impl DocState {
// Looking the first object up builds the id cache when there is none.
let first = self.selection.objects.first().and_then(|id| self.doc.node(*id));
let (mut selected, mut fills, mut strokes) = (vec![], vec![], vec![]);
// The faces and edges of the selected Live Paint groups: selected as well, they count with their group's.
let mut covered = std::collections::HashSet::new();
// The faces and edges of the selected Live Paint groups (or of those inside selected groups): selected as well,
// they count with their group's.
let covered = live_paint_covered(&self.doc, &self.selection.objects);
// Every node with a selected id, in tree order: a repeated id (a damaged file) counts at each
// place it appears.
for n in self.doc.nodes_in_order(self.selection.objects.iter().copied()) {
@@ -341,7 +337,6 @@ impl DocState {
if covered.contains(&n.id) {
continue;
}
covered.extend(live_paint_parts(n));
painted(n, true, false, &mut fills);
painted(n, true, true, &mut strokes);
}
@@ -820,6 +815,36 @@ pub(crate) fn live_paint_parts_skipped(d: &Document, roots: &[NodeId], fill: boo
out
}
/// Faces, edges and the other objects (the hidden source paths) of Live Paint groups.
pub(crate) type LivePaintParts = (std::collections::HashSet<NodeId>, std::collections::HashSet<NodeId>, std::collections::HashSet<NodeId>);
/// The faces, the edges and the hidden source paths of the Live Paint groups in `roots` (or inside them),
/// found as [`live_paint_parts_skipped`] finds them.
pub(crate) fn live_paint_split(d: &Document, roots: &[NodeId]) -> LivePaintParts {
let groups = live_paint_groups(d, roots);
let mut hidden = inside_live_paint(d, &groups);
let (mut faces, mut edges) = (std::collections::HashSet::new(), std::collections::HashSet::new());
for (_, f, e) in &groups {
faces.extend(f.iter().copied());
edges.extend(e.iter().copied());
}
hidden.retain(|id| !faces.contains(id) && !edges.contains(id));
(faces, edges, hidden)
}
/// The faces and edges in `selected` whose Live Paint group is selected too, itself or inside another selected
/// object: they count with their group, wherever they are in `selected`. The groups are looked for only when an
/// object in `selected` is inside a Live Paint group.
pub(crate) fn live_paint_covered(d: &Document, selected: &[NodeId]) -> std::collections::HashSet<NodeId> {
let inside = |id: &NodeId| d.ancestry(*id).is_some_and(|up| up.iter().rev().skip(1).filter_map(|a| d.node(*a)).any(is_live_paint));
if !selected.iter().any(inside) {
return std::collections::HashSet::new();
}
let (mut parts, edges, _) = live_paint_split(d, selected);
parts.extend(edges);
parts
}
/// The instance whose object is selected with Direct Selection, and that object's path
/// ([`super::brushsym::selected_part`]), when `p` names no `ids`, `id` or `item`: the paint commands
/// then change that object. A bad `target` or `aligned` is refused as it is for any other selection.
@@ -1337,7 +1362,7 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(
let item = item_target(s, p, cmd)?.of_kind(s, !stroke);
// Read before the check below, so that a bad param (such as `target` or `aligned`, or an explicit `item` the art has
// no row for) is still an error.
let targets = super::appearance::drop_design_art_rows(s, item.targets(s, p)?, item, !stroke, cmd)?;
let targets = super::appearance::drop_design_art_rows(s, item.targets_for(s, p, !stroke)?, item, !stroke, cmd)?;
let of = match item {
ItemTarget::Item { .. } => super::appearance::reference_of(s, p, item, cmd)?,
ItemTarget::Top => None,
+2 -3
View File
@@ -11,7 +11,7 @@ use vectorcraft_color::{Color, Paint};
use vectorcraft_doc::{Appearance, Document, LayerColor, Node, NodeId, NodeKind};
use vectorcraft_geom::{Rect, shapes};
use super::{live_paint_parts, painted, picked_colors, proxy_paint, same_in_proxy};
use super::{live_paint_covered, painted, picked_colors, proxy_paint, same_in_proxy};
use crate::{DocState, Session};
thread_local! {
@@ -39,12 +39,11 @@ fn walked(st: &DocState, item: Option<usize>, points: &[(NodeId, Vec<usize>)]) -
}
let ids: HashSet<NodeId> = st.selection.objects.iter().copied().collect();
let (mut selected, mut fills, mut strokes) = (vec![], vec![], vec![]);
let mut covered = HashSet::new();
let covered = live_paint_covered(&st.doc, &st.selection.objects);
st.doc.walk(|n| {
if ids.contains(&n.id) {
selected.push(n);
if !covered.contains(&n.id) {
covered.extend(live_paint_parts(n));
painted(n, true, false, &mut fills);
painted(n, true, true, &mut strokes);
}
+14 -6
View File
@@ -11,7 +11,7 @@ use vectorcraft_geom::PathData;
use vectorcraft_tools::builder::is_live_paint;
use super::appearance::{ItemTarget, edit_items, item_target};
use super::paint::{live_paint_parts, live_paint_parts_skipped, painted};
use super::paint::{live_paint_covered, live_paint_parts_skipped, painted};
use super::{CommandSpec, Result, Session, always, bad, bool_or, cmd, has_doc, ok, str_param};
use crate::DocState;
use crate::inspect::{ALIGNS, CAPS, JOINS, StrokeMixed, node_stroke, scale_layer};
@@ -250,10 +250,15 @@ fn stroke_set(s: &mut Session, p: &Value) -> Result<Value> {
} else if item == ItemTarget::Top {
own_stroke_or_leaves(s, p)?
} else {
item.targets(s, p)?
item.targets_for(s, p, false)?
};
// A Live Paint group without edges was still selected or given: the options do not go to new art.
let live_paint = !bucket && item == ItemTarget::Top && !live_paint_parts_skipped(&s.doc()?.doc, &super::targets(s, p)?, false).is_empty();
let live_paint = !bucket
&& if item == ItemTarget::Top {
!live_paint_parts_skipped(&s.doc()?.doc, &super::targets(s, p)?, false).is_empty()
} else {
!super::appearance::contents_skipped(s, p, false)?.is_empty()
};
let new_art = bucket || (no_targets(&ids, p) && !live_paint);
let given = !ids.is_empty() || live_paint;
// The art of a graph design in a series keeps the design's stroke.
@@ -453,12 +458,15 @@ impl Session {
}
let Some(first) = st.selection.objects.first() else { return Some(self.new_art_stroke()) };
let first = st.doc.node(*first)?;
// Only an active Appearance row is shown here: it is a row of the first selected object.
if let Some(i) = first.appearance.item_of_kind(self.appearance_item(), false) {
return first.appearance.stroke_at(Some(i)).cloned();
}
// A Live Paint group without edges shows the next selected object's stroke; any other object
// without a painted object shows none.
for id in &st.selection.objects {
// without a painted object shows none. A face or edge selected with its Live Paint group counts
// with the group, wherever it is in the selection.
let covered = live_paint_covered(&st.doc, &st.selection.objects);
for id in st.selection.objects.iter().filter(|id| !covered.contains(*id)) {
let Some(n) = st.doc.node(*id) else { continue };
let mut nodes = vec![];
painted(n, true, true, &mut nodes);
@@ -532,7 +540,7 @@ impl DocState {
} else {
let selected: Vec<&Node> = self.selection.objects.iter().filter_map(|id| self.doc.node(*id)).collect();
// The faces and edges of the selected Live Paint groups: selected as well, they count with their group's.
let covered: std::collections::HashSet<vectorcraft_doc::NodeId> = selected.iter().flat_map(|n| live_paint_parts(n)).collect();
let covered = live_paint_covered(&self.doc, &self.selection.objects);
for n in selected.into_iter().filter(|n| !covered.contains(&n.id)) {
painted(n, true, true, &mut nodes);
}
+3
View File
@@ -233,6 +233,7 @@ pub struct FillAttrs {
impl FillAttrs {
pub const ALL: Self = Self { color: true, transparency: true, overprint: true };
pub const NONE: Self = Self { color: false, transparency: false, overprint: false };
}
impl Default for FillAttrs {
@@ -260,6 +261,8 @@ pub struct StrokeAttrs {
impl StrokeAttrs {
pub const ALL: Self = Self { color: true, transparency: true, overprint: true, weight: true, cap: true, join: true, miter: true, dash: true };
pub const NONE: Self =
Self { color: false, transparency: false, overprint: false, weight: false, cap: false, join: false, miter: false, dash: false };
}
impl Default for StrokeAttrs {