From ea8951536d587c66eee6b4c2d46244182fa4c23a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 18:39:36 -0800 Subject: [PATCH] Scripts: resize scales a compound member's stroke and refuses negative line widths A path inside a compound path or compound shape takes its visible stroke from the compound, so resize with changeLineWidths sets the compound's stroke weight through stroke.set, in the same savepoint as the transform. A negative changeLineWidths throws. The PathItem progress line now says paths take the page item transforms. --- crates/engine/src/script/dom/paths.rs | 13 ++++++-- crates/engine/src/script/dom/transform.rs | 32 +++++++++++++------ crates/engine/src/tests/script_dom_paths.rs | 13 ++++++++ .../engine/src/tests/script_dom_transform.rs | 1 + docs/mcp.md | 5 ++- docs/target-app-parity.md | 2 +- 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/script/dom/paths.rs b/crates/engine/src/script/dom/paths.rs index 2a9f69ec04..3b91756c91 100644 --- a/crates/engine/src/script/dom/paths.rs +++ b/crates/engine/src/script/dom/paths.rs @@ -1096,9 +1096,10 @@ fn path_set_stroke_overprint(h: &super::Host, a: &[Data]) -> Answer { // ---- PathItem stroke weights for `resize` ---- /// The stroke weight `resize`'s `changeLineWidths` of `percent` gives the path `item`, or `None` -/// when the path is not a path (the caller refuses the value) or the weight stays. -pub(super) fn resized_stroke_weight(h: &super::Host, item: Item, percent: f64) -> std::result::Result, HostError> { - if !(0.0..=100_000.0).contains(&percent) { +/// when the weight stays. A `custom` percent, one other than the resize's own scale, is at most +/// 100000. +pub(super) fn resized_stroke_weight(h: &super::Host, item: Item, percent: f64, custom: bool) -> std::result::Result, HostError> { + if custom && !(0.0..=100_000.0).contains(&percent) { return Err(HostError::Range("changeLineWidths must be from 0 to 100000 percent".into())); } let width = look(h, item)?.width; @@ -1114,6 +1115,12 @@ pub(super) fn is_path(h: &super::Host, item: Item) -> bool { with_doc(h, item.doc, |_, st| st.doc.node(item.id).is_some_and(|n| matches!(n.kind, NodeKind::Path { .. }))) } +/// Whether the path `item` is a member of a compound path or compound shape, whose stroke the +/// compound holds. +pub(super) fn paint_held_by_compound(h: &super::Host, item: Item) -> bool { + with_doc(h, item.doc, |_, st| st.doc.node(item.id).is_some_and(|n| paint_owner(&st.doc, item.id, n).id != item.id)) +} + /// Sets the stroke weight of the path `item` to `weight` points. pub(super) fn set_stroke_weight(h: &super::Host, item: Item, weight: f64) -> std::result::Result<(), HostError> { edit_path(h, item, "stroke.set", json!({"weight": weight})).map(|_| ()) diff --git a/crates/engine/src/script/dom/transform.rs b/crates/engine/src/script/dom/transform.rs index 9cda64e60f..89e601a0ac 100644 --- a/crates/engine/src/script/dom/transform.rs +++ b/crates/engine/src/script/dom/transform.rs @@ -33,7 +33,7 @@ use vectorcraft_geom::{Affine, Point, Rect}; use vectorcraft_js::{Data, HostError}; use super::matrix::{self, Matrix}; -use super::{Answer, Coords, Host, Item, arg, coordinate, edit_item, frame, number, paths, this_item, with_doc}; +use super::{Answer, Coords, Host, Item, arg, atomically, coordinate, edit_item, frame, number, paths, this_item, with_doc}; /// The error for an object on a locked artboard. const ON_LOCKED_ARTBOARD: &str = "cannot transform objects on a locked artboard"; @@ -91,6 +91,9 @@ fn own_line_widths(d: &Data, m: Matrix) -> std::result::Result<(Option, f6 Data::Undefined => return Ok((Some(false), 100.0, 100.0)), d => number(d, "changeLineWidths")?, }; + if lw < 0.0 { + return Err(HostError::Range("changeLineWidths must not be negative".into())); + } // The determinant is taken past the range of a number, so a scale whose square is too large // for one still has its own value. let own = matrix::area_scale(m) * 100.0; @@ -239,14 +242,17 @@ fn apply(h: &Host, item: Item, m: Matrix, about: Option<&Data>, opts: &Options, let c = xf.as_coeffs(); let identity = xf == Affine::IDENTITY; let changes = if opts.objects { !identity } else { opts.patterns && uses_pattern && !identity }; - if changes { - let p = json!({"ids": [item.id.0], "matrix": c, "objects": opts.objects, "patterns": opts.patterns, "strokes": opts.strokes}); - edit_item(h, item, "object.transform", &p)?; - } - if let Some(w) = weight { - paths::set_stroke_weight(h, item, w)?; - } - Ok(Data::Undefined) + // The transformation and the stroke weight change together or not at all. + atomically(h, |h| { + if changes { + let p = json!({"ids": [item.id.0], "matrix": c, "objects": opts.objects, "patterns": opts.patterns, "strokes": opts.strokes}); + edit_item(h, item, "object.transform", &p)?; + } + if let Some(w) = weight { + paths::set_stroke_weight(h, item, w)?; + } + Ok(Data::Undefined) + }) } /// `translate(deltaX?, deltaY?, transformObjects?, transformFillPatterns?, transformFillGradients?, @@ -284,11 +290,17 @@ pub(super) fn resize(h: &Host, a: &[Data]) -> Answer { let mut opts = options(h, a, 3, CHANGE_NAMES)?; let item = this_item(h, a)?; let weight = match own_line_widths(arg(a, 7), m)? { + // The compound holds a member's visible stroke, so its weight is set through the compound + // as well as the member's own strokes and effects scaling. + (Some(true), lw, _) if paths::is_path(h, item) && paths::paint_held_by_compound(h, item) => { + opts.strokes = true; + paths::resized_stroke_weight(h, item, lw, false)? + } (Some(strokes), _, _) => { opts.strokes = strokes; None } - (None, lw, _) if paths::is_path(h, item) => paths::resized_stroke_weight(h, item, lw)?, + (None, lw, _) if paths::is_path(h, item) => paths::resized_stroke_weight(h, item, lw, true)?, (None, _, own) => return Err(other_line_widths(own)), }; apply(h, item, m, Some(arg(a, 8)), &opts, weight) diff --git a/crates/engine/src/tests/script_dom_paths.rs b/crates/engine/src/tests/script_dom_paths.rs index a30279c12a..2c616a88c5 100644 --- a/crates/engine/src/tests/script_dom_paths.rs +++ b/crates/engine/src/tests/script_dom_paths.rs @@ -676,6 +676,19 @@ fn filled_true_on_a_compound_member_places_the_gradient_on_the_compound() { } } +#[test] +fn resizing_a_compound_member_with_its_own_line_width_scales_the_compound_stroke() { + let (mut s, a, b) = doc(); + s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + s.execute("object.compoundPath.make", &json!({})).unwrap(); + let out = log( + &mut s, + "var p = app.activeDocument.pathItems[0]; p.strokeWidth = 4; p.resize(50, 50, true, true, true, true, 50);\ + vc.log(p.strokeWidth); vc.log(app.activeDocument.pathItems[1].strokeWidth);", + ); + assert_eq!(out, vec![json!(2), json!(2)], "the compound's stroke halves with the member"); +} + #[test] fn set_anchors_reads_smooth_false_as_a_corner() { let (mut s, a, _) = doc(); diff --git a/crates/engine/src/tests/script_dom_transform.rs b/crates/engine/src/tests/script_dom_transform.rs index 383053c0c2..0172fa8d86 100644 --- a/crates/engine/src/tests/script_dom_transform.rs +++ b/crates/engine/src/tests/script_dom_transform.rs @@ -287,6 +287,7 @@ fn bad_arguments_throw_and_change_nothing() { ("rotate()", "angle must be a finite number"), ("resize(50)", "scaleY must be a finite number"), ("resize(0, 50)", "must not be 0"), + ("resize(50, 50, true, true, true, true, -1)", "changeLineWidths must not be negative"), ("transform({})", "transformationMatrix must be a Matrix"), ("transform(app.getScaleMatrix(0))", "singular"), ("translate(1, 0, 'yes')", "transformObjects must be true or false"), diff --git a/docs/mcp.md b/docs/mcp.md index 832c2ba0f1..f69f7ea552 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3057,7 +3057,10 @@ through `$`: `changeLineWidths` is 100 (the default; stroke weights stay) or the transformation's own scale in percent, the square root of the area it scales by (stroke weights and effects scale with it). `resize` on a path also takes any other percent from 0 to 100000, which sets the stroke weight to that percent of what it was (through `stroke.set`, - at most 1000 points); another value throws the same error. A locked object, one inside a locked layer or group, a + at most 1000 points). On a member of a compound path or compound shape, the compound's stroke weight follows the + percent through `stroke.set`; when the percent is the resize's own scale, the member's own strokes and effects also + scale with it. Another value throws the same + error. A locked object, one inside a locked layer or group, a group that holds one, a hidden object or one inside a hidden layer or group, and an object on a locked artboard throw `cannot transform locked objects`, `cannot transform hidden objects` or `cannot transform objects on a locked artboard`. A scale of 0, a diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index dfaf0b07c7..dadab8ec2e 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1122,7 +1122,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Scripts: File › Scripts › Other Script… and `script.run` run a JavaScript file against the open documents as one transaction with one undo step for each changed document. A failed or stopped run puts every document back. `crates/engine/src/tests/script_run.rs`. - Scripts: a page item's `translate`, `rotate`, `resize` and `transform` move, turn, scale and transform the object by offsets, an angle, percentages or a `Matrix` record, about its center or a `Transformation` point, with positions, patterns, gradients and line widths following their arguments (https://ai-scripting.docsforadobe.dev/jsobjref/PageItem/). Each call runs `object.transform` inside the run's transaction; locked art, art on a locked artboard and bad arguments throw an error with nothing changed (`docs/mcp.md`). `crates/engine/src/tests/script_dom_transform.rs`. - Scripts: `app.preferences` reads, stores and removes values by key with the type they were set as, keeps them across runs and restarts, and turns the warning before a picked script on with the key `ShowExternalJSXWarning`, and off only after the person answers Yes to a confirm (https://ai-scripting.docsforadobe.dev/jsobjref/Preferences/; the confirm is VectorCraft's own rule); `app` makes, joins, inverts and compares `Matrix` records (https://ai-scripting.docsforadobe.dev/jsobjref/Matrix/), rounding each joined value once from its exact sum of products, and runs Copy, Cut and Paste on the active document inside the run's transaction (https://ai-scripting.docsforadobe.dev/jsobjref/Application/). `crates/engine/src/tests/script_dom_prefs.rs`. - - Scripts: `Document.pathItems` lists the paths and makes rectangles, rounded rectangles, ellipses, polygons, stars and empty paths with the defaults the help page https://ai-scripting.docsforadobe.dev/jsobjref/PathItems/ gives; each path's points, closed state, fill rule, area, length, guide state, selected points, fill and stroke colors, stroke options and transforms read and change as https://ai-scripting.docsforadobe.dev/jsobjref/PathItem/, https://ai-scripting.docsforadobe.dev/jsobjref/PathPoints/ and https://ai-scripting.docsforadobe.dev/jsobjref/PathPoint/ describe them, and `RGBColor`, `CMYKColor`, `GrayColor`, `LabColor` and `NoColor` make colors (`docs/mcp.md`). The transforms move gradients with the art: `changeFillGradients` false throws an error, as do `changeFillPatterns` and `changeStrokePattern` given as different values, and `transform` is not there yet (`docs/mcp.md` lists these limits). Gradient stops are not there yet. A `PathPoint` of a path in an Objects on Path group goes stale when an edit of another path in the group moves it. `crates/engine/src/tests/script_dom_paths.rs`. + - Scripts: `Document.pathItems` lists the paths and makes rectangles, rounded rectangles, ellipses, polygons, stars and empty paths with the defaults the help page https://ai-scripting.docsforadobe.dev/jsobjref/PathItems/ gives; each path's points, closed state, fill rule, area, length, guide state, selected points, fill and stroke colors, stroke options and transforms read and change as https://ai-scripting.docsforadobe.dev/jsobjref/PathItem/, https://ai-scripting.docsforadobe.dev/jsobjref/PathPoints/ and https://ai-scripting.docsforadobe.dev/jsobjref/PathPoint/ describe them, and `RGBColor`, `CMYKColor`, `GrayColor`, `LabColor` and `NoColor` make colors (`docs/mcp.md`). A path takes the page item transforms, and `resize` also sets its stroke weight to a `changeLineWidths` percent from 0 to 100000 (at most 1000 points; a member of a compound sets the compound's stroke); gradients move with positions, so a `changeFillGradients` different from `changePositions` throws an error, as do `changeFillPatterns` and `changeStrokePattern` given as different values (`docs/mcp.md` lists these limits). Gradient stops are not there yet. A `PathPoint` of a path in an Objects on Path group goes stale when an edit of another path in the group moves it. `crates/engine/src/tests/script_dom_paths.rs`. - Scripts: a document's `default*` members (https://ai-scripting.docsforadobe.dev/jsobjref/Document/) read and set the fill, stroke and stroke options of the next object drawn through `appearance.setNewArt`, leaving the selection and its art as they were, and `scaleFactor` reads 1 (`docs/mcp.md`). `crates/engine/src/tests/script_dom_defaults.rs`. - Scripts: `app.undo()` and `app.redo()` undo and redo the edits the run made, and each document open before and after the run that it changed gets one undo step. `crates/engine/src/tests/script_dom.rs`. - Scripts: `document.textFrames` makes point type, area type and type on a path, and each text frame gives its kind, its contents, its text as text ranges with their characters, words and paragraphs (which can add text), their character attributes (size, leading, tracking, baseline shift, scales, rotation, underline, strikethrough, font) and paragraph attributes (alignment, indents, space before and after), outlines and point and area conversion; `app.textFonts` lists the fonts, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/TextFrameItems/, https://ai-scripting.docsforadobe.dev/jsobjref/TextFrameItem/, https://ai-scripting.docsforadobe.dev/jsobjref/TextRange/ and https://ai-scripting.docsforadobe.dev/jsobjref/TextFonts/ describe them (`docs/mcp.md`). Offsets count UTF-16 units, VectorCraft's own rule. Lines, tab stops and colors are not there yet. `crates/engine/src/tests/script_text.rs`.