DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge origin/main into codex/new-gradient-swatch
moppeeer7242c4508f92
diff --cc ROADMAP.mdindex 083f8aa2e,d60a6bf49..ef678215d--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -126,9 -343,52 +343,53 @@@ list) · [roadmap.md](docs/roadmap.md)## Progress log+ - **2026-10-13** · Switching between document and parent pages refreshes the canvas immediately, preventing black parent pages and stale document objects when the zoom stays the same. Ordinary edits retain partial repainting. No readiness percentage change.+Newest first.+- **2026-10-13** · New Swatch works as InDesign's: a gradient made in the Gradient panel becomes "New Gradient Swatch" (still applied), an unnamed colour a listed swatch, a named swatch a "copy" (`swatch.new`); `swatch.create {gradient}` makes a gradient swatch from colour swatches. No readiness percentage change.+ - **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** · Flex Layout (InDesign 2026): Object › Flex Layout (Add to, Convert to, Remove) and a Flex Layout panel laid out as InDesign's, also in Properties. A container lays out its objects by direction, wrap, justification, the alignment grid, Fixed/Auto width and height, padding and spacing, after every edit; Add detects aligned objects (direction, Auto size, Space Between at their spacing); resizing a container reflows its objects instead of scaling them; dragging an object in one reorders it. Montilla Design's tutorial replays step for step. No readiness percentage change.+ - **2026-10-14** · Layout › Margins and Columns and Layout › Create Guides are laid out as InDesign's: Margins in Top/Bottom and Inside/Outside pairs with a link button that makes all four the same, Rows and Columns side by side, Fit Guides to Margins or Page, and a Preview checkbox that shows the change on the canvas before OK. A measurement field works out arithmetic when you leave it (`0.4375 in*2` becomes `0.875 in`). No readiness percentage change.+ - **2026-10-14** · The Pathfinder panel is laid out as InDesign's: Paths (Join, Open, Close, Reverse), Pathfinder, Convert Shape and Convert Point, each a row of icon buttons. Join Path closes an open path or joins two at their nearest ends (`path.join`), and Convert Point makes the selected points plain, corner, smooth or symmetrical (`path.convertPoints`). No readiness percentage change.+ - **2026-10-12** · Linked text files (#597): placed Word, RTF and text files can stay linked; the Links panel shows them OK / Modified / Missing, and Update imports the file again into the same frames with the saved style map (the Links panel asks before replacing edits made in the layout). 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.+ - **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule (now with Controlled by Parent) and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.+ - **2026-10-14** · On an object-based page the Page tool shows a selected object's liquid pins and resize locks as InDesign does: a click pins a side to the page edge or locks the width or height, with InDesign's tooltips. No readiness percentage change.+ - **2026-10-14** · The Liquid Layout panel follows InDesign's: Liquid Page Rule with the page number, Content › Auto-Fit, and Object Constraints › Resize with Page and Pin for the selected object on an object-based page; Create Alternate Layout moved to the Layout menu. No readiness percentage change.+ - **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule (now with Controlled by Parent) and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.+ - **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.+ - **2026-10-14** · The Page tool works as InDesign's: a click selects a page and shows its handles and liquid page rule; dragging a handle previews the rule and springs back, Alt-drag resizes the page from the opposite edge, Shift keeps proportions, with a W/H readout. No readiness percentage change.+ - **2026-10-14** · With the Page tool, a guide dragged from a ruler is a liquid guide (dashed), as in InDesign; guide-based pages stretch the objects it crosses. No readiness percentage change.+ - **2026-10-14** · The Pages panel menu follows InDesign's order: Insert Pages…, Move Pages…, Duplicate Spread (and at End of Document), Delete Page/Spread, New Parent…, Apply Parent to Pages, Override All Parent Page Items, Parent Pages, Create Alternate Layout…, Numbering & Section Options…, Allow Selected Spread to Shuffle. No readiness percentage change.+ - **2026-10-14** · Pages panel: Alt-drag copies a page, a page dropped on Create new page is duplicated at the end, Edit page size offers the presets and Custom Page Size…; duplicated pages keep their own size, rule and guides; thumbnails of pages of their own size stay in their rows. No readiness percentage change.+ - **2026-10-12 (PDFW)** · PDF, booklet and book composition share guarded writing, metadata and font preparation through craft-pdf. Layout, shaping, placed graphics, colour policy, tagging and PDF/X postprocessing remain in DesignCraft. Failed native drawing returns an export error; failed writer cleanup cannot serialize an incomplete document. No readiness percentage change.++ - **2026-10-13** · Copy with a placed graphic selected (Direct Selection) copies just the graphic, uncropped, where it sits on the page and without the frame's stroke, so Paste Into puts the whole image in place; Cut and Delete then remove only the graphic and leave its frame empty. Nested selections copy in their spread coordinates. No readiness percentage change.+ - **2026-10-13** · Object effects (Basic Feather, Inner Glow, shadows, glows, bevel, satin, directional and gradient feathers) apply to frames with pasted-in content, on screen and in image exports: the frame, its clipped content and its stroke are one object to the effect. PDF export still has no soft effects for any object. No readiness percentage change.+ - **2026-10-13** · Links rows show their source paths; selecting a link shows its full path wrapped inside the panel, so same-named files from different folders can be distinguished. No readiness percentage change.+ - **2026-10-13** · The Text Wrap panel is laid out as InDesign's: the wrap buttons with Invert, and the four offsets (Top, Left, Bottom, Right) showing the object's values, with the link button that sets them all the same. It used to show a single offset, always 0. No readiness percentage change.+ - **2026-10-13** · Radial gradients stretch with the object's box, as InDesign draws them: by default an ellipse reaching the frame's sides (it was a circle reaching only the longer side), and a Gradient Swatch tool drag keeps the box's proportions; on screen and in PDF. No readiness percentage change.+ - **2026-10-13** · The Window menu follows InDesign's order (Arrange, Workspace, then the panels alphabetically with Color, Editorial, Object & Layout, Styles… submenus), and Window › Workspace lists the workspaces as InDesign does, now with Essentials Classic: the Control panel and an icon column of named panel groups. No readiness percentage change.+ - **2026-10-14** · In a facing document, pages take their side from their section's page numbers, as InDesign shuffles them: a section that starts at 1 on a left page moves it to the right and the pages after it follow, with their objects. No readiness percentage change.+ - **2026-10-14** · The Type menu follows InDesign's order (Size, Character ⌘T, Paragraph ⌥⌘T, Glyphs, the style panels, Notes, footnotes and endnotes, then the insert submenus and Show Hidden Characters); Current Page Number has ⌥⇧⌘N. No readiness percentage change.+ - **2026-10-14** · Colour parameters: a bare `{c,m,y,k}` is always read as 0..100, so C 1 is a 1 % tint and no longer+ solid cyan; fractions take the colour's own `{model: "cmyk", …}` form (#910). No readiness percentage change.+ - **2026-10-14** · The Tools panel follows InDesign's: Gradient Swatch and Gradient Feather are tools of their own; in two columns Content Collector and Placer, Apply Color / Gradient / None and Normal / Preview each get a button; View Options holds Frame Edges, Rulers, Guides, Smart Guides, Baseline Grid and Hidden Characters; Apply Color (,) and Apply Gradient (.) reuse the last colour and gradient. No readiness percentage change.+ - **2026-10-13** · Create Outlines makes one compound path per line (and per text colour within a line), grouped, as InDesign does: Ungroup then leaves each line on its own to be spaced and made into one compound path again. A single line in one colour stays a single compound path. No readiness percentage change.+ - **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-13** · Text takes gradient swatches: a gradient fill or stroke on characters spans the text frame's box (on a path: the path's), on screen and in PDF. No readiness percentage change.- **2026-10-12** · Text threads by hand: click a selected text frame's in or out port to loadthe text cursor, then click a frame to thread it, click empty space for a column-wide frame ordrag one (it snaps like frame drawing); Shift-click autoflows, Alt-click stays loaded on thediff --cc crates/engine/src/cmd/style.rsindex a69952664,1cccc7fd1..e1ab4dfb8--- a/crates/engine/src/cmd/style.rs+++ b/crates/engine/src/cmd/style.rs@@@ -135,7 -136,7 +136,7 @@@ pub fn specs() -> Vec<CommandSpec>"New Color Swatch…",[],None,- "{name?, color: \"#rrggbb\"|{c,m,y,k}(0..100)|[r,g,b], spot?: bool} | {name? (\"New Gradient Swatch\"), gradient: {kind?: linear|radial, stops: [{location: 0–100, swatch?: a colour swatch's name | color?, opacity?: 0–100, midpoint?: 13–87}]}} → {name}",- "{name?, color: \"#rrggbb\"|{c,m,y,k}(0..100)|[r,g,b]|{model: cmyk|rgb|gray, …}(0..1), spot?: bool}",++ "{name?, color: \"#rrggbb\"|{c,m,y,k}(0..100)|[r,g,b]|{model: cmyk|rgb|gray, …}(0..1), spot?: bool} | {name? (\"New Gradient Swatch\"), gradient: {kind?: linear|radial, stops: [{location: 0–100, swatch?: a colour swatch's name | color?, opacity?: 0–100, midpoint?: 13–87}]}} → {name}",has_doc,create_swatch),@@@ -725,11 -748,30 +757,33 @@@ fn edit_char(s: &mut Session, p: &Value})}+ fn delete_char(s: &mut Session, p: &Value) -> Result<Value> {+ let name = str_param(p, "name").filter(|n| !n.is_empty()).ok_or_else(|| bad("style.character.delete", "missing name"))?.to_string();+ let repl = str_param(p, "replaceWith").unwrap_or(designcraft_doc::NO_CHAR_STYLE).to_string();+ if name.starts_with('[') {+ return Err(bad("style.character.delete", "built-in styles can't be deleted"));+ }+ if repl == name {+ return Err(bad("style.character.delete", "`replaceWith` can't be the deleted style"));+ }+ s.edit(|d, _| {+ if d.styles.char_style(&name).is_none() {+ return Err(bad("style.character.delete", format!("no character style `{name}`")));+ }+ if d.styles.char_style(&repl).is_none() {+ return Err(bad("style.character.delete", format!("no character style `{repl}`")));+ }+ redirect_style_refs(d, false, &name, &repl);+ d.styles_mut().character.retain(|x| x.name != name);+ ok()+ })+ }+fn create_swatch(s: &mut Session, p: &Value) -> Result<Value> {- let c = p.get("color").ok_or_else(|| bad("swatch.create", "missing color"))?;+ if let Some(g) = p.get("gradient") {+ return create_gradient_swatch(s, p, g);+ }+ let c = p.get("color").ok_or_else(|| bad("swatch.create", "missing color (or gradient)"))?;let color = parse_color(c).ok_or_else(|| bad("swatch.create", "bad color"))?;let spot = p.get("spot").and_then(Value::as_bool).unwrap_or(false);let name = str_param(p, "name").map(str::to_string).unwrap_or_else(|| match color {@@@ -1934,83 -2037,163 +2128,238 @@@ mod sample_color_testsassert_eq!(text.format_after(0).over.stroke.as_deref(), r["swatch"].as_str(), "selected text stroke: {command}");}}++ #[test]+ fn sampling_with_the_stroke_in_front_colours_a_lines_stroke() {+ let (mut s, _) = session_with_image();+ let line = s.execute("line.create", &json!({"a": [300, 300], "b": [500, 300]})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [line]})).unwrap();+ let r = s.execute("color.sample", &json!({"at": [100, 100], "target": "stroke"})).unwrap();+ let it = s.doc().unwrap().doc.item(ItemId(line)).unwrap().clone();+ assert_eq!(it.stroke.swatch, r["swatch"].as_str().unwrap(), "{r}");+ assert!(it.fill.is_none(), "the fill stays empty");+ }+ }++ #[cfg(test)]+ mod radial_gradient_tests {+ use serde_json::json;++ /// White at the side and the top of a 100×200 radial (black → white) rectangle at (50, 20) on+ /// a 200×240 page, rendered at 1 px/pt.+ fn sides(img: &designcraft_render::Rendered) -> (u8, u8, u8) {+ (img.pixel(100, 120)[0], img.pixel(52, 120)[0], img.pixel(100, 22)[0])+ }++ #[test]+ fn a_radial_gradient_is_the_objects_ellipse_on_screen_and_in_pdf() {+ let mut s = crate::Session::new();+ s.execute("file.new", &json!({"width": 200, "height": 240, "facingPages": false})).unwrap();+ let id = s.execute("frame.create", &json!({"rect": [50, 20, 150, 220], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ s.execute("object.stroke", &json!({"ids": [id], "swatch": "[None]"})).unwrap();+ s.execute(+ "object.gradient",+ &json!({"ids": [id], "kind": "radial", "stops": [{"location": 0, "color": "#000000"}, {"location": 100, "color": "#ffffff"}]}),+ )+ .unwrap();+ let d = s.doc().unwrap().doc.clone();+ let mut r = designcraft_render::Renderer::new();+ let (c, side, top) = sides(&r.render_page(&d, &s.cache, 0, 1.0, false, &Default::default()).unwrap());+ assert!(c < 30 && side > 220 && top > 220, "screen: centre {c}, side {side}, top {top}");+ // The PDF, placed back and drawn: the same ellipse.+ 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": 240, "facingPages": false})).unwrap();+ p.execute("file.place", &json!({"base64": crate::cmd::file::base64_encode(&pdf), "name": "radial.pdf", "x": 0, "y": 0, "width": 200}))+ .unwrap();+ let d = p.doc().unwrap().doc.clone();+ let (c, side, top) = sides(&r.render_page(&d, &p.cache, 0, 1.0, false, &Default::default()).unwrap());+ assert!(c < 30 && side > 220 && top > 220, "pdf: centre {c}, side {side}, top {top}");+ }++ #[test]+ fn a_box_with_no_height_or_width_has_a_circle_across_its_length() {+ let f = designcraft_doc::Fill::swatch("g");+ let line = designcraft_geom::Rect::new(20.0, 60.0, 180.0, 60.0);+ let (c, rx, ry) = f.radial_ellipse(line);+ assert_eq!((c.x, c.y, rx, ry), (100.0, 60.0, 80.0, 80.0));+ let (_, rx, ry) = f.radial_ellipse(designcraft_geom::Rect::new(10.0, 0.0, 10.0, 50.0));+ assert_eq!((rx, ry), (25.0, 25.0));+ // A point: a tiny circle, never a zero radius.+ let (_, rx, ry) = f.radial_ellipse(designcraft_geom::Rect::new(5.0, 5.0, 5.0, 5.0));+ assert!(rx > 0.0 && rx == ry);+ // A box keeps its ellipse.+ let (_, rx, ry) = f.radial_ellipse(designcraft_geom::Rect::new(0.0, 0.0, 100.0, 200.0));+ assert_eq!((rx, ry), (50.0, 100.0));+ }+ }++ #[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());+ }++ /// A 20 pt horizontal line with a gradient on its stroke, drawn on screen and from its PDF.+ fn line_with_stroke_gradient(g: serde_json::Value) -> (designcraft_render::Rendered, designcraft_render::Rendered) {+ 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 mut g = g;+ g["ids"] = json!([id]);+ g["target"] = json!("stroke");+ s.execute("object.gradient", &g).unwrap();+ let d = s.doc().unwrap().doc.clone();+ let mut rr = designcraft_render::Renderer::new();+ let screen = rr.render_page(&d, &s.cache, 0, 1.0, false, &Default::default()).unwrap();+ 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": "line.pdf", "x": 0, "y": 0, "width": 200})).unwrap();+ let pd = p.doc().unwrap().doc.clone();+ let placed = rr.render_page(&pd, &p.cache, 0, 1.0, false, &Default::default()).unwrap();+ (screen, placed)+ }++ #[test]+ fn a_radial_gradient_on_a_straight_lines_stroke_shows_all_its_stops() {+ // The line's box has no height: the gradient is a circle across the line's length.+ let (screen, pdf) = line_with_stroke_gradient(+ json!({"kind": "radial", "stops": [{"location": 0, "color": "#000000"}, {"location": 100, "color": "#ffffff"}]}),+ );+ for (what, img) in [("screen", &screen), ("pdf", &pdf)] {+ let (a, m, b) = along(img);+ assert!(m < 40 && a > 180 && b > 180, "{what}: {a} {m} {b}");+ }+ }++ #[test]+ fn a_linear_gradient_across_a_straight_line_paints_its_stroke_alike_on_screen_and_in_pdf() {+ let (screen, pdf) =+ line_with_stroke_gradient(json!({"angle": 90, "stops": [{"location": 0, "color": "#ff0000"}, {"location": 100, "color": "#0000ff"}]}));+ let (s, p) = (screen.pixel(100, 60), pdf.pixel(100, 60));+ // The line's box has no height: the gradient runs across the line's length, so the stroke+ // shows its middle.+ assert!(s[1] < 60 && s[0] > 80 && s[2] > 80, "screen: the stroke is painted, {s:?}");+ assert!((0..3).all(|i| s[i].abs_diff(p[i]) < 40), "screen {s:?}, pdf {p:?}");+ }}+#[cfg(test)]+mod gradient_swatch_tests {+ use designcraft_color::SwatchValue;+ use serde_json::json;++ fn doc() -> crate::Session {+ let mut s = crate::Session::new();+ s.execute("file.new", &json!({})).unwrap();+ s+ }++ #[test]+ fn a_gradient_swatch_from_colour_swatches() {+ let mut s = doc();+ // As the Gradient panel's stops take swatches dragged onto them.+ let r = s+ .execute(+ "swatch.create",+ &json!({"gradient": {"stops": [{"location": 100, "swatch": "C=100 M=0 Y=0 K=0"}, {"location": 0, "swatch": "C=0 M=100 Y=0 K=0"}]}}),+ )+ .unwrap();+ assert_eq!(r["name"], "New Gradient Swatch");+ let d = &s.doc().unwrap().doc;+ let w = d.swatch("New Gradient Swatch").unwrap();+ assert!(w.named && !w.hidden);+ let SwatchValue::Gradient { gradient } = &w.value else { panic!("{w:?}") };+ assert_eq!(gradient.stops[0].color, d.resolve_color("C=0 M=100 Y=0 K=0", 1.0).unwrap(), "sorted: magenta first");+ assert_eq!(gradient.stops[1].color, d.resolve_color("C=100 M=0 Y=0 K=0", 1.0).unwrap());+ // A second one gets its own name; bad stops are refused.+ let r = s+ .execute(+ "swatch.create",+ &json!({"gradient": {"kind": "radial", "stops": [{"color": "#ff0000"}, {"location": 100, "color": "#0000ff"}]}}),+ )+ .unwrap();+ assert_eq!(r["name"], "New Gradient Swatch 2");+ for bad in [+ json!({"stops": [{"swatch": "C=0 M=100 Y=0 K=0"}]}),+ json!({"stops": [{"swatch": "Nope"}, {"swatch": "[Black]"}]}),+ json!({"stops": [{"swatch": "New Gradient Swatch"}, {"swatch": "[Black]"}]}),+ json!({"kind": "conic", "stops": [{"color": "#000000"}, {"color": "#ffffff"}]}),+ ] {+ assert!(s.execute("swatch.create", &json!({"gradient": bad})).is_err(), "{bad}");+ }+ }++ #[test]+ fn new_swatch_names_the_selections_gradient_or_duplicates_a_swatch() {+ let mut s = doc();+ let id = s.execute("frame.create", &json!({"rect": [0, 0, 100, 100], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ // A gradient made in the Gradient panel is unnamed (and not listed) …+ s.execute("object.gradient", &json!({"ids": [id], "stops": [{"location": 0, "color": {"c": 0, "m": 100, "y": 0, "k": 0}}, {"location": 100, "color": {"c": 100, "m": 0, "y": 0, "k": 0}}]})).unwrap();+ let fill = |s: &crate::Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().fill.swatch.clone();+ assert!(s.doc().unwrap().doc.swatch(&fill(&s)).unwrap().hidden);+ // … until New Swatch: "New Gradient Swatch", listed, still the object's fill.+ s.execute("selection.set", &json!({"ids": [id]})).unwrap();+ assert_eq!(s.execute("swatch.new", &json!({})).unwrap()["name"], "New Gradient Swatch");+ assert_eq!(fill(&s), "New Gradient Swatch");+ let w = s.doc().unwrap().doc.swatch("New Gradient Swatch").unwrap().clone();+ assert!(w.named && !w.hidden && matches!(w.value, SwatchValue::Gradient { .. }));+ // A named swatch: a copy.+ assert_eq!(s.execute("swatch.new", &json!({})).unwrap()["name"], "New Gradient Swatch copy");+ assert_eq!(s.execute("swatch.new", &json!({"swatch": "C=100 M=0 Y=0 K=0"})).unwrap()["name"], "C=100 M=0 Y=0 K=0 copy");+ assert!(s.execute("swatch.new", &json!({"swatch": "[None]"})).is_err());+ // The stroke in front: the stroke's swatch.+ s.execute("object.stroke", &json!({"ids": [id], "swatch": "C=100 M=0 Y=0 K=0"})).unwrap();+ assert_eq!(s.execute("swatch.new", &json!({"target": "stroke"})).unwrap()["name"], "C=100 M=0 Y=0 K=0 copy 2");+ // Nothing selected, no swatch given: a new colour swatch.+ s.execute("edit.deselectAll", &json!({})).unwrap();+ let n = s.execute("swatch.new", &json!({})).unwrap()["name"].as_str().unwrap().to_string();+ let w = s.doc().unwrap().doc.swatch(&n).unwrap();+ assert!(w.named && !w.hidden && matches!(w.value, SwatchValue::Color { .. }), "{w:?}");+ }+}+#[cfg(test)]#[path = "text_color_tests.rs"]mod text_color_tests;diff --cc crates/ui-egui/src/panels/swatches.rsindex b07048608,a21ffdb93..ff68b4b1c--- a/crates/ui-egui/src/panels/swatches.rs+++ b/crates/ui-egui/src/panels/swatches.rs@@@ -64,18 -58,25 +58,28 @@@ pub fn show(app: &mut DesignApp, ui: &m}}ui.add_space(6.0);+ // InDesign's bottom row: New Color Group, New Swatch, Delete Swatch (the one last clicked).+ let picked: Option<String> = ui.data(|d| d.get_temp(egui::Id::new(PICKED))).filter(|n: &String| doc.swatch(n).is_some_and(|w| !w.locked));ui.horizontal(|ui| {- ui.label(crate::rtl::widget(- ui,- egui::RichText::new(crate::i18n::tr(&app.ui.language, "Right-click: stroke, groups")).size(10.5).color(t.text_disabled),- ));ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {+ let del = ui+ .add_enabled_ui(picked.is_some(), |ui| icons::button(ui, "trash", 20.0, false, crate::i18n::tr(&app.ui.language, "Delete Swatch")))+ .inner;+ if del.clicked()+ && let Some(name) = &picked+ && app.run("swatch.delete", json!({"name": name})).is_ok()+ {+ ui.data_mut(|d| d.remove::<String>(egui::Id::new(PICKED)));+ }+ // The selection's fill or stroke (whichever is in front) becomes a swatch; with nothing+ // selected, a new colour.if icons::button(ui, "plus", 20.0, false, crate::i18n::tr(&app.ui.language, "New Swatch")).clicked() {- let _ = app.run("swatch.create", json!({"color": {"c": 0, "m": 50, "y": 100, "k": 0}}));+ let target = if app.ui.stroke_front { "stroke" } else { "fill" };+ let _ = app.run("swatch.new", json!({"target": target}));}+ if folder_button(ui, crate::i18n::tr(&app.ui.language, "New Color Group")).clicked() {+ let _ = app.run("swatch.newColorGroup", json!({}));+ }crate::menus::menu_button(ui, "☰", |ui| {crate::menus::menu_button(ui, crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Ink Manager")), |ui| {let Ok(l) = app.session.execute("ink.list", &json!({})) else { return };diff --cc docs/target-app-parity.mdindex 1bad1be7c,62ba7f08a..abd8c3a1e--- a/docs/target-app-parity.md+++ b/docs/target-app-parity.md@@@ -423,7 -428,7 +428,7 @@@ It is evidence of breadth: each item ex- View › Display Performance: Fast (grey boxes, no effects, ⌥⇧⌘Z), Typical (72 ppi proxies, ⌥⌘Z), High Quality (⌥⌘H, our default — the renderer is fast enough).- OpenType menu (Character panel): discretionary ligatures, fractions, ordinal, swash, titling, contextual alternates, slashed zero, the four figure styles and stylistic sets 1–20; `type.openType`; mapped to IDML's OTF attributes.- Add Anchor Point (=), Delete Anchor Point (-) and Convert Direction Point (⇧C) tools (click toggles smooth/corner, drag pulls out handles), with `path.addAnchor`, `path.deleteAnchor`, `path.convertAnchor`.- - Gradients: the Gradient Swatch tool (G) drags a gradient's start and end across objects (Shift: 45°); the Gradient panel sets type, angle, reverse and edits stops on a ramp (drag, add, drag off to remove, location, colour). Edited gradients are unnamed swatches until the Swatches panel's New Swatch names one "New Gradient Swatch" (`swatch.new`, which also duplicates a named swatch); `swatch.create {gradient}` builds one from colour swatches; `object.gradient`; the vector round-trips through IDML.-- Gradients: the Gradient Swatch tool (G) drags a gradient's start and end across objects (Shift: 45°); the Gradient panel sets type, angle, reverse and edits stops on a ramp (drag, add, drag off to remove, location, colour). Edited gradients are unnamed swatches; `object.gradient` (`target: stroke` for a stroke's gradient, drawn across the path's box on screen and in PDF); the vector round-trips through IDML (`GradientFill…`/`GradientStroke…`). The Gradient panel follows the Fill/Stroke proxy. A radial gradient stretches with the object's box as InDesign's does (an ellipse reaching the sides of a non-square frame, on screen and in PDF). Text takes a gradient swatch as its fill or stroke, laid across its frame's box as in InDesign (screen and PDF).++- Gradients: the Gradient Swatch tool (G) drags a gradient's start and end across objects (Shift: 45°); the Gradient panel sets type, angle, reverse and edits stops on a ramp (drag, add, drag off to remove, location, colour). Edited gradients are unnamed swatches until the Swatches panel's New Swatch names one "New Gradient Swatch" (`swatch.new`, which also duplicates a named swatch); `swatch.create {gradient}` builds one from colour swatches; `object.gradient` (`target: stroke` for a stroke's gradient, drawn across the path's box on screen and in PDF); the vector round-trips through IDML (`GradientFill…`/`GradientStroke…`). The Gradient panel follows the Fill/Stroke proxy. A radial gradient stretches with the object's box as InDesign's does (an ellipse reaching the sides of a non-square frame, on screen and in PDF). Text takes a gradient swatch as its fill or stroke, laid across its frame's box as in InDesign (screen and PDF).- Document Setup (⌥⌘P): intent, number of pages, start page # (an even start begins with a left page), facing pages, size presets and orientation, bleed and slug per edge; `layout.documentSetup {}` reports the setup.- Stroke panel: cap, join, miter limit, alignment, type, Start/End arrowheads (12 kinds, drawn on screen and in PDF; the path is shortened under pointed heads) and gap colour under dashes and dots.- Preferences (⌘K: General, Type, Units & Increments, Grids, Guides & Pasteboard, Display Performance) backed by `prefs.set` (application) and `document.preferences` (units, increments, grids — undoable, saved with the document; right-click a ruler to pick its units, the horizontal and vertical rulers each have their own); scaling applies to content and scales stroke weights (Include Stroke Weight), and X/Y/W/H measure the stroke's outer edge (Dimensions Include Stroke Weight). Quick Apply (⌘Return) finds paragraph, character and object styles as well as commands.