DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
A: Document Setup — pages, start page #, intent, size presets, orientation, bleed and slug
Brandon Thomas53272183a224
diff --git a/ROADMAP.md b/ROADMAP.mdindex dfff83fbb..766dec894 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`).+- Document Setup (⌥⌘P): intent, number of pages, start page # (an even start begins with a left page), facing pages, size presets and orientation, bleed and slug per edge; `layout.documentSetup {}` reports the setup.- Stroke panel: cap, join, miter limit, alignment, type, Start/End arrowheads (12 kinds, drawn on screen and in PDF; the path is shortened under pointed heads) and gap colour under dashes and dots.- Preferences (⌘K: General, Type, Units & Increments) backed by `prefs.set` (application) and `document.preferences` (units, increments, grids — undoable, saved with the document); scaling applies to content and scales stroke weights (Include Stroke Weight), and X/Y/W/H measure the stroke's outer edge (Dimensions Include Stroke Weight). Quick Apply (⌘Return) finds paragraph, character and object styles as well as commands.- Parent item overrides: Cmd+Shift-click a parent item on a page (or Override All Parent Page Items, ⌥⇧⌘L) makes an editable local copy that hides the parent's; Remove All Local Overrides and Detach All Objects from Parent in the Pages panel menu.diff --git a/crates/doc/src/build.rs b/crates/doc/src/build.rsindex 38b53ed65..16a387067 100644--- a/crates/doc/src/build.rs+++ b/crates/doc/src/build.rs@@ -277,10 +277,12 @@ impl Document {}spreads.push(sp);};+ // An even start page number (Document Setup › Start Page #) begins with a left page.+ let shift = usize::from(self.sections.iter().find(|x| x.start == 0).and_then(|x| x.start_number).is_some_and(|n| n % 2 == 0));for (i, (mut p, items)) in pages.into_iter().enumerate() {if facing {- // Page i (0-based) is a right page when i is even (page 1, 3, 5 …).- p.side = if i % 2 == 0 { PageSide::Right } else { PageSide::Left };+ // Page i (0-based) is a right page when its number is odd (1, 3, 5 …).+ p.side = if (i + shift) % 2 == 0 { PageSide::Right } else { PageSide::Left };if p.side == PageSide::Left && !cur.is_empty() {let id = SpreadId(self.alloc());flush(&mut cur, &mut spreads, id);diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rsindex 17857303f..f9ce8e2e7 100644--- a/crates/engine/src/cmd/layout.rs+++ b/crates/engine/src/cmd/layout.rs@@ -140,16 +140,65 @@ pub fn specs() -> Vec<CommandSpec> {"Document Setup…",["File"],Some("Cmd+Alt+P"),- "{width?, height?, facingPages?, bleed?: number}",+ "{width?, height?, pages?: count, startPage?: n, facingPages?, intent?: print|web|mobile, bleed?, slug?: n | [top, bottom, inside, outside]} → the document setup",has_doc,|s, p| {let p = p.clone();+ if p.as_object().is_none_or(|o| o.is_empty()) {+ return Ok(document_setup(&s.doc()?.doc));+ }+ let edges = |k: &str| -> Option<[f64; 4]> {+ match p.get(k)? {+ Value::Array(a) if a.len() == 4 => {+ let v: Vec<f64> = a.iter().filter_map(Value::as_f64).map(|v| v.max(0.0)).collect();+ (v.len() == 4).then(|| [v[0], v[1], v[2], v[3]])+ }+ v => v.as_f64().map(|b| [b.max(0.0); 4]),+ }+ };+ let (bleed, slug) = (edges("bleed"), edges("slug"));+ let intent: Option<designcraft_doc::Intent> = p.get("intent").and_then(|v| serde_json::from_value(v.clone()).ok());+ let pages = p.get("pages").and_then(Value::as_u64).map(|n| n.clamp(1, 9999) as usize);s.edit(|d, _| {if let Some(f) = p.get("facingPages").and_then(Value::as_bool) {d.settings.facing_pages = f;}- if let Some(b) = p.get("bleed").and_then(Value::as_f64) {- d.settings.bleed = [b; 4];+ if let Some(b) = bleed {+ d.settings.bleed = b;+ }+ if let Some(b) = slug {+ d.settings.slug = b;+ }+ if let Some(i) = intent {+ d.settings.intent = i;+ }+ if let Some(n) = p.get("startPage").and_then(Value::as_u64) {+ if !d.sections.iter().any(|x| x.start == 0) {+ d.sections.insert(+ 0,+ designcraft_doc::Section {+ start: 0,+ start_number: None,+ style: Default::default(),+ prefix: String::new(),+ marker: String::new(),+ include_prefix: false,+ },+ );+ }+ if let Some(first) = d.sections.iter_mut().find(|x| x.start == 0) {+ first.start_number = Some(n.max(1) as u32);+ }+ }+ // Number of Pages: add at the end (with the last page's parent) or remove from the end.+ if let Some(n) = pages {+ let have = d.page_count();+ if n > have {+ let parent = d.page_loc(have - 1).and_then(|(si, pi)| d.spreads[si].pages[pi].parent);+ d.insert_pages(Some(have - 1), n - have, parent)?;+ } else if n < have {+ d.delete_pages(&(n..have).collect::<Vec<_>>())?;+ }}let w = p.get("width").and_then(Value::as_f64);let h = p.get("height").and_then(Value::as_f64);@@ -166,7 +215,7 @@ pub fn specs() -> Vec<CommandSpec> {}}d.repaginate();- ok()+ Ok(document_setup(d))})}),@@ -329,3 +378,38 @@ fn parent_ref(d: &designcraft_doc::Document, v: Option<&Value>) -> Option<Option#[allow(dead_code)]fn _r(_: Result<()>) {}++/// File › Document Setup values.+fn document_setup(d: &designcraft_doc::Document) -> Value {+ let st = &d.settings;+ let start = d.sections.iter().find(|x| x.start == 0).and_then(|x| x.start_number).unwrap_or(1);+ json!({"width": st.page_width, "height": st.page_height, "pages": d.page_count(), "startPage": start, "facingPages": st.facing_pages,+ "intent": st.intent, "bleed": st.bleed, "slug": st.slug})+}++#[cfg(test)]+mod setup_tests {+ use serde_json::json;++ #[test]+ fn document_setup_pages_start_bleed_slug() {+ let mut s = crate::Session::new();+ s.execute("file.new", &json!({"pages": 2})).unwrap();+ let r = s.execute("layout.documentSetup", &json!({})).unwrap();+ assert_eq!(r["pages"], 2);+ assert_eq!(r["startPage"], 1);+ let r = s.execute("layout.documentSetup", &json!({"pages": 5, "startPage": 2, "bleed": 9, "slug": [0, 18, 0, 0], "intent": "web"})).unwrap();+ assert_eq!(r["pages"], 5);+ assert_eq!(r["startPage"], 2);+ assert_eq!(r["bleed"], json!([9.0, 9.0, 9.0, 9.0]));+ assert_eq!(r["slug"], json!([0.0, 18.0, 0.0, 0.0]));+ assert_eq!(r["intent"], "web");+ let d = &s.doc().unwrap().doc;+ assert_eq!(d.page_name(0), "2");+ assert_eq!(d.page(0).unwrap().side, designcraft_doc::PageSide::Left);+ assert_eq!(d.spreads[0].pages.len(), 2, "pages 2–3 form the first spread");+ let r = s.execute("layout.documentSetup", &json!({"pages": 3})).unwrap();+ assert_eq!(r["pages"], 3);+ s.doc().unwrap().doc.check().unwrap();+ }+}diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 198fa284e..d9ef19e99 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -102,6 +102,101 @@ fn text_field(ui: &mut egui::Ui, d: &mut Dialog, key: &str, w: f32) {}}+/// File › Document Setup, filled from the document.+pub fn open_document_setup(app: &mut DesignApp) {+ let Ok(cur) = app.session.execute("layout.documentSetup", &json!({})) else { return };+ let units = app.session.active().map(|s| s.doc.settings.horizontal_units).unwrap_or(Unit::Picas);+ let fm = |v: &Value| json!(format_measure(v.as_f64().unwrap_or(0.0), units));+ let mut f = json!({"intent": cur["intent"], "pages": cur["pages"], "startPage": cur["startPage"], "facingPages": cur["facingPages"],+ "width": fm(&cur["width"]), "height": fm(&cur["height"])});+ for k in ["bleed", "slug"] {+ for (i, e) in ["Top", "Bottom", "Inside", "Outside"].iter().enumerate() {+ f[format!("{k}{e}")] = fm(&cur[k][i]);+ }+ }+ app.ui.dialog = Some(Dialog::new("documentSetup", f));+}++fn document_setup(ui: &mut egui::Ui, d: &mut Dialog) {+ egui::Grid::new("ds").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {+ ui.label("Intent:");+ let cur = d.s("intent");+ egui::ComboBox::from_id_salt("ds_intent")+ .selected_text(match cur.as_str() {+ "web" => "Web",+ "mobile" => "Mobile",+ _ => "Print",+ })+ .width(110.0)+ .show_ui(ui, |ui| {+ for (v, l) in [("print", "Print"), ("web", "Web"), ("mobile", "Mobile")] {+ if ui.selectable_label(cur == v, l).clicked() {+ d.fields.insert("intent".into(), json!(v));+ }+ }+ });+ ui.label("");+ ui.label("");+ ui.end_row();+ ui.label("Number of Pages:");+ text_field(ui, d, "pages", 60.0);+ check(ui, d, "facingPages", "Facing Pages");+ ui.label("");+ ui.end_row();+ ui.label("Start Page #:");+ text_field(ui, d, "startPage", 60.0);+ ui.end_row();+ });+ ui.add_space(8.0);+ ui.label(egui::RichText::new("Page Size").font(semibold(12.0)));+ let (w, h) = (d.m("width").unwrap_or(612.0), d.m("height").unwrap_or(792.0));+ let preset =+ designcraft_doc::build::PRESETS.iter().find(|p| (p.width - w).abs() < 0.5 && (p.height - h).abs() < 0.5).map_or("Custom", |p| p.name);+ egui::Grid::new("ds_size").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {+ ui.label("Size:");+ egui::ComboBox::from_id_salt("ds_preset").selected_text(preset).width(140.0).show_ui(ui, |ui| {+ for p in designcraft_doc::build::PRESETS {+ if ui.selectable_label(p.name == preset, p.name).clicked() {+ d.fields.insert("width".into(), json!(format_measure(p.width, p.units)));+ d.fields.insert("height".into(), json!(format_measure(p.height, p.units)));+ }+ }+ });+ ui.label("Orientation:");+ ui.horizontal(|ui| {+ for (portrait, l) in [(true, "Portrait"), (false, "Landscape")] {+ if ui.selectable_label((h >= w) == portrait, l).clicked() && (h >= w) != portrait {+ let (fw, fh) = (d.s("width"), d.s("height"));+ d.fields.insert("width".into(), json!(fh));+ d.fields.insert("height".into(), json!(fw));+ }+ }+ });+ ui.end_row();+ ui.label("Width:");+ text_field(ui, d, "width", 80.0);+ ui.label("Height:");+ text_field(ui, d, "height", 80.0);+ ui.end_row();+ });+ ui.add_space(8.0);+ ui.label(egui::RichText::new("Bleed and Slug").font(semibold(12.0)));+ egui::Grid::new("ds_bleed").num_columns(5).spacing([8.0, 6.0]).show(ui, |ui| {+ ui.label("");+ for e in ["Top", "Bottom", "Inside", "Outside"] {+ ui.label(e);+ }+ ui.end_row();+ for (k, l) in [("bleed", "Bleed:"), ("slug", "Slug:")] {+ ui.label(l);+ for e in ["Top", "Bottom", "Inside", "Outside"] {+ text_field(ui, d, &format!("{k}{e}"), 60.0);+ }+ ui.end_row();+ }+ });+}+/// Preferences: a section list and the section's options. Application options always; units and/// increments when a document is open (InDesign keeps those with the document).fn preferences(ui: &mut egui::Ui, d: &mut Dialog) {@@ -386,20 +481,7 @@ pub fn show(app: &mut DesignApp, ctx: &egui::Context) {ui.end_row();});}- "documentSetup" => {- let st = app.session.active();- let (w, h) = st.map(|s| (s.doc.settings.page_width, s.doc.settings.page_height)).unwrap_or((612.0, 792.0));- d.fields.entry("width".to_string()).or_insert(json!(format_measure(w, Unit::Picas)));- d.fields.entry("height".to_string()).or_insert(json!(format_measure(h, Unit::Picas)));- egui::Grid::new("ds").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {- ui.label("Width");- text_field(ui, &mut d, "width", 90.0);- ui.end_row();- ui.label("Height");- text_field(ui, &mut d, "height", 90.0);- ui.end_row();- });- }+ "documentSetup" => document_setup(ui, &mut d),_ => {}}ui.add_space(12.0);@@ -467,7 +549,14 @@ pub fn confirm(app: &mut DesignApp) -> Result<Value, String> {"object.textFrameOptions",json!({"columns": d.n("columns").unwrap_or(1.0) as u64, "gutter": d.m("gutter").unwrap_or(12.0), "inset": d.m("inset").unwrap_or(0.0), "verticalJustification": d.s("verticalJustification")}),),- "documentSetup" => app.run("layout.documentSetup", json!({"width": d.m("width"), "height": d.m("height")})),+ "documentSetup" => {+ let edges = |k: &str| json!(["Top", "Bottom", "Inside", "Outside"].map(|e| d.m(&format!("{k}{e}")).unwrap_or(0.0)));+ app.run(+ "layout.documentSetup",+ json!({"intent": d.s("intent"), "pages": d.n("pages").unwrap_or(1.0).max(1.0) as u64, "startPage": d.n("startPage").unwrap_or(1.0).max(1.0) as u64,+ "facingPages": d.b("facingPages"), "width": d.m("width"), "height": d.m("height"), "bleed": edges("bleed"), "slug": edges("slug")}),+ )+ }"paragraphStyleOptions" => {let name = d.s("name");let mut para = serde_json::Map::new();diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex e0a5c54ef..595600b58 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -860,6 +860,10 @@ pub fn menu_enabled(app: &DesignApp, id: &str) -> bool {/// A menu item was chosen. An engine command whose label ends in "…" and that takes parameters/// opens a dialog built from its parameter documentation (see [`crate::dialogs::command_fields`]).pub fn activate(app: &mut DesignApp, id: &str, params: &Value) {+ if params.is_null() && id == "layout.documentSetup" {+ crate::dialogs::open_document_setup(app);+ return;+ }if params.is_null()&& ui_label(id).is_none()&& let Some(c) = designcraft_engine::find_command(id)diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rsindex cc3e63279..a2f58ab64 100644--- a/crates/ui-egui/src/panels/properties.rs+++ b/crates/ui-egui/src/panels/properties.rs@@ -290,7 +290,7 @@ fn document_sections(app: &mut DesignApp, ui: &mut Ui) {ui.add_space(6.0);let fw = full_width(ui);if outline_button(ui, "Adjust Layout", fw).clicked() {- app.ui.dialog = Some(crate::dialogs::Dialog::new("documentSetup", json!({})));+ crate::dialogs::open_document_setup(app);}divider(ui);// Page.@@ -315,7 +315,7 @@ fn document_sections(app: &mut DesignApp, ui: &mut Ui) {}ui.add_space(3.0);if outline_button(ui, "Edit Page", fw).clicked() {- app.ui.dialog = Some(crate::dialogs::Dialog::new("documentSetup", json!({})));+ crate::dialogs::open_document_setup(app);}divider(ui);// Rulers & Grids / Guides: icon toggle rows.diff --git a/docs/parity.md b/docs/parity.mdindex 359b318fe..1c553d305 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -9,14 +9,14 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Priority | Features | Done | Partial | Missing | Parity ||---|---|---|---|---|---|-| P0 | 102 | 91 | 11 | 0 | 95% |+| P0 | 102 | 92 | 10 | 0 | 95% || P1 | 97 | 33 | 23 | 41 | 46% || P2 | 76 | 8 | 7 | 61 | 15% || Area | Parity ||---|---|| Application shell & workspace | 65% |-| Documents, pages, spreads | 69% |+| Documents, pages, spreads | 71% || Layers | 74% || Frames, shapes & paths | 74% || Transform | 78% |@@ -35,7 +35,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Undo, history, saving | 100% || Accessibility | 20% |-Open P0 items: Dockable panels, Preferences, Document Setup, Pen, add/delete anchor, convert direction, Gradient panel & tool, Raster formats, Vector/page formats (PDF/AI/SVG/EPS place), Display performance, OpenType features, Export to PDF (print), Display performance.+Open P0 items: Dockable panels, Preferences, Pen, add/delete anchor, convert direction, Gradient panel & tool, Raster formats, Vector/page formats (PDF/AI/SVG/EPS place), Display performance, OpenType features, Export to PDF (print), Display performance.## Rows@@ -59,7 +59,7 @@ Open P0 items: Dockable panels, Preferences, Document Setup, Pen, add/delete anc| Application shell & workspace | Localization | P2 | M || Application shell & workspace | Scripting (own API: commands, scripts, MCP) | P2 | D || Documents, pages, spreads | New Document dialog | P0 | D |-| Documents, pages, spreads | Document Setup | P0 | P |+| 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 |