Skip to content

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

Merge branch 'worktree-agent-ac6e2e6d3a98c1789'

Brandon Thomas91c1051b63a1
diff --cc Cargo.lock
index 7890f1f6e,d7bc6393f..40ba5d19c
--- a/Cargo.lock
+++ b/Cargo.lock
@@@ -134,15 -134,21 +134,30 @@@ dependencies =
"zerocopy",
]
+[[package]]
+name = "aho-corasick"
+version = "1.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
+dependencies = [
+ "memchr",
+]
+
+ [[package]]
+ name = "alloc-no-stdlib"
+ version = "2.0.4"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3"
+
+ [[package]]
+ name = "alloc-stdlib"
+ version = "0.2.4"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "0e76a019e91224d279006ff972f1e984179a6e9feb050adba6ce8274aef23195"
+ dependencies = [
+ "alloc-no-stdlib",
+ ]
+
[[package]]
name = "allocator-api2"
version = "0.2.21"
@@@ -818,10 -864,14 +875,15 @@@ dependencies =
"designcraft-doc",
"designcraft-fonts",
"designcraft-geom",
+ "designcraft-pdf",
"designcraft-render",
"designcraft-tools",
+ "hayro-cmap",
+ "hayro-interpret",
+ "hayro-syntax",
+ "kurbo",
"log",
+ "regex",
"serde",
"serde_json",
"thiserror 2.0.21",
@@@ -848,19 -898,25 +910,38 @@@ dependencies =
"thiserror 2.0.21",
]
+[[package]]
+name = "designcraft-mcp"
+version = "0.1.0"
+dependencies = [
+ "designcraft-engine",
+ "designcraft-geom",
+ "designcraft-render",
+ "designcraft-tools",
+ "image",
+ "log",
+ "serde_json",
+]
+
+ [[package]]
+ name = "designcraft-pdf"
+ version = "0.1.0"
+ dependencies = [
+ "designcraft-color",
+ "designcraft-compose",
+ "designcraft-doc",
+ "designcraft-fonts",
+ "designcraft-geom",
+ "hayro-cmap",
+ "hayro-interpret",
+ "hayro-syntax",
+ "image",
+ "krilla",
+ "kurbo",
+ "log",
+ "thiserror 2.0.21",
+ ]
+
[[package]]
name = "designcraft-render"
version = "0.1.0"
diff --cc ROADMAP.md
index 7350e49b9,def9f5233..3e3fa0c2d
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -9,13 -9,11 +9,15 @@@ DesignCraft aims at full Adobe InDesig
- Text engine: Knuth–Plass paragraph composer and single-line composer, hyphenation, justification, columns, threading across frames and spreads, tabs, bullets/numbering, rules, shading, baseline grid, first-baseline options, vertical justification, wrap exclusions, overset detection, caret/hit testing.
- Rendering: vello_cpu (SIMD, multithreaded) — pages, items, images with mip levels, gradients, composed text.
- UI (egui): application bar + menus, Control panel (object and text modes), Tools panel with flyouts, document tabs, rulers, pasteboard, guides (margins, columns, bleed, baseline grid), frame edges, selection handles, text ports and threads, Properties / Pages / Layers dock, Swatches, Styles, Character, Paragraph, Stroke, Text Wrap panels, New Document dialog, ⌘K palette, 4 brightness themes.
+- Pen tool, Direct Selection anchor/handle editing, rotate from corners, Rotate/Scale/Shear tools, Eyedropper, snapping & smart guides, Align/Distribute, Find/Change (text + GREP), Story Editor, Paragraph Style Options, Effects panel, hidden characters, native macOS menu bar, measured InDesign 2026 look (Medium Dark).
+- Tools: Selection (click, marquee, move, Alt-duplicate, resize handles), Direct Selection, Type (draw frame, click caret, select, type), Rectangle/Ellipse/Polygon (+ frame variants), Line, Hand, Zoom.
+ - Tools: Selection (click, marquee, move, Alt-duplicate, resize handles), Direct Selection (basic), Type (draw frame, click caret, select, type), Rectangle/Ellipse/Polygon (+ frame variants), Line, Hand, Zoom.
+ - PDF export (krilla): real selectable text with embedded font subsets, DeviceCMYK/RGB + spot Separations, bleed boxes, crop/bleed marks + page info, pages or spreads, PDF/A-2b (PDF/X-4 output intent pending) — `file.exportPdf`, File › Export PDF…, `designcraft-cli run --export out.pdf`.
- ~100 commands, all reachable through the JSON control channel; headless CLI rendering to PNG.
+- MCP server (`designcraft-cli mcp [--connect PORT]`, docs/mcp.md): headless engine or the running app; commands, batch, document/story inspection, page renders as images, window screenshots, pointer/keyboard/dialog input.
+- Web build (`apps/designcraft-web`, trunk): the same UI on WebGPU with a WebGL2 fallback; open/place via the browser file picker or drag-and-drop, save/export as downloads.
- **Next (in order):** PDF export (krilla, PDF/X-4) · IDML import/export · native format as zip · tables · dictionary hyphenation · Links panel + relink · Preflight panel · TOC/index/footnotes · EPUB.
-**Next (in order):** MCP server · PDF/X-4 output intent, bookmarks, tagged PDF · IDML import/export · native format as zip · web build · Pen tool & Direct Selection anchors · Story Editor · Find/Change (+GREP) · tables · Liang hyphenation · smart guides · Links panel + relink · Preflight · TOC/index/footnotes · EPUB.
++**Next (in order):** IDML import/export · dictionary hyphenation · native format as zip · tables · PDF/X-4 output intent, bookmarks, tagged PDF · Links panel + relink · Preflight panel · TOC/index/footnotes · EPUB.
## Milestones
diff --cc apps/designcraft-cli/src/main.rs
index 7f09bf540,4555c9623..3496da170
--- a/apps/designcraft-cli/src/main.rs
+++ b/apps/designcraft-cli/src/main.rs
@@@ -1,9 -1,9 +1,9 @@@
//! Headless DesignCraft.
//!
//! ```text
- //! designcraft-cli run [--in FILE | --sample] [--cmd ID[=JSON]]... [--page N] [--scale S] [--export OUT.png|.jpg|.designcraft] [--all-pages DIR]
+ //! designcraft-cli run [--in FILE | --sample] [--cmd ID[=JSON]]... [--page N] [--scale S] [--export OUT.png|.jpg|.pdf|.designcraft] [--pdf-options JSON] [--all-pages DIR]
//! designcraft-cli commands # list every command (JSON)
-//! designcraft-cli mcp [--connect PORT] # MCP server over stdio
+//! designcraft-cli mcp [--connect PORT] [--sample] # MCP server over stdio (docs/mcp.md)
//! ```
use std::process::ExitCode;
@@@ -22,7 -22,7 +22,7 @@@ fn main() -> ExitCode
Some("mcp") => report(mcp(&args[1..])),
_ => {
eprintln!(
- "usage: designcraft-cli run [--in FILE | --sample] [--cmd ID[=JSON]]... [--page N] [--scale S] [--export OUT] [--all-pages DIR]\n designcraft-cli commands\n designcraft-cli mcp [--connect PORT] [--sample]"
- "usage: designcraft-cli run [--in FILE | --sample] [--cmd ID[=JSON]]... [--page N] [--scale S] [--pdf-options JSON] [--export OUT] [--all-pages DIR]\n designcraft-cli commands\n designcraft-cli mcp [--connect PORT]"
++ "usage: designcraft-cli run [--in FILE | --sample] [--cmd ID[=JSON]]... [--page N] [--scale S] [--pdf-options JSON] [--export OUT] [--all-pages DIR]\n designcraft-cli commands\n designcraft-cli mcp [--connect PORT] [--sample]"
);
ExitCode::FAILURE
}
diff --cc crates/engine/Cargo.toml
index 9a54462dd,237690cf3..2ada23a7b
--- a/crates/engine/Cargo.toml
+++ b/crates/engine/Cargo.toml
@@@ -20,4 -21,9 +21,10 @@@ serde = { workspace = true
serde_json = { workspace = true }
thiserror = { workspace = true }
log = { workspace = true }
+regex = { workspace = true }
+
+ [dev-dependencies]
+ hayro-syntax = "0.7.2"
+ hayro-interpret = { version = "0.7.0", default-features = false, features = ["embed-fonts"] }
+ hayro-cmap = "0.1"
+ kurbo = { workspace = true }
diff --cc crates/engine/src/cmd/mod.rs
index 4f58ff003,94a68a3e1..cf8f0a2b7
--- a/crates/engine/src/cmd/mod.rs
+++ b/crates/engine/src/cmd/mod.rs
@@@ -1,8 -1,8 +1,9 @@@
//! The command registry. Ids follow InDesign's menu structure.
mod edit;
+ mod export;
mod file;
+mod find;
mod inspect;
mod layout;
mod object;
diff --cc crates/engine/src/tests.rs
index c0147d277,1f085450b..9c73b2b60
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@@ -110,73 -105,68 +110,139 @@@ fn every_command_has_metadata()
assert!(command_specs().len() > 60);
}
+#[test]
+fn align_and_distribute() {
+ let mut s = session();
+ let mut ids = vec![];
+ for (x, w) in [(10.0, 20.0), (100.0, 40.0), (300.0, 10.0)] {
+ let r = s.execute("frame.create", &json!({"rect": [x, 50.0 + x / 10.0, x + w, 100.0], "content": "unassigned"})).unwrap();
+ ids.push(r["id"].as_u64().unwrap());
+ }
+ s.execute("object.align", &json!({"ids": ids, "edge": "top"})).unwrap();
+ let st = s.doc().unwrap();
+ let tops: Vec<f64> = ids.iter().map(|i| st.doc.item(designcraft_doc::ItemId(*i)).unwrap().bounds().y0).collect();
+ assert!(tops.iter().all(|t| (*t - 51.0).abs() < 1e-9), "{tops:?}");
+ s.execute("object.distribute", &json!({"ids": ids, "by": "spacing"})).unwrap();
+ let st = s.doc().unwrap();
+ let b: Vec<designcraft_geom::Rect> = ids.iter().map(|i| st.doc.item(designcraft_doc::ItemId(*i)).unwrap().bounds()).collect();
+ assert!(((b[1].x0 - b[0].x1) - (b[2].x0 - b[1].x1)).abs() < 1e-9);
+ s.execute("object.align", &json!({"ids": [ids[0]], "edge": "left", "to": "margins"})).unwrap();
+ assert_eq!(s.doc().unwrap().doc.item(designcraft_doc::ItemId(ids[0])).unwrap().bounds().x0, 36.0);
+}
+
+#[test]
+fn pen_draws_and_direct_selection_edits() {
+ use designcraft_tools::{PointerEvent, PointerKind};
+ let mut s = session();
+ let v = ViewInfo { zoom: 1.0 };
+ s.set_tool("pen");
+ let click = |s: &mut Session, x: f64, y: f64| {
+ s.pointer(&PointerEvent::new(PointerKind::Down, x, y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, x, y), v).unwrap();
+ };
+ click(&mut s, 100.0, 100.0);
+ click(&mut s, 200.0, 100.0);
+ // A smooth point (drag).
+ s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, 240.0, 200.0), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, 240.0, 200.0), v).unwrap();
+ click(&mut s, 100.0, 100.0); // close
+ let st = s.doc().unwrap();
+ let it = &st.doc.spreads[0].items[0];
+ assert_eq!(it.path.subpaths[0].anchors.len(), 3);
+ assert!(it.path.subpaths[0].closed);
+ assert!(it.path.subpaths[0].anchors[2].has_out());
+ let id = it.id;
+ // Direct Selection: drag the first anchor.
+ s.set_tool("directSelection");
+ s.execute("selection.set", &json!({"ids": [id.0]})).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Down, 100.0, 100.0), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, 90.0, 80.0), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, 90.0, 80.0), v).unwrap();
+ let a = s.doc().unwrap().doc.item(id).unwrap().path.subpaths[0].anchors[0].p;
+ assert_eq!(a, designcraft_geom::Point::new(90.0, 80.0));
+}
+
+#[test]
+fn rotate_scale_shear_and_eyedropper() {
+ let mut s = session();
+ let a = s.execute("frame.create", &json!({"rect": [100, 100, 200, 150], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();
+ s.execute("object.fill", &json!({"swatch": "C=100 M=0 Y=0 K=0"})).unwrap();
+ let b = s.execute("frame.create", &json!({"rect": [300, 100, 340, 140], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();
+ s.execute("transform.rotate", &json!({"ids": [a], "angle": 90})).unwrap();
+ let r = s.doc().unwrap().doc.item(designcraft_doc::ItemId(a)).unwrap().bounds();
+ assert!((r.width() - 50.0).abs() < 1e-6 && (r.height() - 100.0).abs() < 1e-6, "{r:?}");
+ s.execute("transform.scale", &json!({"ids": [b], "sx": 2.0})).unwrap();
+ let r = s.doc().unwrap().doc.item(designcraft_doc::ItemId(b)).unwrap().bounds();
+ assert!((r.width() - 80.0).abs() < 1e-6, "{r:?}");
+ s.execute("selection.set", &json!({"ids": [b]})).unwrap();
+ s.execute("object.matchAttributes", &json!({"from": a})).unwrap();
+ assert_eq!(s.doc().unwrap().doc.item(designcraft_doc::ItemId(b)).unwrap().fill.swatch, "C=100 M=0 Y=0 K=0");
+ s.execute("transform.shear", &json!({"ids": [b], "angle": 20})).unwrap();
+}
++
+ /// Unicode text per page, through hayro's interpreter (ToUnicode / ActualText).
+ fn pdf_text(bytes: &[u8]) -> Vec<String> {
+ use hayro_interpret::font::Glyph;
+ use hayro_interpret::{
+ BlendMode, ClipPath, Context, Device, GlyphDrawMode, Image, InterpreterCache, InterpreterSettings, Paint, PathDrawMode, SoftMask,
+ interpret_page,
+ };
+ struct Ex(String);
+ impl Device<'_> for Ex {
+ fn set_soft_mask(&mut self, _: Option<SoftMask<'_>>) {}
+ fn set_blend_mode(&mut self, _: BlendMode) {}
+ fn draw_path(&mut self, _: &kurbo::BezPath, _: kurbo::Affine, _: &Paint<'_>, _: &PathDrawMode) {}
+ fn push_clip_path(&mut self, _: &ClipPath) {}
+ fn push_transparency_group(&mut self, _: f32, _: Option<SoftMask<'_>>, _: BlendMode) {}
+ fn draw_glyph(&mut self, g: &Glyph<'_>, _: kurbo::Affine, _: kurbo::Affine, _: &Paint<'_>, _: &GlyphDrawMode) {
+ match g.as_unicode() {
+ Some(hayro_cmap::BfString::Char(c)) => self.0.push(c),
+ Some(hayro_cmap::BfString::String(s)) => self.0.push_str(&s),
+ None => self.0.push('\u{FFFD}'),
+ }
+ }
+ fn draw_image(&mut self, _: Image<'_, '_>, _: kurbo::Affine) {}
+ fn pop_clip_path(&mut self) {}
+ fn pop_transparency_group(&mut self) {}
+ }
+ let pdf = hayro_syntax::Pdf::new(bytes.to_vec()).expect("valid PDF");
+ let cache = InterpreterCache::new();
+ pdf.pages()
+ .iter()
+ .map(|page| {
+ let mut ctx =
+ Context::new(kurbo::Affine::IDENTITY, kurbo::Rect::new(0.0, 0.0, 1.0, 1.0), &cache, pdf.xref(), InterpreterSettings::default());
+ let mut ex = Ex(String::new());
+ interpret_page(page, &mut ctx, &mut ex);
+ ex.0
+ })
+ .collect()
+ }
+
+ #[test]
+ fn export_pdf_of_the_sample() {
+ let mut s = Session::new();
+ s.execute("file.newSample", &json!({})).unwrap();
+ let r = s.execute("file.exportPdf", &json!({"bleed": true, "marks": true})).unwrap();
+ assert_eq!(r["pages"], 4);
+ let bytes = cmd::base64_decode(r["base64"].as_str().unwrap());
+ assert!(bytes.starts_with(b"%PDF-"));
+ let pdf = hayro_syntax::Pdf::new(bytes.clone()).expect("parse");
+ assert_eq!(pdf.pages().len(), 4);
+ let raw = String::from_utf8_lossy(&bytes);
+ assert!(raw.contains("/FontFile2") || raw.contains("/FontFile3"), "fonts embedded");
+ let text = pdf_text(&bytes);
+ let all: String = text.join("\n");
+ assert!(all.contains("Notes on the Grid"), "{all}");
+ // Page range + spreads + file output.
+ let dir = std::env::temp_dir().join(format!("dc-pdf-{}", std::process::id()));
+ std::fs::create_dir_all(&dir).unwrap();
+ let path = dir.join("out.pdf");
+ let r = s.execute("file.exportPdf", &json!({"path": path.to_string_lossy(), "pages": "2-3", "spreads": true})).unwrap();
+ assert_eq!(r["pages"], 1, "pages 2–3 are one spread");
+ assert!(std::fs::read(&path).unwrap().starts_with(b"%PDF-"));
+ std::fs::remove_dir_all(&dir).ok();
+ assert!(s.execute("file.exportPdf", &json!({"pages": "9"})).is_err());
+ assert!(s.execute("file.exportPdf", &json!({"standard": "bogus"})).is_err());
+ }
diff --cc crates/ui-egui/src/menus.rs
index d20a55493,156b8ce96..aa702d30e
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@@ -12,9 -12,8 +12,10 @@@ pub const UI_COMMANDS: &[(&str, &str, O
("app.saveDialog", "Save As…", Some("Cmd+Shift+S"), "{}"),
("app.save", "Save", Some("Cmd+S"), "{}"),
("app.exportPng", "Export Page as PNG…", Some("Cmd+E"), "{}"),
+ ("app.exportPdf", "Export PDF…", None, "{path?, …file.exportPdf options} — asks for a path when none is given"),
("app.palette", "Command Palette…", Some("Cmd+K"), "{}"),
+ ("app.findChange", "Find/Change…", Some("Cmd+F"), "{}"),
+ ("app.storyEditor", "Edit in Story Editor", Some("Cmd+Y"), "{story?}"),
("view.zoomIn", "Zoom In", Some("Cmd+="), "{}"),
("view.zoomOut", "Zoom Out", Some("Cmd+-"), "{}"),
("view.fitPage", "Fit Page in Window", Some("Cmd+0"), "{}"),
@@@ -200,23 -199,7 +202,24 @@@ pub fn run_ui(app: &mut DesignApp, id:
Ok(Value::Null)
}
"app.exportPng" => export_png(app, p),
+ "app.storyEditor" => {
+ let sid = p.get("story").and_then(Value::as_u64).map(designcraft_doc::StoryId).or_else(|| {
+ let st = app.session.active()?;
+ st.selection.text.map(|t| t.story).or_else(|| st.selection.items.iter().find_map(|i| st.doc.item(*i)?.text_frame().map(|t| t.story)))
+ });
+ match sid {
+ Some(s) => {
+ app.story_editor = if app.story_editor == Some(s) { None } else { Some(s) };
+ Ok(Value::Null)
+ }
+ None => Err("select a text frame or place the cursor in text".into()),
+ }
+ }
+ "app.findChange" => {
+ app.ui.dialog = Some(crate::dialogs::Dialog::new("findChange", json!({})));
+ Ok(Value::Null)
+ }
+ "app.exportPdf" => export_pdf(app, p),
"app.palette" => {
app.ui.palette = Some(String::new());
Ok(Value::Null)