Scripts: empty paths scale their strokes and refuse a compound's pattern

resize and transform with changeLineWidths equal to the scale now scale the
strokes, dashes and effects of a path with no anchors, as they do for a path
with anchors. A member with no anchors of a compound path or compound shape
that shows a pattern is refused when the call transforms patterns, as a path
with a pattern of its own is.

node.move's description and docs/mcp.md now say that a compound path on a
locked artboard takes a path while it is new art there and still selected.
This commit is contained in:
dotCooCoo committed 2026-12-03 04:19:34 -08:00
1 parent 7e8c6bae5c
commit 06fc659299
6 files changed
+74 -12

No files matched your search

+1 -1
View File
@@ -400,7 +400,7 @@ pub(super) fn flush(h: &super::Host) -> std::result::Result<(), HostError> {
/// The object whose paint the path `n` with id `id` shows: its compound path or compound shape
/// when it is a member of one, since the paint commands paint that owner in its place.
fn paint_owner<'a>(d: &'a crate::Document, id: NodeId, n: &'a crate::doc::Node) -> &'a crate::doc::Node {
pub(super) fn paint_owner<'a>(d: &'a crate::Document, id: NodeId, n: &'a crate::doc::Node) -> &'a crate::doc::Node {
d.parent_of(id).and_then(|p| d.node(p)).filter(|p| matches!(p.kind, NodeKind::Compound { .. }) || p.is_compound_shape()).unwrap_or(n)
}
+19 -8
View File
@@ -194,13 +194,15 @@ fn apply(h: &Host, item: Item, m: Matrix, about: Option<&Data>, opts: &Options,
if matrix::singular(m) {
return Err(HostError::Error("the transformation is singular and would flatten the object".into()));
}
let (locked, hidden, on_locked, bounds, uses_pattern, clipped) = with_doc(h, item.doc, |_, st| {
let (locked, hidden, on_locked, bounds, uses_pattern, shows_pattern, clipped) = with_doc(h, item.doc, |_, st| {
let d = &st.doc;
let line = d.ancestry(item.id);
let mut locked = line.as_ref().is_none_or(|a| a.iter().any(|i| d.node(*i).is_none_or(|n| n.locked)));
let hidden = line.as_ref().is_none_or(|a| a.iter().chain(std::iter::once(&item.id)).any(|i| d.node(*i).is_none_or(|n| !n.visible)));
let (mut uses, mut clipped) = (false, false);
let (mut uses, mut shows, mut clipped) = (false, false, false);
if let Some(n) = d.node(item.id) {
// A member of a compound path or compound shape shows its compound's paint.
shows = vectorcraft_doc::pattern::uses_pattern(paths::paint_owner(d, item.id, n), None);
n.walk(&mut |c| {
locked |= c.locked;
uses |= vectorcraft_doc::pattern::uses_pattern(c, None);
@@ -208,7 +210,7 @@ fn apply(h: &Host, item: Item, m: Matrix, about: Option<&Data>, opts: &Options,
matches!(c.kind, vectorcraft_doc::NodeKind::Group { clip: true, .. } | vectorcraft_doc::NodeKind::Layer { clip: true, .. });
});
}
(locked, hidden, d.on_locked_artboard(item.id), d.bounds_of(&[item.id], false), uses, clipped)
(locked, hidden, d.on_locked_artboard(item.id), d.bounds_of(&[item.id], false), uses, shows || uses, clipped)
});
if locked {
return Err(HostError::Error(format!("{LOCKED}: {}", item.id.0)));
@@ -235,11 +237,20 @@ fn apply(h: &Host, item: Item, m: Matrix, about: Option<&Data>, opts: &Options,
// A path with no anchors has no bounds to turn or scale about, and turning or scaling it
// changes nothing; only a stroke weight the call sets is applied. A pattern it uses has no
// point to turn or scale about either, so a call that asks to transform it is refused.
(Some(_), None) if paths::is_path(h, item) && !(opts.patterns && uses_pattern) => {
if let Some(w) = weight {
paths::set_stroke_weight(h, item, w)?;
}
return Ok(Data::Undefined);
(Some(_), None) if paths::is_path(h, item) && !(opts.patterns && shows_pattern) => {
// A call that scales strokes and effects with the object still scales the path's own
// strokes and effects, as for a path with anchors.
return atomically(h, |h| {
if opts.strokes {
let c = on_page(m, Point::ORIGIN).as_coeffs();
let p = json!({"ids": [item.id.0], "matrix": c, "objects": true, "patterns": false, "strokes": true});
edit_item(h, item, "object.transform", &p)?;
}
if let Some(w) = weight {
paths::set_stroke_weight(h, item, w)?;
}
Ok(Data::Undefined)
});
}
(Some(_), None) => return Err(HostError::Error("the object has no bounds".into())),
(None, _) => Point::ORIGIN,