Merge pull request #10654 from dotCooCoo/fix/script-image-matrix-locks

Scripts: image matrix assignment refuses locked and hidden images
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-03 07:34:43 -08:00
commit de71cfc9ef
4 files changed
+59 -5

No files matched your search

+18 -1
View File
@@ -481,7 +481,8 @@ fn area_of(m: Affine) -> bool {
/// `matrix = Matrix`: `object.transform` of the image by what takes its pixels to the new matrix.
/// A matrix with no area, one that puts a corner of the image outside the canvas, or a distorted
/// image is refused before anything changes; the matrix the image has already changes nothing.
/// image is refused before anything changes, and so is a locked or hidden image or one on a locked
/// artboard, as the transform methods refuse them; the matrix the image has already changes nothing.
fn set_matrix(h: &Host, a: &[Data], cls: &str) -> Answer {
let item = this_of(h, a, cls)?;
let m = matrix_value(arg(a, 1))?;
@@ -492,6 +493,22 @@ fn set_matrix(h: &Host, a: &[Data], cls: &str) -> Answer {
if n.is_distorted_image() {
return Err(HostError::Error(DISTORTED.into()));
}
// The transform methods' refusals: a locked or hidden image, one inside a locked or hidden
// layer or group, and one on a locked artboard, whether or not the matrix changes.
let d = &st.doc;
let line = d.ancestry(item.id);
let any = |f: fn(&vectorcraft_doc::Node) -> bool| {
line.as_ref().is_none_or(|l| l.iter().chain(std::iter::once(&item.id)).any(|i| d.node(*i).is_none_or(f)))
};
if any(|n| n.locked) {
return Err(HostError::Error(format!("{}: {}", super::transform::LOCKED, item.id.0)));
}
if any(|n| !n.visible) {
return Err(HostError::Error(format!("{}: {}", super::transform::HIDDEN, item.id.0)));
}
if super::on_locked_artboard(h, st, item.id) {
return Err(HostError::Error(format!("{}: {}", super::transform::ON_LOCKED_ARTBOARD, item.id.0)));
}
let f = frame(st)?;
let target = Affine::new(match h.dom.coords.get() {
Coords::Document => [m[0], -m[1], m[2], -m[3], m[4] + f.left0, f.bottom0 - m[5]],
+3 -3
View File
@@ -41,16 +41,16 @@ use super::matrix::{self, Matrix};
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";
pub(super) const ON_LOCKED_ARTBOARD: &str = "cannot transform objects on a locked artboard";
/// The error for a locked object.
const LOCKED: &str = "cannot transform locked objects";
pub(super) const LOCKED: &str = "cannot transform locked objects";
/// The error for a guide while guides are locked.
const GUIDES_LOCKED: &str = "cannot transform a guide while guides are locked";
/// The error for a hidden object.
const HIDDEN: &str = "cannot transform hidden objects";
pub(super) const HIDDEN: &str = "cannot transform hidden objects";
/// The identity matrix.
const IDENTITY: Matrix = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0];