DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge remote-tracking branch 'origin/main' into character-style-from-selection
moppeeer527c0d350b49
diff --cc ROADMAP.mdindex a35f4a315,153555913..ac423d821--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -11,7 -11,15 +11,15 @@@DesignCraft aims at full Adobe InDesign parity — and to be better: faster, open (documented JSON format + IDML), scriptable by agents (MCP), and available on the web.+ - **2026-10-23** · PDF layer choices now validate before editing all targets; rejected rewrites+ leave document/undo state intact. Null trailer entries remain unencrypted, and unsupported+ all-content crops retain the whole page rather than silently clipping hidden layers.+ - **2026-10-23** · PDF layer visibility variants retain catalog/configuration entries and full+ object references; bounded incremental updates replace the existing catalog. Synthetic+ regression tests cover metadata, output-intent references, nonzero generations and+ forward Prev links; repeated cross-reference offsets are rejected explicitly. No readiness percentage change.+-## Status (2026-10-01)+## Status (2026-10-21)**Working today**- Document model: facing/non-facing spreads, parent pages with page-number markers, sections, layers, frames (text / graphic / unassigned), threaded stories, paragraph/character/object styles with based-on, swatches (process/spot/tints/gradients), corner options, text wrap, drop shadow, opacity/blend.diff --cc crates/engine/src/tests.rsindex 769051740,b1792485d..4d4c3e6d5--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@@ -1652,41 -1652,107 +1652,146 @@@ fn a_line_fits_when_its_baseline_does(assert!(overset(&mut s, 50.0), "a baseline below the frame still oversets the line");}+/// Reset To Base with a new Based On: a partial rule edit resolves over the new parent, not the+/// old one.+#[test]+fn reset_to_base_with_a_new_parent_resolves_rule_edits_over_it() {+ let mut s = session();+ let rule = |weight: f64, offset: f64| json!({"on": true, "weight": weight, "color": "[Black]", "offset": offset});+ s.execute("style.paragraph.create", &json!({"name": "Old", "para": {"ruleBelow": rule(3.0, 1.0)}})).unwrap();+ s.execute("style.paragraph.create", &json!({"name": "New", "para": {"ruleBelow": rule(1.0, 9.0)}})).unwrap();+ s.execute("style.paragraph.create", &json!({"name": "Child", "basedOn": "Old"})).unwrap();+ s.execute("style.paragraph.edit", &json!({"name": "Child", "resetToBase": true, "basedOn": "New", "para": {"ruleBelow": {"weight": 2}}}))+ .unwrap();+ let r = s.doc().unwrap().doc.styles.resolve_para_style("Child").0.rule_below;+ assert_eq!((r.weight, r.offset), (2.0, 9.0), "the offset is the new parent's");+}++/// Paragraph style references are checked: a Based On or Next Style that names no style, or+/// that isn't a name or null, is refused and changes nothing.+#[test]+fn paragraph_style_references_must_name_styles() {+ let mut s = session();+ s.execute("style.paragraph.create", &json!({"name": "Body"})).unwrap();+ assert!(s.execute("style.paragraph.create", &json!({"name": "Lost", "nextStyle": "Nowhere"})).is_err());+ assert!(s.doc().unwrap().doc.styles.para("Lost").is_none());+ // On creation too, a reference that isn't a name or null is refused, not dropped.+ for p in [json!({"name": "Lost", "nextStyle": true}), json!({"name": "Lost", "basedOn": 3})] {+ assert!(s.execute("style.paragraph.create", &p).is_err(), "{p}");+ assert!(s.doc().unwrap().doc.styles.para("Lost").is_none(), "{p}");+ }+ assert!(s.execute("style.character.create", &json!({"name": "Lost", "basedOn": ["Body"]})).is_err());+ assert!(s.doc().unwrap().doc.styles.char_style("Lost").is_none());+ s.execute("style.paragraph.create", &json!({"name": "Self", "nextStyle": "Self"})).unwrap();+ let before = s.doc().unwrap().doc.clone();+ for p in [json!({"name": "Body", "basedOn": "Nowhere"}), json!({"name": "Body", "basedOn": 3}), json!({"name": "Body", "nextStyle": true})] {+ assert!(s.execute("style.paragraph.edit", &p).is_err(), "{p}");+ }+ assert!(std::sync::Arc::ptr_eq(&before, &s.doc().unwrap().doc), "nothing changed");+ s.execute("style.paragraph.edit", &json!({"name": "Body", "basedOn": null, "nextStyle": "Self"})).unwrap();+}+++ /// Issue #1637: with several objects selected, a click on one of them (no drag) makes it the key+ /// object, and Align to Key Object leaves it in place. A second click on it drops the key.+ #[test]+ fn a_click_in_the_selection_makes_the_key_object() {+ use designcraft_tools::{PointerEvent, PointerKind};+ let mut s = session();+ let a = s.execute("frame.create", &json!({"rect": [50.0, 100.0, 100.0, 150.0], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ let b = s.execute("frame.create", &json!({"rect": [200.0, 120.0, 300.0, 170.0], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [a, b]})).unwrap();+ s.set_tool("selection");+ let v = ViewInfo::at_zoom(1.0);+ // On the part of the key object that the aligned object never covers, away from the handles.+ let click = |s: &mut Session| {+ s.pointer(&PointerEvent::new(PointerKind::Down, 280.0, 160.0), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Up, 280.0, 160.0), v).unwrap();+ };+ click(&mut s);+ assert_eq!(s.doc().unwrap().selection.items.len(), 2, "the click keeps both selected");+ // The key is the right-hand object, so aligning left edges to the selection would move it.+ s.execute("object.align", &json!({"edge": "left", "to": "keyObject"})).unwrap();+ let x0 = |s: &Session, id: u64| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().bounds().x0;+ assert!((x0(&s, b) - 200.0).abs() < 1e-6, "the key object moved to {}", x0(&s, b));+ assert!((x0(&s, a) - 200.0).abs() < 1e-6, "the other object is at {}", x0(&s, a));+ // The Align panel and the Control panel send no target: the key object is the default one.+ s.execute("object.align", &json!({"edge": "top"})).unwrap();+ let y0 = |s: &Session, id: u64| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().bounds().y0;+ assert!((y0(&s, b) - 120.0).abs() < 1e-6, "the key object moved to {}", y0(&s, b));+ assert!((y0(&s, a) - 120.0).abs() < 1e-6, "the other object is at {}", y0(&s, a));+ click(&mut s);+ assert_eq!(s.doc().unwrap().selection.key, None, "a click on the key object drops the key");+ }++ /// Dragging one of several selected objects moves them all and makes no key object.+ #[test]+ fn dragging_the_selection_makes_no_key_object() {+ use designcraft_tools::{PointerEvent, PointerKind};+ let mut s = session();+ let a = s.execute("frame.create", &json!({"rect": [50.0, 100.0, 100.0, 150.0], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ let b = s.execute("frame.create", &json!({"rect": [200.0, 100.0, 260.0, 150.0], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [a, b]})).unwrap();+ s.set_tool("selection");+ let v = ViewInfo::at_zoom(1.0);+ s.pointer(&PointerEvent::new(PointerKind::Down, 230.0, 125.0), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Drag, 250.0, 135.0), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Up, 250.0, 135.0), v).unwrap();+ assert_eq!(s.doc().unwrap().selection.key, None);+ }++ /// Shift-clicking the key object out of the selection drops the key.+ #[test]+ fn deselecting_the_key_object_drops_the_key() {+ let mut s = session();+ let a = s.execute("frame.create", &json!({"rect": [50.0, 100.0, 100.0, 150.0]})).unwrap()["id"].as_u64().unwrap();+ let b = s.execute("frame.create", &json!({"rect": [200.0, 100.0, 260.0, 150.0]})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [a, b]})).unwrap();+ s.execute("selection.key", &json!({"id": b})).unwrap();+ assert_eq!(s.doc().unwrap().selection.key, Some(designcraft_doc::ItemId(b)));+ s.execute("selection.toggle", &json!({"id": b})).unwrap();+ assert_eq!(s.doc().unwrap().selection.key, None);+ }++ /// A key object needs another object to align to: with one object selected there is nothing to key+ /// against, and the stored key would turn that object into the target as soon as a second one joins.+ #[test]+ fn a_single_selected_object_cannot_be_the_key_object() {+ let mut s = session();+ let a = s.execute("frame.create", &json!({"rect": [50.0, 100.0, 100.0, 150.0]})).unwrap()["id"].as_u64().unwrap();+ let b = s.execute("frame.create", &json!({"rect": [200.0, 120.0, 300.0, 170.0]})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [a]})).unwrap();+ assert!(s.execute("selection.key", &json!({"id": a})).is_err());+ assert_eq!(s.doc().unwrap().selection.key, None);+ s.execute("selection.toggle", &json!({"id": b})).unwrap();+ assert_eq!(s.doc().unwrap().selection.key, None, "the second object joining must not find a key already set");+ }++ /// With the selection down to the key object alone, Align no longer has a key object: a single+ /// object aligns to the page, as before.+ #[test]+ fn a_lone_key_object_aligns_to_the_page() {+ let mut s = session();+ let a = s.execute("frame.create", &json!({"rect": [50.0, 100.0, 100.0, 150.0]})).unwrap()["id"].as_u64().unwrap();+ let b = s.execute("frame.create", &json!({"rect": [200.0, 120.0, 300.0, 170.0]})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [a, b]})).unwrap();+ s.execute("selection.key", &json!({"id": b})).unwrap();+ s.execute("selection.toggle", &json!({"id": a})).unwrap();+ assert_eq!(s.doc().unwrap().selection.key, None);+ s.execute("object.align", &json!({"edge": "left"})).unwrap();+ let x0 = s.doc().unwrap().doc.item(designcraft_doc::ItemId(b)).unwrap().bounds().x0;+ assert!(x0.abs() < 1e-6, "the object is at {x0}, not at the page's left edge");+ }++ /// Aligning one object alone (`ids`) while it is the key object of a larger selection also takes+ /// the page.+ #[test]+ fn aligning_the_key_object_alone_takes_the_page() {+ let mut s = session();+ let a = s.execute("frame.create", &json!({"rect": [50.0, 100.0, 100.0, 150.0]})).unwrap()["id"].as_u64().unwrap();+ let b = s.execute("frame.create", &json!({"rect": [200.0, 120.0, 300.0, 170.0]})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [a, b]})).unwrap();+ s.execute("selection.key", &json!({"id": b})).unwrap();+ s.execute("object.align", &json!({"edge": "left", "ids": [b]})).unwrap();+ let x0 = s.doc().unwrap().doc.item(designcraft_doc::ItemId(b)).unwrap().bounds().x0;+ assert!(x0.abs() < 1e-6, "the object is at {x0}, not at the page's left edge");+ }diff --cc crates/ui-egui/src/dialogs.rsindex 5b14e5425,9b7bc2b79..7075e38b3--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@@ -3721,9 -3700,19 +3743,20 @@@ fn style_option_maps(d: &Dialog) -> (sechars.insert(a.into(), v.clone());}}+ (para, chars)+ }++ fn confirm_paragraph_style_options(app: &mut DesignApp, d: &mut Dialog) -> Result<Value, String> {+ let name = d.s("name");+ if let Err(e) = check_paragraph_style_justification(app, d) {+ // The caller shows the reason in the dialog's status line.+ d.fields.insert("section".into(), json!("justify"));+ return Err(e);+ }+ let (para, chars) = style_option_maps(d);let based = d.s("basedOn");let rename = d.s("rename");+ let next = d.fields.get("nextStyle").cloned();let (r, style) = if d.b("new") {let mut params = json!({"name": if rename.trim().is_empty() { "Paragraph Style 1" } else { rename.trim() }, "para": para, "chars": chars});if !based.is_empty() && based != designcraft_doc::NO_PARA_STYLE {@@@ -5263,41 -5193,61 +5301,92 @@@ pub fn open_style_options(app: &mut Despub fn open_new_style(app: &mut DesignApp, para: bool) {let Some(st) = app.session.active() else { return };let name = next_style_name(&st.doc.styles, para);+ let has_text = st.selection.text.is_some();+ let (bp, bc) = st.doc.styles.resolve_para_style(designcraft_doc::NO_PARA_STYLE);let id = if para { "paragraphStyleOptions" } else { "characterStyleOptions" };- app.ui.dialog = Some(Dialog::new(id, json!({"new": true, "rename": name})));+ let mut fields = json!({"new": true, "rename": name});+ // New Paragraph Style with text selected starts from it, as InDesign's: Based On [No Paragraph+ // Style] and every setting of the text that differs, applied to the selection on OK.+ if para+ && has_text+ && let Some(sel) = app.session.execute("type.selectionAttrs", &json!({})).ok().filter(|v| !v.is_null())+ {+ for (prefix, now, base) in+ [("p.", &sel["para"], serde_json::to_value(bp).unwrap_or_default()), ("c.", &sel["chars"], serde_json::to_value(bc).unwrap_or_default())]+ {+ for (k, v) in now.as_object().into_iter().flatten() {+ if !v.is_null() && base.get(k) != Some(v) && base.get(k).is_some() {+ fields[format!("{prefix}{k}")] = v.clone();+ }+ }+ }+ fields["apply"] = json!(true);+ }+ // New Character Style with text selected starts from what the text has of its own over its+ // paragraph ("[None] + Bold + color"), applied to the selection on OK, as InDesign's.+ if !para+ && has_text+ && let Some(sel) = app.session.execute("type.selectionAttrs", &json!({})).ok().filter(|v| !v.is_null())+ {+ for (k, v) in sel["ownChars"].as_object().into_iter().flatten().filter(|(_, v)| !v.is_null()) {+ fields[format!("c.{k}")] = v.clone();+ }+ fields["apply"] = json!(true);+ }+ app.ui.dialog = Some(Dialog::new(id, fields));}+ /// The General section of the Character Style Options dialog: name, Based On, and a summary of+ /// the style's settings.+ fn character_style_general(+ lang: &str,+ ui: &mut egui::Ui,+ d: &mut Dialog,+ styles: &designcraft_doc::Styles,+ style: &designcraft_doc::CharacterStyle,+ based: &str,+ ) {+ let (name, new) = (d.s("name"), d.b("new"));+ egui::Grid::new("csg").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {+ crate::rtl::label(ui, crate::i18n::tr(lang, "Style Name:"));+ text_field(ui, d, "rename", 220.0);+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Based On:"));+ egui::ComboBox::from_id_salt("csbased").selected_text(crate::rtl::widget(ui, crate::i18n::style_name(lang, based))).width(220.0).show_ui(+ ui,+ |ui| {+ // Not itself, nor a style based on it.+ for s in styles.character.iter().filter(|s| new || !styles.char_based_on_cycles(&name, &s.name)) {+ if ui.selectable_label(s.name == based, crate::rtl::widget(ui, crate::i18n::style_name(lang, &s.name))).clicked() {+ d.fields.insert("basedOn".into(), json!(s.name));+ }+ }+ },+ );+ ui.end_row();+ });+ let status = d.s("status");+ if !status.is_empty() {+ crate::rtl::label(ui, egui::RichText::new(status).color(crate::theme::Tokens::get(ui.ctx()).text_strong));+ }+ ui.add_space(8.0);+ crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(lang, "Style Settings:")).font(semibold(12.0)));+ // What OK would leave the style setting, after its Based On.+ let mut own = serde_json::to_value(&style.chars).unwrap_or_default();+ if let Some(o) = own.as_object_mut() {+ for (k, v) in d.fields.iter().filter_map(|(k, v)| Some((k.strip_prefix("c.")?, v))) {+ if v.is_null() {+ o.remove(k);+ } else {+ o.insert(k.to_string(), v.clone());+ }+ }+ }+ let mut parts = vec![crate::i18n::style_name(lang, based).to_string()];+ parts.extend(own.as_object().into_iter().flatten().map(|(k, v)| format!("{}: {}", setting_label(lang, k), setting_text(v))));+ ui.add(egui::Label::new(egui::RichText::new(parts.join(" + ")).color(crate::theme::Tokens::get(ui.ctx()).text_dim)).wrap());+ }+/// Character Style Options: General, then the character sections it shares with Paragraph Style/// Options. A character style sets only some attributes: the fields show those it and its Based/// On set and leave the rest blank. Edits are `c.<attr>` fields (`null` = no longer set), applied@@@ -5360,50 -5310,7 +5449,13 @@@ fn character_style_options(app: &mut De"underline" => line_options(&lang, ui, d, &cf, &doc, "underline"),"strikethrough" => line_options(&lang, ui, d, &cf, &doc, "strikethrough"),s if style_cjk::is_section(s) => style_cjk::section_ui(app, ui, d, s, &cf, None, &doc),- _ => character_style_general(&lang, ui, d, styles, &style, &based),+ _ => {- egui::Grid::new("csg").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {- crate::rtl::label(ui, crate::i18n::tr(&lang, "Style Name:"));- text_field(ui, d, "rename", 220.0);- ui.end_row();- crate::rtl::label(ui, crate::i18n::tr(&lang, "Based On:"));- egui::ComboBox::from_id_salt("csbased")- .selected_text(crate::rtl::widget(ui, crate::i18n::style_name(&lang, &based)))- .width(220.0)- .show_ui(ui, |ui| {- // Not itself, nor a style based on it.- for s in styles.character.iter().filter(|s| new || !styles.char_based_on_cycles(&name, &s.name)) {- if ui.selectable_label(s.name == based, crate::rtl::widget(ui, crate::i18n::style_name(&lang, &s.name))).clicked() {- d.fields.insert("basedOn".into(), json!(s.name));- }- }- });- ui.end_row();- });- let status = d.s("status");- if !status.is_empty() {- crate::rtl::label(ui, egui::RichText::new(status).color(crate::theme::Tokens::get(ui.ctx()).text_strong));- }- ui.add_space(8.0);- crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&lang, "Style Settings:")).font(semibold(12.0)));- // What OK would leave the style setting, after its Based On.- let mut own = serde_json::to_value(&style.chars).unwrap_or_default();- if let Some(o) = own.as_object_mut() {- for (k, v) in d.fields.iter().filter_map(|(k, v)| Some((k.strip_prefix("c.")?, v))) {- if v.is_null() {- o.remove(k);- } else {- o.insert(k.to_string(), v.clone());- }- }- }- let mut parts = vec![crate::i18n::style_name(&lang, &based).to_string()];- parts.extend(own.as_object().into_iter().flatten().map(|(k, v)| format!("{}: {}", setting_label(&lang, k), setting_text(v))));- ui.add(egui::Label::new(egui::RichText::new(parts.join(" + ")).color(crate::theme::Tokens::get(ui.ctx()).text_dim)).wrap());++ character_style_general(&lang, ui, d, styles, &style, &based);+ if new {+ ui.add_space(8.0);+ check(ui, d, "apply", crate::i18n::tr(&lang, "Apply Style to Selection"));+ }+ }});});}diff --cc crates/ui-egui/src/i18n.rsindex 3985d9929,bdca83589..f930b0076--- a/crates/ui-egui/src/i18n.rs+++ b/crates/ui-egui/src/i18n.rs@@@ -34,23 -34,18 +34,33 @@@ pub const LANGUAGES: &[(&str, &str)] =("ka", "ქართული"),];+ /// The interface languages in the order the Preferences picker lists them: English first (the+ /// source language), then the rest by their own name with accents folded, so Čeština sits under+ /// C. Names in other scripts follow the Latin ones in code point order: Cyrillic, Arabic,+ /// Georgian, then the CJK languages.+ pub fn picker_languages() -> Vec<(&'static str, &'static str)> {+ let mut rest: Vec<(&str, &str)> = LANGUAGES.iter().copied().filter(|(code, _)| !code.is_empty()).collect();+ rest.sort_by_cached_key(|(_, name)| name_sort_key(name));+ std::iter::once(LANGUAGES[0]).chain(rest).collect()+ }+/// English → [German, French, Spanish, Japanese, Simplified Chinese].const TABLE: &[(&str, [&str; 5])] = &[+ ("Next Style:", ["Nächstes Format:", "Style suivant :", "Estilo siguiente:", "次のスタイル :", "下一样式:"]),+ ("[Same style]", ["[Gleiches Format]", "[Même style]", "[Mismo estilo]", "[同じスタイル]", "[相同样式]"]),+ ("Reset To Base", ["Auf Basis zurücksetzen", "Rétablir la base", "Restablecer a base", "基準に戻す", "重置为基准"]),+ ("New Paragraph Style", ["Neues Absatzformat", "Nouveau style de paragraphe", "Nuevo estilo de párrafo", "新規段落スタイル", "新建段落样式"]),+ ("New Character Style", ["Neues Zeichenformat", "Nouveau style de caractère", "Nuevo estilo de carácter", "新規文字スタイル", "新建字符样式"]),+ (+ "Apply Style to Selection",+ [+ "Format auf Auswahl anwenden",+ "Appliquer le style à la sélection",+ "Aplicar estilo a la selección",+ "選択範囲にスタイルを適用",+ "将样式应用于选区",+ ],+ ),// Menus.("File", ["Datei", "Fichier", "Archivo", "ファイル", "文件"]),("Edit", ["Bearbeiten", "Édition", "Edición", "編集", "编辑"]),