DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge docx-lists: Word import: bullets and numbering from numbering.xml (#626)
aiongg8ce45eaef623
diff --cc ROADMAP.mdindex b9fe40292,9caf72aae..538650941--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -128,40 -129,8 +128,41 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+ - **2026-10-12** · Placed Word documents keep their bullets and numbering (#626): `numbering.xml` levels become bullet or numbered paragraphs with Word's number formats, label text, start numbers, restarts and list indents, also when a paragraph style carries the list. No readiness percentage change.+- **2026-10-12** · Text strokes can sit behind the fill: the stroke lies wholly outside the letters at its full weight on screen, in PNG and in PDF, set from the Properties panel or Character Style Options. IDML `StrokeAlignment` on text imports and exports as this setting, so imported text with outside-aligned strokes keeps its letter shapes (#619). No readiness percentage change.+- **2026-10-12** · Type tool: Option/Alt+Left/Right kerns the pair at the caret (manual kerning) or tracks a selection by the Kerning/Tracking increment (Preferences › Units & Increments, 20/1000 em), five times with Cmd/Ctrl; moving by words is Cmd+Left/Right on macOS and Ctrl+Left/Right elsewhere, and Option/Alt+Shift+Left/Right still selects by words (#621). No readiness percentage change.+- **2026-10-12** · Autoflow on Place threads one frame per page column (right to left in a right-to-left story), so text no longer runs across the gutter; pages Smart Text Reflow adds get a primary frame with the page's columns (#625). No readiness percentage change.+- **2026-10-12** · Vector art copied in Illustrator, VectorCraft, Figma or Inkscape pastes as editable paths, as InDesign pastes Illustrator art: the SVG those apps put on the clipboard becomes paths with their fills, strokes (weight, caps, joins, dashes) and opacity, groups stay groups and text comes in as outlines, centred in the view (`edit.pasteSvg`, `ui.paste`). Edit › Paste reads the system clipboard when nothing was copied in DesignCraft. No readiness percentage change.+- **2026-10-12** · Pages panel: double-clicking a parent shows that parent and selects only its row; parent rows show rendered thumbnails. Commands name parents by id, full name, or a prefix only one parent has; an unknown or ambiguous name is an error instead of clearing the page's parent (#624). No readiness percentage change.+- **2026-10-12** · With the Type tool, dragging a table's column or row border resizes it (the double-arrow cursor shows over a border): later columns and rows move along, Shift keeps the table size, and Shift on the right or bottom edge scales every column or row. A dragged row becomes At Least; one undo step per drag, Esc cancels; works in rotated frames and turned spreads. Scripts use `table.resizeBorder`. No readiness percentage change.+- **2026-10-12** · The Tools panel's Fill/Stroke keys work: D (default fill and stroke), X (fill or stroke in front), Shift+X (swap per object, tints included) and / (Apply None), as `color.*` commands; swap and default are one undo step (`object.swapFillStroke`, `object.defaultFillStroke`); the Color panel follows the proxy's fill/stroke choice. No readiness percentage change.+- **2026-10-12** · With a placed graphic selected (Direct Selection), the Transform values act on the graphic inside its frame, as in InDesign: a tilted frame's image can be straightened to 0°. No readiness percentage change.+- **2026-10-11** · Font menu laid out like InDesign's: filters (classification, favourites,+ recently added), families opening to their styles, the selected text as the sample in three+ sizes, Recently Used fonts, Show Similar Fonts and each font's format.+- **2026-10-12** · The Effects panel shows the level its settings apply to ("Group: Color Dodge 100%") and, as in InDesign, Isolate Blending and Knockout Group for a selected group. No readiness percentage change.+- **2026-10-12** · Edit › Step and Repeat has its InDesign dialog: Repeat (Count, or Rows and Columns with Create as a grid), Offset (Vertical, Horizontal, in ruler units) and Preview, which shows the copies while the dialog is open; Cancel takes them away and OK makes them as one undo step. No readiness percentage change.+- **2026-10-12** · Load Styles: the Paragraph Styles and Character Styles panels load styles from another DesignCraft document or an IDML file, with the styles, swatches and lists they name; a dialog picks the styles and what happens to one the document defines differently (`style.load`). No readiness percentage change.+- **2026-10-12** · On screen, blend modes blend with the objects below and not with the paper, as in InDesign and in PDF export: a Color Dodge or Screen object over blank paper shows as it is. No readiness percentage change.+- **2026-10-12** · Text threads by hand: click a selected text frame's in or out port to load+ the text cursor, then click a frame to thread it, click empty space for a column-wide frame or+ drag one (it snaps like frame drawing); Shift-click autoflows, Alt-click stays loaded on the+ frame just added; click the linked frame or double-click a port to break the thread.+ `text.thread`, `text.unthread`, `text.removeFromThread` with undo; locked frames and layers+ refuse threads. The alpha gate now waits only on the Primary Text Frame page fixes (#165). No+ readiness percentage change.+- **2026-10-12** · Properties › Transform shows rotation, shear and X/Y scale, and Rotate 90° and Flip Horizontal/Vertical buttons, as InDesign's does. No readiness percentage change.+- **2026-10-12** · Underlines and strikethroughs are drawn as one bar per stretch of text on screen, as in PDF export: a bar per letter left faint seams between the letters. No readiness percentage change.+- **2026-10-12** · The section marker character shows its section's marker text on document pages (nothing when the section has none) instead of the word "Section", which stays on parent pages; editing the marker recomposes (#556). No readiness percentage change.+- **2026-10-12** · IDML import keeps a font family name exactly as written, trailing spaces included, and font lookup falls back to the name without surrounding spaces; `FontStyle="Nothing"` leaves the style to the paragraph (#558). No readiness percentage change.+- **2026-10-12** · Clipping paths saved with images in IDML (Detect Edges, Alpha Channel, Photoshop Path, User-Modified Path, inverted or not) clip the image on screen and in PDF and survive IDML export; `object.clippingPathOptions` reports, inverts or removes one (#450). No readiness percentage change.+- **2026-10-12** · Anchored objects with text wrap push text aside: other stories' text under them and the lines of their own story after the anchor's line (#557). No readiness percentage change.+- **2026-10-12** · Hyphenation Zone applies to the Single-line Composer only, as in InDesign. With the default Paragraph Composer, ragged text hyphenates where InDesign does (aper-natem), giving the same line breaks. No readiness percentage change.+- **2026-10-12** · Text frame auto-size: Height Only, Width Only, Height and Width (also keeping proportions) frames grow and shrink to fit their text after edits and IDML import, around their reference point, with minimum sizes and No Line Breaks, in the same undo step (#180). No readiness percentage change.+- **2026-10-12** · Text Frame Options › Balance Columns (`object.textFrameOptions {balanceColumns}`, IDML `VerticalBalanceColumns`) evens out the columns of the frame a story ends in, from its last column break on; frames the text runs on from fill normally (#609). No readiness percentage change.+- **2026-10-12** · macOS Dock Quit uses the same unsaved-document prompts as window and menu Quit. Repeated requests keep the current answers; Cancel retains every tab and unsaved recovery checkpoint, and completed Save/Don't Save answers exit through the ordinary event loop. No readiness percentage change.- **2026-10-12** · Orderly native exit writes the latest recovery state after finalizing current quit approvals; incomplete or stale plans keep their documents, and Undo to the saved state clears stale recovery. Unavailable or failed recovery is reported. Cancelable macOS Dock Quit remains open (#544). No readiness percentage change.+- **2026-10-12** · Windows: dragging the window across monitors with different display scales keeps its size instead of growing until it crashes (winit pinned to its 0.30.x backport of the fix). The GPU surface may be as large as the adapter's largest texture (16384 px on DirectX 12, Vulkan and Metal hardware) instead of 8192, and a wgpu error is logged instead of closing the app. No readiness percentage change.- **2026-10-12** · Recovered documents keep a checkpoint until saved, closed or reverted, including a second crash before autosave. Restarted document IDs and explicit recovery folders preserve other snapshots; failed republishing retains the original. No readiness percentage change.- **2026-10-12** · Book numbering and style updates prepare every chapter before saving. Only closed native chapters are changed; imported IDML remains a read-only style/PDF source. If a later disk write fails, the error names the completed chapters; the batch is not a whole-book transaction. No readiness percentage change.- **2026-10-12** · Desktop write callbacks and CLI raster exports use the atomic writer too; open readers retain the original bytes, while private Unix modes and symlink targets survive replacement. Permanent tests cover both actual callers. No readiness percentage change.diff --cc crates/textimport/src/docx.rsindex 63fb60da0,a51e9fe02..46aa3afb8--- a/crates/textimport/src/docx.rs+++ b/crates/textimport/src/docx.rs@@@ -302,16 -348,14 +348,18 @@@ impl Ctx"footnoteReference" if allow_notes => {if let Some(note) = e.attr("id").and_then(|id| self.footnotes.get(id).cloned()) {let mut ns = Story::new(StoryId(0));+ let counter = std::mem::take(&mut self.model_counter);self.blocks(¬e, &mut ns, false);+ self.model_counter = counter;// Word puts the reference mark in the note text: we generate the number.let len = st.len();- let id = st.insert_note(len, "", ParaFormat::default());- if let Some(n) = st.note_mut(id) {- n.text = ns;+ match st.insert_note(len, "", ParaFormat::default()) {+ Some(id) => {+ if let Some(n) = st.note_mut(id) {+ n.text = ns;+ }+ }+ None => self.warnings.push("A footnote in the Word file could not be imported.".into()),}}continue;@@@ -497,21 -610,186 +596,204 @@@ mod testsassert_eq!(i.story.text, "Kept text. MOVED HERE. Plain INSERTED\nEnd.");}+ /// A page break ends its paragraph: the text after it is a paragraph of its own (same style).+ #[test]+ fn page_break_ends_its_paragraph() {+ let styles = format!(r#"<w:styles {W}><w:style w:type="paragraph" w:styleId="H"><w:name w:val="Chapter"/></w:style></w:styles>"#);+ let document = format!(+ r#"<w:document {W}><w:body>+ <w:p><w:r><w:t>End of one</w:t></w:r><w:r><w:br w:type="page"/></w:r></w:p>+ <w:p><w:pPr><w:pStyle w:val="H"/></w:pPr><w:r><w:br w:type="page"/><w:t>Two</w:t><w:br w:type="column"/></w:r></w:p>+ </w:body></w:document>"#+ );+ let st = import(&docx(&document, &styles, "")).unwrap().story;+ st.check().unwrap();+ let (pb, cb) = (designcraft_doc::PAGE_BREAK, designcraft_doc::COLUMN_BREAK);+ assert_eq!(st.text, format!("End of one{pb}\n{pb}\nTwo{cb}\n"));+ let styles: Vec<&str> = st.paras.iter().map(|p| p.style.as_str()).collect();+ assert_eq!(styles, [BASIC_PARAGRAPH, "Chapter", "Chapter", "Chapter"]);+ }+++ /// A paragraph in a Word list: `w:numPr` with `numId` and, unless `None`, `ilvl`.+ fn list_p(num_id: &str, ilvl: Option<&str>, text: &str) -> String {+ let ilvl = ilvl.map(|l| format!(r#"<w:ilvl w:val="{l}"/>"#)).unwrap_or_default();+ format!(r#"<w:p><w:pPr><w:numPr>{ilvl}<w:numId w:val="{num_id}"/></w:numPr></w:pPr><w:r><w:t>{text}</w:t></w:r></w:p>"#)+ }++ fn plain_p(text: &str) -> String {+ format!(r#"<w:p><w:r><w:t>{text}</w:t></w:r></w:p>"#)+ }++ fn lists_docx(numbering: &str, styles: &str, body: &[String]) -> Imported {+ let document = format!(r#"<w:document {W}><w:body>{}</w:body></w:document>"#, body.concat());+ let i = import(&docx_parts(&[("word/document.xml", &document), ("word/styles.xml", styles), ("word/numbering.xml", numbering)])).unwrap();+ i.story.check().unwrap();+ i+ }++ /// The label the model gives paragraph `i` when its number is `n`.+ fn label(st: &Story, i: usize, n: u32) -> String {+ let mut p = designcraft_doc::ParaProps::default();+ p.apply(&st.paras[i].para);+ match p.list_type {+ ListType::Numbers => p.number_label(n),+ ListType::Bullets => p.bullet_label(),+ ListType::None => String::new(),+ }+ }++ /// Regression (#626): pandoc's Markdown list example lost its bullets and numbers.+ #[test]+ fn bullets_and_numbers_from_numbering_xml() {+ let numbering = format!(+ r#"<w:numbering {W}>+ <w:abstractNum w:abstractNumId="990"><w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="•"/>+ <w:pPr><w:ind w:left="480" w:hanging="480"/></w:pPr></w:lvl></w:abstractNum>+ <w:abstractNum w:abstractNumId="991"><w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/>+ <w:pPr><w:ind w:left="480" w:hanging="480"/></w:pPr></w:lvl></w:abstractNum>+ <w:num w:numId="1000"><w:abstractNumId w:val="990"/></w:num>+ <w:num w:numId="1001"><w:abstractNumId w:val="991"/><w:lvlOverride w:ilvl="0"><w:startOverride w:val="1"/></w:lvlOverride></w:num>+ </w:numbering>"#+ );+ let body = [+ plain_p("Intro paragraph."),+ list_p("1000", Some("0"), "first item"),+ list_p("1000", Some("0"), "second item"),+ list_p("1001", Some("0"), "step one"),+ list_p("1001", Some("0"), "step two"),+ ];+ let st = lists_docx(&numbering, "", &body).story;+ let types: Vec<Option<ListType>> = st.paras.iter().map(|p| p.para.list_type).collect();+ assert_eq!(types, [None, Some(ListType::Bullets), Some(ListType::Bullets), Some(ListType::Numbers), Some(ListType::Numbers)]);+ assert_eq!(label(&st, 1, 1), "•\t");+ assert_eq!(st.paras[3].para.number_style, Some(designcraft_doc::NumberStyle::Arabic));+ assert_eq!((label(&st, 3, 1), label(&st, 4, 2)), ("1.\t".to_string(), "2.\t".to_string()));+ // The model's own counter already starts at 1 and carries on: no Start At needed.+ assert_eq!((st.paras[3].para.start_at, st.paras[4].para.start_at), (None, None));+ assert_eq!((st.paras[1].para.left_indent, st.paras[1].para.first_line_indent), (Some(24.0), Some(-24.0)));+ }++ /// Level 1 inside level 0, parent numbers in a label, numbering that carries on past a plain+ /// paragraph, and a `num` with a start override restarting.+ #[test]+ fn nested_levels_and_restarts() {+ let numbering = format!(+ r#"<w:numbering {W}>+ <w:abstractNum w:abstractNumId="1">+ <w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/></w:lvl>+ <w:lvl w:ilvl="1"><w:start w:val="1"/><w:numFmt w:val="lowerLetter"/><w:lvlText w:val="%2)"/><w:suff w:val="space"/>+ <w:pPr><w:ind w:left="1440" w:hanging="360"/></w:pPr></w:lvl>+ <w:lvl w:ilvl="2"><w:start w:val="1"/><w:numFmt w:val="upperRoman"/><w:lvlText w:val="%1.%2.%3"/></w:lvl>+ </w:abstractNum>+ <w:num w:numId="1"><w:abstractNumId w:val="1"/></w:num>+ <w:num w:numId="2"><w:abstractNumId w:val="1"/><w:lvlOverride w:ilvl="0"><w:startOverride w:val="1"/></w:lvlOverride></w:num>+ <w:num w:numId="3"><w:abstractNumId w:val="1"/></w:num>+ </w:numbering>"#+ );+ let body = [+ list_p("1", None, "A"),+ list_p("1", Some("1"), "B"),+ list_p("1", Some("1"), "C"),+ list_p("1", Some("2"), "D"),+ list_p("1", Some("0"), "E"),+ plain_p("Between"),+ list_p("1", Some("0"), "F"),+ list_p("2", Some("0"), "G"),+ list_p("3", Some("0"), "H"),+ ];+ let st = lists_docx(&numbering, "", &body).story;+ let start: Vec<Option<Option<u32>>> = st.paras.iter().map(|p| p.para.start_at).collect();+ // Word's numbers: 1, a, b, 1.b.I, 2, –, 3, 1 (own counter), 4 (shares numId 1's). E's 2+ // follows the model's counter (1 after D).+ assert_eq!(start, [None, Some(Some(1)), None, Some(Some(1)), None, None, Some(Some(3)), Some(Some(1)), Some(Some(4))]);+ assert_eq!(label(&st, 1, 1), "a) ");+ assert_eq!(label(&st, 3, 1), "1.b.I\t");+ assert_eq!(st.paras[1].para.left_indent, Some(72.0));+ assert_eq!(st.paras[1].para.first_line_indent, Some(-18.0));+ }++ /// A paragraph style's `w:numPr` (inherited through `w:basedOn`) makes its paragraphs a list;+ /// numId 0 on a paragraph takes it out of the list.+ #[test]+ fn style_lists_and_num_id_zero() {+ let numbering = format!(+ r#"<w:numbering {W}>+ <w:abstractNum w:abstractNumId="7">+ <w:lvl w:ilvl="0"><w:numFmt w:val="bullet"/><w:lvlText w:val=""/><w:rPr><w:rFonts w:ascii="Symbol" w:hAnsi="Symbol"/></w:rPr></w:lvl>+ <w:lvl w:ilvl="1"><w:numFmt w:val="bullet"/><w:lvlText w:val="o"/><w:rPr><w:rFonts w:ascii="Courier New"/></w:rPr></w:lvl>+ </w:abstractNum>+ <w:num w:numId="5"><w:abstractNumId w:val="7"/></w:num>+ </w:numbering>"#+ );+ let styles = format!(+ r#"<w:styles {W}>+ <w:style w:type="paragraph" w:styleId="ListBullet"><w:name w:val="List Bullet"/><w:pPr><w:numPr><w:numId w:val="5"/></w:numPr></w:pPr></w:style>+ <w:style w:type="paragraph" w:styleId="ListBullet2"><w:name w:val="List Bullet 2"/><w:basedOn w:val="ListBullet"/>+ <w:pPr><w:numPr><w:ilvl w:val="1"/></w:numPr></w:pPr></w:style>+ </w:styles>"#+ );+ let styled =+ |id: &str, extra: &str, text: &str| format!(r#"<w:p><w:pPr><w:pStyle w:val="{id}"/>{extra}</w:pPr><w:r><w:t>{text}</w:t></w:r></w:p>"#);+ let body = [+ styled("ListBullet", "", "one"),+ styled("ListBullet2", "", "two"),+ styled("ListBullet", r#"<w:numPr><w:ilvl w:val="0"/><w:numId w:val="0"/></w:numPr>"#, "not a list"),+ ];+ let st = lists_docx(&numbering, &styles, &body).story;+ assert_eq!(label(&st, 0, 1), "•\t");+ assert_eq!(label(&st, 1, 1), "◦\t");+ assert_eq!(st.paras[2].para.list_type, None);+ assert_eq!(st.paras[2].style, "List Bullet");+ }++ /// Hostile list definitions: missing abstractNums and levels, huge or negative levels and+ /// starts, a long label, a `w:basedOn` cycle. No panic; what can't be a list is plain.+ #[test]+ fn hostile_numbering_falls_back_to_plain_paragraphs() {+ let long = "x".repeat(10_000);+ let numbering = format!(+ r#"<w:numbering {W}>+ <w:abstractNum w:abstractNumId="1">+ <w:lvl w:ilvl="0"><w:start w:val="99999999999999"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1{long}%9%"/></w:lvl>+ <w:lvl w:ilvl="99999999999999"><w:numFmt w:val="decimal"/></w:lvl>+ <w:lvl w:ilvl="-1"><w:numFmt w:val="decimal"/></w:lvl>+ <w:lvl w:ilvl="3"><w:start w:val="-5"/><w:numFmt w:val="ordinalText"/><w:lvlText w:val="%4^"/><w:lvlRestart w:val="99"/></w:lvl>+ </w:abstractNum>+ <w:num w:numId="1"><w:abstractNumId w:val="1"/></w:num>+ <w:num w:numId="2"><w:abstractNumId w:val="404"/></w:num>+ <w:num w:numId="3"/>+ <w:num><w:abstractNumId w:val="1"/></w:num>+ </w:numbering>"#+ );+ let styles = format!(+ r#"<w:styles {W}>+ <w:style w:type="paragraph" w:styleId="A"><w:name w:val="A"/><w:basedOn w:val="B"/></w:style>+ <w:style w:type="paragraph" w:styleId="B"><w:name w:val="B"/><w:basedOn w:val="A"/></w:style>+ </w:styles>"#+ );+ let body = [+ list_p("2", None, "missing abstractNum"),+ list_p("3", None, "num without abstractNum"),+ list_p("404", None, "unknown numId"),+ list_p("1", Some("99999999999999"), "huge level"),+ list_p("1", Some("9"), "level 9"),+ list_p("1", Some("-1"), "negative level"),+ list_p("1", Some("1"), "undefined level"),+ r#"<w:p><w:pPr><w:pStyle w:val="A"/><w:numPr><w:ilvl w:val="0"/></w:numPr></w:pPr><w:r><w:t>cycle</w:t></w:r></w:p>"#.to_string(),+ list_p("1", None, "huge start"),+ list_p("1", Some("3"), "negative start"),+ ];+ let st = lists_docx(&numbering, &styles, &body).story;+ assert!(st.paras[..8].iter().all(|p| p.para.list_type.is_none()), "{:?}", st.paras);+ assert_eq!(st.paras[8].para.start_at, Some(Some(u32::MAX)));+ let expr = st.paras[8].para.number_expression.clone().unwrap_or_default();+ assert!(expr.starts_with("^#x") && expr.chars().count() < 80, "{expr}");+ // A start below 0 counts from 0, which the model shows as 1; `^` in a label is literal.+ assert_eq!(label(&st, 9, 1), "1^\t");+ // Unreadable list definitions leave plain paragraphs and a warning, not a failed import.+ let document = format!(r#"<w:document {W}><w:body>{}</w:body></w:document>"#, list_p("1", None, "x"));+ let i = import(&docx_parts(&[("word/document.xml", &document), ("word/numbering.xml", "<w:numbering></w:num>")])).unwrap();+ assert_eq!(i.story.paras[0].para.list_type, None);+ assert_eq!(i.warnings.len(), 1);+ }}