mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 02:07:10 +01:00
Scripts: build on main's optional item bounds and painting-tool check
main's item_rect now gives no bounds for an empty object, and the Live Paint Bucket check became tool_paints for the fill and the stroke. rotate and resize leave a path without bounds unchanged, and appearance.setNewArt uses the same inheritance test as paint.rs.
This commit is contained in:
1 parent
d2a14e2ef5
commit
0d5850f616
5 files changed
+28
-25
No files matched your search
@@ -172,7 +172,11 @@ fn set_new_art(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
return Err(bad(C, "dashOffset needs a dash pattern"));
|
||||
}
|
||||
let nothing = fill.is_none() && stroke.is_none() && change.is_empty() && fill_overprint.is_none() && stroke_overprint.is_none();
|
||||
if !nothing && !s.prefs.new_art_basic && !s.bucket_paints() && s.active().is_some_and(|st| !st.selection.subjects().is_empty()) {
|
||||
if !nothing
|
||||
&& !s.prefs.new_art_basic
|
||||
&& !(s.tool_paints(false) && s.tool_paints(true))
|
||||
&& s.active().is_some_and(|st| !st.selection.subjects().is_empty())
|
||||
{
|
||||
return Err(bad(
|
||||
C,
|
||||
"with New Art Has Basic Appearance off, new art takes the selected object's appearance: deselect it or turn the option on",
|
||||
|
||||
@@ -2868,9 +2868,7 @@ fn classes(link: &Link) -> Vec<HostClass> {
|
||||
]);
|
||||
document.extend(defaults::document_members(l));
|
||||
document.extend(
|
||||
["layers", "artboards", "groupItems", "swatches", "symbols", "activeLayer", "saveAs", "close"]
|
||||
.into_iter()
|
||||
.map(|m| later(l, "Document", m)),
|
||||
["layers", "artboards", "groupItems", "swatches", "symbols", "activeLayer", "saveAs", "close"].into_iter().map(|m| later(l, "Document", m)),
|
||||
);
|
||||
document.extend(variables::document_members(l));
|
||||
document.push(("tags".into(), get(l, tags::doc_tags), MemberInfo { collection: true, ..typed("Tags") }));
|
||||
|
||||
@@ -192,18 +192,10 @@ pub(super) fn document_members(l: &Link) -> Vec<Described> {
|
||||
named(vec![
|
||||
("defaultFillColor", property(l, |h, a| default_color(h, a, true), |h, a| set_default_color(h, a, true)), typed("Color")),
|
||||
("defaultFilled", property(l, |h, a| default_painted(h, a, true), |h, a| set_default_painted(h, a, true)), typed("boolean")),
|
||||
(
|
||||
"defaultFillOverprint",
|
||||
property(l, |h, a| default_overprint(h, a, true), |h, a| set_default_overprint(h, a, true)),
|
||||
typed("boolean"),
|
||||
),
|
||||
("defaultFillOverprint", property(l, |h, a| default_overprint(h, a, true), |h, a| set_default_overprint(h, a, true)), typed("boolean")),
|
||||
("defaultStrokeColor", property(l, |h, a| default_color(h, a, false), |h, a| set_default_color(h, a, false)), typed("Color")),
|
||||
("defaultStroked", property(l, |h, a| default_painted(h, a, false), |h, a| set_default_painted(h, a, false)), typed("boolean")),
|
||||
(
|
||||
"defaultStrokeOverprint",
|
||||
property(l, |h, a| default_overprint(h, a, false), |h, a| set_default_overprint(h, a, false)),
|
||||
typed("boolean"),
|
||||
),
|
||||
("defaultStrokeOverprint", property(l, |h, a| default_overprint(h, a, false), |h, a| set_default_overprint(h, a, false)), typed("boolean")),
|
||||
(
|
||||
"defaultStrokeWidth",
|
||||
property(l, default_stroke_width, set_default_stroke_width),
|
||||
|
||||
@@ -67,9 +67,9 @@ use vectorcraft_js::{Data, HostClass, HostError, HostItem, HostMember, MemberInf
|
||||
use vectorcraft_tools::params::gradient_params;
|
||||
|
||||
use super::{
|
||||
Answer, Coords, Described, Doc, Item, Link, NOT_FOUND, STALE_ITEM, arg, boolean, class, colors, command, command_value, coordinate, doc_of, edit_item,
|
||||
editable, find_doc, float, frame, get, given, handle_of, id_of, id_parts, item_of, item_rect, later, method, named, num, number, on_doc, pair,
|
||||
point, point_get, point_method, point_property, property, returns, this_doc, typed, whole, with_doc,
|
||||
Answer, Coords, Described, Doc, Item, Link, NOT_FOUND, STALE_ITEM, arg, boolean, class, colors, command, command_value, coordinate, doc_of,
|
||||
edit_item, editable, find_doc, float, frame, get, given, handle_of, id_of, id_parts, item_of, item_rect, later, method, named, num, number,
|
||||
on_doc, pair, point, point_get, point_method, point_property, property, returns, this_doc, typed, whole, with_doc,
|
||||
};
|
||||
use crate::{DocState, NodeId, NodeKind};
|
||||
|
||||
@@ -1155,8 +1155,9 @@ fn path_rotate(h: &super::Host, a: &[Data]) -> Answer {
|
||||
let place = about_name(arg(a, 6))?;
|
||||
let mut params = json!({"angle": angle});
|
||||
transform_options(a, 2, &mut params)?;
|
||||
if angle.rem_euclid(360.0) != 0.0 {
|
||||
let (r, _) = item_rect(h, item, false)?;
|
||||
if angle.rem_euclid(360.0) != 0.0
|
||||
&& let (Some(r), _) = item_rect(h, item, false)?
|
||||
{
|
||||
let origin = about(h, item, place, r)?;
|
||||
params["origin"] = json!([origin.x, origin.y]);
|
||||
edit_path(h, item, "object.rotate", params)?;
|
||||
@@ -1185,8 +1186,9 @@ fn path_resize(h: &super::Host, a: &[Data]) -> Answer {
|
||||
if new_width.is_some_and(|w| w > MAX_STROKE_WIDTH) {
|
||||
return Err(HostError::Range("changeLineWidths would make the stroke weight more than 1000 points".into()));
|
||||
}
|
||||
if sx != 100.0 || sy != 100.0 {
|
||||
let (r, _) = item_rect(h, item, false)?;
|
||||
if (sx != 100.0 || sy != 100.0)
|
||||
&& let (Some(r), _) = item_rect(h, item, false)?
|
||||
{
|
||||
let origin = about(h, item, place, r)?;
|
||||
params["origin"] = json!([origin.x, origin.y]);
|
||||
edit_path(h, item, "object.scale", params)?;
|
||||
@@ -1637,7 +1639,12 @@ fn pt_remove(h: &super::Host, a: &[Data]) -> Answer {
|
||||
pub(super) fn path_item_members(l: &Link) -> Vec<Described> {
|
||||
let transform = |first: &[(&'static str, &'static str)]| {
|
||||
let mut args: Vec<(&str, &str)> = first.to_vec();
|
||||
args.extend([("changePositions", "boolean"), ("changeFillPatterns", "boolean"), ("changeFillGradients", "boolean"), ("changeStrokePattern", "boolean")]);
|
||||
args.extend([
|
||||
("changePositions", "boolean"),
|
||||
("changeFillPatterns", "boolean"),
|
||||
("changeFillGradients", "boolean"),
|
||||
("changeStrokePattern", "boolean"),
|
||||
]);
|
||||
args
|
||||
};
|
||||
let mut resize = transform(&[("scaleX", "number"), ("scaleY", "number")]);
|
||||
|
||||
@@ -1243,9 +1243,11 @@ fn a_startup_preset_alone_gives_its_first_size() {
|
||||
#[test]
|
||||
fn page_item_members_not_built_yet_throw_on_read_and_assignment() {
|
||||
let (mut s, _, _) = doc();
|
||||
for source in
|
||||
["app.activeDocument.pageItems[0].isIsolated;", "app.activeDocument.pageItems[0].uuid = 'x';", "app.activeDocument.pageItems[0].transform(5);"]
|
||||
{
|
||||
for source in [
|
||||
"app.activeDocument.pageItems[0].isIsolated;",
|
||||
"app.activeDocument.pageItems[0].uuid = 'x';",
|
||||
"app.activeDocument.pageItems[0].transform(5);",
|
||||
] {
|
||||
assert!(failure(&mut s, source).contains("is not available yet"), "{source}");
|
||||
}
|
||||
assert!(failure(&mut s, "app.activeDocument.layers = 1;").contains("Document.layers is not available yet"));
|
||||
|
||||
Reference in new issue
Block a user