DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge t15-b: #863 #860 #869 #870, new heads of #802 #319 #829 #589 #490 #562, #643's test
aiongg1c788654bf00
diff --cc ROADMAP.mdindex 35bb2babd,7a62ec3de..dd6195f45--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -128,11 -128,9 +128,14 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+- **2026-10-14** · The Liquid Layout panel follows InDesign's: Liquid Page Rule with the page number, Content › Auto-Fit, and Object Constraints › Resize with Page and Pin for the selected object on an object-based page; Create Alternate Layout moved to the Layout menu. No readiness percentage change.+- **2026-10-14** · On an object-based page the Page tool shows a selected object's liquid pins and resize locks as InDesign does: a click pins a side to the page edge or locks the width or height, with InDesign's tooltips. No readiness percentage change.+- **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.+- **2026-10-14** · The Page tool works as InDesign's: a click selects a page and shows its handles and liquid page rule; dragging a handle previews the rule and springs back, Alt-drag resizes the page from the opposite edge, Shift keeps proportions, with a W/H readout. No readiness percentage change.+- **2026-10-14** · With the Page tool, a guide dragged from a ruler is a liquid guide (dashed), as in InDesign; guide-based pages stretch the objects it crosses. No readiness percentage change.+ - **2026-10-14** · The Pages panel menu follows InDesign's order: Insert Pages…, Move Pages…, Duplicate Spread (and at End of Document), Delete Page (and Delete Spread for a spread of several pages), New Parent…, Apply Parent to Pages, Override All Parent Page Items, Parent Pages, Create Alternate Layout…, Numbering & Section Options…, Allow Selected Spread to Shuffle. No readiness percentage change.+ - **2026-10-14** · Pages panel: Alt-drag copies a page that is a spread of its own (one undo step; `layout.pages.duplicateSpread` takes `to`), a page dropped on Create new page is duplicated at the end, Edit page size offers the presets and Custom Page Size…; duplicated pages keep their own size, rule and guides; thumbnails of pages of their own size stay in their rows. No readiness percentage change.+ - **2026-10-13** · IDML: an anchored object takes each anchor setting it leaves unset from its object style, the styles that one is based on, then `[None]`; other item attributes read through the same chain. A left-aligned anchored object's X offset reads in the layout's direction. A rotated group's bounds follow its children's outlines instead of the box of their rotated boxes. No readiness percentage change.- **2026-10-13** · Control-channel clicks and drags validate positive counts and the complete pending-event budget before queuing input (#732). Oversized requests leave pending gestures intact, preventing unbounded click-count allocation. No readiness percentage change.- **2026-10-13** · Switching between document and parent pages refreshes the canvas immediately, preventing black parent pages and stale document objects when the zoom stays the same. Ordinary edits retain partial repainting. No readiness percentage change.- **2026-10-13** · Placed PDFs are drawn through pdfcraft's patched hayro crates: calculator functions whose `idiv` divides by zero or overflows, chains of stitching functions a hundred thousand deep, and mesh shadings with points far off the page, ten thousand overlapping triangles or forty thousand patches no longer panic, overflow the stack, run for over a minute or use more than 2 GiB of memory. A page with a `/UserUnit`, and its trim, bleed and art boxes, are sized in points. No readiness percentage change.diff --cc crates/engine/src/tests.rsindex 76e364770,6e715f617..41ffba0ba--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@@ -1259,156 -1259,56 +1259,210 @@@ fn alt_arrows_kern_at_the_caret_and_traassert_eq!((t.anchor, t.focus), (0, 5));}+#[test]+fn page_tool_selects_a_page_and_its_handles_preview_or_resize_it() {+ use designcraft_tools::{CanvasLayout, Mods, PointerEvent, PointerKind};+ let mut s = Session::new();+ s.execute("file.new", &json!({"width": 612, "height": 792, "facingPages": false})).unwrap();+ let id = s.execute("frame.create", &json!({"rect": [400, 100, 500, 200]})).unwrap()["id"].as_u64().unwrap();+ let frame = |s: &Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().bounds();+ let width = |s: &Session| s.doc().unwrap().doc.spreads[0].pages[0].width;+ // The page on the canvas (a single page is centred on the spine).+ let page = |s: &Session| {+ let d = &s.doc().unwrap().doc;+ CanvasLayout::new(d, false).page_rect(d, 0).unwrap()+ };+ s.set_tool("page");+ let v = ViewInfo::at_zoom(1.0);+ let ev = |kind, x: f64, y: f64, alt: bool| PointerEvent { mods: Mods { alt, ..Default::default() }, ..PointerEvent::new(kind, x, y) };+ let drag = |s: &mut Session, from: (f64, f64), by: f64, alt: bool, check: &dyn Fn(&Session)| {+ s.pointer(&ev(PointerKind::Down, from.0, from.1, alt), v).unwrap();+ s.pointer(&ev(PointerKind::Drag, from.0 + by, from.1, alt), v).unwrap();+ check(s);+ s.pointer(&ev(PointerKind::Up, from.0 + by, from.1, alt), v).unwrap();+ };+ // A click selects the page.+ let c = page(&s).center();+ s.pointer(&ev(PointerKind::Down, c.x, c.y, false), v).unwrap();+ s.pointer(&ev(PointerKind::Up, c.x, c.y, false), v).unwrap();+ assert_eq!(s.doc().unwrap().selection.page, Some(0));+ // A plain drag of the right handle previews the page's liquid rule and springs back.+ s.execute("liquid.pageRule", &json!({"rule": "scale"})).unwrap();+ let undo = s.doc().unwrap().history.undo.len();+ let r = page(&s);+ drag(&mut s, (r.x1, r.center().y), 612.0, false, &|s| {+ assert_eq!(width(s), 1224.0, "previewed");+ // Scale keeps proportions: only wider, so the frame is centred on the wider page.+ assert_eq!(frame(s).x0, 706.0, "the Scale rule in the preview: {:?}", frame(s));+ });+ assert_eq!((width(&s), frame(&s)), (612.0, designcraft_geom::Rect::new(400.0, 100.0, 500.0, 200.0)), "sprung back");+ assert_eq!(s.doc().unwrap().history.undo.len(), undo, "nothing to undo");+ // Alt-drag resizes; with the rule off the frame stays where it is.+ s.execute("liquid.pageRule", &json!({"rule": "off"})).unwrap();+ let r = page(&s);+ drag(&mut s, (r.x1, r.center().y), 100.0, true, &|_| {});+ assert_eq!(width(&s), 712.0);+ assert_eq!(frame(&s).x0, 400.0);+ // The left handle grows the page to the left: the frame keeps its place by the right edge.+ let r = page(&s);+ drag(&mut s, (r.x0, r.center().y), -100.0, true, &|_| {});+ let pg = s.doc().unwrap().doc.spreads[0].pages[0].clone();+ assert_eq!(pg.width, 812.0);+ assert_eq!(frame(&s).x0 - pg.x, 500.0, "100 pt further from the page's left edge");+ // A click on the pasteboard deselects the page.+ let r = page(&s);+ s.pointer(&ev(PointerKind::Down, r.x0 - 200.0, r.center().y, false), v).unwrap();+ assert_eq!(s.doc().unwrap().selection.page, None);+}++#[test]+fn page_size_keeps_objects_by_its_anchor() {+ let mut s = Session::new();+ s.execute("file.new", &json!({"width": 400, "height": 400, "facingPages": false})).unwrap();+ let id = s.execute("frame.create", &json!({"rect": [100, 100, 200, 200]})).unwrap()["id"].as_u64().unwrap();+ let frame = |s: &Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().bounds();+ // Bottom-right stays put: 100 wider and 50 taller moves the frame 100 right and 50 down.+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 500, "height": 450, "anchor": 8})).unwrap();+ assert_eq!(frame(&s), designcraft_geom::Rect::new(200.0, 150.0, 300.0, 250.0));+ // The centre: half of it.+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 700, "height": 450, "anchor": 4})).unwrap();+ assert_eq!(frame(&s).x0, 300.0);+ assert!(s.execute("layout.pageSize", &json!({"pages": [1], "width": 700, "anchor": 9})).is_err());+ assert!(s.execute("layout.selectPage", &json!({"page": 2})).is_err());+ assert_eq!(s.execute("layout.selectPage", &json!({"page": 1})).unwrap()["page"], 1);+}++#[test]+fn controlled_by_parent_takes_the_parent_pages_rule() {+ let mut s = Session::new();+ s.execute("file.new", &json!({"width": 400, "height": 400, "facingPages": false})).unwrap();+ let id = s.execute("frame.create", &json!({"rect": [100, 100, 200, 200]})).unwrap()["id"].as_u64().unwrap();+ let frame = |s: &Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().bounds();+ // The page follows its parent; the parent page re-centres.+ s.execute("liquid.pageRule", &json!({"rule": "controlledByParent", "pages": [1]})).unwrap();+ s.edit(|d, _| {+ std::sync::Arc::make_mut(&mut d.parents[0]).pages[0].liquid = designcraft_doc::LiquidRule::ReCenter;+ Ok(())+ })+ .unwrap();+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 600})).unwrap();+ assert_eq!(frame(&s).x0, 200.0, "re-centred: {:?}", frame(&s));+ // Without a parent (or a parent that's also controlled by its parent) nothing moves.+ s.execute("layout.pages.applyParent", &json!({"pages": [0], "parent": null})).unwrap();+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 800})).unwrap();+ assert_eq!(frame(&s).x0, 200.0);+ // Show Parent Page Overlay is a page option.+ s.execute("layout.pageOptions", &json!({"pages": [1], "showParentOverlay": true})).unwrap();+ assert!(s.doc().unwrap().doc.spreads[0].pages[0].show_parent_overlay);+ assert!(s.execute("layout.pageOptions", &json!({"pages": [2], "showParentOverlay": true})).is_err());+}++#[test]+fn page_tool_pins_and_locks_objects_on_object_based_pages() {+ use designcraft_tools::{CanvasLayout, Mods, PointerEvent, PointerKind};+ let mut s = Session::new();+ s.execute("file.new", &json!({"width": 612, "height": 792, "facingPages": false})).unwrap();+ let id = s.execute("frame.create", &json!({"rect": [256, 72, 356, 132]})).unwrap()["id"].as_u64().unwrap();+ s.execute("liquid.pageRule", &json!({"rule": "objectBased"})).unwrap();+ s.execute("edit.deselectAll", &json!({})).unwrap();+ s.set_tool("page");+ let v = ViewInfo::at_zoom(1.0);+ let ev =+ |kind, p: designcraft_geom::Point, alt: bool| PointerEvent { mods: Mods { alt, ..Default::default() }, ..PointerEvent::new(kind, p.x, p.y) };+ let canvas = |s: &Session| {+ let d = &s.doc().unwrap().doc;+ let l = CanvasLayout::new(d, false);+ (+ l.page_rect(d, 0).unwrap(),+ l.xf(designcraft_doc::SpreadRef::Doc(0)).transform_rect_bbox(d.item(designcraft_doc::ItemId(id)).unwrap().bounds()),+ )+ };+ let click = |s: &mut Session, p: designcraft_geom::Point| {+ s.pointer(&ev(PointerKind::Down, p, false), v).unwrap();+ s.pointer(&ev(PointerKind::Up, p, false), v).unwrap();+ };+ let liquid = |s: &Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().liquid;+ // A click on the object selects it with its page; its pins and locks show.+ let (_, o) = canvas(&s);+ click(&mut s, o.center());+ let sel = s.doc().unwrap().selection.clone();+ assert_eq!((sel.page, sel.items.clone()), (Some(0), vec![designcraft_doc::ItemId(id)]));+ assert!(+ s.overlays(v)+ .iter()+ .any(|o| matches!(o, designcraft_tools::Overlay::LiquidPins { pins: [false, false, false, false], resize: [true, true], .. }))+ );+ // The right pin (14 px outside the right edge) and the width lock (10 px right of the centre).+ click(&mut s, designcraft_geom::Point::new(o.x1 + 14.0, o.center().y));+ click(&mut s, designcraft_geom::Point::new(o.center().x + 10.0, o.center().y));+ let l = liquid(&s).unwrap();+ assert!(l.pin_right && !l.resize_width && l.resize_height && !l.pin_left, "{l:?}");+ // Alt-drag the page 100 pt wider: the pinned, width-locked frame keeps its size by the right edge.+ let (p, _) = canvas(&s);+ let right = designcraft_geom::Point::new(p.x1, p.center().y);+ s.pointer(&ev(PointerKind::Down, right, true), v).unwrap();+ s.pointer(&ev(PointerKind::Drag, right + designcraft_geom::Vec2::new(100.0, 0.0), true), v).unwrap();+ s.pointer(&ev(PointerKind::Up, right + designcraft_geom::Vec2::new(100.0, 0.0), true), v).unwrap();+ let d = &s.doc().unwrap().doc;+ let (pg, b) = (&d.spreads[0].pages[0], d.item(designcraft_doc::ItemId(id)).unwrap().bounds());+ assert_eq!(pg.width, 712.0);+ assert!((b.width() - 100.0).abs() < 1e-6 && (pg.x + pg.width - b.x1 - 256.0).abs() < 1e-6, "{b:?}");+ // Hovering a pin shows its tooltip.+ let (_, o) = canvas(&s);+ s.pointer(&ev(PointerKind::Move, designcraft_geom::Point::new(o.x1 + 14.0, o.center().y), false), v).unwrap();+ assert!(s.overlays(v).iter().any(|o| matches!(o, designcraft_tools::Overlay::Tip { text, .. } if text.starts_with("Object is pinned"))));+}+++ #[test]+ fn duplicating_a_page_to_an_index_is_one_undo_step() {+ let mut s = Session::new();+ s.execute("file.new", &json!({"facingPages": false})).unwrap();+ s.execute("layout.pages.insert", &json!({"count": 2})).unwrap();+ for (page, width) in [(1, 300), (2, 400), (3, 500)] {+ s.execute("layout.pageSize", &json!({"pages": [page], "width": width, "height": 600})).unwrap();+ }+ let widths = |s: &Session| {+ let d = &s.doc().unwrap().doc;+ (0..d.page_count()).map(|i| d.page_loc(i).map(|(si, pi)| d.spreads[si].pages[pi].width)).collect::<Option<Vec<_>>>().unwrap()+ };+ // Backwards: the last page copied to the front.+ let r = s.execute("layout.pages.duplicateSpread", &json!({"spread": 2, "to": 0})).unwrap();+ assert_eq!(r["page"], 0);+ assert_eq!(widths(&s), [500.0, 300.0, 400.0, 500.0]);+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(widths(&s), [300.0, 400.0, 500.0]);+ // Forwards: the first page copied to the end.+ s.execute("layout.pages.duplicateSpread", &json!({"spread": 0, "to": 3})).unwrap();+ assert_eq!(widths(&s), [300.0, 400.0, 500.0, 300.0]);+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(widths(&s), [300.0, 400.0, 500.0]);+ // Past the end: refused, nothing changes.+ assert!(s.execute("layout.pages.duplicateSpread", &json!({"spread": 0, "to": 4})).is_err());+ assert_eq!(widths(&s), [300.0, 400.0, 500.0]);+ }++ #[test]+ fn duplicating_a_page_keeps_its_own_size_rule_guides_and_objects() {+ // Chris Cicchino's Page Tool video (2:06): the letterhead page is duplicated, then resized.+ let mut s = Session::new();+ s.execute("file.new", &json!({"width": 252, "height": 144, "facingPages": false})).unwrap();+ s.execute("layout.pages.insert", &json!({"count": 1})).unwrap();+ s.execute("layout.pageSize", &json!({"pages": [2], "width": 612, "height": 792})).unwrap();+ s.execute("liquid.pageRule", &json!({"rule": "scale", "pages": [2]})).unwrap();+ s.execute("guide.add", &json!({"spread": 1, "page": 0, "orientation": "vertical", "position": 300})).unwrap();+ s.execute("frame.create", &json!({"spread": 1, "rect": [100, 100, 200, 200]})).unwrap();+ let r = s.execute("layout.pages.duplicateSpread", &json!({"spread": 1})).unwrap();+ assert_eq!(r["page"], 2);+ let d = s.doc().unwrap().doc.clone();+ let (si, pi) = d.page_loc(2).unwrap();+ let pg = &d.spreads[si].pages[pi];+ assert_eq!((pg.width, pg.height, pg.liquid), (612.0, 792.0, designcraft_doc::LiquidRule::Scale));+ assert_eq!(pg.guides.len(), 1);+ assert_eq!(d.spreads[si].items.len(), 1);+ // At the end of the document (the New Page button): the business card, not the last page's size.+ let r = s.execute("layout.pages.duplicateSpread", &json!({"spread": 0, "atEnd": true})).unwrap();+ assert_eq!(r["page"], 3);+ let d = s.doc().unwrap().doc.clone();+ let (si, pi) = d.page_loc(3).unwrap();+ assert_eq!((d.spreads[si].pages[pi].width, d.spreads[si].pages[pi].height), (252.0, 144.0));+ }