Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

A: spreads of up to 10 pages — add to spread, allow shuffle

Brandon Thomas53fc678978c6
diff --git a/ROADMAP.md b/ROADMAP.md
index 0c5ead2ab..2db5077d1 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -30,6 +30,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope
- Edit › Paste Into (copied objects become a frame's content, clipped by it; rendered, PDF and IDML both ways — verified in InDesign 2026); Polygon Settings (sides, star inset; double-click the Polygon tool).
- Color panel (fill/stroke proxy, CMYK/RGB/Lab sliders with channel ramps, tint slider for swatches, spectrum ramp, Add to Swatches) and Color Picker (double-click the proxy); mixed colours are unnamed (not listed in Swatches until added); `object.color`, `swatch.addToSwatches`, `swatch.addUnnamed`.
- Place text files: Word (.docx: styles by name with their attributes, bold/italic/underline/size/font, footnotes, tables, tabs, breaks), RTF and plain text, into the insertion point, the selected frame or a new frame; autoflow adds pages and threaded frames until the text fits; Remove Styles option (`designcraft-textimport`).
+- Spreads of up to 10 pages: Add to Previous Spread and Allow Spread to Shuffle (Pages panel; `layout.pages.toSpread`, `layout.spreadShuffle`); inserted pages go around kept spreads.
- Page tool (⇧P) and `layout.pageSize`: pages of their own size (or a preset); the spine stays put and objects keep their place on their page.
- File › Print (⌘P): printer, copies, page range, spreads, marks, bleed; printed as PDF through the system spooler (`file.print`, `file.printers`, `dryRun` for agents). Shortcuts now act like choosing the menu item (dialogs open), and UI commands win shortcut ties (⌘N opens New Document).
- Nested styles (through/up to N sentences, words, characters, letters, digits, tabs, breaks, spaces or given characters) and GREP styles (regex → character style), edited in Paragraph Style Options and composed under local formatting; `ui.dialog.open` for agents. Nested line styles and their IDML mapping are still to come.
diff --git a/crates/doc/src/build.rs b/crates/doc/src/build.rs
index 6faf583a7..f7cd35ace 100644
--- a/crates/doc/src/build.rs
+++ b/crates/doc/src/build.rs
@@ -366,8 +366,20 @@ impl Document {
p
})
.collect();
- // Splice into the spread holding page `at` (or append a new spread), then repaginate.
- match self.page_loc(at) {
+ // Splice into the spread holding page `at` (or append a new spread), then repaginate. At
+ // the start of a spread that doesn't shuffle, the pages go in before it instead.
+ let loc = match self.page_loc(at) {
+ Some((si, 0)) if !self.spreads[si].allow_shuffle => {
+ let id = SpreadId(self.alloc());
+ let mut sp = Spread { id, pages: new_pages, items: vec![], parent: None, allow_shuffle: true };
+ sp.relayout();
+ self.spreads.insert(si, Arc::new(sp));
+ self.repaginate();
+ return Ok(ids);
+ }
+ l => l,
+ };
+ match loc {
Some((si, pi)) => {
let sp = Arc::make_mut(&mut self.spreads[si]);
let x = sp.pages[pi].x;
@@ -453,6 +465,47 @@ impl Document {
Ok(())
}
+ /// Move absolute page `abs` (with the objects on it) to the end of spread `to`, which stops
+ /// shuffling (Layout › Pages: spreads of up to 10 pages).
+ pub fn page_to_spread(&mut self, abs: usize, to: usize) -> Result<()> {
+ let (si, pi) = self.page_loc(abs).ok_or(DocError::NoPage(abs))?;
+ if to >= self.spreads.len() {
+ return Err(DocError::Invalid(format!("no spread {to}")));
+ }
+ if si == to {
+ return Ok(());
+ }
+ if self.spreads[to].pages.len() >= 10 {
+ return Err(DocError::Invalid("a spread holds at most 10 pages".into()));
+ }
+ // Take the page and its objects out of their spread.
+ let src = Arc::make_mut(&mut self.spreads[si]);
+ let page = src.pages.remove(pi);
+ let pb = page.bounds();
+ let (moving, staying): (Vec<_>, Vec<_>) = std::mem::take(&mut src.items).into_iter().partition(|it| {
+ let c = it.bounds().center();
+ c.x >= pb.x0 && c.x < pb.x1
+ });
+ src.items = staying;
+ src.relayout();
+ // Append to the target; objects keep their place on the page.
+ let dst = Arc::make_mut(&mut self.spreads[to]);
+ let x = dst.pages.last().map_or(0.0, |p| p.x + p.width);
+ let dx = x - page.x;
+ dst.pages.push(page);
+ dst.relayout();
+ dst.allow_shuffle = false;
+ for it in moving {
+ let mut it = Arc::unwrap_or_clone(it);
+ it.xf = Affine::translate((dx, 0.0)) * it.xf;
+ dst.items.push(Arc::new(it));
+ }
+ if self.spreads[si].pages.is_empty() {
+ self.spreads.remove(si);
+ }
+ Ok(())
+ }
+
/// Apply a parent (None = [None]) to absolute pages.
pub fn apply_parent(&mut self, pages: &[usize], parent: Option<SpreadId>) -> Result<()> {
if let Some(p) = parent
diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs
index 54b4c6a57..167ddfec0 100644
--- a/crates/engine/src/cmd/layout.rs
+++ b/crates/engine/src/cmd/layout.rs
@@ -219,6 +219,43 @@ pub fn specs() -> Vec<CommandSpec> {
})
}
),
+ cmd!(
+ "layout.pages.toSpread",
+ "Add Page to Spread",
+ ["Layout", "Pages"],
+ None,
+ "{page (1-based), spread (0-based)} — the page joins that spread (up to 10 pages; the spread stops shuffling)",
+ has_doc,
+ |s, p| {
+ let page =
+ p.get("page").and_then(Value::as_u64).filter(|n| *n >= 1).ok_or_else(|| bad("layout.pages.toSpread", "missing page"))? as usize;
+ let spread = p.get("spread").and_then(Value::as_u64).ok_or_else(|| bad("layout.pages.toSpread", "missing spread"))? as usize;
+ s.edit(|d, _| {
+ d.page_to_spread(page - 1, spread)?;
+ Ok(json!({"spreads": d.spreads.len()}))
+ })
+ }
+ ),
+ cmd!(
+ "layout.spreadShuffle",
+ "Allow Selected Spread to Shuffle",
+ ["Layout", "Pages"],
+ None,
+ "{spread (0-based), allow: bool} — off keeps the spread's pages together when pages are added or removed",
+ has_doc,
+ |s, p| {
+ let si = p.get("spread").and_then(Value::as_u64).unwrap_or(0) as usize;
+ let allow = p.get("allow").and_then(Value::as_bool).unwrap_or(true);
+ s.edit(|d, _| {
+ let sp = d.spreads.get_mut(si).ok_or_else(|| bad("layout.spreadShuffle", "no such spread"))?;
+ std::sync::Arc::make_mut(sp).allow_shuffle = allow;
+ if allow {
+ d.repaginate();
+ }
+ ok()
+ })
+ }
+ ),
cmd!(
"layout.pageSize",
"Page Size",
@@ -618,3 +655,30 @@ mod page_size_tests {
assert!(s.execute("layout.pageSize", &json!({"pages": [9], "width": 100})).is_err());
}
}
+
+#[cfg(test)]
+mod spread_tests {
+ use serde_json::json;
+
+ #[test]
+ fn three_page_spread_survives_page_inserts() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({"pages": 5})).unwrap();
+ // [1] [2 3] [4 5]: page 4 joins spread 1 → [1] [2 3 4] [5].
+ let d = s.doc().unwrap().doc.clone();
+ let (si, pi) = d.page_loc(3).unwrap();
+ let x = d.spreads[si].pages[pi].x;
+ let id = s.execute("frame.create", &json!({"spread": si, "rect": [x + 50.0, 50, x + 150.0, 150]})).unwrap()["id"].as_u64().unwrap();
+ s.execute("layout.pages.toSpread", &json!({"page": 4, "spread": 1})).unwrap();
+ let d = s.doc().unwrap().doc.clone();
+ assert_eq!(d.spreads[1].pages.len(), 3);
+ assert!(!d.spreads[1].allow_shuffle);
+ assert_eq!(d.page_of_item(designcraft_doc::ItemId(id)), Some(3), "the object went with its page");
+ // Adding a page at the start reshuffles the others but keeps the 3-page spread.
+ s.execute("layout.pages.insert", &json!({"after": 0, "count": 1})).unwrap();
+ let d = s.doc().unwrap().doc.clone();
+ assert!(d.spreads.iter().any(|sp| sp.pages.len() == 3 && !sp.allow_shuffle));
+ assert_eq!(d.page_count(), 6);
+ d.check().unwrap();
+ }
+}
diff --git a/crates/ui-egui/src/panels/pages.rs b/crates/ui-egui/src/panels/pages.rs
index 39565ef83..d10a2e1c6 100644
--- a/crates/ui-egui/src/panels/pages.rs
+++ b/crates/ui-egui/src/panels/pages.rs
@@ -220,6 +220,15 @@ fn page_menu(app: &mut DesignApp, ui: &mut egui::Ui, doc: &designcraft_doc::Docu
let _ = app.run("layout.pages.duplicateSpread", json!({"spread": si}));
ui.close();
}
+ if si > 0 && ui.button("Add to Previous Spread").on_hover_text("Spreads of up to 10 pages").clicked() {
+ let _ = app.run("layout.pages.toSpread", json!({"page": abs + 1, "spread": si - 1}));
+ ui.close();
+ }
+ let mut shuffle = doc.spreads.get(si).is_none_or(|sp| sp.allow_shuffle);
+ if ui.checkbox(&mut shuffle, "Allow Spread to Shuffle").clicked() {
+ let _ = app.run("layout.spreadShuffle", json!({"spread": si, "allow": shuffle}));
+ ui.close();
+ }
ui.separator();
for (id, label) in [
("layout.overrideParentItems", "Override All Parent Page Items"),
diff --git a/docs/parity.md b/docs/parity.md
index 218705b34..f0f62ebd7 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -5,18 +5,18 @@ The summary is generated by `cargo xtask parity` from the table at the bottom of
Each row of the InDesign feature catalogue is scored **D** (done), **P** (partial: works but lacks options or UI) or **M** (missing), weighted by priority (**P0** core = 3, **P1** = 2, **P2** = 1). Out-of-scope rows (Adobe cloud services, plug-ins, Typekit, Flash) are excluded.
<!-- SUMMARY -->
-**Weighted breadth parity: 79%** over 275 features.
+**Weighted breadth parity: 80%** over 275 features.
| Priority | Features | Done | Partial | Missing | Parity |
|---|---|---|---|---|---|
| P0 | 102 | 99 | 3 | 0 | 99% |
-| P1 | 97 | 59 | 25 | 13 | 74% |
+| P1 | 97 | 60 | 25 | 12 | 75% |
| P2 | 76 | 8 | 7 | 61 | 15% |
| Area | Parity |
|---|---|
| Application shell & workspace | 80% |
-| Documents, pages, spreads | 81% |
+| Documents, pages, spreads | 84% |
| Layers | 95% |
| Frames, shapes & paths | 87% |
| Transform | 93% |
@@ -62,7 +62,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t
| Documents, pages, spreads | Document Setup | P0 | D |
| Documents, pages, spreads | Page sizes | P0 | D |
| Documents, pages, spreads | Facing pages / spreads | P0 | D |
-| Documents, pages, spreads | Pages per spread up to 10 | P1 | M |
+| Documents, pages, spreads | Pages per spread up to 10 | P1 | D |
| Documents, pages, spreads | Insert/move/duplicate/delete pages | P0 | D |
| Documents, pages, spreads | Per-page size (Page tool) | P1 | D |
| Documents, pages, spreads | Margins and Columns per page | P0 | D |