Skip to content

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

Merge PR #959

Brandon Thomas4b88d7d29c6d
diff --cc ROADMAP.md
index 029856255,aadbad502..53f773756
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -135,15 -132,7 +135,16 @@@ list) · [roadmap.md](docs/roadmap.md)
Newest first.
+- **2026-10-14** · The Type tool draws a new text frame over a locked empty frame, as InDesign does, instead of turning the locked frame into a text frame. No readiness percentage change.
+- **2026-10-14** · 100% black shows as pure black on screen by default, as InDesign's Appearance of Black does out of the box (Display All Blacks as Rich Black); Preferences › Appearance of Black › Display All Blacks Accurately still shows it as the dark grey it prints, and a saved choice is kept. No readiness percentage change.
+- **2026-10-14** · Pathfinder keeps the frontmost object, as InDesign does: a photo placed over shapes and intersected with them shows through the shapes (it was dropped, and the shapes kept their black fill); Add, Exclude Overlap and Minus Back take the front object's fill too, Subtract still keeps the back one. No readiness percentage change.
+- **2026-10-14** · The Color panel's Tint field keeps what is typed while it has focus and applies it on Enter or when it loses focus, clamped to 0–100 %. Typing 60 over 100 % no longer snaps back to 100 after the first digit (10060), and a typed tint is no longer ignored. No readiness percentage change.
+- **2026-10-15** · IDML: ruler guides import and export (they were dropped). Each page's guides come in measured from the document's ruler origin (spread, page or spine), with Fit to Page, Locked and their layer, parent pages' included, and go out again under their pages. No readiness percentage change.
+- **2026-10-15** · Find Font no longer reports a style missing when it differs from the installed one only in spacing or case (InDesign files can name `Regular ` with a trailing space); the text was already drawn in the right face. No readiness percentage change.
+- **2026-10-15** · A line of text is set when its baseline fits in the frame, as in InDesign: descenders may hang below the frame's bottom. A frame sized to the cap height of a big heading (103 pt in a 2.77 cm frame, as Zero2Graphic's magazine tutorial draws them) no longer oversets. No readiness percentage change.
+- **2026-10-15** · A story that ends with a return is no longer overset when only its empty last paragraph doesn't fit, as in InDesign (Preflight said "Overset text: 0 characters" for a caption InDesign shows with no errors). No readiness percentage change.
+- **2026-10-15** · IDML: the CJK leading model InDesign writes on [No paragraph style] of every document (Aki Below) only applies when the document uses a Japanese composer, as in InDesign; a Western document's paragraphs after a size change no longer sit lower than in InDesign (Montilla Design's Flex Layout file: its captions came out overset). No readiness percentage change.
+ - **2026-10-14** · Type › Fill with Placeholder Text fills a frame with paragraphs of a few sentences, as InDesign does, so one paragraph can be styled on its own (it was one long paragraph, and the filler ran sentences together, "interit.Ovid"). No readiness percentage change.
- **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.
diff --cc crates/engine/src/cmd/text.rs
index a2a034b9b,52c3588c5..fd5de519c
--- a/crates/engine/src/cmd/text.rs
+++ b/crates/engine/src/cmd/text.rs
@@@ -2777,234 -2570,29 +2787,261 @@@ mod sentence_selection_tests
}
}
+#[cfg(test)]
+mod open_type_features_tests {
+ use serde_json::{Value, json};
+
+ use crate::Session;
+
+ fn feature<'a>(v: &'a Value, tag: &str) -> &'a Value {
+ v["features"].as_array().unwrap().iter().find(|f| f["tag"] == tag).unwrap_or(&Value::Null)
+ }
+
+ #[test]
+ fn the_selected_fonts_features_are_listed_with_their_state() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 400, 200], "content": "text", "text": "Hello fi"})).unwrap();
+ s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 8})).unwrap();
+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();
+ assert_eq!(v["fonts"][0]["family"], "Source Serif 4", "{v}");
+ assert_eq!(feature(&v, "liga")["applied"], "all", "liga is on by default: {v}");
+ assert_eq!(feature(&v, "kern")["available"], "all", "{v}");
+ }
+
+ #[test]
+ fn a_feature_on_part_of_the_selection_is_some_and_on_all_of_it_is_all() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 400, 200], "content": "text", "text": "Hello world"})).unwrap();
+ let story = r["story"].clone();
+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 5})).unwrap();
+ s.execute("type.feature", &json!({"features": {"lnum": true}})).unwrap();
+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 11})).unwrap();
+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();
+ assert_eq!(feature(&v, "lnum")["applied"], "some", "{v}");
+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 5})).unwrap();
+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();
+ assert_eq!(feature(&v, "lnum")["applied"], "all", "{v}");
+ s.execute("type.feature", &json!({"features": {"lnum": false}})).unwrap();
+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 11})).unwrap();
+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();
+ assert_eq!(feature(&v, "lnum")["applied"], "none", "{v}");
+ }
+}
+
+#[cfg(test)]
+mod gradient_text_tests {
+ use serde_json::json;
+
+ /// Mean red and blue of the ink (pixels whose green is low: red → blue has none) in columns
+ /// `x0..x1`.
+ fn ink(img: &designcraft_render::Rendered, x0: u32, x1: u32) -> (f64, f64) {
+ let (mut r, mut b, mut n) = (0.0, 0.0, 0.0);
+ for x in x0..x1 {
+ for y in 0..img.height {
+ let p = img.pixel(x, y);
+ if p[1] < 100 {
+ (r, b, n) = (r + p[0] as f64, b + p[2] as f64, n + 1.0);
+ }
+ }
+ }
+ assert!(n > 50.0, "no ink in {x0}..{x1}");
+ (r / n, b / n)
+ }
+
+ /// Red ink at the frame's left, blue at its right.
+ fn check(img: &designcraft_render::Rendered, what: &str) {
+ let (lr, lb) = ink(img, 0, 60);
+ let (rr, rb) = ink(img, 200, 300);
+ assert!(lr > lb + 80.0, "{what}: the left ink is red ({lr:.0}, {lb:.0})");
+ assert!(rb > rr + 80.0, "{what}: the right ink is blue ({rr:.0}, {rb:.0})");
+ }
+
+ #[test]
+ fn a_gradient_on_text_spans_its_frame_on_screen_and_in_pdf() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false, "margins": 0})).unwrap();
+ // A gradient swatch (an off-page object's unnamed one), red → blue.
+ let shape = s.execute("frame.create", &json!({"rect": [-60, 0, -50, 10], "content": "unassigned"})).unwrap()["id"].clone();
+ s.execute("object.gradient", &json!({"ids": [shape], "stops": [{"location": 0, "color": "#ff0000"}, {"location": 100, "color": "#0000ff"}]}))
+ .unwrap();
+ let id = designcraft_doc::ItemId(shape.as_u64().unwrap());
+ let swatch = s.doc().unwrap().doc.item(id).unwrap().fill.swatch.clone();
+ let r = s.execute("frame.create", &json!({"rect": [0, 0, 300, 120], "content": "text", "text": "IIIIIIIIIIIIIIIIIIIIIIIIIIIIII"})).unwrap();
+ s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 30})).unwrap();
+ s.execute("type.char", &json!({"size": 60, "tracking": 0, "fill": swatch})).unwrap();
+ let d = s.doc().unwrap().doc.clone();
+ let mut rr = designcraft_render::Renderer::new();
+ check(&rr.render_page(&d, &s.cache, 0, 1.0, false, &Default::default()).unwrap(), "screen");
+ // The PDF, placed back and drawn: the same gradient.
+ let pdf = designcraft_pdf::export_pdf(&d, &s.cache, &Default::default()).unwrap();
+ let mut p = crate::Session::new();
+ p.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false})).unwrap();
+ p.execute("file.place", &json!({"base64": super::super::file::base64_encode(&pdf), "name": "text.pdf", "x": 0, "y": 0, "width": 300}))
+ .unwrap();
+ let d = p.doc().unwrap().doc.clone();
+ check(&rr.render_page(&d, &p.cache, 0, 1.0, false, &Default::default()).unwrap(), "pdf");
+ }
+
+ /// The columns the red → blue ink spans (black table edges left out).
+ fn ink_span(img: &designcraft_render::Rendered) -> (u32, u32) {
+ let cols: Vec<u32> = (0..img.width)
+ .filter(|&x| {
+ (0..img.height).any(|y| {
+ let p = img.pixel(x, y);
+ p[1] < 100 && p[0].max(p[2]) > 100
+ })
+ })
+ .collect();
+ (*cols.first().unwrap(), *cols.last().unwrap())
+ }
+
+ /// Mean red and blue of the red → blue ink in columns `x0..x1`.
+ fn coloured_ink(img: &designcraft_render::Rendered, x0: u32, x1: u32) -> (f64, f64) {
+ let (mut r, mut b, mut n) = (0.0, 0.0, 0.0);
+ for x in x0..x1 {
+ for y in 0..img.height {
+ let p = img.pixel(x, y);
+ if p[1] < 100 && p[0].max(p[2]) > 100 {
+ (r, b, n) = (r + p[0] as f64, b + p[2] as f64, n + 1.0);
+ }
+ }
+ }
+ assert!(n > 20.0, "no ink in {x0}..{x1}");
+ (r / n, b / n)
+ }
+
+ #[test]
+ fn a_gradient_on_table_cell_text_spans_the_cells_text_in_pdf_as_on_screen() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false, "margins": 0})).unwrap();
+ // A gradient swatch (an off-page object's unnamed one), red → blue.
+ let shape = s.execute("frame.create", &json!({"rect": [-60, 0, -50, 10], "content": "unassigned"})).unwrap()["id"].clone();
+ s.execute("object.gradient", &json!({"ids": [shape], "stops": [{"location": 0, "color": "#ff0000"}, {"location": 100, "color": "#0000ff"}]}))
+ .unwrap();
+ let g = s.doc().unwrap().doc.item(designcraft_doc::ItemId(shape.as_u64().unwrap())).unwrap().fill.swatch.clone();
+ let r = s.execute("frame.create", &json!({"rect": [0, 0, 300, 120], "content": "text", "text": ""})).unwrap();
+ s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 0})).unwrap();
+ s.execute("table.insert", &json!({"rows": 1, "cols": 3})).unwrap();
+ // A third of the frame's width: the cell's text, red → blue.
+ let mut d: designcraft_doc::Document = (*s.doc().unwrap().doc).clone();
+ let sid = d.stories.values().find(|st| !st.tables.is_empty()).unwrap().id;
+ let t = std::sync::Arc::make_mut(d.story_mut(sid).unwrap().tables.values_mut().next().unwrap());
+ let text = &mut t.cell_mut(0, 0).unwrap().text;
+ text.insert(0, "HHHH");
+ text.format_chars(0..4, |f| {
+ f.over.fill = Some(g.clone());
+ f.over.size = Some(24.0);
+ });
+ let mut rr = designcraft_render::Renderer::new();
+ let cache = designcraft_compose::Cache::new();
+ let screen = rr.render_page(&d, &cache, 0, 1.0, false, &Default::default()).unwrap();
+ let pdf = designcraft_pdf::export_pdf(&d, &cache, &Default::default()).unwrap();
+ let mut p = crate::Session::new();
+ p.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false})).unwrap();
+ p.execute("file.place", &json!({"base64": super::super::file::base64_encode(&pdf), "name": "cell.pdf", "x": 0, "y": 0, "width": 300}))
+ .unwrap();
+ let placed = rr.render_page(&p.doc().unwrap().doc.clone(), &p.cache, 0, 1.0, false, &Default::default()).unwrap();
+ let (x0, x1) = ink_span(&screen);
+ assert!(x1 < 120, "the text stays in the first column: {x0}..{x1}");
+ let q = (x1 - x0) / 4;
+ for (what, img) in [("screen", &screen), ("pdf", &placed)] {
+ let (lr, lb) = coloured_ink(img, x0, x0 + q);
+ let (rr, rb) = coloured_ink(img, x1 + 1 - q, x1 + 1);
+ assert!(lr > lb + 50.0, "{what}: the left ink is red ({lr:.0}, {lb:.0})");
+ assert!(rb > rr + 50.0, "{what}: the right ink is blue ({rr:.0}, {rb:.0})");
+ }
+ }
+}
+
+#[cfg(test)]
+mod compose_tests {
+ use serde_json::json;
+
+ use crate::Session;
+
+ /// A story "Ta" with the caret after "T" and 30 pt chosen for the next typing.
+ fn session() -> (Session, u64) {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 500, 200], "content": "text", "text": "Ta"})).unwrap();
+ let sid = r["story"].as_u64().unwrap();
+ s.set_tool("type");
+ s.execute("text.select", &json!({"story": sid, "anchor": 1})).unwrap();
+ s.execute("type.char", &json!({"attrs": {"size": 30}})).unwrap();
+ (s, sid)
+ }
+
+ fn text(s: &Session, sid: u64) -> String {
+ s.doc().unwrap().doc.story(designcraft_doc::StoryId(sid)).unwrap().text.clone()
+ }
+
+ /// ⌥E shows the accent in the story, in the format it will be typed in, then I types "í":
+ /// one undo step, and the accent was never part of the document.
+ #[test]
+ fn composed_text_shows_in_the_typing_format_until_it_is_typed() {
+ let (mut s, sid) = session();
+ let r = s.execute("text.compose", &json!({"text": "´"})).unwrap();
+ assert_eq!(r["range"], json!([1, 3]));
+ assert_eq!(text(&s, sid), "T´a");
+ let size_at = |s: &Session, b| s.doc().unwrap().doc.story(designcraft_doc::StoryId(sid)).unwrap().char_format_at(b).over.size;
+ assert_eq!(size_at(&s, 2), Some(30.0), "the accent is shown in the format chosen at the caret");
+ assert_eq!(s.composition().map(|c| c.2), Some(1..3));
+ s.execute("text.compose", &json!({"text": "¨"})).unwrap();
+ assert_eq!(text(&s, sid), "T¨a", "a new composition replaces the last one");
+ s.execute("text.compose", &json!({"text": ""})).unwrap();
+ assert_eq!(text(&s, sid), "Ta");
+ assert!(s.composition().is_none());
+ s.execute("text.insert", &json!({"text": "í"})).unwrap();
+ assert_eq!(text(&s, sid), "Tía");
+ assert_eq!(size_at(&s, 2), Some(30.0), "the typing format survived the composition");
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!(text(&s, sid), "Ta");
+ }
+
+ /// Anything else that edits, a tool change or a drag drops the uncommitted accent.
+ #[test]
+ fn other_edits_drop_the_composed_text() {
+ for act in 0..3 {
+ let (mut s, sid) = session();
+ s.execute("text.compose", &json!({"text": "´"})).unwrap();
+ match act {
+ 0 => {
+ s.execute("text.move", &json!({"dir": "right"})).unwrap();
+ }
+ 1 => s.set_tool("selection"),
+ _ => s.begin_interaction("Move").unwrap(),
+ }
+ assert_eq!(text(&s, sid), "Ta", "case {act}");
+ assert!(s.composition().is_none());
+ }
+ }
+}
++
+ #[cfg(test)]
+ mod placeholder_tests {
+ use serde_json::json;
+
+ use crate::Session;
+
+ /// Fill with Placeholder Text gives paragraphs of a few sentences, as InDesign's does (it was one
+ /// paragraph, and the filler ran sentences together: "interit.Ovid").
+ #[test]
+ fn placeholder_text_comes_in_paragraphs() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let r = s.execute("frame.create", &json!({"rect": [36, 36, 336, 736], "content": "text", "text": ""})).unwrap();
+ s.execute("type.fillWithPlaceholder", &json!({"frame": r["id"]})).unwrap();
+ let st = s.execute("story.get", &json!({"story": r["story"]})).unwrap();
+ let text = st["text"].as_str().unwrap();
+ let paragraphs: Vec<&str> = text.split('\n').collect();
+ assert!(paragraphs.len() >= 4, "{} paragraphs", paragraphs.len());
+ for p in &paragraphs {
+ assert!(p.ends_with('.') && !p.starts_with(' '), "a paragraph of whole sentences: {p:?}");
+ }
+ assert!(!text.contains(".O") && !text.contains(".L"), "sentences are spaced: {text}");
+ assert!(st["overset"].is_null(), "nothing overset: {}", st["overset"]);
+ assert!(text.len() > 1500, "the frame is filled: {}", text.len());
+ }
+ }