Brushes: a Paintbrush stroke that changes a path's brush clears the path's own brush settings

Extending a path with brush.freehand and another brush set the new brush
but kept the settings Options of Selected Object stored for the old one.
They are now cleared, as brush.apply clears them.
This commit is contained in:
dotCooCoo
2026-11-15 10:49:11 -08:00
parent 87acb57d0d
commit 74370b1cdb
4 changed files with 26 additions and 3 deletions
+1 -1
View File
@@ -171,7 +171,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Options of Selected Object…",
[],
None,
"{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle, roundness, size, variation, modes; scatter size, spacing, scatter, rotation, modes, rotation_relative_to_path, colorization; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives; a null item of an array such as size: [40, null] keeps each stroke's own item, else the brush's)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, or stroke.setAdvanced with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}",
"{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle, roundness, size, variation, modes; scatter size, spacing, scatter, rotation, modes, rotation_relative_to_path, colorization; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives; a null item of an array such as size: [40, null] keeps each stroke's own item, else the brush's)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, stroke.setAdvanced or a brush.freehand extend with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}",
has_doc,
brush_object_options
),
+5 -1
View File
@@ -174,9 +174,13 @@ fn no_stroke(name: &str) -> EngineError {
bad("brush.freehand", format!("cannot apply brush `{name}`: path has no stroke"))
}
/// Sets brush `name` on the stroke of object `id` of `d`.
/// Sets brush `name` on the stroke of object `id` of `d`. The stroke's own settings for another
/// brush (Options of Selected Object) are cleared.
fn set_brush(d: &mut Document, id: NodeId, name: &str) {
if let Some(st) = d.node_mut(id).and_then(|n| n.appearance.stroke_mut()) {
if st.brush.as_deref() != Some(name) {
st.brush_options.clear();
}
st.brush = Some(name.to_string());
}
}
+18
View File
@@ -175,6 +175,24 @@ fn options_of_selected_object_null_items_keep_each_paths_own() {
assert_eq!(own_options(&s, c)["size"], json!([brush_size[0], 150.0]), "brush size {brush_size}");
}
#[test]
fn options_of_selected_object_go_when_a_freehand_stroke_changes_the_brush() {
let mut s = session();
let a = line(&mut s);
s.execute("brush.apply", &json!({"name": "Arrow", "ids": [a.0]})).unwrap();
s.execute("brush.objectOptions", &json!({"ids": [a.0], "params": {"width": 50}})).unwrap();
let extend = |s: &mut Session, brush: &str, points: Value| {
s.execute("brush.freehand", &json!({"points": points, "style": "brush", "brush": brush, "extend": {"id": a.0}})).unwrap();
};
// Continuing the path with its own brush keeps the settings.
extend(&mut s, "Arrow", json!([[0, 0], [40, 30], [80, 10]]));
assert_eq!(own_options(&s, a), json!({"width": 50.0}));
// Another brush, with a stroke or with only the brush changing, clears them.
extend(&mut s, "Diamonds", json!([[0, 0]]));
assert_eq!(brush_of(&s, a).as_deref(), Some("Diamonds"));
assert_eq!(own_options(&s, a), json!({}));
}
#[test]
fn options_of_selected_object_keys_convert_with_the_document() {
let mut s = session();
+2 -1
View File
@@ -3430,7 +3430,8 @@ already walks Image Trace. Short agent entry points:
refuses `params` together with `reset`, a selection with no brushed path, paths whose brushes are of different
types, a bristle brush and a field the type does not take. It records one undo step, and none when nothing changes.
`brush.options` edits still reach the settings a path does not set, `brush.apply`, a brush change in
`stroke.setAdvanced` and removing the brush clear the path's settings, and renaming the brush keeps them. Without
`stroke.setAdvanced`, Global Edit or a `brush.freehand` extend, and removing the brush clear the path's settings,
and renaming the brush keeps them. Without
`params` or `reset` the command only returns the first path's settings. The native file saves them on the stroke as `brush_options`.
- Pen tilt, bearing and barrel rotation (#764): `path.freehand` and `brush.freehand` take points as
`[x, y, pressure, tiltX, tiltY, rotation]` or `{x, y, pressure?, tiltX?, tiltY?, rotation?}`, with `null` for what a