DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge PR #870 (with #869)
Brandon Thomas4f193834bd18
diff --cc ROADMAP.mdindex 667827691,6d8b27bfe..0dbb60372--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -127,20 -126,10 +127,22 @@@ list) · [roadmap.md](docs/roadmap.md)## Progress log+- **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.+Newest first.+- **2026-10-13** · Object › Fitting has InDesign's shortcuts: Fill Frame Proportionally ⌘⌥⇧C, Fit Content Proportionally ⌘⌥⇧E, Fit Frame to Content ⌘⌥C, Fit Content to Frame ⌘⌥E, Center Content ⌘⇧E. No readiness percentage change.+- **2026-10-13** · Gradients between process colours blend as inks, as InDesign shows them: magenta to cyan passes through C 50 M 50 (a light lilac) on screen instead of the darker RGB mix, and a midpoint between CMYK or grey stops no longer turns the PDF shading RGB. No readiness percentage change.+- **2026-10-14** · The Swatches panel has InDesign's header: a Fill/Stroke proxy, Formatting Affects Container/Text and the Tint of the colour in front (a tint alone keeps each object's own swatch). Clicking a swatch applies it to the fill or stroke in front (of the text, when formatting affects text), and the bottom row has New Color Group, New Swatch and Delete Swatch. 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 (now with Controlled by Parent) and Show Parent Page Overlay, which draws the parent page's size over a resized page. 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** · 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** · 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 (now with Controlled by Parent) and Show Parent Page Overlay, which draws the parent page's size over a resized page. 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/Spread, 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, 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-12** · Text threads by hand: click a selected text frame's in or out port to loadthe text cursor, then click a frame to thread it, click empty space for a column-wide frame ordrag one (it snaps like frame drawing); Shift-click autoflows, Alt-click stays loaded on thediff --cc crates/engine/src/tests.rsindex e74485df3,962a0f69d..712dc06bc--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@@ -570,160 -570,32 +570,186 @@@ fn commands_take_non_object_params_with}}+#[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_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));+ }+/// Load the text from a frame's out port with the Selection tool and click on the pasteboard:/// a new frame is threaded there and the overset text flows into it.#[test]