mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 13:32:45 -05:00
Color Effects: copied artboards leave other artboards' screen print marks alone
Duplicate Artboards, Alt-drag, Copy and Cut select art by position, so a marks group of another artboard lying wholly on the copied one was copied and kept its owner. Create Screen Print Marks then found two groups for that owner. Each marks group on the marks layer now goes with the artboard it belongs to: it is copied with that artboard when that one is copied too, and otherwise stays where it is. A group moved off the marks layer, or one whose artboard was deleted, is copied like other art. When the marks layer was deleted, pasting an artboard with its marks made the layer again without its marks tag, so the next run made a second marks layer. The layer a paste makes for those marks is now the marks layer when the document has none.
This commit is contained in:
1 parent
3c60bf4d6a
commit
0c679ddf64
8 files changed
+164
-11
No files matched your search
@@ -16,7 +16,9 @@ mod shapes;
|
||||
mod typetools;
|
||||
mod units;
|
||||
|
||||
pub(crate) use color::screen_marks::retag as retag_screen_marks;
|
||||
pub(crate) use color::screen_marks::{
|
||||
LAYER_NAME as SCREEN_MARKS_LAYER, adopt_layer as adopt_screen_marks_layer, managed_owners as screen_marks_owners, retag as retag_screen_marks,
|
||||
};
|
||||
pub(crate) use image::{DecodedImages, refresh_color_masks};
|
||||
pub use packaging::{FoldAngles, fold_source, print_hidden, selection_fold_angles, selection_fold_lines};
|
||||
pub(crate) use packaging::{role_swatch_edited, role_swatches_merged};
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Create Screen Print Marks",
|
||||
["Object", "Plug-ins", "Color Effects"],
|
||||
None,
|
||||
"{positions?: [topLeft|top|topRight|left|right|bottomLeft|bottom|bottomRight…] (each at most once; default: [top, bottom, left, right]; [] draws no targets), size?: target width in pt 4..1000 (36), weight?: stroke weight in pt 0.1..20 (1), inset?: pt from the artboard's edge to the target's outer edge -1000..1000 (18; below 0 the targets sit outside the artboard), ink?: \"[Registration]\" (default) or a spot swatch's name (the targets and the file line), inks?: false (a line naming the document's spot inks, each name in its own ink; tints and [Registration] left out), info?: false (a line with the file name, or the title of a document never saved, and the date and time in UTC), time?: Unix seconds (default: now; null, or no clock as on the web: no date), textSize?: pt 4..72 (9), textPlace?: \"top\"|\"bottom\" (default), textAlign?: \"left\" (default)|\"right\" (the lines start past a target ticked in that corner, and move in past the top or bottom target they would cross; they stay where they are when moving would cross another target or leave the artboard), artboard?: index (default: the active artboard), allArtboards?: false; null is refused except for time} draw registration targets (a circle half the target's width with a cross through it, stroked) inside each artboard, and the lines asked for, as one group per artboard on the layer \"Screen Print Marks\", which is made locked at the bottom of the stack when there is none; running it again replaces that artboard's group. One undo step, none when the marks come out the same; the selection is kept → {changed, layer, ids: [group id…], inks: [spot ink name…]}",
|
||||
"{positions?: [topLeft|top|topRight|left|right|bottomLeft|bottom|bottomRight…] (each at most once; default: [top, bottom, left, right]; [] draws no targets), size?: target width in pt 4..1000 (36), weight?: stroke weight in pt 0.1..20 (1), inset?: pt from the artboard's edge to the target's outer edge -1000..1000 (18; below 0 the targets sit outside the artboard), ink?: \"[Registration]\" (default) or a spot swatch's name (the targets and the file line), inks?: false (a line naming the document's spot inks, each name in its own ink; tints and [Registration] left out), info?: false (a line with the file name, or the title of a document never saved, and the date and time in UTC), time?: Unix seconds (default: now; null, or no clock as on the web: no date), textSize?: pt 4..72 (9), textPlace?: \"top\"|\"bottom\" (default), textAlign?: \"left\" (default)|\"right\" (the lines start past a target ticked in that corner, and move in past the top or bottom target they would cross; they stay where they are when moving would cross another target or leave the artboard), artboard?: index (default: the active artboard), allArtboards?: false; null is refused except for time} draw registration targets (a circle half the target's width with a cross through it, stroked) inside each artboard, and the lines asked for, as one group per artboard on the layer \"Screen Print Marks\", which is made locked at the bottom of the stack when there is none; running it again replaces that artboard's group. Another artboard's group lying on a copied artboard goes with its own artboard. One undo step, none when the marks come out the same; the selection is kept → {changed, layer, ids: [group id…], inks: [spot ink name…]}",
|
||||
has_doc,
|
||||
screen_marks
|
||||
)]
|
||||
@@ -265,6 +265,11 @@ fn owner(n: &Node) -> Option<u32> {
|
||||
tag(n)?.parse().ok()
|
||||
}
|
||||
|
||||
/// Each marks group on the marks layer of `d`, with the id of the artboard it belongs to.
|
||||
pub(crate) fn managed_owners(d: &Document) -> std::collections::HashMap<NodeId, u32> {
|
||||
marks_layer(d).and_then(|l| l.children()).into_iter().flatten().filter_map(|k| Some((k.id, owner(k)?))).collect()
|
||||
}
|
||||
|
||||
/// Make copy `n` of an artboard's marks group belong to the artboard copied with it: its data
|
||||
/// names artboard `from`, and from now on names `to`. Duplicate Artboards, Alt-drag and paste call
|
||||
/// it on each copy they make. → whether `n` was such a group.
|
||||
@@ -283,6 +288,17 @@ pub(crate) fn retag(n: &mut Node, from: u32, to: u32) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Make top-level layer `layer`, which a paste made for a marks group it copied with an artboard,
|
||||
/// the marks layer, when the document has none.
|
||||
pub(crate) fn adopt_layer(d: &mut Document, layer: NodeId) {
|
||||
if marks_layer(d).is_some() || !d.layers.iter().any(|l| l.id == layer) {
|
||||
return;
|
||||
}
|
||||
if let Some(l) = d.node_mut(layer) {
|
||||
l.edit_attrs(|a| a.data.push((KEY.into(), "layer".into())));
|
||||
}
|
||||
}
|
||||
|
||||
/// `n` with every object's id 0: marks drawn again compare equal to marks drawn the same way.
|
||||
fn without_ids(n: &Node) -> Node {
|
||||
let mut n = n.clone();
|
||||
|
||||
@@ -356,6 +356,90 @@ fn marks_copied_with_a_pasted_artboard_belong_to_the_pasted_one() {
|
||||
assert_eq!(source["changed"], json!(false), "the source artboard's marks are unchanged");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_pasted_after_their_layer_was_deleted_are_found_again() {
|
||||
let mut s = session();
|
||||
let r = run(&mut s, json!({}));
|
||||
s.execute("layer.setProps", &json!({"id": r["layer"], "locked": false})).unwrap();
|
||||
s.execute("artboard.copy", &json!({"index": 0, "art": true, "lockedAndHidden": true})).unwrap();
|
||||
s.execute("layer.delete", &json!({"ids": [r["layer"]]})).unwrap();
|
||||
s.execute("edit.paste", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.artboards.len(), 2);
|
||||
run(&mut s, json!({"artboard": 1, "size": 30}));
|
||||
let doc = &s.doc().unwrap().doc;
|
||||
let layers: Vec<_> = doc.layers.iter().filter(|l| l.name.as_deref() == Some(LAYER_NAME)).collect();
|
||||
assert_eq!(layers.len(), 1, "one marks layer");
|
||||
assert_eq!(layers[0].children().unwrap().len(), 1, "marking the pasted artboard replaces the pasted copy");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn another_artboards_marks_lying_on_a_copied_artboard_stay_with_their_own() {
|
||||
let mut s = session();
|
||||
s.execute("artboard.new", &json!({"x": 700, "y": 0, "width": 600, "height": 400})).unwrap();
|
||||
let r = run(&mut s, json!({"positions": ["right"], "inset": -200}));
|
||||
let g = node(&s, r["ids"][0].as_u64().unwrap());
|
||||
let b = bounds(&g);
|
||||
assert!(b.x0 >= 700.0 && b.x1 <= 1300.0, "the marks lie wholly on the second artboard: {b:?}");
|
||||
let kids = |s: &Session| s.doc().unwrap().doc.layers[0].children().unwrap().len();
|
||||
s.execute("artboard.duplicate", &json!({"index": 1, "art": true, "lockedAndHidden": true})).unwrap();
|
||||
assert_eq!(kids(&s), 1, "duplicating the second artboard leaves the first one's marks out");
|
||||
s.execute("layer.setProps", &json!({"id": r["layer"], "locked": false})).unwrap();
|
||||
let copied = s.execute("artboard.copy", &json!({"index": 1, "art": true, "lockedAndHidden": true})).unwrap();
|
||||
assert_eq!(copied["copied"], json!(0), "copying the second artboard leaves the first one's marks out");
|
||||
let again = run(&mut s, json!({"positions": ["right"], "inset": -200}));
|
||||
assert_eq!(again["changed"], json!(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicating_overlapping_artboards_copies_marks_lying_on_both_once() {
|
||||
let mut s = session();
|
||||
s.execute("artboard.new", &json!({"x": 300, "y": 0, "width": 600, "height": 400})).unwrap();
|
||||
run(&mut s, json!({"artboard": 1, "positions": ["left"]}));
|
||||
s.execute("artboard.duplicate", &json!({"indices": [0, 1], "art": true, "lockedAndHidden": true})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.layers[0].children().unwrap().len(), 2, "the second artboard's copy carries its marks");
|
||||
let copy = run(&mut s, json!({"artboard": 3, "positions": ["left"], "size": 30}));
|
||||
assert_eq!(copy["changed"], json!(true));
|
||||
assert_eq!(s.doc().unwrap().doc.layers[0].children().unwrap().len(), 2, "marking that copy replaces the copied marks");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_lying_on_another_copied_artboard_go_with_their_own_artboards_copy() {
|
||||
let mut s = session();
|
||||
s.execute("artboard.new", &json!({"x": 700, "y": 0, "width": 600, "height": 400})).unwrap();
|
||||
let p = json!({"positions": ["right"], "inset": -200});
|
||||
run(&mut s, p.clone());
|
||||
s.execute("artboard.duplicate", &json!({"indices": [0, 1], "art": true, "lockedAndHidden": true})).unwrap();
|
||||
let kids = |s: &Session| s.doc().unwrap().doc.layers[0].children().unwrap().len();
|
||||
assert_eq!(kids(&s), 2, "the first artboard's copy carries its marks");
|
||||
run(&mut s, json!({"artboard": 2, "positions": ["right"], "inset": -200, "size": 30}));
|
||||
assert_eq!(kids(&s), 2, "marking the first artboard's copy replaces the copied marks");
|
||||
assert_eq!(run(&mut s, p)["changed"], json!(false), "the first artboard's marks are unchanged");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_marks_group_moved_off_the_marks_layer_is_copied_like_other_art() {
|
||||
let mut s = session();
|
||||
s.execute("artboard.new", &json!({"x": 700, "y": 0, "width": 600, "height": 400})).unwrap();
|
||||
let r = run(&mut s, json!({"positions": ["right"], "inset": -200}));
|
||||
s.execute("layer.setProps", &json!({"id": r["layer"], "locked": false})).unwrap();
|
||||
let other = s.doc().unwrap().doc.layers[1].id.0;
|
||||
s.execute("layer.move", &json!({"ids": [r["ids"][0]], "target": other})).unwrap();
|
||||
let kids = |s: &Session| s.doc().unwrap().doc.layers[1].children().unwrap().len();
|
||||
let before = kids(&s);
|
||||
s.execute("artboard.duplicate", &json!({"index": 1, "art": true, "lockedAndHidden": true})).unwrap();
|
||||
assert_eq!(kids(&s), before + 1, "the duplicate carries a copy of the moved group");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_of_a_deleted_artboard_are_copied_like_other_art() {
|
||||
let mut s = session();
|
||||
s.execute("artboard.new", &json!({"x": 700, "y": 0, "width": 600, "height": 400})).unwrap();
|
||||
run(&mut s, json!({"positions": ["right"], "inset": -200}));
|
||||
s.execute("artboard.delete", &json!({"indices": [0]})).unwrap();
|
||||
s.execute("artboard.duplicate", &json!({"index": 0, "art": true, "lockedAndHidden": true})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.layers[0].children().unwrap().len(), 2, "the duplicate carries a copy of the marks");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_copied_with_a_duplicated_artboard_stay_with_the_copy_after_a_resize() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -1692,11 +1692,7 @@ fn paste_clip(s: &mut Session, p: &Value, mode: PasteMode, clip: &Clipboard, cho
|
||||
// A pasted symbol set packs from the density recorded for it at Copy.
|
||||
d.carry_set_densities(n, &c, &clip.set_densities);
|
||||
imported.apply(&mut c, d);
|
||||
for (from, to) in &board_ids {
|
||||
if super::addons::retag_screen_marks(&mut c, *from, *to) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let marks = board_ids.iter().any(|(from, to)| super::addons::retag_screen_marks(&mut c, *from, *to));
|
||||
let sc = vectorcraft_doc::Scaling { patterns: mode == PasteMode::Drag, ..Default::default() };
|
||||
if xf != Affine::IDENTITY {
|
||||
// A cross-document drag carries the graphic's appearance with it,
|
||||
@@ -1705,7 +1701,17 @@ fn paste_clip(s: &mut Session, p: &Value, mode: PasteMode, clip: &Clipboard, cho
|
||||
}
|
||||
let layer = match remembered.get(k) {
|
||||
Some(Some(Remembered::Layer(l))) => Some(*l),
|
||||
Some(Some(Remembered::Make { parent, names })) => make_layers(d, &mut made, *parent, names)?,
|
||||
Some(Some(Remembered::Make { parent, names })) => {
|
||||
let last = make_layers(d, &mut made, *parent, names)?;
|
||||
// The marks layer made again for a copy of an artboard's marks is the marks
|
||||
// layer, so Create Screen Print Marks finds the copy there.
|
||||
if let (true, None, [name], Some(l)) = (marks, parent, names.as_slice(), last)
|
||||
&& name == super::addons::SCREEN_MARKS_LAYER
|
||||
{
|
||||
super::addons::adopt_screen_marks_layer(d, l);
|
||||
}
|
||||
last
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
// In a clip group or a clipping layer the bottom child is the clipping path: art pasted
|
||||
|
||||
@@ -306,6 +306,42 @@ pub(crate) fn artboard_art(s: &Session, i: usize, art: bool, all: bool, moving:
|
||||
})
|
||||
}
|
||||
|
||||
/// `arts` (artboard indices with their art) with each artboard's screen print marks group in its
|
||||
/// own artboard's entry: another artboard's group lying on one of them goes with its own artboard
|
||||
/// when that one is among `arts`, and is left out when it is not. Only the groups on the marks
|
||||
/// layer count; a group whose artboard was deleted stays where it is. Copies and cuts of artboards.
|
||||
pub(crate) fn marks_with_owners(d: &vectorcraft_doc::Document, arts: Vec<(usize, Vec<NodeId>)>) -> Vec<(usize, Vec<NodeId>)> {
|
||||
let owners = super::addons::screen_marks_owners(d);
|
||||
if owners.is_empty() {
|
||||
return arts;
|
||||
}
|
||||
let board = |i: usize| d.artboards.get(i).map(|a| a.id);
|
||||
let owner = |id: NodeId| owners.get(&id).copied().filter(|o| d.artboards.iter().any(|a| a.id == *o));
|
||||
let mut moved: Vec<(u32, NodeId)> = vec![];
|
||||
let mut arts: Vec<(usize, Vec<NodeId>)> = arts
|
||||
.into_iter()
|
||||
.map(|(i, art)| {
|
||||
let art = art
|
||||
.into_iter()
|
||||
.filter(|id| match owner(*id) {
|
||||
Some(o) if Some(o) != board(i) => {
|
||||
moved.push((o, *id));
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
})
|
||||
.collect();
|
||||
(i, art)
|
||||
})
|
||||
.collect();
|
||||
for (o, id) in moved {
|
||||
if let Some((_, art)) = arts.iter_mut().find(|(i, _)| board(*i) == Some(o)) {
|
||||
art.push(id);
|
||||
}
|
||||
}
|
||||
arts
|
||||
}
|
||||
|
||||
/// Each of `indices` with the art that goes with it when `art` ([`artboard_art`]), an object
|
||||
/// counted once, with the first of them it is on (artboards can overlap).
|
||||
pub(crate) fn artboards_art(s: &Session, indices: &[usize], art: bool, all: bool, moving: bool) -> Result<Vec<(usize, Vec<NodeId>)>> {
|
||||
@@ -315,7 +351,7 @@ pub(crate) fn artboards_art(s: &Session, indices: &[usize], art: bool, all: bool
|
||||
let art = artboard_art(s, i, art, all, moving)?.into_iter().filter(|id| seen.insert(*id)).collect();
|
||||
arts.push((i, art));
|
||||
}
|
||||
Ok(arts)
|
||||
Ok(if moving { arts } else { marks_with_owners(&s.doc()?.doc, arts) })
|
||||
}
|
||||
|
||||
/// How far a copy of `rect` moves to sit right of the last artboard (Duplicate Artboards, Paste).
|
||||
@@ -368,6 +404,8 @@ pub(crate) fn artboard_copy(s: &mut Session, p: &Value, cut: bool) -> Result<Val
|
||||
if cut {
|
||||
refuse_locked(&st.doc, &indices)?;
|
||||
}
|
||||
// A cut leaves the screen print marks of an artboard it does not take where they are.
|
||||
let arts = if cut { marks_with_owners(&st.doc, arts) } else { arts };
|
||||
let art = st.doc.paint_order(arts.into_iter().flat_map(|(_, a)| a));
|
||||
let boards: Vec<_> = indices.iter().filter_map(|i| st.doc.artboards.get(*i).cloned()).collect();
|
||||
let clip = Clipboard { source_artboard: boards.first().map(|a| a.rect), artboards: boards, ..Clipboard::copy(st, &art, false) };
|
||||
|
||||
@@ -692,6 +692,9 @@ fn artboard_move(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let art = art.into_iter().filter(|id| !arts.iter().any(|(_, a)| a.contains(id))).collect();
|
||||
arts.push((i, art));
|
||||
}
|
||||
if copy {
|
||||
arts = super::panelcmds::marks_with_owners(&s.doc()?.doc, arts);
|
||||
}
|
||||
let ids: Vec<NodeId> = arts.iter().flat_map(|(_, a)| a.iter().copied()).collect();
|
||||
let sc = Scaling { patterns: super::object::transform_patterns(s, p, &ids)?, ..Scaling::default() };
|
||||
let (index, moved) = s.edit(if copy { "Duplicate Artboard" } else { "Move Artboard" }, |d, _| {
|
||||
|
||||
+5
-1
@@ -17797,7 +17797,11 @@ The marks of each artboard are one group, on the top-level layer "Screen Print M
|
||||
layer, the command makes it at the bottom of the stack, locked. A layer moved, unlocked or hidden stays as it is.
|
||||
`artboard` is an artboard's index (default: the active artboard) and `allArtboards: true` marks every artboard;
|
||||
giving both is an error. Running the command again replaces that artboard's group and leaves the other artboards'
|
||||
groups alone. A group copied with an artboard duplicated, Alt-dragged or pasted in the same document belongs to the copy. Marks
|
||||
groups alone. A group copied with an artboard duplicated, Alt-dragged or pasted in the same document belongs to the copy.
|
||||
Another artboard's group lying on an artboard that is duplicated, Alt-dragged, copied or cut goes with its own artboard:
|
||||
it is copied with that artboard when that one is copied too, and otherwise stays where it is. A group whose artboard was
|
||||
deleted is copied like other art. When the "Screen Print Marks" layer was
|
||||
deleted, pasting an artboard with its marks makes the layer again, and the command uses that layer. Marks
|
||||
outside the artboard (a negative `inset`) appear in an export or a print clipped to the artboard only as far as its
|
||||
bleed reaches. It is one undo step, and none when the marks come out the same (`changed: false`). The selection is
|
||||
kept. An unknown position or one named twice, a number out of range, an `ink` that is not [Registration] or a spot
|
||||
|
||||
@@ -3290,7 +3290,7 @@ A VectorCraft addition (it replaces a script some users ran), so no area score m
|
||||
|
||||
## Create Screen Print Marks (2026-11-29)
|
||||
|
||||
A VectorCraft addition, so no area score moves. Object › Plug-ins › Color Effects › Create Screen Print Marks… (`addon.color.screenMarks`) opens a dialog (the eight target positions, size, stroke weight, inset, ink, the spot ink and file lines with their type size, place and alignment, all artboards, with a preview) and draws registration targets (a circle half the target's width with a cross through it) inside the artboard in [Registration] or a spot ink, with an optional line naming the document's spot inks, each in its own ink, and an optional line with the file name and the date and time in UTC. The marks are document art: one group per artboard on a locked "Screen Print Marks" layer made at the bottom of the stack, so they print, separate and export with the rest of the art, where Create Trim Marks draws trim marks only and the PDF export's printer's marks exist only in the exported file. The lines move in past a top or bottom target they would cross. They stay where they are when moving would cross another target or leave the artboard. Marks copied with a duplicated artboard belong to the copy. Running it again replaces that artboard's marks; one undo step, none when the marks come out the same. Remaining: saved presets of the dialog's settings. Tests: `cmd::addons::color::screen_marks::tests` (engine), `addons::color::screen_marks::tests` (ui-egui).
|
||||
A VectorCraft addition, so no area score moves. Object › Plug-ins › Color Effects › Create Screen Print Marks… (`addon.color.screenMarks`) opens a dialog (the eight target positions, size, stroke weight, inset, ink, the spot ink and file lines with their type size, place and alignment, all artboards, with a preview) and draws registration targets (a circle half the target's width with a cross through it) inside the artboard in [Registration] or a spot ink, with an optional line naming the document's spot inks, each in its own ink, and an optional line with the file name and the date and time in UTC. The marks are document art: one group per artboard on a locked "Screen Print Marks" layer made at the bottom of the stack, so they print, separate and export with the rest of the art, where Create Trim Marks draws trim marks only and the PDF export's printer's marks exist only in the exported file. The lines move in past a top or bottom target they would cross. They stay where they are when moving would cross another target or leave the artboard. Marks copied with a duplicated artboard belong to the copy, and another artboard's marks lying on a copied artboard stay with their own artboard. A paste that makes the deleted marks layer again makes it the marks layer. Running it again replaces that artboard's marks; one undo step, none when the marks come out the same. Remaining: saved presets of the dialog's settings. Tests: `cmd::addons::color::screen_marks::tests` (engine), `addons::color::screen_marks::tests` (ui-egui).
|
||||
|
||||
## Stroke Weight Up and Down shortcuts (2026-11-06)
|
||||
|
||||
|
||||
Reference in new issue
Block a user