Merge pull request #8685 from dotCooCoo/fix/live-paint-group-faces-edges

Live Paint: a fill given to a whole group paints its faces and a stroke paints its edges
This commit is contained in:
BFlat authored and GitHub committed 2026-11-19 18:41:35 +07:00
commit 2bc41aeb86
10 files changed
+760 -80

No files matched your search

+22
View File
@@ -278,6 +278,28 @@ 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`]).
pub(crate) fn targets_for(self, s: &Session, p: &Value, fill: bool) -> Result<Vec<NodeId>> {
Ok(self.targets_and_skipped(s, p, fill)?.0)
}
/// [`ItemTarget::targets_for`], and whether it left out any object inside a Live Paint group: a
/// group with no part of the edited kind was still given or selected, so the edit does not go
/// 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;
}
Ok((ids, skipped_any))
}
/// The target of a fill (`fill`) or stroke edit: the panel's active item stands only for edits
/// of its own kind, so a fill row leaves stroke edits on the topmost stroke of the painted
/// leaves (as without an active item) and vice versa. Explicit items are kept (and checked).
+8 -7
View File
@@ -19,7 +19,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Add Freeform Point",
[],
None,
"{at: [x,y] (document coordinates), color? (default: the gradient's colour there; #rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), opacity?: 0..1 (or 0..100), spread?: 0..1 (or 0..100 %; the radius of pure colour around the point, a fraction of half the object's larger side; default 0), line?: true (join it to the selected point: extends the line ending there, else starts one), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} add a point to the freeform gradient (an unplaced one keeps its automatic points first) and select it. On a path directly in a graph series, the graph also stores the edited gradient when it is on the topmost visible fill or stroke, as for the other paint.freeform edits (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its points); the points on a label's characters are not stored → {index}",
"{at: [x,y] (document coordinates), color? (default: the gradient's colour there; #rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), opacity?: 0..1 (or 0..100), spread?: 0..1 (or 0..100 %; the radius of pure colour around the point, a fraction of half the object's larger side; default 0), line?: true (join it to the selected point: extends the line ending there, else starts one), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} add a point to the freeform gradient (an unplaced one keeps its automatic points first) and select it. On a path directly in a graph series, the graph also stores the edited gradient when it is on the topmost visible fill or stroke, as for the other paint.freeform edits (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its points); the points on a label's characters are not stored → {index}",
has_doc,
add_point
),
@@ -28,7 +28,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Edit Freeform Point",
[],
None,
"{index? (default: the selected point), at?: [x,y] (document coordinates), color? (#rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), opacity?: 0..1 (or 0..100), spread?: 0..1 (or 0..100 %), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} move or recolour a point of the freeform gradient → {index}",
"{index? (default: the selected point), at?: [x,y] (document coordinates), color? (#rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), opacity?: 0..1 (or 0..100), spread?: 0..1 (or 0..100 %), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} move or recolour a point of the freeform gradient → {index}",
has_doc,
set_point
),
@@ -37,7 +37,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Delete Freeform Point",
[],
None,
"{index? (default: the selected point), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} remove a point (never the last one); lines through it close up around it and lines left with one point go → {index}",
"{index? (default: the selected point), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} remove a point (never the last one); lines through it close up around it and lines left with one point go → {index}",
has_doc,
delete_point
),
@@ -46,7 +46,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Add Freeform Line",
[],
None,
"{points: [index, …] (at least two), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} join points with a smooth line through them, in order → {line}",
"{points: [index, …] (at least two), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} join points with a smooth line through them, in order → {line}",
has_doc,
add_line
),
@@ -55,7 +55,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Split Freeform Line",
[],
None,
"{line: line index, segment: the segment from the line's point `segment` to the next, t?: 0..1 along it (default 0.5), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} add a point on a line there (colour, opacity and spread between the segment's ends) and select it → {index}",
"{line: line index, segment: the segment from the line's point `segment` to the next, t?: 0..1 along it (default 0.5), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} add a point on a line there (colour, opacity and spread between the segment's ends) and select it → {index}",
has_doc,
split_line
),
@@ -182,8 +182,9 @@ fn edit<R>(s: &mut Session, p: &Value, cmd: &str, mut f: impl FnMut(&mut Freefor
let item = item_target(s, p, cmd)?;
let stroke = edits_stroke(s, p, item, !s.fill_active, cmd)?;
let item = item.of_kind(s, !stroke);
// The art of a graph design in a series keeps the design's gradient.
let ids = super::appearance::without_design_art(&s.doc()?.doc, item.targets(s, p)?, cmd)?;
// The art of a graph design in a series keeps the design's gradient; a Live Paint group's fill is on its faces and its
// stroke on its edges.
let ids = super::appearance::without_design_art(&s.doc()?.doc, item.targets_for(s, p, !stroke)?, cmd)?;
if ids.is_empty() {
return Err(bad(cmd, "select an object with a freeform gradient"));
}
+14 -7
View File
@@ -24,7 +24,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Gradient",
["Window", "Gradient"],
None,
"{stroke?: bool (default: the targeted item's kind, else the active proxy), kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical, sweeps the stops once around the center, clockwise from the vector, with a seam where the last stop meets the first; diamond runs the stops from the center out to a square with a corner at the end of the vector; freeform places points on each object, coloured along the stops), mode?: points|lines (freeform: how the Gradient tool adds points), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (how the colours between the stops mix: in display RGB, perceptually (OKLab) so the steps look even, or around the hue wheel: hue, saturation and brightness each change evenly from one stop to the next, the hue angle falling with hue-clockwise (red, magenta, blue, cyan, green, yellow) and rising with hue-counterclockwise; two stops whose hues are less than half a color level apart keep that hue; a stop whose RGB numbers are less than half a color level apart is gray and takes the hue of the stop it mixes with, and black that stop's saturation too; these two methods are VectorCraft's own, and SVG and PDF exports draw their gradients as RGB images, CMYK and spot color stops included; SVG exports draw a Perceptual gradient as an image, and PDF exports do too unless it is linear, radial, conic or diamond, has spot color stops, every other stop is paper white or written in CMYK or gray (an export that converts colors to a CMYK destination profile writes RGB and Lab stops in CMYK, and so does a CMYK document unless the export converts colors to an RGB destination profile), it is not a dithered fill and its curve does not have too many stops: then PDF writes tints of one spot ink as a Separation shading in that ink, and spot inks mixed with other spot, CMYK or gray inks as a DeviceN shading; freeform gradients mix their own way), spread?: pad|repeat|reflect (linear, radial, conic and diamond: what the gradient paints past the ends of its stops: pad carries the end colors on; repeat and reflect run the stops `repeats` times along the vector (around the circle, for a conic) and on past both ends, reflect mirroring every other run; an error on a freeform gradient), repeats?: 1..100 (a whole number: how many times repeat and reflect run the stops along the vector; VectorCraft's own limit; pad keeps it unused), stops?: [{offset 0..1, color? (needed without swatch; #rrggbbaa and #rgba are refused), opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: colour swatch name (a global or spot colour or tint swatch links the stop, so swatch edits recolour it and a spot stop prints on its plate; a process colour just gives its colour), tint?: 0..100 (% of the linked swatch; default 100, or a tint swatch's own)}] (at least 2; a freeform gradient's points are recoloured along them), keepModel?: bool (as paint.setFill; a stop color the gradient already has keeps its model), angle?: deg counter-clockwise (0: the gradient runs left to right; radial, conic and diamond: the vector turns about the center), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep and is an error for the other kinds), reverse?: bool (the same ramp the other way round: the stops in reverse order, and a hue method turned the other way unless `method` is given too), dither?: bool (fills only: a linear, radial, conic or diamond gradient fill is drawn with fine noise that hides banding, and as pixels in SVG and PDF exports), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.setFill; without stroke, the kind of the row edited), ids?|id?, strokeMode?: within|along|across (strokes only: the gradient lies on the page and shows through the stroke, runs from the start of each subpath to its end, or runs from the stroke's left edge to its right all along it; with nothing selected, for the next object drawn; type characters' own strokes always paint within), target?: \"object\"|\"contents\"} edit the gradient in place (keeps its placement); solid/none paints become the default gradient. On a path directly in a graph series, the graph also stores the gradient when it is on the topmost visible fill or stroke (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its placement), and on its characters their gradient without its placement, fitted to each label. While the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), only the default changes (the paint the bucket paints with)",
"{stroke?: bool (default: the targeted item's kind, else the active proxy), kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical, sweeps the stops once around the center, clockwise from the vector, with a seam where the last stop meets the first; diamond runs the stops from the center out to a square with a corner at the end of the vector; freeform places points on each object, coloured along the stops), mode?: points|lines (freeform: how the Gradient tool adds points), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (how the colours between the stops mix: in display RGB, perceptually (OKLab) so the steps look even, or around the hue wheel: hue, saturation and brightness each change evenly from one stop to the next, the hue angle falling with hue-clockwise (red, magenta, blue, cyan, green, yellow) and rising with hue-counterclockwise; two stops whose hues are less than half a color level apart keep that hue; a stop whose RGB numbers are less than half a color level apart is gray and takes the hue of the stop it mixes with, and black that stop's saturation too; these two methods are VectorCraft's own, and SVG and PDF exports draw their gradients as RGB images, CMYK and spot color stops included; SVG exports draw a Perceptual gradient as an image, and PDF exports do too unless it is linear, radial, conic or diamond, has spot color stops, every other stop is paper white or written in CMYK or gray (an export that converts colors to a CMYK destination profile writes RGB and Lab stops in CMYK, and so does a CMYK document unless the export converts colors to an RGB destination profile), it is not a dithered fill and its curve does not have too many stops: then PDF writes tints of one spot ink as a Separation shading in that ink, and spot inks mixed with other spot, CMYK or gray inks as a DeviceN shading; freeform gradients mix their own way), spread?: pad|repeat|reflect (linear, radial, conic and diamond: what the gradient paints past the ends of its stops: pad carries the end colors on; repeat and reflect run the stops `repeats` times along the vector (around the circle, for a conic) and on past both ends, reflect mirroring every other run; an error on a freeform gradient), repeats?: 1..100 (a whole number: how many times repeat and reflect run the stops along the vector; VectorCraft's own limit; pad keeps it unused), stops?: [{offset 0..1, color? (needed without swatch; #rrggbbaa and #rgba are refused), opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: colour swatch name (a global or spot colour or tint swatch links the stop, so swatch edits recolour it and a spot stop prints on its plate; a process colour just gives its colour), tint?: 0..100 (% of the linked swatch; default 100, or a tint swatch's own)}] (at least 2; a freeform gradient's points are recoloured along them), keepModel?: bool (as paint.setFill; a stop color the gradient already has keeps its model), angle?: deg counter-clockwise (0: the gradient runs left to right; radial, conic and diamond: the vector turns about the center), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep and is an error for the other kinds), reverse?: bool (the same ramp the other way round: the stops in reverse order, and a hue method turned the other way unless `method` is given too), dither?: bool (fills only: a linear, radial, conic or diamond gradient fill is drawn with fine noise that hides banding, and as pixels in SVG and PDF exports), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.setFill; without stroke, the kind of the row edited), ids?|id?, strokeMode?: within|along|across (strokes only: the gradient lies on the page and shows through the stroke, runs from the start of each subpath to its end, or runs from the stroke's left edge to its right all along it; with nothing selected, for the next object drawn; type characters' own strokes always paint within), target?: \"object\"|\"contents\"} edit the gradient in place (keeps its placement); solid/none paints become the default gradient. Without `item`, a Live Paint group's faces take a fill edit and its edges take a stroke edit. On a path directly in a graph series, the graph also stores the gradient when it is on the topmost visible fill or stroke (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its placement), and on its characters their gradient without its placement, fitted to each label. While the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), only the default changes (the paint the bucket paints with)",
has_doc,
edit_gradient
),
@@ -33,7 +33,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Gradient Vector",
[],
None,
"{start?: [x,y], end?: [x,y] (document coordinates; both or neither: omitted, the vector stays), aspect?: % (radial, conic and diamond: the extent's height / width across the vector, a negative one mirroring a conic's sweep and an error for the other kinds; default: kept), focal?: [x,y] (document coordinates) | null (radial: the focal point, where the first stop sits, pulled inside the extent ellipse; null centres it; default: it keeps its place in the ellipse; an error on a conic or diamond gradient), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (alias: index; omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\", index?: appearance item index (as item)} set the gradient vector, aspect ratio and focal point (solid paints become the default gradient; type objects set it on their runs, in text space). On a path directly in a graph series, the graph also stores the gradient with its placement relative to the path's box when it is on the topmost visible fill or stroke, and every path of the series takes it at the same place on its own box (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its placement), and on its characters their gradient without the placement this command sets, fitted to each label",
"{start?: [x,y], end?: [x,y] (document coordinates; both or neither: omitted, the vector stays), aspect?: % (radial, conic and diamond: the extent's height / width across the vector, a negative one mirroring a conic's sweep and an error for the other kinds; default: kept), focal?: [x,y] (document coordinates) | null (radial: the focal point, where the first stop sits, pulled inside the extent ellipse; null centres it; default: it keeps its place in the ellipse; an error on a conic or diamond gradient), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (alias: index; omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\", index?: appearance item index (as item)} set the gradient vector, aspect ratio and focal point (solid paints become the default gradient; type objects set it on their runs, in text space). On a path directly in a graph series, the graph also stores the gradient with its placement relative to the path's box when it is on the topmost visible fill or stroke, and every path of the series takes it at the same place on its own box (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its placement), and on its characters their gradient without the placement this command sets, fitted to each label; without item, a Live Paint group's faces take a fill edit and its edges take a stroke edit",
has_doc,
set_gradient_geom
),
@@ -92,6 +92,9 @@ fn select_stop(s: &mut Session, p: &Value) -> Result<Value> {
pub(crate) struct StopOwner {
doc: Option<usize>,
object: Option<NodeId>,
/// The object whose paint the active proxy shows: a Live Paint group without faces (or edges)
/// first in the selection shows the next object's.
source: Option<NodeId>,
part: bool,
fill: bool,
item: Option<usize>,
@@ -104,6 +107,7 @@ impl StopOwner {
Self {
doc: s.active,
object: st.and_then(|d| d.selection.objects.first().copied()),
source: s.proxy_source(!s.fill_active).map(|(n, _)| n.id),
part: st.is_some_and(|d| d.selection.symbol_part.is_some()),
fill: s.fill_active,
item: s.appearance_item(),
@@ -539,10 +543,10 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result<Value> {
check_switches(p, &["reverse", "dither"], C)?;
check_numbers(p, &["angle"], C)?;
let item = item.of_kind(s, !stroke);
let ids = item.targets(s, p)?;
// Objects were given or selected, even when all of them are graph design art left out below: the stroke mode is then
// not one for new art.
let selected = !ids.is_empty();
let (ids, skipped) = item.targets_and_skipped(s, p, !stroke)?;
// Objects were given or selected, even when all of them are graph design art left out below, or Live Paint group parts
// of the other kind left out above: the stroke mode is then not one for new art.
let selected = !ids.is_empty() || skipped;
let ids = super::appearance::drop_design_art_rows(s, ids, item, !stroke, C)?;
// How the gradient lies on a stroke (the panel's Stroke buttons).
let mode = match str_param(p, "strokeMode") {
@@ -778,7 +782,10 @@ fn set_gradient_geom(s: &mut Session, p: &Value) -> Result<Value> {
let item = item.of_kind(s, !stroke);
let targets = match item {
ItemTarget::Top => {
leaf_targets(s, &super::given_objects(s, p, C)?.map_or_else(|| selected_roots(s), |ids| Ok(outermost(&s.doc()?.doc, ids)))?)?
let roots = super::given_objects(s, p, C)?.map_or_else(|| selected_roots(s), |ids| Ok(outermost(&s.doc()?.doc, ids)))?;
// A Live Paint group's fill gradient is on its faces and its stroke gradient on its edges.
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)?,
};
+5 -3
View File
@@ -228,9 +228,11 @@ impl Session {
if !self.prefs.new_art_basic {
return;
}
let has_paint = self
.proxy_source(false)
.is_some_and(|(n, _)| matches!(n.kind, NodeKind::Text(_)) || !n.appearance.items.is_empty() || n.extras().colorize.is_some());
// A Live Paint group with edges and no faces shows only a stroke.
let has_paint = [false, true].into_iter().any(|stroke| {
self.proxy_source(stroke)
.is_some_and(|(n, _)| matches!(n.kind, NodeKind::Text(_)) || !n.appearance.items.is_empty() || n.extras().colorize.is_some())
});
if !has_paint {
return;
}
+222 -35
View File
@@ -4,7 +4,9 @@ use std::borrow::Cow;
use serde_json::{Value, json};
use vectorcraft_color::{BlendMode, Color, GradientPaint, Paint};
use vectorcraft_doc::{Appearance, CharStyle, Document, GraySource, Node, NodeId, NodeKind};
use vectorcraft_doc::appearance::{FillLayer, StrokeLayer};
use vectorcraft_doc::{Appearance, AppearanceItem, CharStyle, Document, GraySource, Node, NodeId, NodeKind};
use vectorcraft_tools::builder::{edges, faces, is_live_paint};
use super::appearance::{ItemTarget, edit_items, edit_items_then, item_target, row_targets};
use super::gradient::{item_paint_bounds, place_paint, place_run_paint, run_paint_mut, run_stroke_weight, unplaced};
@@ -25,7 +27,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Fill",
[],
None,
"{color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray}|{l,a,b} (CIE Lab; #rrggbbaa and #rgba are refused), none?: true, swatch?: name (a global or spot colour stays linked, so swatch edits recolour it; a tint swatch links to its base at its tint; a gradient swatch is recorded as the gradient's swatch and fits each object, keeping its aspect; the built-in \"[Registration]\" prints on every plate), tint?: 0..100 (% of a global or spot `swatch`; default 100, or a tint swatch's own), gradient?: {kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical: the stops sweep once around the center `start`, clockwise from the vector; diamond: the stops run from the center `start` out to a square with a corner at `end`), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (as paint.editGradient; default classic), spread?: pad|repeat|reflect (as paint.editGradient; default pad), repeats?: 1..100 (as paint.editGradient; default 1), stops?: [{offset 0..1, color, opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: global or spot colour (or tint) swatch the stop links to (its colour comes from the swatch), tint?: 0..100}] (at least 2; default white→black), angle?: deg counter-clockwise (0: the gradient runs left to right), start?: [x,y], end?: [x,y] (the vector in document coordinates, both or neither; type objects keep it in text space), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep, counterclockwise, and is an error for the other kinds; without start/end the gradient is placed on each object's bounds), focal?: [x,y] (radial, with start/end: the focal point, where the first stop sits; an error with a conic or diamond), dither?: bool (linear, radial, conic and diamond fills: drawn with fine noise that hides banding, and as pixels in SVG and PDF exports; strokes ignore it), swatch?: linked gradient swatch name}, item?: appearance item index|null (omitted: the Appearance panel's active item if it is a fill, else the top fill), aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md), ids?|id?, focus?: true (false keeps the active proxy), keepModel?: false (in a CMYK document, RGB colours and gradient stops are stored as CMYK unless true; Gray stays Gray), target?: \"object\"|\"contents\", span?: \"object\" (default: each target fits a gradient to its own bounds)|\"selection\" (a linear, radial, conic or diamond `gradient` without start/end is placed once on the union of the targets' bounds, so it runs across them)} sets the selection's fill and the default (new art fits a gradient to itself); a solid color recolors only the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso (unless an `item` index is given or the Appearance panel's active item is a fill); while the Type tool has characters selected (and no ids or item are given), the paint goes to those characters only; without `item`, a grayscale or 1-bit image takes a solid color as the color it is drawn in (white pixels transparent; `none` takes it off; an image with an alpha channel takes only a spot color, black or white; a colorized image whose link is missing takes a solid color as its new colorize color, and refuses a process color while its color is a spot color, black or white); with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's fill changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint of the topmost visible fill when the command wrote that row or changed it (exceptions: docs/mcp.md); on a graph label, the graph stores the paint for every label of its kind, as a character fill when the characters took it and with the label's rows when a row did; on a graph's axis line, tick mark or radar ring, its rows for every line of its kind. While the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), only the default changes (the color the bucket paints with) and the selection keeps its paint → {objects: how many objects took the paint (the objects inside a group, unless an appearance item of the group's own is targeted; 0 when only the default changed)}",
"{color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray}|{l,a,b} (CIE Lab; #rrggbbaa and #rgba are refused), none?: true, swatch?: name (a global or spot colour stays linked, so swatch edits recolour it; a tint swatch links to its base at its tint; a gradient swatch is recorded as the gradient's swatch and fits each object, keeping its aspect; the built-in \"[Registration]\" prints on every plate), tint?: 0..100 (% of a global or spot `swatch`; default 100, or a tint swatch's own), gradient?: {kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical: the stops sweep once around the center `start`, clockwise from the vector; diamond: the stops run from the center `start` out to a square with a corner at `end`), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (as paint.editGradient; default classic), spread?: pad|repeat|reflect (as paint.editGradient; default pad), repeats?: 1..100 (as paint.editGradient; default 1), stops?: [{offset 0..1, color, opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: global or spot colour (or tint) swatch the stop links to (its colour comes from the swatch), tint?: 0..100}] (at least 2; default white→black), angle?: deg counter-clockwise (0: the gradient runs left to right), start?: [x,y], end?: [x,y] (the vector in document coordinates, both or neither; type objects keep it in text space), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep, counterclockwise, and is an error for the other kinds; without start/end the gradient is placed on each object's bounds), focal?: [x,y] (radial, with start/end: the focal point, where the first stop sits; an error with a conic or diamond), dither?: bool (linear, radial, conic and diamond fills: drawn with fine noise that hides banding, and as pixels in SVG and PDF exports; strokes ignore it), swatch?: linked gradient swatch name}, item?: appearance item index|null (omitted: the Appearance panel's active item if it is a fill, else the top fill), aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md), ids?|id?, focus?: true (false keeps the active proxy), keepModel?: false (in a CMYK document, RGB colours and gradient stops are stored as CMYK unless true; Gray stays Gray), target?: \"object\"|\"contents\", span?: \"object\" (default: each target fits a gradient to its own bounds)|\"selection\" (a linear, radial, conic or diamond `gradient` without start/end is placed once on the union of the targets' bounds, so it runs across them)} sets the selection's fill and the default (new art fits a gradient to itself); a solid color recolors only the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso (unless an `item` index is given or the Appearance panel's active item is a fill); while the Type tool has characters selected (and no ids or item are given), the paint goes to those characters only; without `item`, a Live Paint group among the targets (or inside one) takes the fill on its faces only; without `item`, a grayscale or 1-bit image takes a solid color as the color it is drawn in (white pixels transparent; `none` takes it off; an image with an alpha channel takes only a spot color, black or white; a colorized image whose link is missing takes a solid color as its new colorize color, and refuses a process color while its color is a spot color, black or white); with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's fill changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint of the topmost visible fill when the command wrote that row or changed it (exceptions: docs/mcp.md); on a graph label, the graph stores the paint for every label of its kind, as a character fill when the characters took it and with the label's rows when a row did; on a graph's axis line, tick mark or radar ring, its rows for every line of its kind. While the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), only the default changes (the color the bucket paints with) and the selection keeps its paint → {objects: how many objects took the paint (the objects inside a group, unless an appearance item of the group's own is targeted; 0 when only the default changed)}",
has_doc,
|s, p| set_paint(s, p, true)
),
@@ -34,7 +36,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Stroke",
[],
None,
"{…as paint.setFill, item?: the stroke item to set, aligned?: bool (as paint.setFill)} same as paint.setFill, for the stroke; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's stroke changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint and weight of the topmost visible stroke when the command wrote that row or changed it (exceptions: docs/mcp.md); on a graph label, as paint.setFill",
"{…as paint.setFill, item?: the stroke item to set, aligned?: bool (as paint.setFill)} same as paint.setFill, for the stroke; without `item`, a Live Paint group among the targets (or inside one) takes the stroke on its edges only; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's stroke changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint and weight of the topmost visible stroke when the command wrote that row or changed it (exceptions: docs/mcp.md); on a graph label, as paint.setFill",
has_doc,
|s, p| { set_paint(s, p, false) }
),
@@ -43,7 +45,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Swap Fill and Stroke",
[],
Some("Shift+X"),
"{ids?|id?} swap the fill and stroke of the selection (type too) and of the defaults. On a path directly in a graph series, the graph also stores the swapped paints and the stroke weight, and on a graph label the swapped paints of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring what the swap changes on its rows for every line of its kind (exceptions: docs/mcp.md). While the Live Paint Bucket is the active tool and no ids or id are given (a null one counts as none), only the defaults change",
"{ids?|id?} swap the fill and stroke of the selection (type too) and of the defaults. A Live Paint group's faces take the stroke its edges share and its edges take the fill its faces share, a gradient fitted to each face or edge; a group whose faces' fills or edges' strokes differ (a freeform gradient counts as differing), or that has no face or no edge, keeps its paint. On a path directly in a graph series, the graph also stores the swapped paints and the stroke weight, and on a graph label the swapped paints of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring what the swap changes on its rows for every line of its kind (exceptions: docs/mcp.md). While the Live Paint Bucket is the active tool and no ids or id are given (a null one counts as none), only the defaults change",
has_doc,
swap
),
@@ -52,7 +54,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Default Fill and Stroke",
[],
Some("D"),
"{ids?|id?} white fill and 1 pt black stroke for the selection and the defaults (in a document whose Default Graphic Style differs from the shipped one, as a New Document profile can redefine it: that style's fills, strokes and effects, without its opacity or a link to it); type gets black fill and no stroke. 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 on a graph label the black fill and no stroke of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (exceptions: docs/mcp.md). While the Live Paint Bucket is the active tool and no ids or id are given (a null one counts as none), only the defaults change",
"{ids?|id?} white fill and 1 pt black stroke for the selection and the defaults (in a document whose Default Graphic Style differs from the shipped one, as a New Document profile can redefine it: that style's fills, strokes and effects, without its opacity or a link to it); type gets black fill and no stroke. A Live Paint group's faces get no fill and its edges get a 0.5 pt black stroke, in place of their whole appearance and also when the Default Graphic Style is redefined, and with only Live Paint groups selected (or in ids) the defaults become no fill and a 0.5 pt black stroke (with New Art Has Basic Appearance off, new art then takes the selection's appearance, as after any command). 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 on a graph label the black fill and no stroke of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (exceptions: docs/mcp.md). While the Live Paint Bucket is the active tool and no ids or id are given (a null one counts as none), only the defaults change",
has_doc,
default_paint
),
@@ -100,7 +102,7 @@ pub fn proxy_specs() -> Vec<CommandSpec> {
"Invert",
[],
None,
"{stroke?: bool (default: the active proxy), ids?|id?, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} invert the active proxy's colours of the selection (or ids; groups recolour their contents and, except with target \"contents\", their own fills and strokes; a compound path's member stands for its compound path) keeping each colour's model, as edit.colors.invert does; the Appearance panel's active fill/stroke item (appearance.setActiveItem) is inverted instead when it is of that kind and no ids are given; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's solid color changes for this instance only, and a gradient or pattern, or type whose characters differ in color, is refused; with nothing selected, or while the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), invert the default. On a path directly in a graph series, the graph also stores the new color of the topmost visible fill or stroke, and on a graph label the new color of its characters and rows for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (docs/mcp.md); no undo step when no color changes → {changed}",
"{stroke?: bool (default: the active proxy), ids?|id?, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} invert the active proxy's colours of the selection (or ids; groups recolour their contents and, except with target \"contents\", their own fills and strokes; a compound path's member stands for its compound path; a Live Paint group recolors its faces' fills or its edges' strokes) keeping each colour's model, as edit.colors.invert does; the Appearance panel's active fill/stroke item (appearance.setActiveItem) is inverted instead when it is of that kind and no ids are given; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's solid color changes for this instance only, and a gradient or pattern, or type whose characters differ in color, is refused; with nothing selected, or while the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), invert the default. On a path directly in a graph series, the graph also stores the new color of the topmost visible fill or stroke, and on a graph label the new color of its characters and rows for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (docs/mcp.md); no undo step when no color changes → {changed}",
has_doc,
|s, p| proxy_recolor(s, p, "paint.invert", "Invert", &super::colorcmds::invert)
),
@@ -109,7 +111,7 @@ pub fn proxy_specs() -> Vec<CommandSpec> {
"Complement",
[],
None,
"{stroke?: bool (default: the active proxy), ids?|id?, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} replace the active proxy's colours by their complements ((highest + lowest) − each component, over RGB or CMY; grey unchanged) keeping each colour's model; honours the Appearance panel's active item and a selected object of a dynamic symbol instance as paint.invert does; with nothing selected, or while the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), the default; no undo step when no color changes → {changed}",
"{stroke?: bool (default: the active proxy), ids?|id?, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} replace the active proxy's colours by their complements ((highest + lowest) − each component, over RGB or CMY; grey unchanged) keeping each colour's model; a Live Paint group recolors its faces' fills or its edges' strokes as with paint.invert; honours the Appearance panel's active item and a selected object of a dynamic symbol instance as paint.invert does; with nothing selected, or while the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), the default; no undo step when no color changes → {changed}",
has_doc,
|s, p| proxy_recolor(s, p, "paint.complement", "Complement", &|c: Color| c.complement_keep_model())
),
@@ -158,7 +160,7 @@ pub fn proxy_specs() -> Vec<CommandSpec> {
"Fill and Stroke",
[],
None,
"{} → {fill, stroke: the paints the Fill/Stroke proxies show (the Appearance panel's active item for the proxy of its kind, else the first selected object's, a group's first painted object's, type: its first run's; else the defaults for new art; when that object is a gradient mesh with points picked by the Mesh tool, Direct Selection or the Lasso and no fill item is active, the fill is its first picked point's color), fillActive, fillMixed, strokeMixed: the selected objects' (or a selected group's contents') fills (strokes) differ, shown as a \"?\" proxy (a gradient mesh with points picked counts with their colors)}",
"{} → {fill, stroke: the paints the Fill/Stroke proxies show (the Appearance panel's active item for the proxy of its kind, else the first selected object's, a group's first painted object's, a Live Paint group's first face's fill and first edge's stroke, type: its first run's; else the defaults for new art; when that object is a gradient mesh with points picked by the Mesh tool, Direct Selection or the Lasso and no fill item is active, the fill is its first picked point's color), fillActive, fillMixed, strokeMixed: the selected objects' (or a selected group's contents') fills (strokes) differ, a Live Paint group counting with its faces' fills and its edges' strokes, shown as a \"?\" proxy (a gradient mesh with points picked counts with their colors)}",
always,
proxies
),
@@ -182,10 +184,11 @@ impl Session {
/// The fill and stroke the Fill/Stroke proxies show: the Appearance panel's active item (in the
/// first selected object's own stack) for the proxy of its kind, else the first selected
/// object's (a group's first painted object's; type: its first run's), else the defaults for
/// new art. When the object whose fill the proxy shows is a gradient mesh with points picked
/// ([`Session::fill_mesh_points`]), the fill is its first picked point's color, which a solid
/// fill color changes.
/// object's (a group's first painted object's; a Live Paint group's first face's fill and first
/// edge's stroke, or the next selected object's when it has no face or edge; type: its first
/// run's), else the defaults for new art. When the object whose fill the proxy shows is a
/// gradient mesh with points picked ([`Session::fill_mesh_points`]), the fill is its first
/// picked point's color, which a solid fill color changes.
pub fn proxy_paints(&self) -> (Paint, Paint) {
let points = self.fill_mesh_points();
let show = |stroke: bool| match self.proxy_source(stroke) {
@@ -215,9 +218,20 @@ impl Session {
if first.appearance.item_of_kind(item, !stroke).is_some() {
return Some((Cow::Borrowed(first), item));
}
let mut nodes = vec![];
painted(first, true, &mut nodes);
nodes.first().map(|n| (Cow::Borrowed(*n), None))
// 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() {
let Some(n) = st.doc.node(*id) else { continue };
let mut nodes = vec![];
painted(n, true, stroke, &mut nodes);
if let Some(n) = nodes.first() {
return Some((Cow::Borrowed(*n), None));
}
if !is_live_paint(n) {
return None;
}
}
None
}
pub(crate) fn remember_paint_now(&mut self, p: &Paint) {
@@ -258,21 +272,35 @@ 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.
pub(crate) fn painted<'a>(n: &'a Node, top: bool, out: &mut Vec<&'a Node>) {
/// other containers inside them), a compound path for its parts. A Live Paint group stands for its
/// faces in the fill proxy (`stroke` false) and for its edges in the stroke proxy, the parts a fill
/// or a stroke given to it changes ([`live_paint_parts_skipped`]).
pub(crate) fn painted<'a>(n: &'a Node, top: bool, stroke: bool, out: &mut Vec<&'a Node>) {
// A ruler guide has no paints.
if n.is_ruler_guide() {
return;
}
if is_live_paint(n) {
out.extend(if stroke { edges(n) } else { faces(n) }.into_iter().map(|part| &**part));
return;
}
let expand = match n.kind {
NodeKind::Group { .. } | NodeKind::Layer { .. } => true,
NodeKind::Compound { .. } => false,
_ => !top && n.is_container(),
};
if expand {
n.children().into_iter().flatten().for_each(|c| painted(c, false, out));
n.children().into_iter().flatten().for_each(|c| painted(c, false, stroke, out));
} else {
out.push(n);
}
@@ -301,18 +329,31 @@ 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 nodes) = (vec![], vec![]);
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();
// 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()) {
#[cfg(test)]
tests::note_gathered();
selected.push(n);
painted(n, true, &mut nodes);
if covered.contains(&n.id) {
continue;
}
covered.extend(live_paint_parts(n));
painted(n, true, false, &mut fills);
painted(n, true, true, &mut strokes);
}
let differ = |stroke: bool| {
let item = first.and_then(|f| f.appearance.item_of_kind(item, !stroke));
let set = if item.is_some() { &selected } else { &nodes };
let set = if item.is_some() {
&selected
} else if stroke {
&strokes
} else {
&fills
};
let mut paints = set.iter().flat_map(|n| match picked_colors(n, if stroke || item.is_some() { &[] } else { points }) {
c if c.is_empty() => vec![proxy_paint(n, stroke, item)],
c => c.into_iter().map(Paint::solid).collect(),
@@ -568,7 +609,7 @@ pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool)
}
// Resolve the requested targets before mutating defaults or the active proxy.
let item = item_target(s, p, cmd)?.of_kind(s, fill);
let selected = item.targets(s, p)?;
let selected = item.targets_for(s, p, fill)?;
let ids = super::graph::paint_targets(&s.doc()?.doc, &selected);
let of = super::appearance::reference_of(s, p, item, cmd)?;
let paint = if span {
@@ -717,6 +758,68 @@ pub(crate) fn bucket_color_params(s: &Session, p: &Value, cmd: &str) -> Result<O
Ok(Some(Value::Object(v)))
}
/// The Live Paint groups in `roots` (or inside them), given or selected whole, with the ids of
/// their faces and of their edges, found where [`leaf_targets`] finds the objects a paint command
/// changes: a given or selected object other than a group or layer (a blend, say) and a compound
/// shape are painted as one object, and a Live Paint group kept among another one's hidden sources
/// is not one of them. The art of graph designs drawn in graph series is left out.
fn live_paint_groups(d: &Document, roots: &[NodeId]) -> Vec<(NodeId, Vec<NodeId>, Vec<NodeId>)> {
fn find<'a>(n: &'a Node, top: bool, out: &mut Vec<&'a Node>) {
let group = matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. });
if is_live_paint(n) {
out.push(n);
} else if (group || !top) && !n.is_compound_shape() && !matches!(n.kind, NodeKind::Compound { .. }) {
n.children().into_iter().flatten().for_each(|c| find(c, false, out));
}
}
let mut found = vec![];
for n in roots.iter().filter_map(|r| d.node(*r)) {
find(n, true, &mut found);
}
let mut seen = std::collections::HashSet::new();
found.retain(|g| seen.insert(g.id));
// A given or selected compound shape or compound path (or one inside a given or selected object) paints its members,
// also when one of them is given as well. A Live Paint group given inside one that is not given stays a Live Paint group.
let owns = |id: &NodeId| d.node(*id).is_some_and(|n| n.is_compound_shape() || matches!(n.kind, NodeKind::Compound { .. }));
let given: std::collections::HashSet<NodeId> = roots.iter().copied().collect();
found.retain(|g| {
!d.ancestry(g.id).is_some_and(|up| {
let outer = up.iter().position(|a| given.contains(a)).unwrap_or(up.len());
up.iter().skip(outer).any(|a| *a != g.id && owns(a))
})
});
let kept: std::collections::HashSet<NodeId> = super::appearance::drop_design_art(d, found.iter().map(|g| g.id).collect()).into_iter().collect();
let ids = |parts: Vec<&std::sync::Arc<Node>>| parts.into_iter().map(|part| part.id).collect();
found.into_iter().filter(|g| kept.contains(&g.id)).map(|g| (g.id, ids(faces(g)), ids(edges(g)))).collect()
}
/// Every object inside the Live Paint groups `groups` (faces, edges and the hidden source paths).
fn inside_live_paint(d: &Document, groups: &[(NodeId, Vec<NodeId>, Vec<NodeId>)]) -> std::collections::HashSet<NodeId> {
let mut out = std::collections::HashSet::new();
for n in groups.iter().filter_map(|(g, _, _)| d.node(*g)) {
n.walk(&mut |c| {
if c.id != n.id {
out.insert(c.id);
}
});
}
out
}
/// The objects inside the Live Paint groups in `roots` (or inside them) that a fill (`fill`) or a
/// stroke given to the whole group leaves as they are: a fill paints the group's faces only, and a
/// stroke its edges only. Their edges (faces) and hidden source paths are left out.
pub(crate) fn live_paint_parts_skipped(d: &Document, roots: &[NodeId], fill: bool) -> std::collections::HashSet<NodeId> {
let groups = live_paint_groups(d, roots);
let mut out = inside_live_paint(d, &groups);
for (_, faces, edges) in &groups {
for id in if fill { faces } else { edges } {
out.remove(id);
}
}
out
}
/// 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.
@@ -1021,20 +1124,62 @@ pub(super) fn restore_unpainted_stroke(ap: &mut Appearance, index: Option<usize>
}
}
/// The paint every one of `parts` has on top as its fill (`fill`) or stroke, swatch link included
/// and gradient placement left out ([`unplaced`]: each part fits it to its own bounds), or None
/// when they differ or there are none. A freeform gradient's points and their colors belong to the
/// part they sit on, so a freeform gradient on any part counts as a paint the parts do not share.
fn shared_paint(d: &Document, parts: &[NodeId], fill: bool) -> Option<Paint> {
let mut paints = parts.iter().filter_map(|id| d.node(*id)).map(|n| if fill { n.appearance.fill_paint() } else { n.appearance.stroke_paint() });
let first = paints.next()?;
let freeform =
|p: &Paint| matches!(p, Paint::Gradient(g) if g.gradient.kind == vectorcraft_color::GradientKind::Freeform || g.freeform.is_some());
if freeform(&first) {
return None;
}
let first = unplaced(&first);
paints.all(|p| !freeform(&p) && unplaced(&p) == first).then_some(first)
}
fn swap(s: &mut Session, p: &Value) -> Result<Value> {
let bucket = bucket_color_params(s, p, "paint.swap")?;
let p = bucket.as_ref().unwrap_or(p);
let targets = paint_targets(s, p)?;
let given = !targets.is_empty();
let ids = super::appearance::drop_design_art(&s.doc()?.doc, targets);
// A whole Live Paint group: its faces take the stroke its edges share and its edges the fill its faces share.
let groups = live_paint_groups(&s.doc()?.doc, &super::targets(s, p)?);
let inside = inside_live_paint(&s.doc()?.doc, &groups);
let ids = super::appearance::drop_design_art(&s.doc()?.doc, targets.into_iter().filter(|id| !inside.contains(id)).collect());
// Only design art was given or selected: nothing changes, the defaults included.
if given && ids.is_empty() {
if given && ids.is_empty() && groups.is_empty() {
return ok();
}
if !ids.is_empty() {
if !ids.is_empty() || !groups.is_empty() {
// When every object comes out as it was, the document and its undo history stay as they are.
let before = s.doc()?.doc.clone();
// A group whose faces' fills (or edges' strokes) differ or are freeform gradients, or that has no face or no edge,
// keeps its paint.
let swaps: Vec<(&[NodeId], &[NodeId], Paint, Paint)> = groups
.iter()
.filter_map(|(_, faces, edges)| {
Some((faces.as_slice(), edges.as_slice(), shared_paint(&before, faces, true)?, shared_paint(&before, edges, false)?))
})
.collect();
let parts: Vec<NodeId> = groups.iter().flat_map(|(_, faces, edges)| faces.iter().chain(edges)).copied().collect();
super::overprint::edit_counted(s, "Swap Fill and Stroke", |d| {
for (faces, edges, fill, stroke) in &swaps {
for id in *faces {
if let Some(n) = d.node_mut(*id) {
n.appearance.set_fill(stroke.clone());
}
}
for id in *edges {
if let Some(n) = d.node_mut(*id) {
restore_unpainted_stroke(&mut n.appearance, None, fill);
n.appearance.set_stroke(fill.clone());
}
}
}
let parts_changed = super::appearance::count_changed(d, &before, &parts);
for id in &ids {
let Some(n) = d.node_mut(*id) else { continue };
if let NodeKind::Text(t) = &mut n.kind {
@@ -1054,7 +1199,7 @@ fn swap(s: &mut Session, p: &Value) -> Result<Value> {
// The swap writes the paint of the topmost fill and stroke, not their opacity.
let kept = super::appearance::capture_series_writes(&before, d, &ids, (true, true), (false, false), true, false);
let labels = super::graph::capture_label_changes(&before, d, &ids, false, None);
Ok(super::appearance::count_changed(d, &before, &ids) + usize::from(kept || labels))
Ok(super::appearance::count_changed(d, &before, &ids) + parts_changed + usize::from(kept || labels))
})?;
}
if s.paint.stroke.is_none() && !s.paint.fill.is_none() && s.paint.stroke_width == 0.0 {
@@ -1064,22 +1209,44 @@ fn swap(s: &mut Session, p: &Value) -> Result<Value> {
ok()
}
/// The weight of the stroke [`paint.default`](default_paint) gives the edges of a whole Live Paint group.
const LIVE_PAINT_DEFAULT_WEIGHT: f64 = 0.5;
fn default_paint(s: &mut Session, p: &Value) -> Result<Value> {
let bucket = bucket_color_params(s, p, "paint.default")?;
let p = bucket.as_ref().unwrap_or(p);
let targets = paint_targets(s, p)?;
let given = !targets.is_empty();
let ids = super::appearance::drop_design_art(&s.doc()?.doc, targets);
// A whole Live Paint group: its faces lose their fill and its edges take a black 0.5 pt stroke.
let groups = live_paint_groups(&s.doc()?.doc, &super::targets(s, p)?);
let inside = inside_live_paint(&s.doc()?.doc, &groups);
let ids = super::appearance::drop_design_art(&s.doc()?.doc, targets.into_iter().filter(|id| !inside.contains(id)).collect());
// Only design art was given or selected: nothing changes, the defaults included.
if given && ids.is_empty() {
if given && ids.is_empty() && groups.is_empty() {
return ok();
}
if !ids.is_empty() {
if !ids.is_empty() || !groups.is_empty() {
// When every object comes out as it was, the document and its undo history stay as they are.
let before = s.doc()?.doc.clone();
// A redefined Default Graphic Style gives other art its fills, strokes and effects, placed on each object.
let style = super::newart::redefined_default_style(&before).cloned();
let parts: Vec<NodeId> = groups.iter().flat_map(|(_, faces, edges)| faces.iter().chain(edges)).copied().collect();
super::overprint::edit_counted(s, "Default Fill and Stroke", |d| {
for (_, faces, edges) in &groups {
let face = Appearance { items: vec![AppearanceItem::Fill(FillLayer::new(Paint::None))], ..Appearance::default() };
let edge = Appearance {
items: vec![AppearanceItem::Stroke(StrokeLayer::new(Paint::solid(Color::BLACK), LIVE_PAINT_DEFAULT_WEIGHT))],
..Appearance::default()
};
for (ids, look) in [(faces, &face), (edges, &edge)] {
for id in ids {
if let Some(n) = d.node_mut(*id) {
n.appearance = look.clone().into();
}
}
}
}
let parts_changed = super::appearance::count_changed(d, &before, &parts);
for id in &ids {
let Some(n) = d.node_mut(*id) else { continue };
match &mut n.kind {
@@ -1106,10 +1273,20 @@ fn default_paint(s: &mut Session, p: &Value) -> Result<Value> {
st.stroke = Paint::None;
});
let lines = super::graph::capture_line_fill_stroke_rows(d, &ids);
Ok(super::appearance::count_changed(d, &before, &ids) + usize::from(kept || labels || lines))
Ok(super::appearance::count_changed(d, &before, &ids) + parts_changed + usize::from(kept || labels || lines))
})?;
}
super::newart::reset(s);
if ids.is_empty() && !groups.is_empty() {
// With only whole Live Paint groups given or selected, new art takes what their parts took, and nothing else.
s.paint = vectorcraft_tools::PaintDefaults {
fill: Paint::None,
stroke: Paint::solid(Color::BLACK),
stroke_width: LIVE_PAINT_DEFAULT_WEIGHT,
..Default::default()
};
} else {
super::newart::reset(s);
}
ok()
}
@@ -1215,11 +1392,20 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(
if roots.is_empty() {
return Ok(json!({ "changed": 0 }));
}
let art = super::appearance::design_art_in(d, &roots).into_iter().collect();
// The fill or stroke the proxy shows of each group among the roots, before the edit.
// A Live Paint group's fill is its faces' fills and its stroke its edges' strokes, also with `target: "contents"`;
// like any group, it recolors rows of its own as well.
let parts_skipped = live_paint_parts_skipped(d, &ids, !stroke);
let roots: Vec<NodeId> = roots.into_iter().filter(|id| !parts_skipped.contains(id)).collect();
if roots.is_empty() {
return Ok(json!({ "changed": 0 }));
}
let mut art: std::collections::HashSet<NodeId> = super::appearance::design_art_in(d, &roots).into_iter().collect();
art.extend(parts_skipped.iter().copied());
// The fill or stroke the proxy shows of each group among the roots, before the edit (a Live Paint group shows
// its faces' or edges').
let own = |d: &Document, id: NodeId| {
d.node(id)
.filter(|n| matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. }))
.filter(|n| matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. }) && !is_live_paint(n))
.and_then(|n| n.proxy_paint_only(stroke, None))
.cloned()
};
@@ -1237,7 +1423,8 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(
shown_at = Some((*id, None));
break;
}
if let Some(leaf) = super::appearance::drop_design_art(d, leaf_targets(s, &[*id])?).first() {
let leaves = leaf_targets(s, &[*id])?.into_iter().filter(|leaf| !parts_skipped.contains(leaf)).collect();
if let Some(leaf) = super::appearance::drop_design_art(d, leaves).first() {
shown_at = Some((*leaf, None));
break;
}
+15 -4
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::{painted, picked_colors, proxy_paint, same_in_proxy};
use super::{live_paint_parts, painted, picked_colors, proxy_paint, same_in_proxy};
use crate::{DocState, Session};
thread_local! {
@@ -38,17 +38,28 @@ fn walked(st: &DocState, item: Option<usize>, points: &[(NodeId, Vec<usize>)]) -
return (false, false);
}
let ids: HashSet<NodeId> = st.selection.objects.iter().copied().collect();
let (mut selected, mut nodes) = (vec![], vec![]);
let (mut selected, mut fills, mut strokes) = (vec![], vec![], vec![]);
let mut covered = HashSet::new();
st.doc.walk(|n| {
if ids.contains(&n.id) {
selected.push(n);
painted(n, true, &mut nodes);
if !covered.contains(&n.id) {
covered.extend(live_paint_parts(n));
painted(n, true, false, &mut fills);
painted(n, true, true, &mut strokes);
}
}
});
let first = st.selection.objects.first().and_then(|id| st.doc.node(*id));
let differ = |stroke: bool| {
let item = first.and_then(|f| f.appearance.item_of_kind(item, !stroke));
let set = if item.is_some() { &selected } else { &nodes };
let set = if item.is_some() {
&selected
} else if stroke {
&strokes
} else {
&fills
};
let mut paints = set.iter().flat_map(|n| match picked_colors(n, if stroke || item.is_some() { &[] } else { points }) {
c if c.is_empty() => vec![proxy_paint(n, stroke, item)],
c => c.into_iter().map(Paint::solid).collect(),
+45 -24
View File
@@ -8,9 +8,10 @@ use vectorcraft_doc::{
Unit, WidthProfile,
};
use vectorcraft_geom::PathData;
use vectorcraft_tools::builder::is_live_paint;
use super::appearance::{ItemTarget, edit_items, item_target};
use super::paint::painted;
use super::paint::{live_paint_parts, 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};
@@ -22,7 +23,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Stroke Options",
["Window", "Stroke"],
None,
"{weight?: pt, cap?: butt|round|square, join?: miter|round|bevel, miterLimit?, align?: center|inside|outside, dash?: [d,g,…]|null (a 0 dash with a round or projecting cap draws dots or squares; a new pattern keeps the current offset and alignment), dashOffset? (exact dashes only), alignDashes?: bool (true: dashes fitted to corners and path ends, every run between them holding whole periods with a dash centred on each corner and end; false, the default for a new pattern: exact lengths), startArrow?, endArrow?: Arrow|ArrowOpen|LineArrow|Barbed|Concave|DoubleArrow|HalfArrowLeft|HalfArrowRight|Chevron|Feather|Swallowtail|Triangle|TriangleOpen|TriangleReverse|TriangleBar|Kite|Leaf|Drop|Circle|CircleOpen|HalfCircle|Oval|Target|Square|SquareOpen|Tag|TagOpen|Diamond|DiamondOpen|Hexagon|HexagonOpen|Star|Cross|Plus|Bar|DoubleBar|DotOnBar|Slash|DoubleSlash|Bracket|Fork|null|{custom: name} (a custom arrowhead of the arrowheads file, stroke.arrowheads.list)|{Custom: {name, path}} (a custom head with its art, as document.inspect reports one; refused when the path fills no area, parts thinner than a millionth of a head unit counting as none, or has more than 4096 anchors, more than 4096 subpaths or a point more than 64 head units from the tip) (HalfArrowLeft/Right: one barb, left or right of the direction the head points), arrowAlign?: \"extend\" (tip past the end point, default)|\"tip\" (tip on the end point; the stroke is shortened), profile?: \"uniform\"|\"lens\"|\"taperStart\"|\"taperEnd\"|\"pinch\"|\"teardrop\"|\"wave\"|a saved profile's name (stroke.widthProfile.list), widthPoints?, gradientMode? (as document.inspect reports them in strokeOptions, so those read back unchanged; ignored here: a custom profile is set with the Width tool, gradientMode with paint.editGradient), item?: stroke item index|null (omitted: the Appearance panel's active item if it is a stroke, else the top stroke, created when missing), ids?|id?, target?: \"object\"|\"contents\", aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} Without a stroke item, type takes weight, cap, join, miterLimit, align (around its glyph outlines; the type stays live) and the dash options as its characters' stroke (every run; text.setRangeStyle `strokeOptions` styles a range), and images and symbol instances (also in groups) are left alone. With nothing selected (and no ids) they set up the next object drawn (appearance.newArt; weight always does). On a path directly in a graph series, the graph also stores a weight it changes on the topmost visible stroke (docs/mcp.md); on a graph label's stroke row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind, and on its characters the stroke options they take; on a graph's axis line, tick mark or radar ring, the graph stores the paint, weight, opacity and blend mode of its topmost visible fill and stroke rows that the edit changes, and the weight it writes to the topmost visible stroke, for every line of its kind, and not its caps, joins, dashes, alignment or arrowheads. While the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), only the stroke for new art changes (the bucket paints edges with its color and weight) → {objects: how many objects took the stroke options}",
"{weight?: pt, cap?: butt|round|square, join?: miter|round|bevel, miterLimit?, align?: center|inside|outside, dash?: [d,g,…]|null (a 0 dash with a round or projecting cap draws dots or squares; a new pattern keeps the current offset and alignment), dashOffset? (exact dashes only), alignDashes?: bool (true: dashes fitted to corners and path ends, every run between them holding whole periods with a dash centred on each corner and end; false, the default for a new pattern: exact lengths), startArrow?, endArrow?: Arrow|ArrowOpen|LineArrow|Barbed|Concave|DoubleArrow|HalfArrowLeft|HalfArrowRight|Chevron|Feather|Swallowtail|Triangle|TriangleOpen|TriangleReverse|TriangleBar|Kite|Leaf|Drop|Circle|CircleOpen|HalfCircle|Oval|Target|Square|SquareOpen|Tag|TagOpen|Diamond|DiamondOpen|Hexagon|HexagonOpen|Star|Cross|Plus|Bar|DoubleBar|DotOnBar|Slash|DoubleSlash|Bracket|Fork|null|{custom: name} (a custom arrowhead of the arrowheads file, stroke.arrowheads.list)|{Custom: {name, path}} (a custom head with its art, as document.inspect reports one; refused when the path fills no area, parts thinner than a millionth of a head unit counting as none, or has more than 4096 anchors, more than 4096 subpaths or a point more than 64 head units from the tip) (HalfArrowLeft/Right: one barb, left or right of the direction the head points), arrowAlign?: \"extend\" (tip past the end point, default)|\"tip\" (tip on the end point; the stroke is shortened), profile?: \"uniform\"|\"lens\"|\"taperStart\"|\"taperEnd\"|\"pinch\"|\"teardrop\"|\"wave\"|a saved profile's name (stroke.widthProfile.list), widthPoints?, gradientMode? (as document.inspect reports them in strokeOptions, so those read back unchanged; ignored here: a custom profile is set with the Width tool, gradientMode with paint.editGradient), item?: stroke item index|null (omitted: the Appearance panel's active item if it is a stroke, else the top stroke, created when missing), ids?|id?, target?: \"object\"|\"contents\", aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} Without a stroke item, type takes weight, cap, join, miterLimit, align (around its glyph outlines; the type stays live) and the dash options as its characters' stroke (every run; text.setRangeStyle `strokeOptions` styles a range), and images and symbol instances (also in groups) are left alone; a Live Paint group takes them on its edges only. With nothing selected (and no ids) they set up the next object drawn (appearance.newArt; weight always does). On a path directly in a graph series, the graph also stores a weight it changes on the topmost visible stroke (docs/mcp.md); on a graph label's stroke row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind, and on its characters the stroke options they take; on a graph's axis line, tick mark or radar ring, the graph stores the paint, weight, opacity and blend mode of its topmost visible fill and stroke rows that the edit changes, and the weight it writes to the topmost visible stroke, for every line of its kind, and not its caps, joins, dashes, alignment or arrowheads. While the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), only the stroke for new art changes (the bucket paints edges with its color and weight) → {objects: how many objects took the stroke options}",
has_doc,
stroke_set
),
@@ -31,7 +32,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Stroke Weight Up",
[],
Some("Cmd+Alt+."),
"{ids?|id?} raise each selected stroke's weight by one step of Units › Stroke (a quarter unit below one unit, then whole units; up to 1000 pt), each from its own weight: the selected objects' active or top stroke, type's stroked characters; objects without a stroke are left alone. With nothing selected (and no ids), the weight of the next object drawn, and so while the Live Paint Bucket is the active tool and no ids or id are given (a null one counts as none). On a path directly in a graph series, the graph also stores the new weight of the topmost visible stroke, and on a graph label the new weight of its characters' stroke or its stroke row for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (docs/mcp.md) → {objects}",
"{ids?|id?} raise each selected stroke's weight by one step of Units › Stroke (a quarter unit below one unit, then whole units; up to 1000 pt), each from its own weight: the selected objects' active or top stroke, type's stroked characters; objects without a stroke, and a Live Paint group's faces, are left alone. With nothing selected (and no ids), the weight of the next object drawn, and so while the Live Paint Bucket is the active tool and no ids or id are given (a null one counts as none). On a path directly in a graph series, the graph also stores the new weight of the topmost visible stroke, and on a graph label the new weight of its characters' stroke or its stroke row for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (docs/mcp.md) → {objects}",
has_doc,
|s, p| stroke_step(s, p, true)
),
@@ -49,7 +50,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Stroke Options",
[],
None,
"{arrowScale?: [start %, end %], swapArrows?: bool, flipProfile?: \"along\"|\"across\", brush?: name|null, item?: stroke item index|null, aligned?: bool (as stroke.set), ids?|id?, target?: \"object\"|\"contents\"} Stroke panel extras (with nothing selected, all but brush set up the next object drawn, and so while the Live Paint Bucket is the active tool and no ids, id, item or brush are given, a null ids or id counting as none)",
"{arrowScale?: [start %, end %], swapArrows?: bool, flipProfile?: \"along\"|\"across\", brush?: name|null, item?: stroke item index|null, aligned?: bool (as stroke.set), ids?|id?, target?: \"object\"|\"contents\"} Stroke panel extras (with nothing selected, all but brush set up the next object drawn, and so while the Live Paint Bucket is the active tool and no ids, id, item or brush are given, a null ids or id counting as none; without item, a Live Paint group's edges take them and its faces are left alone)",
has_doc,
stroke_advanced
),
@@ -210,20 +211,25 @@ fn no_targets(ids: &[vectorcraft_doc::NodeId], p: &Value) -> bool {
/// The objects `stroke.set` edits with no `item`: a selected group or layer with a stroke row of
/// its own edits that row, as the Stroke panel does with the group targeted (#6739); the other
/// targets reach their painted leaves, as before.
/// targets reach their painted leaves, as before (a Live Paint group's edges, not its faces).
fn own_stroke_or_leaves(s: &Session, p: &Value) -> Result<Vec<vectorcraft_doc::NodeId>> {
let picked = super::targets(s, p)?;
let d = &s.doc()?.doc;
// A Live Paint group's stroke is its edges' strokes, also when it has a stroke row of its own.
let own = |id: &vectorcraft_doc::NodeId| {
d.node(*id).is_some_and(|n| {
matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. }) && !n.is_compound_shape() && n.appearance.stroke().is_some()
matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. })
&& !n.is_compound_shape()
&& n.appearance.stroke().is_some()
&& !is_live_paint(n)
})
};
let (mut out, rest): (Vec<_>, Vec<_>) = picked.into_iter().partition(own);
let faces = live_paint_parts_skipped(d, &rest, false);
// A leaf already listed is skipped; a set keeps this linear in the number of leaves.
let mut seen: std::collections::HashSet<vectorcraft_doc::NodeId> = out.iter().copied().collect();
for id in super::leaf_targets(s, &rest)? {
if seen.insert(id) {
if !faces.contains(&id) && seen.insert(id) {
out.push(id);
}
}
@@ -246,11 +252,13 @@ fn stroke_set(s: &mut Session, p: &Value) -> Result<Value> {
} else {
item.targets(s, p)?
};
let new_art = bucket || no_targets(&ids, p);
let given = !ids.is_empty();
// 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 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.
ids = super::appearance::drop_design_art_rows(s, ids, item, false, C)?;
// With only design art, the weight for new art stays as it is too.
// With only design art, or only Live Paint groups without edges, the weight for new art stays as it is too.
let only_design_art = given && ids.is_empty();
if item == ItemTarget::Top {
// Images and symbol instances take no stroke from the panel.
@@ -388,8 +396,8 @@ fn stroke_step(s: &mut Session, p: &Value, up: bool) -> Result<Value> {
let bucket = bucket_p.is_some();
let p = bucket_p.as_ref().unwrap_or(p);
let item = item_target(s, p, c)?.of_kind(s, false);
let ids = if bucket { vec![] } else { item.targets(s, p)? };
if bucket || no_targets(&ids, p) {
let (ids, skipped) = if bucket { (vec![], false) } else { item.targets_and_skipped(s, p, false)? };
if bucket || (no_targets(&ids, p) && !skipped) {
let w = step_weight(s.paint.stroke_width, unit, up);
s.paint.stroke_width = w;
if let Some(st) = s.new_art_stroke_mut() {
@@ -428,8 +436,9 @@ impl Session {
/// The stroke the Stroke panel, the Control bar and the Properties panel show, picked as the
/// Stroke proxy picks its paint: the Appearance panel's active item when it is a stroke, else
/// the first selected object's (a group's first painted object's) top stroke, type's first
/// run's character stroke; with an object of a dynamic symbol instance selected
/// the first selected object's (a group's first painted object's, a Live Paint group's first
/// edge's, or the next selected object's when a Live Paint group has no edge) top stroke, type's
/// first run's character stroke; with an object of a dynamic symbol instance selected
/// ([`DocState::selected_symbol_part`]), that object's as the instance draws it; with nothing
/// selected, the next object drawn's ([`Session::new_art_stroke`]), and so while the Live Paint
/// Bucket is the active tool (the stroke it paints with). None without a document or the
@@ -447,9 +456,20 @@ impl Session {
if let Some(i) = first.appearance.item_of_kind(self.appearance_item(), false) {
return first.appearance.stroke_at(Some(i)).cloned();
}
let mut nodes = vec![];
painted(first, true, &mut nodes);
node_stroke(nodes.first()?)
// 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 {
let Some(n) = st.doc.node(*id) else { continue };
let mut nodes = vec![];
painted(n, true, true, &mut nodes);
if let Some(n) = nodes.first() {
return node_stroke(n);
}
if !is_live_paint(n) {
return None;
}
}
None
}
/// Do all the strokes that `stroke.set` edits without `ids` or `item` draw with a brush
@@ -508,12 +528,13 @@ impl DocState {
let part = self.selected_symbol_part();
let mut nodes = vec![];
if let Some(part) = &part {
painted(part, true, &mut nodes);
painted(part, true, true, &mut nodes);
} else {
for id in &self.selection.objects {
if let Some(n) = self.doc.node(*id) {
painted(n, true, &mut nodes);
}
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();
for n in selected.into_iter().filter(|n| !covered.contains(&n.id)) {
painted(n, true, true, &mut nodes);
}
}
let mut strokes = vec![];
@@ -594,8 +615,8 @@ fn stroke_advanced(s: &mut Session, p: &Value) -> Result<Value> {
let bucket = bucket_p.is_some();
let p = bucket_p.as_ref().unwrap_or(p);
let item = item_target(s, p, C)?.of_kind(s, false);
let ids = if bucket { vec![] } else { item.targets(s, p)? };
let new_art = bucket || no_targets(&ids, p);
let (ids, skipped) = if bucket { (vec![], false) } else { item.targets_and_skipped(s, p, false)? };
let new_art = bucket || (no_targets(&ids, p) && !skipped);
// The art of a graph design in a series keeps the design's stroke.
let ids = super::appearance::drop_design_art_rows(s, ids, item, false, C)?;
let arrows_and_profile = |st: &mut StrokeLayer| {
+413
View File
@@ -3784,6 +3784,419 @@ fn live_paint_fill_skips_hidden_faces() {
assert!(!node(&s, hidden).visible);
}
/// The appearance of each face and each edge of Live Paint group `g`.
fn part_looks(s: &Session, g: NodeId) -> (Vec<vectorcraft_doc::Appearance>, Vec<vectorcraft_doc::Appearance>) {
use vectorcraft_tools::builder::{edges, faces};
let n = node(s, g);
let looks = |parts: Vec<&Arc<Node>>| parts.iter().map(|p| (*p.appearance).clone()).collect();
(looks(faces(&n)), looks(edges(&n)))
}
/// The appearance of each hidden source path of Live Paint group `g`.
fn sources_looks(s: &Session, g: NodeId) -> Vec<vectorcraft_doc::Appearance> {
let n = node(s, g);
let src = vectorcraft_tools::builder::sources(&n).unwrap();
src.children().unwrap().iter().map(|c| (*c.appearance).clone()).collect()
}
/// With a tool other than the Live Paint Bucket, a fill given to a whole selected Live Paint group
/// paints its faces and leaves its edges as they are, and a stroke paints its edges and leaves its
/// faces as they are. The Fill and Stroke proxies show the faces' fill and the edges' stroke.
#[test]
fn live_paint_group_fill_goes_to_faces_and_stroke_to_edges() {
let mut s = session();
let g = live(&mut s);
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
let (faces0, edges0) = part_looks(&s, g);
let magenta = Paint::solid(Color::from_hex("#ff00ff").unwrap());
let sources0 = sources_looks(&s, g);
assert_eq!(s.execute("paint.setFill", &json!({"color": "#ff00ff"})).unwrap()["objects"], faces0.len());
let (faces1, edges1) = part_looks(&s, g);
assert!(faces1.iter().all(|f| f.fill_paint() == magenta));
assert_eq!(edges1, edges0, "edges take no fill");
let p = s.execute("paint.proxies", &json!({})).unwrap();
assert_eq!(p["fillMixed"], false);
assert_eq!(p["fill"], serde_json::to_value(&magenta).unwrap());
let blue = Paint::solid(Color::from_hex("#0000ff").unwrap());
assert_eq!(s.execute("paint.setStroke", &json!({"color": "#0000ff"})).unwrap()["objects"], edges0.len());
assert_eq!(sources_looks(&s, g), sources0, "the hidden source paths keep their paint");
let (faces2, edges2) = part_looks(&s, g);
assert!(edges2.iter().all(|e| e.stroke_paint() == blue));
assert_eq!(faces2, faces1, "faces take no stroke");
let p = s.execute("paint.proxies", &json!({})).unwrap();
assert_eq!(p["strokeMixed"], false);
assert_eq!(p["stroke"], serde_json::to_value(&blue).unwrap());
// The same with the group given by id, and inside a selected group.
s.execute("paint.setFill", &json!({"ids": [g.0], "color": "#00ff00"})).unwrap();
let (faces3, edges3) = part_looks(&s, g);
assert_eq!(edges3, edges2, "edges take no fill given by id");
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
assert!(faces3.iter().all(|f| f.fill_paint() == green));
s.execute("object.group", &json!({"ids": [g.0]})).unwrap();
s.execute("paint.setStroke", &json!({"color": "#ff0000"})).unwrap();
let (faces4, edges4) = part_looks(&s, g);
assert_eq!(faces4, faces3, "faces of a grouped Live Paint group take no stroke");
assert!(edges4.iter().all(|e| e.stroke_paint() == Paint::solid(Color::from_hex("#ff0000").unwrap())));
// The bucket then paints one face, and nothing in the group draws a fill over it.
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [75, 50], "color": "#ffff00"})).unwrap();
let face = NodeId(r["face"].as_u64().unwrap());
assert_eq!(node(&s, face).appearance.fill_paint(), Paint::solid(Color::from_hex("#ffff00").unwrap()));
assert!(part_looks(&s, g).1.iter().all(|e| e.fill_paint().is_none()));
}
/// Swap Fill and Stroke on a whole selected Live Paint group gives its faces the stroke its edges
/// share and its edges the fill its faces share; with faces of different fills, or without faces,
/// it leaves the group as it is.
#[test]
fn live_paint_group_swap_trades_the_faces_fill_and_the_edges_stroke() {
let mut s = session();
let g = live(&mut s);
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
let sources0 = sources_looks(&s, g);
// The faces are red and blue: nothing on the group changes, in no undo step.
let (faces0, edges0) = part_looks(&s, g);
let depth = history_state(&s).0;
s.execute("paint.swap", &json!({})).unwrap();
assert_eq!(part_looks(&s, g), (faces0, edges0));
assert_eq!(history_state(&s).0, depth);
// One fill on every face: the faces take the edges' black, the edges the faces' red, at their weight.
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
s.execute("stroke.set", &json!({"weight": 2})).unwrap();
s.execute("paint.swap", &json!({})).unwrap();
let (faces1, edges1) = part_looks(&s, g);
assert!(faces1.iter().all(|f| f.fill_paint() == Paint::solid(Color::BLACK)));
assert!(edges1.iter().all(|e| e.stroke_paint() == Paint::solid(Color::rgb(1.0, 0.0, 0.0)) && e.stroke_width() == 2.0));
assert!(edges1.iter().all(|e| e.fill_paint().is_none()), "edges take no fill");
assert_eq!(sources_looks(&s, g), sources0);
s.execute("edit.undo", &json!({})).unwrap();
assert!(part_looks(&s, g).0.iter().all(|f| f.fill_paint() == Paint::solid(Color::rgb(1.0, 0.0, 0.0))), "one undo step");
// A gradient placed on each face's own bounds is one shared fill: the edges take it, fitted to each edge.
s.execute("paint.setFill", &json!({"gradient": {"aspect": 50}})).unwrap();
let placed: Vec<Paint> = part_looks(&s, g).0.iter().map(|f| f.fill_paint()).collect();
assert!(placed.iter().all(|p| matches!(p, Paint::Gradient(gr) if gr.geom.is_some())) && placed[0] != placed[1]);
s.execute("paint.swap", &json!({})).unwrap();
let (faces2, edges2) = part_looks(&s, g);
assert!(faces2.iter().all(|f| f.fill_paint() == Paint::solid(Color::BLACK)));
assert!(edges2.iter().all(|e| matches!(e.stroke_paint(), Paint::Gradient(gr) if gr.geom.is_none() && gr.freeform.is_none())));
// A freeform gradient's points belong to its face: faces with freeform fills keep their paint, in no undo step.
s.execute("paint.setFill", &json!({"gradient": {"kind": "freeform"}})).unwrap();
assert!(
part_looks(&s, g)
.0
.iter()
.all(|f| matches!(f.fill_paint(), Paint::Gradient(gr) if gr.gradient.kind == vectorcraft_color::GradientKind::Freeform))
);
let looks = part_looks(&s, g);
let depth = history_state(&s).0;
s.execute("paint.swap", &json!({})).unwrap();
assert_eq!(part_looks(&s, g), looks);
assert_eq!(history_state(&s).0, depth);
// A group with edges and no faces keeps its paint.
let line = NodeId(s.execute("shape.line", &json!({"x1": 0, "y1": 300, "x2": 100, "y2": 300})).unwrap()["id"].as_u64().unwrap());
let edges_only = NodeId(s.execute("livePaint.make", &json!({"ids": [line.0]})).unwrap()["id"].as_u64().unwrap());
assert!(part_looks(&s, edges_only).0.is_empty());
s.execute("select.set", &json!({"ids": [edges_only.0]})).unwrap();
let looks = part_looks(&s, edges_only);
s.execute("paint.swap", &json!({})).unwrap();
assert_eq!(part_looks(&s, edges_only), looks);
}
/// Default Fill and Stroke on a whole selected Live Paint group leaves its faces with no fill and
/// gives its edges a 0.5 pt black stroke, and new art takes the same; other art selected with it
/// takes the white fill and 1 pt black stroke.
#[test]
fn live_paint_group_default_clears_the_faces_and_gives_the_edges_a_thin_black_stroke() {
let mut s = session();
let g = live(&mut s);
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
let sources0 = sources_looks(&s, g);
s.execute("paint.setStroke", &json!({"color": "#0000ff"})).unwrap();
s.execute("paint.default", &json!({})).unwrap();
let (faces, edges) = part_looks(&s, g);
assert!(faces.iter().all(|f| f.fill_paint().is_none() && f.stroke_paint().is_none()));
assert!(edges.iter().all(|e| e.stroke_paint() == Paint::solid(Color::BLACK) && e.stroke_width() == 0.5 && e.fill_paint().is_none()));
assert_eq!(sources_looks(&s, g), sources0);
assert_eq!((s.paint.fill.clone(), s.paint.stroke.clone(), s.paint.stroke_width), (Paint::None, Paint::solid(Color::BLACK), 0.5));
let p = s.execute("paint.proxies", &json!({})).unwrap();
assert_eq!((p["fillMixed"].clone(), p["strokeMixed"].clone()), (json!(false), json!(false)));
// The next shape drawn has no fill and a 0.5 pt black stroke.
let next = rect(&mut s, 400.0, 0.0, 50.0, 50.0);
let look = node(&s, next).appearance.clone();
assert!(!look.has_visible_fill());
assert_eq!((look.stroke_paint(), look.stroke_width()), (Paint::solid(Color::BLACK), 0.5));
// With a plain rectangle selected too, the rectangle and new art take the white fill and 1 pt black stroke.
let r = rect(&mut s, 300.0, 0.0, 50.0, 50.0);
s.execute("paint.setFill", &json!({"ids": [r.0], "color": "#00ff00"})).unwrap();
s.execute("select.set", &json!({"ids": [g.0, r.0]})).unwrap();
s.execute("paint.default", &json!({})).unwrap();
assert_eq!(node(&s, r).appearance.fill_paint(), Paint::solid(Color::WHITE));
assert_eq!(part_looks(&s, g), (faces.clone(), edges.clone()));
assert_eq!((s.paint.fill.clone(), s.paint.stroke_width), (Paint::solid(Color::WHITE), 1.0));
// A redefined Default Graphic Style goes to other art; the parts still take no fill and a 0.5 pt black stroke.
s.execute("select.set", &json!({"ids": [r.0]})).unwrap();
s.execute("paint.setFill", &json!({"color": "#00ff00"})).unwrap();
s.execute("graphicStyle.redefine", &json!({"name": "Default Graphic Style"})).unwrap();
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
s.execute("stroke.set", &json!({"weight": 3})).unwrap();
s.execute("select.set", &json!({"ids": [g.0, r.0]})).unwrap();
s.execute("paint.default", &json!({})).unwrap();
assert_eq!(part_looks(&s, g), (faces, edges), "the parts do not take the redefined style");
assert_eq!(node(&s, r).appearance.fill_paint(), Paint::solid(Color::from_hex("#00ff00").unwrap()));
}
/// Invert on a whole selected Live Paint group recolors its faces' fills and leaves its edges and
/// hidden source paths as they are.
#[test]
fn live_paint_group_invert_recolors_the_faces_fill() {
let mut s = session();
let g = live(&mut s);
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
let sources0 = sources_looks(&s, g);
let (_, edges0) = part_looks(&s, g);
s.execute("paint.invert", &json!({"stroke": false})).unwrap();
let (faces, edges) = part_looks(&s, g);
assert!(faces.iter().all(|f| f.fill_paint() == Paint::solid(Color::rgb(0.0, 1.0, 1.0))));
assert_eq!(edges, edges0);
assert_eq!(sources_looks(&s, g), sources0);
// The same with `target: "contents"`, for the stroke.
s.execute("paint.invert", &json!({"stroke": true, "target": "contents"})).unwrap();
let (faces1, edges1) = part_looks(&s, g);
assert_eq!(faces1, faces);
assert!(edges1.iter().all(|e| e.stroke_paint() == Paint::solid(Color::WHITE)));
assert_eq!(sources_looks(&s, g), sources0);
// A gradient edit of the fill goes to the faces only.
s.execute("paint.setFill", &json!({"gradient": {}})).unwrap();
s.execute("paint.editGradient", &json!({"stroke": false, "angle": 45})).unwrap();
let (faces2, edges2) = part_looks(&s, g);
assert!(faces2.iter().all(|f| matches!(f.fill_paint(), Paint::Gradient(_))));
assert_eq!(edges2, edges1, "edges take no fill gradient");
assert_eq!(sources_looks(&s, g), sources0);
// Selecting a Live Paint group with edges and no faces gives new art its edges' stroke.
let line = NodeId(s.execute("shape.line", &json!({"x1": 0, "y1": 300, "x2": 100, "y2": 300})).unwrap()["id"].as_u64().unwrap());
let edges_only = NodeId(s.execute("livePaint.make", &json!({"ids": [line.0]})).unwrap()["id"].as_u64().unwrap());
s.execute("paint.setStroke", &json!({"ids": [edges_only.0], "color": "#00ff00"})).unwrap();
s.execute("select.none", &json!({})).unwrap();
s.paint.stroke = Paint::None;
s.execute("select.set", &json!({"ids": [edges_only.0]})).unwrap();
assert_eq!(s.paint.stroke, Paint::solid(Color::from_hex("#00ff00").unwrap()));
}
/// A gradient vector or freeform point edit of a whole selected Live Paint group's fill changes its
/// faces' gradients and leaves its edges and hidden source paths as they are.
#[test]
fn live_paint_group_gradient_vector_and_freeform_edits_change_its_faces() {
let mut s = session();
let g = live(&mut s);
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
s.execute("paint.setFill", &json!({"gradient": {}})).unwrap();
let sources0 = sources_looks(&s, g);
let (_, edges0) = part_looks(&s, g);
let face_ids: Vec<u64> = vectorcraft_tools::builder::faces(&node(&s, g)).iter().map(|f| f.id.0).collect();
let r = s.execute("paint.setGradientGeom", &json!({"stroke": false, "start": [0, 0], "end": [100, 0]})).unwrap();
let mut changed: Vec<u64> = r["ids"].as_array().unwrap().iter().map(|v| v.as_u64().unwrap()).collect();
changed.sort_unstable();
let mut faces = face_ids.clone();
faces.sort_unstable();
assert_eq!(changed, faces, "only the faces take the vector");
assert_eq!(part_looks(&s, g).1, edges0);
assert_eq!(sources_looks(&s, g), sources0);
s.execute("paint.setFill", &json!({"gradient": {"kind": "freeform"}})).unwrap();
s.execute("paint.freeform.addPoint", &json!({"stroke": false, "at": [25, 50], "color": "#00ff00"})).unwrap();
assert!(part_looks(&s, g).0.iter().all(|f| matches!(f.fill_paint(), Paint::Gradient(gr) if gr.freeform.is_some())));
assert_eq!(part_looks(&s, g).1, edges0);
assert_eq!(sources_looks(&s, g), sources0);
}
/// The Live Paint rules stop where a paint command stops: a Live Paint group in a compound shape or
/// a blend keeps its parts' paint when the compound shape or blend takes the default, Invert
/// remembers the faces' color the proxy shows, and a Live Paint group without faces lets the Fill
/// proxy show the next selected object's fill, while an empty plain group does not.
#[test]
fn live_paint_group_rules_stop_where_paint_commands_stop() {
let mut s = session();
let g = live(&mut s);
let looks = part_looks(&s, g);
let r = rect(&mut s, 300.0, 0.0, 50.0, 50.0);
s.execute("select.set", &json!({"ids": [g.0, r.0]})).unwrap();
let c = NodeId(s.execute("object.compoundShape.make", &json!({"mode": "add"})).unwrap()["id"].as_u64().unwrap());
s.execute("select.set", &json!({"ids": [c.0]})).unwrap();
s.execute("paint.default", &json!({})).unwrap();
s.execute("paint.swap", &json!({})).unwrap();
assert_eq!(part_looks(&s, g), looks, "a compound shape's member keeps its paint");
s.execute("paint.default", &json!({"ids": [c.0, g.0]})).unwrap();
assert_eq!(part_looks(&s, g), looks, "a compound shape's member given as well keeps its paint");
// Given alone, the member is a Live Paint group: a fill paints its faces and leaves its edges.
s.execute("paint.setFill", &json!({"ids": [g.0], "color": "#ff00ff"})).unwrap();
let (faces, edges) = part_looks(&s, g);
assert!(faces.iter().all(|f| f.fill_paint() == Paint::solid(Color::from_hex("#ff00ff").unwrap())));
assert_eq!(edges, looks.1, "the edges of a member given alone take no fill");
// A Live Paint group selected with one of its edges: the edge counts with the group.
let mut s = session();
let g = live(&mut s);
let edge = vectorcraft_tools::builder::edges(&node(&s, g))[0].id;
s.execute("select.set", &json!({"ids": [g.0, edge.0]})).unwrap();
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
assert_eq!(s.execute("paint.proxies", &json!({})).unwrap()["fillMixed"], false);
assert!(node(&s, edge).appearance.fill_paint().is_none(), "an edge selected with its group takes no fill");
// The same for an edge given in `ids` with its group.
s.execute("paint.setFill", &json!({"ids": [g.0, edge.0], "color": "#0000ff"})).unwrap();
assert!(node(&s, edge).appearance.fill_paint().is_none(), "an edge given with its group takes no fill");
// The same for a blend's key.
let mut s = session();
let g = live(&mut s);
let looks = part_looks(&s, g);
let r = rect(&mut s, 300.0, 0.0, 50.0, 50.0);
s.execute("select.set", &json!({"ids": [g.0, r.0]})).unwrap();
let b = NodeId(s.execute("object.blend.make", &json!({})).unwrap()["id"].as_u64().unwrap());
s.execute("select.set", &json!({"ids": [b.0]})).unwrap();
s.execute("paint.default", &json!({})).unwrap();
s.execute("paint.swap", &json!({})).unwrap();
assert_eq!(part_looks(&s, g), looks, "a blend's key keeps its paint");
// A Live Paint group inside a selected group: Invert recolors its faces' fills only.
let mut s = session();
let g = live(&mut s);
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
let sources0 = sources_looks(&s, g);
let (_, edges0) = part_looks(&s, g);
s.execute("object.group", &json!({"ids": [g.0]})).unwrap();
s.execute("paint.invert", &json!({"stroke": false})).unwrap();
assert!(part_looks(&s, g).0.iter().all(|f| f.fill_paint() == Paint::solid(Color::rgb(0.0, 1.0, 1.0))));
assert_eq!(part_looks(&s, g).1, edges0);
assert_eq!(sources_looks(&s, g), sources0);
let mut s = session();
let g = live(&mut s);
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
s.edit("t", |d, _| {
d.node_mut(g).unwrap().appearance.set_fill(Paint::solid(Color::rgb(0.0, 0.0, 1.0)));
Ok(())
})
.unwrap();
s.execute("paint.invert", &json!({"stroke": false})).unwrap();
// Like any group's, the group's own row is recolored too; the color remembered is the faces' one the proxy shows.
assert_eq!(node(&s, g).appearance.fill_paint(), Paint::solid(Color::rgb(1.0, 1.0, 0.0)));
assert!(part_looks(&s, g).0.iter().all(|f| f.fill_paint() == Paint::solid(Color::rgb(0.0, 1.0, 1.0))));
assert_eq!(s.last_solid, Color::rgb(0.0, 1.0, 1.0));
let mut s = session();
let line = NodeId(s.execute("shape.line", &json!({"x1": 0, "y1": 0, "x2": 100, "y2": 0})).unwrap()["id"].as_u64().unwrap());
let edges_only = NodeId(s.execute("livePaint.make", &json!({"ids": [line.0]})).unwrap()["id"].as_u64().unwrap());
assert!(part_looks(&s, edges_only).0.is_empty());
let r = rect(&mut s, 300.0, 0.0, 50.0, 50.0);
set_fill(&mut s, r, Color::from_hex("#00ff00").unwrap());
s.execute("select.set", &json!({"ids": [edges_only.0, r.0]})).unwrap();
let p = s.execute("paint.proxies", &json!({})).unwrap();
assert_eq!(p["fill"], serde_json::to_value(Paint::solid(Color::from_hex("#00ff00").unwrap())).unwrap());
// The edges-only group shows its edges' stroke in the Stroke panel.
let edge_width = part_looks(&s, edges_only).1[0].stroke_width();
assert_eq!(s.shown_stroke().map(|st| st.width), Some(edge_width));
// Any other object with nothing painted in it first in the selection (a group left empty) shows
// the defaults for new art, not the next object's paint.
let inner = rect(&mut s, 0.0, 300.0, 50.0, 50.0);
let empty = NodeId(s.execute("object.group", &json!({"ids": [inner.0]})).unwrap()["id"].as_u64().unwrap());
s.edit("t", |d, _| {
d.children_mut(Some(empty)).unwrap().clear();
Ok(())
})
.unwrap();
s.execute("stroke.set", &json!({"ids": [r.0], "weight": 7})).unwrap();
s.paint.fill = Paint::None;
s.execute("select.set", &json!({"ids": [empty.0, r.0]})).unwrap();
let p = s.execute("paint.proxies", &json!({})).unwrap();
assert_eq!(p["fill"], serde_json::to_value(Paint::None).unwrap());
assert!(s.shown_stroke().is_none());
}
/// Stroke panel edits of a whole selected Live Paint group (a weight, a step up or down, options)
/// change its edges and leave its faces as they are, and the panel shows the edges' stroke.
#[test]
fn live_paint_group_stroke_panel_edits_change_its_edges() {
let mut s = session();
let g = live(&mut s);
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
let (faces0, edges0) = part_looks(&s, g);
assert_eq!(s.execute("stroke.set", &json!({"weight": 5})).unwrap()["objects"], edges0.len());
let (faces1, edges1) = part_looks(&s, g);
assert_eq!(faces1, faces0, "faces take no stroke weight");
assert!(edges1.iter().all(|e| e.stroke().is_some_and(|st| st.width == 5.0)));
assert_eq!(s.shown_stroke().map(|st| st.width), Some(5.0));
assert!(!s.doc().unwrap().stroke_mixed().weight);
s.execute("stroke.weightUp", &json!({})).unwrap();
s.execute("stroke.set", &json!({"cap": "round"})).unwrap();
let (faces2, edges2) = part_looks(&s, g);
assert_eq!(faces2, faces0, "faces take no stroke step or cap");
assert!(edges2.iter().all(|e| e.stroke().is_some_and(|st| st.width == 6.0 && st.cap == LineCap::Round)));
// A stroke on the faces (from a file, say) leaves the panel showing the edges' stroke.
let face_ids: Vec<NodeId> = vectorcraft_tools::builder::faces(&node(&s, g)).iter().map(|f| f.id).collect();
s.edit("t", |d, _| {
for id in &face_ids {
let face = d.node_mut(*id).unwrap();
face.appearance.set_stroke(Paint::solid(Color::BLACK));
face.appearance.stroke_at_mut(None).unwrap().width = 2.0;
}
Ok(())
})
.unwrap();
assert_eq!(s.shown_stroke().map(|st| st.width), Some(6.0));
assert!(!s.doc().unwrap().stroke_mixed().weight);
// A face selected with its group counts with the group, whose stroke is its edges'.
s.execute("select.set", &json!({"ids": [g.0, face_ids[0].0]})).unwrap();
assert!(!s.doc().unwrap().stroke_mixed().weight);
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
// A stroke row on the group itself: a weight still goes to the edges the panel shows.
s.edit("t", |d, _| {
d.node_mut(g).unwrap().appearance.set_stroke(Paint::solid(Color::BLACK));
Ok(())
})
.unwrap();
s.execute("stroke.set", &json!({"weight": 3})).unwrap();
assert!(part_looks(&s, g).1.iter().all(|e| e.stroke_width() == 3.0));
assert_eq!(node(&s, g).appearance.stroke().map(|st| st.width), Some(1.0));
}
/// A selected Live Paint group with no part of the edited kind is still a selection: a stroke edit
/// of a group without edges, or a fill gradient edit of a group without faces, changes nothing and
/// leaves the settings for new art as they are.
#[test]
fn live_paint_group_without_parts_of_the_edited_kind_leaves_new_art_alone() {
let mut s = session();
let g = live(&mut s);
let edge_ids: Vec<NodeId> = vectorcraft_tools::builder::edges(&node(&s, g)).iter().map(|e| e.id).collect();
s.edit("t", |d, _| {
d.children_mut(Some(g)).unwrap().retain(|c| !edge_ids.contains(&c.id));
Ok(())
})
.unwrap();
assert!(part_looks(&s, g).1.is_empty());
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
let looks = part_looks(&s, g);
let (paint0, stroke0) = (s.paint.clone(), s.new_art_stroke());
s.execute("stroke.set", &json!({"cap": "round"})).unwrap();
s.execute("stroke.set", &json!({"weight": 4})).unwrap();
s.execute("stroke.weightUp", &json!({})).unwrap();
s.execute("stroke.setAdvanced", &json!({"arrowScale": [200, 150]})).unwrap();
assert_eq!((s.paint.clone(), s.new_art_stroke()), (paint0, stroke0), "new art keeps its stroke");
assert_eq!(part_looks(&s, g), looks);
let mut s = session();
let line = NodeId(s.execute("shape.line", &json!({"x1": 0, "y1": 0, "x2": 100, "y2": 0})).unwrap()["id"].as_u64().unwrap());
let edges_only = NodeId(s.execute("livePaint.make", &json!({"ids": [line.0]})).unwrap()["id"].as_u64().unwrap());
s.execute("select.set", &json!({"ids": [edges_only.0]})).unwrap();
let looks = part_looks(&s, edges_only);
let paint0 = s.paint.clone();
s.execute("paint.editGradient", &json!({"stroke": false, "angle": 45})).unwrap();
assert_eq!(s.paint, paint0, "new art keeps its fill");
assert_eq!(part_looks(&s, edges_only), looks);
}
/// A Live Paint group of 50 pt squares side by side, 50 pt tall, with their left sides at each of
/// `xs`.
fn live_squares(s: &mut Session, xs: &[f64]) -> NodeId {
+15
View File
@@ -4734,6 +4734,21 @@ already walks Image Trace. Short agent entry points:
dialog's OK) when every group already has the options and `closeGaps` finds no gap, and `livePaint.make` or
`livePaint.merge` given one Live Paint group alone, which they select. Such a fill or stroke also leaves the recent
colors and the last color as they are. `livePaint.gapOptions` makes a group's faces again, with new ids, only when it adds a path or when Gap Detection is turned on or off or given a new size while it is on.
With a tool other than the Live Paint Bucket, a whole Live Paint group that is selected, given in `ids`, or inside a
selected group takes a fill on its faces only and a stroke on its edges only, and its hidden source paths keep their
paint. Without an `item`, `paint.setFill`, `paint.setStroke`, `paint.lastColor`, `paint.lastGradient` and
`paint.none` paint the faces or the edges. `paint.editGradient`, `paint.setGradientGeom` and the `paint.freeform`
point and line edits change the faces' or the edges' gradients, `paint.invert` and `paint.complement` recolor the
faces' fills or the edges' strokes, and `stroke.set`, `stroke.weightUp`, `stroke.weightDown` and
`stroke.setAdvanced` change the edges. The Fill proxy shows the faces' fill, and the Stroke proxy, the Stroke panel
and the Control bar show the edges' stroke. A face or edge selected or given together with its whole group follows
the group's rule: a fill does not reach an edge, and a stroke does not reach a face. `paint.swap` gives the faces
the stroke the edges share and gives the edges the fill the faces share, with a gradient fitted to each face or
edge. It leaves a group as it is when its faces' fills or its edges' strokes differ, when any of them is a freeform
gradient, or when it has no face or no edge. `paint.default` replaces each face's appearance with no fill and each
edge's appearance with a 0.5 pt black stroke, also when the document's Default Graphic Style is redefined. With
only Live Paint groups selected or given, the fill and stroke for new art become no fill and a 0.5 pt black stroke;
with New Art Has Basic Appearance off, new art then takes the selection's appearance, as after any command.
`brush.selectionArt {ids?|id?}` (a query) replies `{art}`: the object that `brush.new` given the same `ids` or `id`,
or the same selection, takes as a new scatter or art brush's art and as a new pattern brush's side tile. Several
+1
View File
@@ -1892,6 +1892,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
As VectorCraft's own rule, OK in Live Paint Selection Tool Options, Live Paint Bucket Options, Gap Options and Tile Edge Color gives an error for a color with an alpha part (`#rrggbbaa` or `#rgba`) and changes nothing.
As VectorCraft's own rule, a Live Paint edit that changes nothing records no undo step, keeps the redo steps and leaves a saved document saved: a Live Paint Bucket click or drag over faces that already have the fill, a stroke on an edge that already has the paint and weight, Gap Options OK with the options the groups have and no gap to close, and Make or Merge with one Live Paint group alone. Such a fill or stroke also leaves the recent colors as they are. Regression tests: `live_paint_fill_same_paint_is_no_op`, `live_paint_bucket_click_with_the_face_paint_is_no_op`, `live_paint_stroke_edge_same_paint_and_width_is_no_op`, `live_paint_gap_options_same_values_are_no_op`, `live_paint_gap_options_close_without_gaps_is_no_op`, `live_paint_make_existing_group_is_no_op` and `live_paint_merge_single_group_is_no_op` in `crates/engine/src/tests/build.rs`, and `ok_on_unchanged_options_records_no_undo_step` in `crates/ui-egui/src/dialogs/live_paint_gaps.rs`.
As VectorCraft's own rule, the Live Paint Bucket replaces all of a face's fills, or all of an edge's strokes, with one fill or stroke of the paint, shown, fully opaque and blending normally, so a lower fill or stroke no longer draws under the new paint and a fill or stroke of none leaves nothing of that kind drawing; the face's strokes, the edge's fills, the part's own opacity and the topmost shown stroke's dashes, caps and arrowheads stay as they are, and a part that already has only that one fill or stroke records no undo step. [The help page](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/learn-painting-basics/paint-with-the-live-paint-bucket-tool.html) says the tool paints faces with the current fill and edges with the current stroke. Regression tests: `live_paint_bucket_replaces_every_fill_row`, `live_paint_stroke_edge_replaces_every_stroke_row` and `live_paint_stroke_edge_paints_the_shown_stroke` in `crates/engine/src/tests/build.rs`.
As VectorCraft's own rule, with a tool other than the Live Paint Bucket, a fill given to a whole selected Live Paint group paints its faces only and a stroke paints its edges only, and the hidden source paths keep their paint. Swap Fill and Stroke trades the fill the faces share with the stroke the edges share, and Default Fill and Stroke leaves the faces with no fill and gives the edges a 0.5 pt black stroke (`docs/mcp.md`). Evidence: `tests::build::{live_paint_group_fill_goes_to_faces_and_stroke_to_edges, live_paint_group_swap_trades_the_faces_fill_and_the_edges_stroke, live_paint_group_default_clears_the_faces_and_gives_the_edges_a_thin_black_stroke, live_paint_group_invert_recolors_the_faces_fill, live_paint_group_gradient_vector_and_freeform_edits_change_its_faces, live_paint_group_stroke_panel_edits_change_its_edges, live_paint_group_rules_stop_where_paint_commands_stop, live_paint_group_without_parts_of_the_edited_kind_leaves_new_art_alone}`.
As VectorCraft's own rule, `tool.setOption` for the Live Paint Bucket and the Live Paint Selection tool, chosen or not, checks every value before it sets any: a switch that is not `true` or `false`, a `color` that is not an RGB color or a layer color's name, or that has an alpha part, a `width` that is not a number and an option the tool does not have give an error naming the option, and nothing is set or saved. A `width` outside 1 to 20 px is still set to the nearest end of that range. Saved settings that hold an invalid value still load, and the tool keeps its default for that option. Evidence: `tests::build::{live_paint_tool_options_refuse_invalid_values_and_change_nothing, live_paint_tool_options_take_rgb_colors_and_clamp_the_width, live_paint_tools_load_saved_settings_with_invalid_values}`.
As VectorCraft's own rule, `tool.setOption` for the Shape Builder, chosen or not, checks every value the same way: a switch that is not `true` or `false`, a `pickColorFrom` or `selection` that is not one of its names, a `gapLength` that is not a number, a `highlightColor` that is not an RGB color or a layer color's name, or that has an alpha part, and an option the tool does not have give an error naming the option, and nothing is set or saved. A `gapLength` outside 0 to 72 pt is still set to the nearest end of that range. Evidence: `tests::build::{shape_builder_tool_options_refuse_invalid_values_and_change_nothing, shape_builder_tool_options_take_valid_values_and_clamp_the_gap}`.
A drag of 3 screen pixels or more with the Live Paint Selection tool draws a marquee and selects the faces and edges it touches, partly enclosed ones included, and a Shift-drag adds them to the selection or removes them from it ([Modify Live Paint groups](https://web.archive.org/web/20261006115247/https://helpx.adobe.com/illustrator/desktop/paint-and-fill/learn-painting-basics/modify-live-paint-groups.html)). A click and a marquee change the selection on release, and Escape before the release leaves the selection as it was. Locked Live Paint groups, those on a locked layer or artboard, and in isolation mode those outside the isolated art are not highlighted or selected.