DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #521: Copies report their ids
aiongg3af8c6275d43
diff --cc ROADMAP.mdindex 67dde6abd,a0f9c5431..bf51e9cc9--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -129,24 -129,7 +129,25 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+ - **2026-10-11** · `transform.move {copy}`, Edit › Duplicate and Step and Repeat return the copies' ids, so a script can go on with them. No readiness percentage change.+- **2026-10-11** · `object.fill` and `object.stroke` refuse a swatch name the document doesn't have (it painted nothing) and suggest the name meant (`Paper` → `[Paper]`). No readiness percentage change.+- **2026-10-11** · Japanese captions now cover print ranges, imported style handling and table+ row/column movement, including row-height distribution. Existing translation and RTL helpers+ handle the display; command IDs, stored option values and user-defined style names are unchanged.+- **2026-10-11** · Moving a sheared and rotated text frame no longer leaves trails of text behind: canvas repaints cover the frame's whole text box, not just its outline. No readiness percentage change.+- **2026-10-11** · Live corners: the yellow widget on a selected rectangle frame shows corner+ diamonds; dragging one rounds the corners, Alt-click steps the corner shape (#186).+- **2026-10-11** · Optical kerning (#181): pairs are spaced from their outlines (ink gap per band,+ pulled towards the font's stem gap, bounded) instead of silently using the font's kern pairs.+- **2026-10-11** · New Document laid out like InDesign's (#325): Recent, Saved, Print, Web and+ Mobile preset tabs beside the preset's details; saved document presets live in the engine+ (`file.savePreset`, `file.deletePreset`, `file.new {preset}`); `file.new` takes intent, units,+ start page and per-edge bleed and slug.+- **2026-10-11** · macOS: fonts that font services and managers activate (Adobe Fonts,+ RightFont) are listed, read from the files CoreText has available (#261, #327).+- **2026-10-11:** Document pages take their parent page's margins and columns (left or right parent page by side) and follow its changes unless they have their own; parent ruler guides draw and snap on the pages based on it. IDML import marks a page margin preference that differs from its parent as the page's own. No readiness percentage change.+- **2026-10-11** · Document Setup laid out like InDesign's: Page Size, Margins (new: every+ page's, `layout.documentSetup {margins}`), Bleed and Slug with links, Adjust Layout.- **2026-10-10 (UI.4–UI.5):** Panel tabs can move into other groups, split the dock, float, resize and return to their saved locations through shared docking transactions. Layouts persist in custom workspaces; UI and control commands share the same validated action path. Shared pane geometry and widget-state theme application retain all five palettes and local fonts. Split panes send keyboard input only to the focused canvas and scope contextual toolbar IDs per pane. No readiness percentage change.- **2026-10-10** · Version 0.6.0; releases add a Linux riscv64 tar.gz (cross-compiled, CLIsmoke-tested under QEMU).diff --cc crates/engine/src/cmd/object.rsindex c67659cec,33568a41e..c8a00173d--- a/crates/engine/src/cmd/object.rs+++ b/crates/engine/src/cmd/object.rs@@@ -43,7 -31,7 +43,7 @@@ pub fn specs() -> Vec<CommandSpec>"Move",["Object", "Transform"],None,- "{dx, dy, copy?: bool, ids?, toSpread?, content?: bool (move the placed graphic or pasted-in items inside each frame; the frame stays. Default: whether the selection is content, when neither ids nor copy is given)}",- "{dx, dy, copy?: bool, ids?, toSpread?} → {moved, ids: the objects moved (with copy, the copies)}",++ "{dx, dy, copy?: bool, ids?, toSpread?, content?: bool (move the placed graphic or pasted-in items inside each frame; the frame stays. Default: whether the selection is content, when neither ids nor copy is given)} → {moved, ids: the objects moved (with copy, the copies)}",has_selection,transform_move),@@@ -1000,9 -975,9 +1000,9 @@@ fn transform_move(s: &mut Session, p: &if it.locked {continue;}- it.xf = Affine::translate((dx, dy)) * it.xf;+ it.xf = Affine::translate(v) * it.xf;}- Ok(json!({"moved": ids.len()}))+ Ok(json!({"moved": ids.len(), "ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()}))})}@@@ -3087,316 -2724,31 +3088,345 @@@ mod blend_mode_tests}}+#[cfg(test)]+mod reorder_tests {+ use super::*;++ fn frame(s: &mut Session) -> u64 {+ s.execute("frame.create", &json!({"rect": [0, 0, 10, 10]})).unwrap()["id"].as_u64().unwrap()+ }++ /// Top-level objects of the first spread on `layer`, topmost first.+ fn stack(s: &Session, layer: u64) -> Vec<u64> {+ let d = &s.doc().unwrap().doc;+ d.spreads[0].items.iter().rev().filter(|i| i.layer.0 == layer).map(|i| i.id.0).collect()+ }++ #[test]+ fn reorder_within_and_across_layers_validates_and_undoes() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let l1 = s.doc().unwrap().doc.layers[0].id.0;+ let l2 = s.execute("layer.new", &json!({"name": "Art"})).unwrap()["id"].as_u64().unwrap();+ s.execute("layer.activate", &json!({"id": l1})).unwrap();+ let (a, b, c) = (frame(&mut s), frame(&mut s), frame(&mut s));+ s.execute("layer.activate", &json!({"id": l2})).unwrap();+ let (x, y) = (frame(&mut s), frame(&mut s));+ assert_eq!(stack(&s, l1), [c, b, a]);+ s.execute("object.reorder", &json!({"ids": [a], "above": c})).unwrap();+ assert_eq!(stack(&s, l1), [a, c, b]);+ s.execute("object.reorder", &json!({"ids": [b], "index": 0})).unwrap();+ assert_eq!(stack(&s, l1), [b, a, c]);+ // To another layer at a position.+ s.execute("object.reorder", &json!({"ids": [a], "layer": l2, "index": 1})).unwrap();+ assert_eq!((stack(&s, l1), stack(&s, l2)), (vec![b, c], vec![y, a, x]));+ s.execute("object.reorder", &json!({"ids": [x, y], "below": c})).unwrap();+ assert_eq!((stack(&s, l1), stack(&s, l2)), (vec![b, c, y, x], vec![a]));+ // Bad input is an error and changes nothing.+ let before = s.doc().unwrap().doc.clone();+ for bad in [+ json!({"ids": [999], "index": 0}),+ json!({"ids": [b], "index": 4}),+ json!({"ids": [b], "above": b}),+ json!({"ids": [b], "above": 999}),+ json!({"ids": [b], "layer": 999}),+ json!({"ids": [b], "layer": l2, "above": c}),+ json!({"ids": [b], "above": c, "index": 0}),+ json!({"ids": [b], "index": "top"}),+ json!({"ids": []}),+ ] {+ assert!(s.execute("object.reorder", &bad).is_err(), "{bad}");+ assert_eq!(*s.doc().unwrap().doc, *before, "{bad}");+ }+ // The bottom of a layer is index = its count.+ s.execute("object.reorder", &json!({"ids": [b], "index": 3})).unwrap();+ assert_eq!(stack(&s, l1), [c, y, x, b]);+ // A reorder that changes nothing adds no undo step.+ let undo = |s: &Session| s.doc().unwrap().history.undo.len();+ let steps = undo(&s);+ s.execute("object.reorder", &json!({"ids": [x], "index": 2})).unwrap();+ s.execute("object.reorder", &json!({"ids": [y], "above": x})).unwrap();+ s.execute("object.reorder", &json!({"ids": [c], "layer": l1, "index": 0})).unwrap();+ assert_eq!(stack(&s, l1), [c, y, x, b]);+ assert_eq!(undo(&s), steps);+ // One undo step per reorder.+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(stack(&s, l1), [b, c, y, x]);+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!((stack(&s, l1), stack(&s, l2)), (vec![b, c], vec![y, a, x]));+ }++ #[test]+ fn group_members_reorder_only_within_their_group() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let (a, b, c) = (frame(&mut s), frame(&mut s), frame(&mut s));+ let g = s.execute("object.group", &json!({"ids": [a, b]})).unwrap()["id"].as_u64().unwrap();+ let kids = |s: &Session| s.doc().unwrap().doc.item(ItemId(g)).unwrap().children().iter().map(|i| i.id.0).collect::<Vec<_>>();+ assert_eq!(kids(&s), [a, b]);+ s.execute("object.reorder", &json!({"ids": [a], "above": b})).unwrap();+ assert_eq!(kids(&s), [b, a]);+ s.execute("object.reorder", &json!({"ids": [a], "index": 1})).unwrap();+ assert_eq!(kids(&s), [a, b]);+ let before = s.doc().unwrap().doc.clone();+ assert!(s.execute("object.reorder", &json!({"ids": [a], "above": c})).is_err(), "out of the group");+ assert!(s.execute("object.reorder", &json!({"ids": [c], "above": a})).is_err(), "into the group");+ assert!(s.execute("object.reorder", &json!({"ids": [a, c], "index": 0})).is_err(), "mixed parents");+ assert_eq!(*s.doc().unwrap().doc, *before);+ }++ #[test]+ fn moving_a_group_member_to_a_layer_moves_its_group() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let (a, b) = (frame(&mut s), frame(&mut s));+ let g = s.execute("object.group", &json!({"ids": [a, b]})).unwrap()["id"].as_u64().unwrap();+ let art = s.execute("layer.new", &json!({"name": "Art"})).unwrap()["id"].as_u64().unwrap();+ let r = s.execute("object.setLayer", &json!({"ids": [a, b], "layer": art})).unwrap();+ assert_eq!(r["changed"], 1, "the group, once");+ let d = &s.doc().unwrap().doc;+ assert!([g, a, b].iter().all(|i| d.item(ItemId(*i)).unwrap().layer.0 == art));+ assert!(s.execute("object.setLayer", &json!({"ids": [a], "layer": 999})).is_err());+ }+}++#[cfg(test)]+mod content_move_tests {+ use super::*;++ /// A session with a 40×20 image placed in a frame at (100, 100)–(300, 300).+ fn placed() -> (Session, ItemId) {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let png = designcraft_render::Rendered { width: 40, height: 20, pixels: vec![200; 40 * 20 * 4] }.to_png();+ let f = s.execute("frame.create", &json!({"rect": [100, 100, 300, 300], "content": "graphic"})).unwrap()["id"].as_u64().unwrap();+ s.execute("place.load", &json!({"base64": super::super::base64_encode(&png)})).unwrap();+ s.execute("place.drop", &json!({"frame": f})).unwrap();+ (s, ItemId(f))+ }++ /// Spread bounds of the frame and of its graphic.+ fn boxes(s: &Session, id: ItemId) -> (Rect, Rect) {+ let it = s.doc().unwrap().doc.item(id).unwrap().clone();+ let g = it.graphic().unwrap();+ (it.bounds(), (it.xf * g.xf).transform_rect_bbox(Rect::new(0.0, 0.0, g.size.0, g.size.1)))+ }++ fn near(a: Rect, b: Rect) -> bool {+ [a.x0 - b.x0, a.y0 - b.y0, a.x1 - b.x1, a.y1 - b.y1].iter().all(|d| d.abs() < 1e-6)+ }++ #[test]+ fn content_moves_inside_the_frame_in_one_undo_step() {+ let (mut s, f) = placed();+ let (frame0, g0) = boxes(&s, f);+ s.execute("selection.set", &json!({"ids": [f.0], "content": true})).unwrap();+ s.execute("transform.move", &json!({"dx": 10, "dy": -5})).unwrap();+ let (frame1, g1) = boxes(&s, f);+ assert!(near(frame1, frame0), "the frame stays");+ assert!(near(g1, g0 + Vec2::new(10.0, -5.0)), "{g1:?}");+ s.execute("edit.undo", &json!({})).unwrap();+ assert!(near(boxes(&s, f).1, g0));+ // Explicit ids with `content` act on the content whatever the selection is.+ s.execute("selection.set", &json!({"ids": [f.0]})).unwrap();+ s.execute("transform.move", &json!({"ids": [f.0], "content": true, "dx": 3})).unwrap();+ assert!(near(boxes(&s, f).0, frame0) && near(boxes(&s, f).1, g0 + Vec2::new(3.0, 0.0)));+ // A frame selection moves frame and content together.+ s.execute("transform.move", &json!({"dx": 4})).unwrap();+ assert!(near(boxes(&s, f).0, frame0 + Vec2::new(4.0, 0.0)) && near(boxes(&s, f).1, g0 + Vec2::new(7.0, 0.0)));+ }++ #[test]+ fn content_moves_on_the_page_axes_in_a_rotated_frame_and_pasted_items_move_too() {+ let (mut s, f) = placed();+ s.execute("transform.rotate", &json!({"ids": [f.0], "angle": 90})).unwrap();+ let (frame0, g0) = boxes(&s, f);+ s.execute("transform.move", &json!({"ids": [f.0], "content": true, "dx": 10})).unwrap();+ let (frame1, g1) = boxes(&s, f);+ assert!(near(frame1, frame0) && near(g1, g0 + Vec2::new(10.0, 0.0)), "{g0:?} → {g1:?}");+ // Items pasted into a frame are its content.+ let a = s.execute("frame.create", &json!({"rect": [400, 100, 420, 120], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [a]})).unwrap();+ s.execute("edit.copy", &json!({})).unwrap();+ let b = s.execute("frame.create", &json!({"rect": [400, 300, 500, 400], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [b]})).unwrap();+ s.execute("edit.pasteInto", &json!({})).unwrap();+ let kids = |s: &Session| {+ let it = s.doc().unwrap().doc.item(ItemId(b)).unwrap().clone();+ (it.bounds(), it.children().iter().map(|c| it.xf.transform_rect_bbox(c.bounds())).collect::<Vec<_>>())+ };+ let (fb0, k0) = kids(&s);+ s.execute("transform.move", &json!({"ids": [b], "content": true, "dx": 5, "dy": 6})).unwrap();+ let (fb1, k1) = kids(&s);+ assert!(near(fb1, fb0) && near(k1[0], k0[0] + Vec2::new(5.0, 6.0)), "{k0:?} → {k1:?}");+ }+}++#[cfg(test)]+mod group_tests {+ use super::*;++ fn frame(s: &mut Session, rect: [f64; 4], spread: usize) -> ItemId {+ ItemId(s.execute("frame.create", &json!({"rect": rect, "spread": spread})).unwrap()["id"].as_u64().unwrap())+ }++ fn group_ids(s: &mut Session, ids: &[ItemId]) -> Result<ItemId> {+ let r = s.execute("object.group", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()}))?;+ Ok(ItemId(r["id"].as_u64().unwrap()))+ }++ fn children(s: &Session, id: ItemId) -> Vec<ItemId> {+ s.doc().unwrap().doc.item(id).unwrap().children().iter().map(|c| c.id).collect()+ }++ fn world(s: &Session, id: ItemId) -> Affine {+ let d = &s.doc().unwrap().doc;+ let loc = d.find(id).unwrap();+ d.parent_xf(&loc) * d.item(id).unwrap().xf+ }++ fn group_enabled(s: &Session) -> bool {+ super::super::find_command("object.group").unwrap().info(s).enabled+ }++ #[test]+ fn grouping_objects_already_in_a_group_does_not_panic() {+ let mut s = Session::new();+ s.execute("file.new", &json!({"pages": 1})).unwrap();+ let a = frame(&mut s, [36.0, 36.0, 136.0, 136.0], 0);+ let b = frame(&mut s, [200.0, 36.0, 300.0, 136.0], 0);+ let g = group_ids(&mut s, &[a, b]).unwrap();+ let inner = group_ids(&mut s, &[a, b]).unwrap();+ assert_eq!(children(&s, g), vec![inner]);+ assert_eq!(children(&s, inner), vec![a, b]);++ // The same through the selection, and through Convert to Multi-State Object.+ s.execute("selection.set", &json!({"ids": [a.0, b.0], "content": true})).unwrap();+ assert!(group_enabled(&s));+ let inner2 = ItemId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());+ assert_eq!(children(&s, inner), vec![inner2]);+ let st = ItemId(s.execute("states.create", &json!({"ids": [a.0, b.0]})).unwrap()["id"].as_u64().unwrap());+ assert_eq!(children(&s, inner2), vec![st]);+ assert_eq!(s.doc().unwrap().doc.item(st).unwrap().states.len(), 2);+ }++ #[test]+ fn grouping_siblings_inside_a_group_nests_them_and_undo_restores() {+ let mut s = Session::new();+ s.execute("file.new", &json!({"pages": 1})).unwrap();+ let a = frame(&mut s, [0.0, 0.0, 10.0, 10.0], 0);+ let b = frame(&mut s, [20.0, 0.0, 30.0, 10.0], 0);+ let c = frame(&mut s, [40.0, 0.0, 50.0, 10.0], 0);+ let g = group_ids(&mut s, &[a, b, c]).unwrap();+ s.execute("transform.rotate", &json!({"ids": [g.0], "angle": 30})).unwrap();+ let before = (world(&s, a), world(&s, c));++ let inner = group_ids(&mut s, &[c, a]).unwrap();+ assert_eq!(children(&s, g), vec![b, inner], "the new group takes the frontmost object's place");+ assert_eq!(children(&s, inner), vec![a, c], "stacking order kept");+ assert_eq!((world(&s, a), world(&s, c)), before, "nothing moves");+ assert_eq!(s.doc().unwrap().selection.items, vec![inner]);++ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(children(&s, g), vec![a, b, c]);+ assert!(s.doc().unwrap().doc.find(inner).is_none());+ }++ #[test]+ fn grouping_across_levels_or_spreads_is_refused_and_changes_nothing() {+ let mut s = Session::new();+ s.execute("file.new", &json!({"pages": 2, "facingPages": false})).unwrap();+ let a = frame(&mut s, [0.0, 0.0, 10.0, 10.0], 0);+ let b = frame(&mut s, [20.0, 0.0, 30.0, 10.0], 0);+ let top = frame(&mut s, [40.0, 0.0, 50.0, 10.0], 0);+ let other = frame(&mut s, [0.0, 0.0, 10.0, 10.0], 1);+ let other2 = frame(&mut s, [20.0, 0.0, 30.0, 10.0], 1);+ let g = group_ids(&mut s, &[a, b]).unwrap();+ let doc = s.doc().unwrap().doc.clone();++ for ids in [[a, top], [top, a], [a, other], [top, other], [g, a]] {+ let e = group_ids(&mut s, &ids).unwrap_err().to_string();+ assert!(e.contains("same spread and at the same level"), "{ids:?}: {e}");+ let e = s.execute("states.create", &json!({"ids": [ids[0].0, ids[1].0]})).unwrap_err().to_string();+ assert!(e.contains("same spread and at the same level"), "states.create {ids:?}: {e}");+ assert!(Arc::ptr_eq(&s.doc().unwrap().doc, &doc), "{ids:?} changed the document");+ }+ assert!(group_ids(&mut s, &[a, ItemId(999_999)]).is_err());++ s.execute("selection.set", &json!({"ids": [a.0, other.0], "content": true})).unwrap();+ assert!(!group_enabled(&s), "Group is disabled for objects on different spreads");+ s.execute("selection.set", &json!({"ids": [other.0, other2.0]})).unwrap();+ assert!(group_enabled(&s));+ // Named objects win over a selection that can't be grouped.+ s.execute("selection.set", &json!({"ids": [a.0, other.0], "content": true})).unwrap();+ assert!(group_ids(&mut s, &[other, other2]).is_ok());++ // A multi-state object keeps one state per object.+ let ms = ItemId(s.execute("states.create", &json!({"ids": [g.0]})).unwrap()["id"].as_u64().unwrap());+ assert_eq!(ms, g);+ let e = group_ids(&mut s, &[a, b]).unwrap_err().to_string();+ assert!(e.contains("multi-state"), "{e}");+ assert_eq!(children(&s, g), vec![a, b]);+ }+}++#[cfg(test)]+mod swatch_name_tests {+ use serde_json::json;++ #[test]+ fn fills_and_strokes_must_name_a_swatch_and_change_nothing_otherwise() {+ let mut s = crate::Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let id = s.execute("frame.create", &json!({"rect": [0, 0, 100, 100]})).unwrap()["id"].clone();+ for (cmd, params, hint) in [+ ("object.fill", json!({"swatch": "Paper", "ids": [id]}), Some("[Paper]")),+ ("object.fill", json!({"swatch": "[black]", "ids": [id]}), Some("[Black]")),+ ("object.fill", json!({"swatch": "Missing Ink", "ids": [id]}), None),+ ("object.stroke", json!({"swatch": "#ff0000", "weight": 4, "ids": [id]}), None),+ ("object.stroke", json!({"gapSwatch": "paper", "ids": [id]}), Some("[Paper]")),+ ] {+ let before = s.doc().unwrap().doc.clone();+ let e = s.execute(cmd, ¶ms).unwrap_err().to_string();+ assert!(e.contains("no swatch named") && e.contains("swatch.create"), "{cmd}: {e}");+ if let Some(h) = hint {+ assert!(e.contains(&format!("did you mean `{h}`")), "{cmd}: {e}");+ }+ assert!(std::sync::Arc::ptr_eq(&before, &s.doc().unwrap().doc), "{cmd}: nothing changed");+ }+ // Real names, [None] included, still work.+ for sw in ["[Paper]", "[None]", "C=100 M=0 Y=0 K=0"] {+ s.execute("object.fill", &json!({"swatch": sw, "ids": [id]})).unwrap();+ s.execute("object.stroke", &json!({"swatch": sw, "ids": [id]})).unwrap();+ }+ }+}+++ #[cfg(test)]+ mod copy_ids_tests {+ use serde_json::json;++ #[test]+ fn copies_report_their_ids() {+ let mut s = crate::Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let a = s.execute("frame.create", &json!({"rect": [0, 0, 50, 50]})).unwrap()["id"].as_u64().unwrap();+ let ids = |r: &serde_json::Value| r["ids"].as_array().unwrap().iter().map(|v| v.as_u64().unwrap()).collect::<Vec<_>>();+ let selected = |s: &crate::Session| s.doc().unwrap().selection.items.iter().map(|i| i.0).collect::<Vec<_>>();+ // Moving reports what moved; copying reports the copies, which are selected.+ assert_eq!(ids(&s.execute("transform.move", &json!({"dx": 5, "dy": 0, "ids": [a]})).unwrap()), [a]);+ let r = s.execute("transform.move", &json!({"dx": 100, "dy": 0, "copy": true, "ids": [a]})).unwrap();+ let copy = ids(&r);+ assert!(copy.len() == 1 && copy[0] != a && s.doc().unwrap().doc.item(designcraft_doc::ItemId(copy[0])).is_some(), "{r}");+ assert_eq!(selected(&s), copy);+ // Edit › Duplicate.+ let r = s.execute("edit.duplicate", &json!({})).unwrap();+ let dup = ids(&r);+ assert!(dup.len() == 1 && dup[0] != copy[0], "{r}");+ assert_eq!(selected(&s), dup);+ // Step and Repeat: every copy.+ let r = s.execute("edit.stepAndRepeat", &json!({"count": 3, "dx": 0, "dy": 60, "ids": [a]})).unwrap();+ assert_eq!((r["created"].as_u64(), ids(&r).len()), (Some(3), 3), "{r}");+ assert!(ids(&r).iter().all(|i| s.doc().unwrap().doc.item(designcraft_doc::ItemId(*i)).is_some()));+ }+ }