DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge remote-tracking branch 'origin/main' into codex/gradient-strokes
moppeeer5f00aa7bb301
diff --cc ROADMAP.mdindex ac9e48805,c60a04107..4493ac1ad--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -129,7 -128,13 +128,14 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+- **2026-10-13** · Gradient swatches work on strokes: drawn across the path's box on screen and in PDF (they drew nothing), set with `object.gradient {target: stroke}` and in the Gradient panel when the Stroke box is in front; the stroke's gradient vector moves with the shape and round-trips through IDML. 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** · 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** · 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.diff --cc crates/engine/src/cmd/style.rsindex 8562ca74d,0280612d1..08cb736a9--- a/crates/engine/src/cmd/style.rs+++ b/crates/engine/src/cmd/style.rs@@@ -1763,48 -1845,6 +1856,52 @@@ mod sample_color_tests}}+#[cfg(test)]+mod gradient_stroke_tests {+ use serde_json::json;++ /// Grey along a 20 pt line from (20, 60) to (180, 60): near its start, middle and end.+ fn along(img: &designcraft_render::Rendered) -> (u8, u8, u8) {+ (img.pixel(26, 60)[0], img.pixel(100, 60)[0], img.pixel(174, 60)[0])+ }++ #[test]+ fn a_gradient_on_a_stroke_runs_across_the_path_on_screen_and_in_pdf() {+ let mut s = crate::Session::new();+ s.execute("file.new", &json!({"width": 200, "height": 120, "facingPages": false})).unwrap();+ let id = s.execute("line.create", &json!({"a": [20, 60], "b": [180, 60]})).unwrap()["id"].as_u64().unwrap();+ s.execute("object.stroke", &json!({"ids": [id], "weight": 20})).unwrap();+ let r = s+ .execute(+ "object.gradient",+ &json!({"ids": [id], "target": "stroke", "stops": [{"location": 0, "color": "#000000"}, {"location": 100, "color": "#ffffff"}]}),+ )+ .unwrap();+ let d = s.doc().unwrap().doc.clone();+ let it = d.item(designcraft_doc::ItemId(id)).unwrap();+ assert_eq!(it.stroke.swatch, r["swatch"].as_str().unwrap());+ assert_eq!(it.fill.swatch, designcraft_color::swatch::NONE, "the fill is left alone");+ let mut rr = designcraft_render::Renderer::new();+ let (a, m, b) = along(&rr.render_page(&d, &s.cache, 0, 1.0, false, &Default::default()).unwrap());+ assert!(a < 40 && (90..170).contains(&m) && b > 215, "screen: {a} {m} {b}");+ // The PDF, placed back and drawn: the same.+ let pdf = designcraft_pdf::export_pdf(&d, &s.cache, &Default::default()).unwrap();+ let mut p = crate::Session::new();+ p.execute("file.new", &json!({"width": 200, "height": 120, "facingPages": false})).unwrap();+ p.execute("file.place", &json!({"base64": crate::cmd::file::base64_encode(&pdf), "name": "stroke.pdf", "x": 0, "y": 0, "width": 200}))+ .unwrap();+ let pd = p.doc().unwrap().doc.clone();+ let (a, m, b) = along(&rr.render_page(&pd, &p.cache, 0, 1.0, false, &Default::default()).unwrap());+ assert!(a < 40 && (90..170).contains(&m) && b > 215, "pdf: {a} {m} {b}");+ // The Gradient Swatch tool's drag on the stroke: reversed by dragging right to left.+ s.execute("object.gradient", &json!({"ids": [id], "target": "stroke", "from": [180, 60], "to": [20, 60]})).unwrap();+ let d = s.doc().unwrap().doc.clone();+ let (a, _, b) = along(&rr.render_page(&d, &s.cache, 0, 1.0, false, &Default::default()).unwrap());+ assert!(a > 215 && b < 40, "dragged: {a} {b}");+ assert!(s.execute("object.gradient", &json!({"ids": [id], "target": "gap"})).is_err());+ }+}+++ #[cfg(test)]+ #[path = "text_color_tests.rs"]+ mod text_color_tests;diff --cc crates/idml/src/import.rsindex c0959d7c9,1a4fa65e3..030e87d6b--- a/crates/idml/src/import.rs+++ b/crates/idml/src/import.rs@@@ -2129,33 -2151,22 +2151,35 @@@ impl<'r> Importer<'r>it.stroke.swatch = swatch::NONE.into();it.stroke.weight = 1.0;}+ // A gradient on the stroke: its angle, or the Gradient Swatch tool's vector.+ if let Some(a) = e.num("GradientStrokeAngle")+ && a != 0.0+ {+ it.stroke.gradient_angle = Some(a);+ }+ let start: Option<Vec<f64>> = e.prop("GradientStrokeStart").map(|s| s.split_whitespace().filter_map(|v| v.parse().ok()).collect());+ if let (Some([x, y]), Some(len)) = (start.as_deref().and_then(|v| <[f64; 2]>::try_from(v).ok()), e.num("GradientStrokeLength"))+ && len > 0.0+ {+ let a = e.num("GradientStrokeAngle").unwrap_or(0.0).to_radians();+ it.stroke.gradient_vector = Some([x, y, x + len * a.cos(), y - len * a.sin()]);+ }}- // Corners.- let cn = crate::export::corner_names(&it.path);- // The legacy all-corners attributes apply only when no per-corner attribute is present.- let per_corner = cn.iter().any(|n| e.get(&format!("{n}CornerOption")).is_some());- let legacy = if per_corner { (None, None) } else { (e.get("CornerOption"), e.num("CornerRadius")) };- let mut corners = CornerOptions::default();- for (i, n) in cn.iter().enumerate() {- let shape = e.get(&format!("{n}CornerOption")).or(legacy.0).map(names::corner_in).unwrap_or_default();- let size = e.num(&format!("{n}CornerRadius")).or(legacy.1).unwrap_or(0.0);- corners.corners[i] = Corner { shape, size };- }- if !corners.is_none() {- it.corners = corners;+ // Corners: each corner's shape and radius come from the item, then its object style chain;+ // at each level a per-corner attribute wins over the legacy all-corners one.+ if tag != "Group" {+ let levels: Vec<&El> = std::iter::once(e).chain(self.object_style_chain(e)).collect();+ let corner =+ |n: &str, what: &str| levels.iter().find_map(|s| s.get(&format!("{n}Corner{what}")).or_else(|| s.get(&format!("Corner{what}"))));+ let mut corners = CornerOptions::default();+ for (i, n) in crate::export::corner_names(&it.path).iter().enumerate() {+ let shape = corner(n, "Option").map(names::corner_in).unwrap_or_default();+ let size = corner(n, "Radius").and_then(|v| v.trim().parse::<f64>().ok()).filter(|v| v.is_finite()).unwrap_or(INDESIGN_CORNER_SIZE);+ corners.corners[i] = Corner { shape, size };+ }+ if !corners.is_none() {+ it.corners = corners;+ }}// Transparency.if let Some(t) = e.find("TransparencySetting") {diff --cc crates/idml/src/tests.rsindex 8eacd1142,57801e34f..a28bfe51c--- a/crates/idml/src/tests.rs+++ b/crates/idml/src/tests.rs@@@ -1480,19 -2127,45 +2127,62 @@@ fn type_on_a_path_keeps_its_start_and_e}}+#[test]+fn a_strokes_gradient_vector_round_trips() {+ let mut d = designcraft_doc::Document::new(&designcraft_doc::build::NewDocument::default());+ let id = designcraft_doc::ItemId(d.alloc());+ let mut it = designcraft_doc::Item::new(+ id,+ d.default_layer(),+ designcraft_doc::Shape::Path,+ designcraft_geom::shapes::rectangle(designcraft_geom::Rect::new(10.0, 10.0, 110.0, 60.0)),+ );+ it.stroke.gradient_vector = Some([10.0, 35.0, 110.0, 35.0]);+ d.insert_item(designcraft_doc::SpreadRef::Doc(0), it, None).unwrap();+ let back = crate::import_idml(&crate::export_idml(&d)).unwrap();+ let v = back.spreads[0].items[0].stroke.gradient_vector.unwrap();+ assert!(v.iter().zip([10.0, 35.0, 110.0, 35.0]).all(|(a, b)| (a - b).abs() < 1e-6), "{v:?}");+}+++ #[test]+ fn frame_preference_import_caps_column_count_without_composition() {+ for (raw, expected) in [("4000000000", 216), ("1e300", 216), ("-100", 1), ("0", 1), ("NaN", 1), ("inf", 1), ("-inf", 1)] {+ for attribute in [true, false] {+ let preference = if attribute {+ format!(r#"<TextFramePreference TextColumnCount="{raw}"/>"#)+ } else {+ format!(+ r#"<TextFramePreference><Properties><TextColumnCount type="number">{raw}</TextColumnCount></Properties></TextFramePreference>"#+ )+ };+ let document = format!(+ r#"<Document><Story Self="s"/><Spread Self="spread"><Page Self="page"/><TextFrame Self="frame" ParentStory="s">{preference}</TextFrame></Spread></Document>"#+ );+ let d = import_idml_with(&zip_files(&[("designmap.xml", &document)]), &|_| None).unwrap();+ let frame = d.spreads[0].items[0].text_frame().unwrap();+ // Inspect imported data only: never compose an unbounded input value.+ assert_eq!(frame.options.columns, expected, "{raw}, attribute={attribute}");+ }+ }+ }++ #[test]+ fn frame_preference_property_color_resolves_for_frames_and_object_styles() {+ let document = r#"<Document>+ <Color Self="Color/Near" Model="Process" Space="RGB" ColorValue="255 0 0" Name="Near" Visible="true"/>+ <Color Self="Color/Far" Model="Process" Space="RGB" ColorValue="0 0 255" Name="Far" Visible="true"/>+ <RootObjectStyleGroup Self="root">+ <ObjectStyle Self="ObjectStyle/Base" Name="Base" EnableTextFrameGeneralOptions="true"><TextFramePreference ColumnRuleStrokeColor="Color/Far"/></ObjectStyle>+ <ObjectStyle Self="ObjectStyle/Child" Name="Child" EnableTextFrameGeneralOptions="true"><Properties><BasedOn type="object">ObjectStyle/Base</BasedOn></Properties><TextFramePreference><Properties><ColumnRuleStrokeColor type="object">Color/Near</ColumnRuleStrokeColor></Properties></TextFramePreference></ObjectStyle>+ </RootObjectStyleGroup>+ <Story Self="s"/><Spread Self="spread"><Page Self="page"/>+ <TextFrame Self="local" ParentStory="s" AppliedObjectStyle="ObjectStyle/Base"><TextFramePreference><Properties><ColumnRuleStrokeColor type="object">Color/Near</ColumnRuleStrokeColor></Properties></TextFramePreference></TextFrame>+ <TextFrame Self="inherited" ParentStory="s" AppliedObjectStyle="ObjectStyle/Child"/>+ <TextFrame Self="attribute" ParentStory="s" AppliedObjectStyle="ObjectStyle/Child"><TextFramePreference ColumnRuleStrokeColor="Color/Far"><Properties><ColumnRuleStrokeColor type="object">Color/Near</ColumnRuleStrokeColor></Properties></TextFramePreference></TextFrame>+ <TextFrame Self="invalid" ParentStory="s" AppliedObjectStyle="ObjectStyle/Child"><TextFramePreference><Properties><ColumnRuleStrokeColor type="object">missing</ColumnRuleStrokeColor></Properties></TextFramePreference></TextFrame>+ </Spread></Document>"#;+ let d = import_idml_with(&zip_files(&[("designmap.xml", document)]), &|_| None).unwrap();+ let colors: Vec<_> = d.spreads[0].items.iter().map(|it| it.text_frame().unwrap().options.column_rule_color.as_str()).collect();+ assert_eq!(colors, vec!["Near", "Near", "Far", designcraft_color::swatch::NONE]);+ assert_eq!(d.styles.object_style("Child").unwrap().text_frame.as_ref().unwrap().column_rule_color, "Near");+ }