DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #180: text frame auto-size grows and shrinks frames to fit their text
aiongg38bdc192325e
diff --cc ROADMAP.mdindex 2ec5ab02b,f3bccdbac..f04e93fc9--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -128,32 -129,8 +128,33 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+- **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** · 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/doc/src/item.rsindex e090af2f3,a7199871a..417027a14--- a/crates/doc/src/item.rs+++ b/crates/doc/src/item.rs@@@ -368,8 -321,21 +368,21 @@@ pub struct TextFrameOptionspub first_baseline_min: f64,pub ignore_wrap: bool,pub auto_size: AutoSize,- /// Reference point (0..9, row-major from top-left) that stays fixed when auto-sizing.+ /// Reference point (0..9, row-major from the top left) that stays fixed when auto-sizing.pub auto_size_ref: u8,+ /// Auto-size never makes the frame shorter than `auto_size_min_height` while this is on.+ #[serde(skip_serializing_if = "std::ops::Not::not")]+ pub auto_size_use_min_height: bool,+ #[serde(skip_serializing_if = "is_default")]+ pub auto_size_min_height: f64,+ /// Auto-size never makes the frame narrower than `auto_size_min_width` while this is on.+ #[serde(skip_serializing_if = "std::ops::Not::not")]+ pub auto_size_use_min_width: bool,+ #[serde(skip_serializing_if = "is_default")]+ pub auto_size_min_width: f64,+ /// Width-growing auto-size sets each paragraph on one line (the frame widens to the longest).+ #[serde(skip_serializing_if = "std::ops::Not::not")]+ pub auto_size_no_line_breaks: bool,pub column_rule: bool,pub column_rule_weight: f64,pub column_rule_color: String,@@@ -425,7 -391,12 +438,12 @@@ impl Default for TextFrameOptionsfirst_baseline_min: 0.0,ignore_wrap: false,auto_size: AutoSize::Off,- auto_size_ref: 1,+ auto_size_ref: 4,+ auto_size_use_min_height: false,+ auto_size_min_height: 0.0,+ auto_size_use_min_width: false,+ auto_size_min_width: 0.0,+ auto_size_no_line_breaks: false,column_rule: false,column_rule_weight: 1.0,column_rule_color: designcraft_color::swatch::BLACK.into(),diff --cc crates/engine/src/cmd/interchange.rsindex befb2c58d,2a437091b..c3ff9756b--- a/crates/engine/src/cmd/interchange.rs+++ b/crates/engine/src/cmd/interchange.rs@@@ -246,8 -157,9 +246,10 @@@ pub(crate) fn open_idml(s: &mut SessionNone => (None, 0, Vec::new()),};warnings.extend(font_warnings);+ warnings.extend(super::style::grep_style_warnings(&d));+ // Auto-size frames fit their text as set here (with the document's fonts loaded).+ crate::autosize::apply(&mut d, None);- // Never save over the .idml with the native format: the document starts unsaved.+ // Never save over the .idml or .indd with the native format: the document starts unsaved.let mut st = DocState::new(d, None);st.fonts = fonts;let i = s.add_document(st);diff --cc crates/engine/src/cmd/object.rsindex ba647334a,dac8504d9..07c1ba600--- a/crates/engine/src/cmd/object.rs+++ b/crates/engine/src/cmd/object.rs@@@ -541,7 -514,7 +541,7 @@@ pub fn specs() -> Vec<CommandSpec>"Text Frame Options…",["Object"],Some("Cmd+B"),- "{columns?, gutter?, inset?: number|[t,l,b,r] (null keeps that side), verticalJustification?: top|center|bottom|justify, firstBaseline?: ascent|capHeight|leading|xHeight|emboxHeight|fixed, autoSize?, ignoreWrap?, balanceColumns?, columnRule?: bool, columnRuleWeight? (pt), columnRuleColor? (swatch name), columnRuleTint? (0..1), columnRuleOffset? (pt, horizontal), columnRuleTopInset? (pt), columnRuleBottomInset? (pt), vertical?: bool (sets the story direction of the frames' stories, as Type ▸ Story Direction), ids?}",- "{columns?, gutter?, inset?: number|[t,l,b,r] (null keeps that side), verticalJustification?: top|center|bottom|justify, firstBaseline?, autoSize?: off|heightOnly|widthOnly|heightAndWidth|heightAndWidthProportionally, autoSizeReference?: topLeft|topCenter|topRight|leftCenter|center|rightCenter|bottomLeft|bottomCenter|bottomRight (the point that stays put), useMinimumHeight?: bool, minimumHeight? (pt), useMinimumWidth?: bool, minimumWidth? (pt), noLineBreaks?: bool, ignoreWrap?, balanceColumns?, columnRule?: bool, columnRuleWeight? (pt), columnRuleColor? (swatch name), columnRuleTint? (0..1), columnRuleOffset? (pt, horizontal), columnRuleTopInset? (pt), columnRuleBottomInset? (pt), vertical?: bool (sets the story direction of the frames' stories, as Type ▸ Story Direction), ids?}",++ "{columns?, gutter?, inset?: number|[t,l,b,r] (null keeps that side), verticalJustification?: top|center|bottom|justify, firstBaseline?: ascent|capHeight|leading|xHeight|emboxHeight|fixed, autoSize?: off|heightOnly|widthOnly|heightAndWidth|heightAndWidthProportionally, autoSizeReference?: topLeft|topCenter|topRight|leftCenter|center|rightCenter|bottomLeft|bottomCenter|bottomRight (the point that stays put), useMinimumHeight?: bool, minimumHeight? (pt), useMinimumWidth?: bool, minimumWidth? (pt), noLineBreaks?: bool, ignoreWrap?, balanceColumns?, columnRule?: bool, columnRuleWeight? (pt), columnRuleColor? (swatch name), columnRuleTint? (0..1), columnRuleOffset? (pt, horizontal), columnRuleTopInset? (pt), columnRuleBottomInset? (pt), vertical?: bool (sets the story direction of the frames' stories, as Type ▸ Story Direction), ids?}",has_selection,text_frame_options),diff --cc crates/engine/src/lib.rsindex 7db6a7ea6,783ea0a85..cede9b0cb--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@@ -521,16 -440,23 +522,32 @@@ impl Sessionst.doc = Arc::new(d);}}+ // Auto-size frames fit the text the command changed, in the same undo step.+ if spec.undoable+ && let Some(st) = self.active_mut()+ {+ let prev = before.as_ref().filter(|(uid, _)| *uid == st.uid).map(|(_, d)| d.as_ref());+ if prev.is_none_or(|p| !std::ptr::eq(p, st.doc.as_ref())) {+ let todo = autosize::candidates(&st.doc, prev);+ if !todo.is_empty() {+ let mut d = (*st.doc).clone();+ if autosize::fit(&mut d, todo) {+ st.doc = Arc::new(d);- st.revision += 1;++ st.bump_revision();+ }+ }+ }+ }- // Record undo if the document changed (and we're not previewing an interaction).+ self.record_undo_step(spec, before, nested);+ if spec.journal {+ self.journal.push((id.to_string(), params.clone()));+ }+ Ok(r)+ }++ /// Record undo if the document changed (and we're not previewing an interaction). A command+ /// run by an undoable one leaves the step to it: one command is one undo step.+ fn record_undo_step(&mut self, spec: &CommandSpec, before: Option<(u64, Arc<Document>)>, nested: bool) {if let (Some((uid, old)), Some(st)) = (before, self.active_mut())&& st.uid == uid&& !Arc::ptr_eq(&old, &st.doc)@@@ -644,8 -573,8 +661,10 @@@ pub(crate) use push_undo as record_undo#[cfg(test)]mod tests;#[cfg(test)]+ mod tests_autosize;+ #[cfg(test)]mod tests_idml;#[cfg(test)]+mod tests_ime;+#[cfg(test)]mod tests_table;diff --cc crates/idml/src/export.rsindex ec894abda,7a8e26752..234de2890--- a/crates/idml/src/export.rs+++ b/crates/idml/src/export.rs@@@ -2784,18 -2485,33 +2784,23 @@@ fn text_frame_pref(o: &TextFrameOptions.attr("VerticalThreshold", num(o.vj_paragraph_spacing_limit)).attr("IgnoreWrap", bool_s(o.ignore_wrap)).attr("AutoSizingType", names::auto_size_out(o.auto_size))- .attr("AutoSizingReferencePoint", names::REF_POINTS[(o.auto_size_ref as usize).min(8)]);+ .attr("AutoSizingReferencePoint", names::REF_POINTS[(o.auto_size_ref as usize).min(8)])+ .attr("UseMinimumHeightForAutoSizing", bool_s(o.auto_size_use_min_height))+ .attr("MinimumHeightForAutoSizing", num(o.auto_size_min_height))+ .attr("UseMinimumWidthForAutoSizing", bool_s(o.auto_size_use_min_width))+ .attr("MinimumWidthForAutoSizing", num(o.auto_size_min_width))+ .attr("UseNoLineBreaksForAutoSizing", bool_s(o.auto_size_no_line_breaks));let el = if o.column_width > 0.0 { el.attr("TextColumnFixedWidth", num(o.column_width)) } else { el };- let d = TextFrameOptions::default();- let rule_set = o.column_rule- || o.column_rule_weight != d.column_rule_weight- || o.column_rule_color != d.column_rule_color- || o.column_rule_tint != d.column_rule_tint- || o.column_rule_offset != d.column_rule_offset- || o.column_rule_top_inset != d.column_rule_top_inset- || o.column_rule_bottom_inset != d.column_rule_bottom_inset;- let el = if rule_set {- el.attr("ColumnRuleOverride", bool_s(o.column_rule))- .attr("ColumnRuleStrokeWidth", num(o.column_rule_weight))- .attr("ColumnRuleStrokeColor", rule_color)- .attr("ColumnRuleStrokeTint", num(f64::from(o.column_rule_tint) * 100.0))- .attr("ColumnRuleOffset", num(o.column_rule_offset))- .attr("ColumnRuleTopInset", num(o.column_rule_top_inset))- .attr("ColumnRuleBottomInset", num(o.column_rule_bottom_inset))- .attr("ColumnRuleInsetChainOverride", bool_s(o.column_rule_top_inset == o.column_rule_bottom_inset))- } else {- el- };+ // Written on every frame: on import a frame takes any value it lacks from its object style.+ let el = el+ .attr("ColumnRuleOverride", bool_s(o.column_rule))+ .attr("ColumnRuleStrokeWidth", num(o.column_rule_weight))+ .attr("ColumnRuleStrokeColor", rule_color)+ .attr("ColumnRuleStrokeTint", num(f64::from(o.column_rule_tint) * 100.0))+ .attr("ColumnRuleOffset", num(o.column_rule_offset))+ .attr("ColumnRuleTopInset", num(o.column_rule_top_inset))+ .attr("ColumnRuleBottomInset", num(o.column_rule_bottom_inset))+ .attr("ColumnRuleInsetChainOverride", bool_s(o.column_rule_top_inset == o.column_rule_bottom_inset));with_props(el, vec![inset])}diff --cc docs/gaps.mdindex dfb3a3f00,66f7f8733..6e4e66b00--- a/docs/gaps.md+++ b/docs/gaps.md@@@ -63,9 -69,9 +63,9 @@@ Kind: **F** feature · **U** UI/UX · *### 4. Composition isn't compared with InDesign (T)- **Missing:** an oracle harness: the same synthetic stories set by InDesign 2026 (observedblack-box, results kept under `plan/`) and by DesignCraft, comparing line breaks, overset and- frame fit. Known differences: optical kerning falls back to metrics, so imported text sets- wider (#181); a frame goes overset when descenders don't fit, InDesign needs only the baseline+ frame fit. Known differences: optical kerning is an outline-based approximation, not Adobe's+ algorithm (#181); a frame goes overset when descenders don't fit, InDesign needs only the baseline- (#180); setting the text language was missing (#130; Language is now in Properties, #145, the issue is still open); "hyphenation doesn't work"+ (#180; auto-size frames fit their text on import); setting the text language was missing (#130; Language is now in Properties, #145, the issue is still open); "hyphenation doesn't work"(#87).- **Impact:** an opened IDML reflows: different line breaks, different page count, overset text.Professionals notice on the first page.diff --cc docs/target-app-parity.mdindex 75bbb494e,bf40d1677..d7491eac6--- a/docs/target-app-parity.md+++ b/docs/target-app-parity.md@@@ -340,9 -337,10 +340,10 @@@ It is evidence of breadth: each item ex- Stroke styles: striped (thick-thin… and custom bands), wavy and straight-hash strokes now draw on screen and in PDF; named custom stripe/dash/dot styles (`strokeStyle.new/delete/list`, Stroke panel Type list; IDML Striped/Dashed/DottedStrokeStyle).- Object ▸ Primary Text Frame (`object.primaryTextFrame`): any text frame's story can become (or stop being) the primary story Smart Text Reflow follows.- Column rules (Text Frame Options › Column Rules, `object.textFrameOptions {columnRule, columnRuleWeight, columnRuleColor, columnRuleTint, columnRuleOffset, columnRuleTopInset, columnRuleBottomInset}`, reported by `document.inspect`): a bar centred in each gutter of a multi-column frame, inside the insets and between the columns of right-to-left and vertical frames too, broken around paragraphs that span columns, with weight, colour, tint, horizontal offset and top/bottom insets; on screen, in PDF (tagged as an artifact) and in IDML (`ColumnRule…` attributes of `TextFramePreference`, also in object styles). The dialog shows the frame's options and changes only the fields edited. Rule stroke types and overprint aren't there yet.+ - Auto-size (Text Frame Options › Auto-Size, `object.textFrameOptions {autoSize: off|heightOnly|widthOnly|heightAndWidth|heightAndWidthProportionally, autoSizeReference, useMinimumHeight, minimumHeight, useMinimumWidth, minimumWidth, noLineBreaks}`): the frame fits its text exactly after every edit (typing, pasting, style changes, option changes) in the same undo step, and after IDML import; it grows and shrinks around the reference point, which stays put in spread space for rotated frames too, never below the minimum height/width and never past 10,000 pt. Width Only and No Line Breaks set each paragraph on one line; Height and Width without No Line Breaks keeps the width; Keep Proportions scales both sides until the text fits. IDML keeps all the options (`AutoSizing…`, `…ForAutoSizing` attributes). Not covered: frames of a thread other than the last, vertical frames, type on a path, and multi-column balancing in Keep Proportions.- Place a page of an IDML or DesignCraft document (`file.place {layoutPage}`): its objects, stories, styles and swatches as one group (INDD files are not readable).- Articles panel (`article.new/add/remove/options/delete/list`): reading order and content of EPUB and HTML exports.-- Object ▸ Clipping Path (`object.clippingPath {type: alpha|edges, threshold, tolerance}`): traces the placed image and makes the outline the frame.+- Object ▸ Clipping Path (`object.clippingPath {type: alpha|edges, threshold, tolerance}`): traces the placed image and makes the outline the frame. Clipping paths saved in IDML (Detect Edges, Alpha Channel, Photoshop Path, User-Modified Path; Invert) hide the image outside the path on screen and in PDF and survive IDML export; `object.clippingPathOptions` reports, inverts or removes one (Object ▸ Clipping Path ▸ None).- Gridify: arrow keys while dragging a frame or shape tool add columns/rows (`frame.grid`), one undo step.- Gap tool (U, `gap.move`): drag the space between objects (or an object and the page edge) and both sides resize.- XML basics (`xml.newTag/deleteTag/tag/mapStyle/structure`, `file.exportXml`, `file.importXml`; Tags panel with structure; View ▸ Show Tagged Frames): tagged frames export in reading order, mapped paragraph styles become elements, imported elements flow into frames with matching tags. Inline text tagging (`xml.tagText`, an `xmlTag` character attribute, exported as nested elements) and tag markers (View ▸ Structure ▸ Show Tag Markers) too. DTDs (`xml.loadDtd`, `xml.validate`, `xml.deleteDtd`; Tags panel): loading one adds its elements as tags and names the root; validation checks content models (sequences, choices, `?*+`, mixed content, EMPTY/ANY, parameter entities) and required attributes, and lists each problem with its element path.