mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 13:32:45 -05:00
Screen print marks: pasted marks never use an ordinary layer of that name
A pasted marks group went into an ordinary top-level layer named "Screen Print Marks" when the document had no tagged marks layer, and the paste failed when that layer was hidden or locked. The paste now makes a new marks layer instead. That layer is made apart from an ordinary layer of the same name pasted at the same time, and ordinary art pasted later skips the marks layer when matching layers by name.
This commit is contained in:
1 parent
e365915ce1
commit
5587dfdbca
3 files changed
+106
-18
No files matched your search
@@ -399,6 +399,78 @@ fn marks_pasted_into_another_document_go_into_its_marks_layer_not_a_layer_of_the
|
||||
assert_eq!(kids(&s, plain), Some((false, 0)), "the ordinary layer of the same name stays empty");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_pasted_without_a_marks_layer_make_one_and_skip_a_layer_of_the_same_name() {
|
||||
for props in [json!({}), json!({"visible": false}), json!({"locked": true})] {
|
||||
let mut s = session();
|
||||
run(&mut s, json!({}));
|
||||
s.execute("artboard.copy", &json!({"index": 0, "art": true, "lockedAndHidden": true})).unwrap();
|
||||
s.execute("file.new", &json!({"width": 600, "height": 400})).unwrap();
|
||||
let plain = s.execute("layer.new", &json!({"name": LAYER_NAME})).unwrap()["id"].clone();
|
||||
let mut set = props.clone();
|
||||
set["id"] = plain.clone();
|
||||
s.execute("layer.setProps", &set).unwrap();
|
||||
let plain = NodeId(plain.as_u64().unwrap());
|
||||
s.execute("edit.paste", &json!({})).unwrap();
|
||||
let doc = &s.doc().unwrap().doc;
|
||||
assert_eq!(doc.artboards.len(), 2, "{props}");
|
||||
assert_eq!(doc.node(plain).and_then(|l| l.children().map(|k| k.len())), Some(0), "the ordinary layer stays empty: {props}");
|
||||
let made: Vec<_> = doc.layers.iter().filter(|l| l.id != plain && l.name.as_deref() == Some(LAYER_NAME)).collect();
|
||||
assert_eq!(made.len(), 1, "a marks layer is made: {props}");
|
||||
assert_eq!(made[0].children().map_or(0, |k| k.len()), 1, "the pasted marks go into it: {props}");
|
||||
let made = made[0].id.0;
|
||||
let r = run(&mut s, json!({"artboard": 1, "size": 30}));
|
||||
assert_eq!(r["layer"], json!(made), "the command uses the made layer: {props}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_and_art_from_a_layer_of_the_same_name_paste_into_separate_layers() {
|
||||
let mut s = session();
|
||||
let r = run(&mut s, json!({}));
|
||||
s.execute("layer.setProps", &json!({"id": r["layer"], "name": "Renamed Marks"})).unwrap();
|
||||
s.execute("layer.new", &json!({"name": LAYER_NAME})).unwrap();
|
||||
s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 50, "height": 50})).unwrap();
|
||||
s.execute("artboard.copy", &json!({"index": 0, "art": true, "lockedAndHidden": true})).unwrap();
|
||||
s.execute("file.new", &json!({"width": 600, "height": 400})).unwrap();
|
||||
for paste in 1..=2 {
|
||||
s.execute("edit.paste", &json!({})).unwrap();
|
||||
let doc = &s.doc().unwrap().doc;
|
||||
let marks = super::layer_id(doc).expect("a marks layer is made");
|
||||
let named: Vec<_> = doc.layers.iter().filter(|l| l.name.as_deref() == Some(LAYER_NAME)).collect();
|
||||
assert_eq!(named.len(), 2, "the marks layer and the ordinary layer are separate: paste {paste}");
|
||||
for l in named {
|
||||
let items = l.children().unwrap().len();
|
||||
assert_eq!(items, paste, "each paste adds one item to each layer: paste {paste}, marks {}", l.id == marks);
|
||||
}
|
||||
let ordinary = doc.layers.iter().find(|l| l.name.as_deref() == Some(LAYER_NAME) && l.id != marks).unwrap();
|
||||
assert!(
|
||||
ordinary.children().unwrap().iter().all(|k| k.children().is_none()),
|
||||
"only the rectangle goes into the ordinary layer: paste {paste}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn art_pasted_again_skips_a_marks_layer_above_its_ordinary_layer() {
|
||||
let mut s = session();
|
||||
run(&mut s, json!({}));
|
||||
s.execute("layer.new", &json!({"name": LAYER_NAME})).unwrap();
|
||||
s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 50, "height": 50})).unwrap();
|
||||
s.execute("artboard.copy", &json!({"index": 0, "art": true, "lockedAndHidden": true})).unwrap();
|
||||
s.execute("file.new", &json!({"width": 600, "height": 400})).unwrap();
|
||||
let ordinary = NodeId(s.execute("layer.new", &json!({"name": LAYER_NAME})).unwrap()["id"].as_u64().unwrap());
|
||||
for paste in 1..=2 {
|
||||
s.execute("edit.paste", &json!({})).unwrap();
|
||||
let doc = &s.doc().unwrap().doc;
|
||||
let marks = super::layer_id(doc).expect("a marks layer is made");
|
||||
assert_ne!(marks, ordinary);
|
||||
let kids = |l: NodeId| doc.node(l).unwrap().children().unwrap().iter().map(|k| k.children().is_none()).collect::<Vec<_>>();
|
||||
assert_eq!(kids(ordinary), vec![true; paste], "the rectangles go into the ordinary layer: paste {paste}");
|
||||
assert_eq!(kids(marks), vec![false; paste], "only marks go into the marks layer: paste {paste}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_lying_off_an_artboard_go_with_its_copy_made_by_moving_it() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -1685,6 +1685,8 @@ fn paste_clip(s: &mut Session, p: &Value, mode: PasteMode, clip: &Clipboard, cho
|
||||
.collect();
|
||||
// The layers made for remembered layers the document lacks, by parent and name.
|
||||
let mut made = HashMap::new();
|
||||
// The marks layer made for screen print marks, kept apart from ordinary layers of its name.
|
||||
let mut made_marks: HashMap<(Option<NodeId>, String), NodeId> = HashMap::new();
|
||||
// Objects pasted into each parent so far (keeps their order in front and back pastes).
|
||||
let mut placed: BTreeMap<Option<NodeId>, usize> = BTreeMap::new();
|
||||
let mut new_ids = vec![];
|
||||
@@ -1708,17 +1710,7 @@ 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 })) => {
|
||||
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
|
||||
}
|
||||
Some(Some(Remembered::Make { parent, names })) => make_remembered(d, &mut made, &mut made_marks, marks, *parent, names)?,
|
||||
_ => None,
|
||||
};
|
||||
// In a clip group or a clipping layer the bottom child is the clipping path: art pasted
|
||||
@@ -1886,12 +1878,15 @@ fn remembered_layers(d: &Document, sources: &[Option<SourceLayer>], marks: &[boo
|
||||
/// layers match the most names, a shown and unlocked one first). The names left unmatched are
|
||||
/// made. A matched layer that is hidden or locked, or inside one that is, is an error. A screen
|
||||
/// print marks group (`marks`) goes into the document's marks layer, locked or hidden as it is,
|
||||
/// when the document has one.
|
||||
/// or into a new top-level marks layer when the document has none.
|
||||
fn remembered_layer(d: &Document, src: &SourceLayer, marks: bool, same_doc: bool) -> Result<Remembered> {
|
||||
// A marks group goes into the document's marks layer when it has one, not into an ordinary
|
||||
// layer of the same name.
|
||||
if marks && let Some(l) = super::addons::screen_marks_layer(d) {
|
||||
return Ok(Remembered::Layer(l));
|
||||
// A marks group goes into the document's marks layer, never into an ordinary layer of the
|
||||
// same name.
|
||||
if marks {
|
||||
return Ok(match super::addons::screen_marks_layer(d) {
|
||||
Some(l) => Remembered::Layer(l),
|
||||
None => Remembered::Make { parent: None, names: vec![super::addons::SCREEN_MARKS_LAYER.to_string()] },
|
||||
});
|
||||
}
|
||||
let held = |id: &NodeId| d.node(*id).is_some_and(|n| n.is_layer() && n.name.as_ref() == src.names.last());
|
||||
let kept = if same_doc && src.ids.last().is_some_and(held) {
|
||||
@@ -1927,7 +1922,9 @@ fn named_chain(d: &Document, parent: Option<NodeId>, names: &[String]) -> (Optio
|
||||
None => Some(&d.layers),
|
||||
Some(p) => d.node(p).and_then(Node::children),
|
||||
};
|
||||
for l in siblings.into_iter().flatten().rev().filter(|l| l.is_layer() && l.name.as_deref() == Some(name.as_str())) {
|
||||
// Ordinary art never goes into the screen print marks layer by its name.
|
||||
let marks_layer = parent.is_none().then(|| super::addons::screen_marks_layer(d)).flatten();
|
||||
for l in siblings.into_iter().flatten().rev().filter(|l| l.is_layer() && l.name.as_deref() == Some(name.as_str()) && Some(l.id) != marks_layer) {
|
||||
let (end, n, open) = named_chain(d, Some(l.id), rest);
|
||||
let chain = (end, n + 1, open && l.visible && !l.locked);
|
||||
if (chain.1, chain.2) > (best.1, best.2) {
|
||||
@@ -1937,6 +1934,25 @@ fn named_chain(d: &Document, parent: Option<NodeId>, names: &[String]) -> (Optio
|
||||
best
|
||||
}
|
||||
|
||||
/// Makes the layers of a `Remembered::Make` for one pasted object. The marks layer for a screen
|
||||
/// print marks group (`marks`) is made apart from ordinary layers of its name (`made_marks`) and
|
||||
/// becomes the marks layer, so Create Screen Print Marks finds the copy there.
|
||||
fn make_remembered(
|
||||
d: &mut Document,
|
||||
made: &mut HashMap<(Option<NodeId>, String), NodeId>,
|
||||
made_marks: &mut HashMap<(Option<NodeId>, String), NodeId>,
|
||||
marks: bool,
|
||||
parent: Option<NodeId>,
|
||||
names: &[String],
|
||||
) -> Result<Option<NodeId>> {
|
||||
let is_marks = marks && parent.is_none() && matches!(names, [n] if n == super::addons::SCREEN_MARKS_LAYER);
|
||||
let last = make_layers(d, if is_marks { made_marks } else { made }, parent, names)?;
|
||||
if let (true, Some(l)) = (is_marks, last) {
|
||||
super::addons::adopt_screen_marks_layer(d, l);
|
||||
}
|
||||
Ok(last)
|
||||
}
|
||||
|
||||
/// Layers `names`, each inside the one before, the first under `parent` (none: on top); `made`
|
||||
/// keeps the ones a paste has made, by parent and name, so they are made once. The last one, or
|
||||
/// none when `names` is empty.
|
||||
|
||||
+1
-1
@@ -17923,7 +17923,7 @@ Another artboard's group lying on an artboard that is duplicated, Alt-dragged, c
|
||||
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. With art enabled, moves and cuts also take marks by their recorded owner, even when
|
||||
the marks lie outside every artboard, subject to `lockedAndHidden`. When the marks layer was
|
||||
deleted while named "Screen Print Marks", pasting an artboard with its marks makes the layer again, and the command uses that layer. Marks
|
||||
deleted, or the document pasted into has none, pasting an artboard with its marks makes a new marks layer named "Screen Print Marks" at the top level, 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
|
||||
|
||||
Reference in new issue
Block a user