Skip to content

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

D: parent item overrides — override (Cmd+Shift-click, Override All), remove local overrides, detach

Brandon Thomasb3679cbe63b1
diff --git a/ROADMAP.md b/ROADMAP.md
index 52b69896c..c2aa759cc 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -30,6 +30,8 @@ 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`).
+- 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.
+- Place PDF: placed PDF pages are sized by their crop box, drawn on screen through hayro (with mip levels) and embedded in exported PDFs as vector form XObjects (krilla), `<PDF>` in IDML.
- Menus expose the engine's features (TOC, numbering & sections, text variables, hyperlinks, cross-references, footnotes, step and repeat, spelling, fitting/content, effects, Data Merge, Preflight, EPUB); any menu command with parameters gets a dialog generated from its parameter documentation.
- Table of contents (generate/update, dot leaders) and text variables (running headers, last page number, chapter number, file name, dates, custom) resolved per page.
- Soft effects: blurred drop shadow, inner shadow, outer glow, basic feather.
diff --git a/crates/engine/src/cmd/mod.rs b/crates/engine/src/cmd/mod.rs
index 271c54d85..e7221dd0b 100644
--- a/crates/engine/src/cmd/mod.rs
+++ b/crates/engine/src/cmd/mod.rs
@@ -16,6 +16,7 @@ mod layout;
mod links;
mod notes;
mod object;
+mod overrides;
mod place_text;
pub mod preflight;
pub mod spelling;
@@ -126,6 +127,7 @@ pub fn command_specs() -> &'static [CommandSpec] {
v.extend(style::specs());
v.extend(table::specs());
v.extend(layout::specs());
+ v.extend(overrides::specs());
v.extend(inspect::specs());
v.extend(find::specs());
v.extend(variables::specs());
diff --git a/crates/engine/src/cmd/overrides.rs b/crates/engine/src/cmd/overrides.rs
new file mode 100644
index 000000000..39d453948
--- /dev/null
+++ b/crates/engine/src/cmd/overrides.rs
@@ -0,0 +1,176 @@
+//! Parent item overrides (Layout › Pages): copy parent-page items onto a document page so they
+//! can be edited there (the parent's version is hidden on that page), remove those local
+//! overrides, or detach them from the parent.
+
+use designcraft_doc::{Document, ItemId, SpreadRef};
+use designcraft_geom::Vec2;
+use serde_json::{Value, json};
+
+use super::{CommandSpec, bad, cmd, has_doc};
+use crate::{Result, Session};
+
+pub fn specs() -> Vec<CommandSpec> {
+ vec![
+ cmd!(
+ "layout.overrideParentItems",
+ "Override All Parent Page Items",
+ ["Layout", "Pages"],
+ Some("Cmd+Alt+Shift+L"),
+ "{page (0-based), ids?: parent items (default: all on the page's parent page)} → {ids} the page's editable copies",
+ has_doc,
+ override_items
+ ),
+ cmd!(
+ "layout.removeOverrides",
+ "Remove All Local Overrides",
+ ["Layout", "Pages"],
+ None,
+ "{page (0-based)} — deletes the page's overridden copies; the parent items show again",
+ has_doc,
+ remove_overrides
+ ),
+ cmd!(
+ "layout.detachAll",
+ "Detach All Objects from Parent",
+ ["Layout", "Pages"],
+ None,
+ "{page (0-based)} — the page's overridden copies become ordinary items",
+ has_doc,
+ detach_all
+ ),
+ ]
+}
+
+fn page_param(s: &Session, p: &Value, cmd: &str) -> Result<usize> {
+ let d = &s.doc()?.doc;
+ let page = p.get("page").and_then(Value::as_u64).map(|v| v as usize).or_else(|| {
+ let st = s.active()?;
+ st.selection.items.first().and_then(|i| st.doc.page_of_item(*i))
+ });
+ let page = page.unwrap_or(0);
+ if page >= d.page_count() {
+ return Err(bad(cmd, format!("no page {page}")));
+ }
+ Ok(page)
+}
+
+/// The parent items that show on a document page, with the offset from parent spread to
+/// document spread.
+fn parent_items(d: &Document, page: usize) -> Option<(Vec<ItemId>, Vec2)> {
+ let (si, pi) = d.page_loc(page)?;
+ let pg = &d.spreads[si].pages[pi];
+ let (ppi, ppage) = d.parent_page_for(page)?;
+ let parent = d.parents.get(ppi)?;
+ let dx = pg.x - parent.pages.get(ppage)?.x;
+ let ids =
+ parent.items.iter().filter(|it| parent.pages.len() <= 1 || parent.page_at_x(it.bounds().center().x) == Some(ppage)).map(|it| it.id).collect();
+ Some((ids, Vec2::new(dx, 0.0)))
+}
+
+fn override_items(s: &mut Session, p: &Value) -> Result<Value> {
+ let page = page_param(s, p, "layout.overrideParentItems")?;
+ let wanted: Option<Vec<ItemId>> = super::ids_param(p, "ids");
+ s.edit(|d, sel| {
+ let (all, off) = parent_items(d, page).ok_or_else(|| bad("layout.overrideParentItems", "the page has no parent"))?;
+ let (si, pi) = d.page_loc(page).ok_or_else(|| bad("layout.overrideParentItems", "no such page"))?;
+ let already = d.spreads[si].pages[pi].overridden.clone();
+ let ids: Vec<ItemId> = all.into_iter().filter(|i| wanted.as_ref().is_none_or(|w| w.contains(i)) && !already.contains(i)).collect();
+ if ids.is_empty() {
+ return Ok(json!({"ids": []}));
+ }
+ let src = d.clone();
+ // Copies on the document spread (stories and images come along).
+ let mut new = Vec::new();
+ for id in &ids {
+ let copy = super::object::duplicate_from(d, &src, &[*id], SpreadRef::Doc(si), off)?;
+ if let Some(nid) = copy.first() {
+ if let Some(it) = d.item_mut(*nid) {
+ it.overrides = Some(*id);
+ }
+ new.push(*nid);
+ }
+ }
+ let pg = &mut std::sync::Arc::make_mut(&mut d.spreads[si]).pages[pi];
+ pg.overridden.extend(ids.iter().copied());
+ *sel = designcraft_doc::Selection::items(new.clone());
+ Ok(json!({"ids": new.iter().map(|i| i.0).collect::<Vec<_>>()}))
+ })
+}
+
+/// Items on a document page that override parent items.
+fn overriding(d: &Document, page: usize) -> Vec<ItemId> {
+ let Some((si, _)) = d.page_loc(page) else { return vec![] };
+ d.spreads[si].items.iter().filter(|it| it.overrides.is_some() && d.page_of_item(it.id) == Some(page)).map(|it| it.id).collect()
+}
+
+fn remove_overrides(s: &mut Session, p: &Value) -> Result<Value> {
+ let page = page_param(s, p, "layout.removeOverrides")?;
+ s.edit(|d, sel| {
+ let ids = overriding(d, page);
+ for id in &ids {
+ d.remove_item(*id)?;
+ }
+ if let Some((si, pi)) = d.page_loc(page) {
+ std::sync::Arc::make_mut(&mut d.spreads[si]).pages[pi].overridden.clear();
+ }
+ sel.items.retain(|i| !ids.contains(i));
+ Ok(json!({"removed": ids.len()}))
+ })
+}
+
+fn detach_all(s: &mut Session, p: &Value) -> Result<Value> {
+ let page = page_param(s, p, "layout.detachAll")?;
+ s.edit(|d, _| {
+ let ids = overriding(d, page);
+ for id in &ids {
+ if let Some(it) = d.item_mut(*id) {
+ it.overrides = None;
+ }
+ }
+ Ok(json!({"detached": ids.len()}))
+ })
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn override_remove_and_detach_parent_items() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"pages": 3, "facingPages": false})).unwrap();
+ // A folio frame on the parent.
+ let r = s
+ .execute(
+ "frame.create",
+ &json!({"spread": {"kind": "parent", "index": 0}, "rect": [72, 720, 300, 750], "content": "text", "text": "Folio"}),
+ )
+ .unwrap();
+ let parent_id = ItemId(r["id"].as_u64().unwrap());
+ let r = s.execute("layout.overrideParentItems", &json!({"page": 1})).unwrap();
+ let ids = r["ids"].as_array().unwrap();
+ assert_eq!(ids.len(), 1);
+ let copy = ItemId(ids[0].as_u64().unwrap());
+ let d = s.doc().unwrap().doc.clone();
+ let it = d.item(copy).unwrap();
+ assert_eq!(it.overrides, Some(parent_id));
+ assert_eq!(d.page_of_item(copy), Some(1));
+ let (si, pi) = d.page_loc(1).unwrap();
+ assert_eq!(d.spreads[si].pages[pi].overridden, vec![parent_id]);
+ // Its own story: editing it doesn't touch the parent's text.
+ let sid = it.text_frame().unwrap().story;
+ assert_ne!(Some(sid), d.item(parent_id).and_then(|p| p.text_frame()).map(|t| t.story));
+ // Overriding again is a no-op.
+ assert_eq!(s.execute("layout.overrideParentItems", &json!({"page": 1})).unwrap()["ids"].as_array().unwrap().len(), 0);
+ // Detach keeps the copy as an ordinary item; remove deletes overrides only.
+ s.execute("layout.detachAll", &json!({"page": 1})).unwrap();
+ assert_eq!(s.doc().unwrap().doc.item(copy).unwrap().overrides, None);
+ s.execute("layout.overrideParentItems", &json!({"page": 2})).unwrap();
+ let r = s.execute("layout.removeOverrides", &json!({"page": 2})).unwrap();
+ assert_eq!(r["removed"], 1);
+ let d = s.doc().unwrap().doc.clone();
+ let (si, pi) = d.page_loc(2).unwrap();
+ assert!(d.spreads[si].pages[pi].overridden.is_empty());
+ d.check().unwrap();
+ }
+}
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs
index 29f616a36..10822695b 100644
--- a/crates/tools/src/lib.rs
+++ b/crates/tools/src/lib.rs
@@ -130,6 +130,25 @@ impl ToolContext<'_> {
self.doc.hit_item(si, sp, self.tol(4.0)).map(|id| (sr, id))
}
+ /// The parent item showing (not yet overridden) on the document page under `p`:
+ /// (absolute page, parent item).
+ pub fn hit_parent_on_page(&self, p: Point) -> Option<(usize, ItemId)> {
+ let (SpreadRef::Doc(si), sp) = self.layout.spread_at(p)? else { return None };
+ let spread = self.doc.spreads.get(si)?;
+ let pi = spread.page_at_x(sp.x)?;
+ let page = self.doc.first_page_of_spread(si) + pi;
+ let (ppi, ppg) = self.doc.parent_page_for(page)?;
+ let parent = &self.doc.parents[ppi];
+ let pg = &spread.pages[pi];
+ let at = sp - designcraft_geom::Vec2::new(pg.x - parent.pages[ppg].x, 0.0);
+ parent
+ .items
+ .iter()
+ .rev()
+ .find(|it| !it.locked && !pg.overridden.contains(&it.id) && designcraft_doc::edit_hit(it, at, self.tol(4.0)))
+ .map(|it| (page, it.id))
+ }
+
fn hit_parent(&self, sr: SpreadRef, sp: Point) -> Option<(SpreadRef, ItemId)> {
let s = self.doc.spread(sr)?;
s.items.iter().rev().find(|it| !it.locked && designcraft_doc::edit_hit(it, sp, self.tol(4.0))).map(|it| (sr, it.id))
diff --git a/crates/tools/src/select.rs b/crates/tools/src/select.rs
index 6d07908fc..141223c47 100644
--- a/crates/tools/src/select.rs
+++ b/crates/tools/src/select.rs
@@ -199,6 +199,15 @@ impl Tool for SelectionTool {
self.drag = Drag::Resize { handle: h, start: p, from: b - off, spread: loc.spread };
return vec![Action::Begin("Resize".into())];
}
+ // Cmd+Shift-click a parent item on a page: override it there and select the copy.
+ if ev.mods.cmd
+ && ev.mods.shift
+ && cx.hit(p).is_none()
+ && let Some((page, id)) = cx.hit_parent_on_page(p)
+ {
+ self.drag = Drag::Pending { start: p, hit: true };
+ return vec![Action::Exec("layout.overrideParentItems".into(), json!({"page": page, "ids": [id.0]}))];
+ }
match cx.hit(p) {
Some((sr, id)) => {
let id = if self.direct { id } else { cx.doc.top_level_of(id).unwrap_or(id) };
diff --git a/crates/tools/src/tests.rs b/crates/tools/src/tests.rs
index 1526c4ccf..e6b20005b 100644
--- a/crates/tools/src/tests.rs
+++ b/crates/tools/src/tests.rs
@@ -56,3 +56,26 @@ fn resize_rect_modifiers() {
let c = select::resize_rect(r, 3, designcraft_geom::Point::new(150.0, 25.0), Mods { alt: true, ..Default::default() });
assert_eq!(c, Rect::new(-50.0, 0.0, 150.0, 50.0));
}
+
+#[test]
+fn cmd_shift_click_overrides_parent_item() {
+ let mut d = Document::new(&NewDocument::default());
+ let lid = d.default_layer();
+ // On the parent's right page, which shows behind document page 1 (a right page).
+ let px = d.parents[0].pages.last().unwrap().x;
+ let (pid, _) =
+ d.add_text_frame(SpreadRef::Parent(0), Rect::new(px + 100.0, 100.0, px + 200.0, 200.0), lid, "folio", ParaFormat::default()).unwrap();
+ let (s, c, l) = (Selection::default(), Cache::new(), CanvasLayout::new(&d, false));
+ let cx = ctx(&d, &s, &c, &l);
+ let off = l.offset(SpreadRef::Doc(0));
+ let x = d.spreads[0].pages[0].x + 150.0 + off.x;
+ let mut t = create("selection");
+ // A plain click doesn't reach parent items.
+ let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, x, 150.0 + off.y));
+ assert_eq!(a, vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": []}))]);
+ t.pointer(&cx, &PointerEvent::new(PointerKind::Up, x, 150.0 + off.y));
+ let mut ev = PointerEvent::new(PointerKind::Down, x, 150.0 + off.y);
+ ev.mods = Mods { cmd: true, shift: true, ..Default::default() };
+ let a = t.pointer(&cx, &ev);
+ assert_eq!(a, vec![Action::Exec("layout.overrideParentItems".into(), serde_json::json!({"page": 0, "ids": [pid.0]}))]);
+}
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index ba147d8ff..64a3d80f0 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -563,7 +563,7 @@ fn draw_frames(app: &DesignApp, painter: &egui::Painter, xf: &Xf, doc: &Document
let parent = &doc.parents[ppi];
let dx = page.x - parent.pages[ppg].x;
for it in &parent.items {
- if parent.pages.len() > 1 && parent.page_at_x(it.bounds().center().x) != Some(ppg) {
+ if (parent.pages.len() > 1 && parent.page_at_x(it.bounds().center().x) != Some(ppg)) || page.overridden.contains(&it.id) {
continue;
}
let col = doc.layer(it.layer).map(|l| c32(l.color)).unwrap_or(Color32::LIGHT_BLUE);
diff --git a/crates/ui-egui/src/panels/pages.rs b/crates/ui-egui/src/panels/pages.rs
index 29586e331..39565ef83 100644
--- a/crates/ui-egui/src/panels/pages.rs
+++ b/crates/ui-egui/src/panels/pages.rs
@@ -220,6 +220,17 @@ 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();
}
+ ui.separator();
+ for (id, label) in [
+ ("layout.overrideParentItems", "Override All Parent Page Items"),
+ ("layout.removeOverrides", "Remove All Local Overrides"),
+ ("layout.detachAll", "Detach All Objects from Parent"),
+ ] {
+ if ui.button(label).clicked() {
+ let _ = app.run(id, json!({"page": abs}));
+ ui.close();
+ }
+ }
ui.menu_button("Apply Parent", |ui| {
if ui.button("[None]").clicked() {
let _ = app.run("layout.pages.applyParent", json!({"pages": [abs], "parent": null}));
diff --git a/docs/parity.md b/docs/parity.md
index a0233ed39..1a17d157a 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -9,20 +9,20 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia
| Priority | Features | Done | Partial | Missing | Parity |
|---|---|---|---|---|---|
-| P0 | 102 | 87 | 12 | 3 | 91% |
+| P0 | 102 | 88 | 12 | 2 | 92% |
| P1 | 97 | 32 | 24 | 41 | 45% |
| P2 | 76 | 8 | 7 | 61 | 15% |
| Area | Parity |
|---|---|
| Application shell & workspace | 65% |
-| Documents, pages, spreads | 66% |
+| Documents, pages, spreads | 69% |
| Layers | 74% |
| Frames, shapes & paths | 74% |
| Transform | 56% |
| Fill, stroke, colour | 62% |
| Effects & transparency | 50% |
-| Placing & links | 53% |
+| Placing & links | 57% |
| Type & text frames | 77% |
| Typography | 76% |
| Styles | 55% |
@@ -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, Parent item overrides, Pen, add/delete anchor, convert direction, Scale strokes / content options, Dimensions Include Stroke Weight, Gradient panel & tool, Stroke panel, 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, Document Setup, Pen, add/delete anchor, convert direction, Scale strokes / content options, Dimensions Include Stroke Weight, Gradient panel & tool, Stroke panel, Raster formats, Vector/page formats (PDF/AI/SVG/EPS place), Display performance, OpenType features, Export to PDF (print), Display performance.
## Rows
@@ -73,7 +73,7 @@ Open P0 items: Dockable panels, Preferences, Document Setup, Parent item overrid
| Documents, pages, spreads | Smart Text Reflow | P1 | M |
| Documents, pages, spreads | Primary text frame | P1 | P |
| Documents, pages, spreads | Parent pages | P0 | D |
-| Documents, pages, spreads | Parent item overrides | P0 | P |
+| Documents, pages, spreads | Parent item overrides | P0 | D |
| Documents, pages, spreads | Page transitions | P2 | M |
| Documents, pages, spreads | Spread view rotation | P2 | M |
| Documents, pages, spreads | Layout Adjustment | P2 | M |
@@ -169,7 +169,7 @@ Open P0 items: Dockable panels, Preferences, Document Setup, Parent item overrid
| Placing & links | Place | P0 | D |
| Placing & links | Place into frame / by click or drag | P0 | D |
| Placing & links | Raster formats | P0 | P |
-| Placing & links | Vector/page formats (PDF/AI/SVG/EPS place) | P0 | M |
+| Placing & links | Vector/page formats (PDF/AI/SVG/EPS place) | P0 | P |
| Placing & links | Placing INDD/IDML pages | P2 | M |
| Placing & links | Text import (TXT/DOCX/RTF) | P0 | D |
| Placing & links | Links panel | P0 | D |