DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge origin/main into codex/transform-content
moppeeere9d3effe65eb
diff --cc ROADMAP.mdindex 1f03828e2,d60a6bf49..96013c207--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -153,10 -438,16 +438,17 @@@ Newest first- **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-11** · Properties gains InDesign's Pathfinder section (Add, Subtract, Intersect, Exclude Overlap, Minus Back) with several objects selected; section titles and icon buttons have accessible names. No readiness percentage change.- **2026-10-12** · The Eyedropper samples a placed image: clicking the photo with text (or objects) selected fills them with the image's colour under the pointer, as an unnamed colour (`color.sample`), as in InDesign. Images on locked layers can be sampled. 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-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** · 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** · A gradient feather on a group fades the group as one, on screen and in PDF. Before, the screen ignored it, and PDF masked the group with a box of zero size because a group has no path of its own. No readiness percentage change.+ - **2026-10-12** · In a CMYK transparency blend space (print documents), blend modes blend in CMYK on screen as in InDesign. Color Dodge with 100% K text turns coloured areas under it white and leaves the paper alone, where RGB blending changed almost nothing. PDF export already did this. No readiness percentage change.+ - **2026-10-11** · Moving a sheared and rotated text frame no longer leaves trails of text behind: canvas repaints cover the frame's whole text box, not just its outline. No readiness percentage change.- **2026-10-12** · Words in capitals hyphenate like capitalized words (FERRUM COM-MODI), as in InDesign; Hyphenate Capitalized Words off keeps them whole. No readiness percentage change.+ - **2026-10-12** · Load Swatches refuses an `.ase` file with more than 100,000 colors, and `swatch.load` merges a file of 100,000 colors in under 0.1 s (it took 9.6 s of CPU in a test build). No readiness percentage change.- **2026-10-11** · `transform.move {copy}`, Edit › Duplicate and Step and Repeat return the copies' ids, so a script can go on with them. No readiness percentage change.- **2026-10-11** · `object.fill` and `object.stroke` refuse a swatch name the document doesn't have (it painted nothing) and suggest the name meant (`Paper` → `[Paper]`). No readiness percentage change.+ - **2026-10-13** · Dropping an `.ase` file on the window loads its swatches, as Load Swatches does (the drop failed with "Can't Place the File"). No readiness percentage change.- **2026-10-11 (printing):** `file.printers` and `file.print` use craft-libs/craft-print for CUPS and Windows. DesignCraft retains PDF export, page selection, spreads, marks and bleed; dry runs create no temporary PDF or print job. Windows selects matching or default driver paper and shrinks oversized sheets without enlarging smaller ones; queue duplex defaults are preserved. Headless tests exercise exported bytes, job settings, dry runs and refusals; shared native Windows CI passes, including paused-queue submission and cleanup. PostScript, production print controls and physical output validation remain open. No readiness percentage change.- **2026-10-10 (UI.4–UI.5):** Panel tabs can move into other groups, split the dock, float, resize and return to their saved locations through shared docking transactions. Layouts persist in custom workspaces; UI and control commands share the same validated action path. Shared pane geometry and widget-state theme application retain all five palettes and local fonts. Split panes send keyboard input only to the focused canvas and scope contextual toolbar IDs per pane. No readiness percentage change.diff --cc crates/engine/src/cmd/object.rsindex e6c61c062,bbc0a36a1..5543fdb77--- a/crates/engine/src/cmd/object.rs+++ b/crates/engine/src/cmd/object.rs@@@ -3431,82 -3461,35 +3564,115 @@@ mod spread_target_tests}}+#[cfg(test)]+mod content_transform_tests {+ use serde_json::json;++ use crate::Session;++ /// A rotated graphic frame holding a 200 x 100 image, its content selected.+ fn rotated_frame_with_image() -> (Session, u64) {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let f = s.execute("frame.create", &json!({"rect": [100, 100, 300, 300], "content": "graphic"})).unwrap()["id"].as_u64().unwrap();+ let png = designcraft_render::Rendered { width: 200, height: 100, pixels: vec![200u8; 200 * 100 * 4] }.to_png();+ s.execute("file.place", &json!({"base64": crate::cmd::file::base64_encode(&png), "name": "a.png", "frame": f})).unwrap();+ s.execute("transform.rotate", &json!({"ids": [f], "angle": -45})).unwrap();+ s.execute("selection.set", &json!({"ids": [f], "content": true})).unwrap();+ (s, f)+ }++ #[test]+ fn rotating_the_content_leaves_the_frame_as_it_is() {+ let (mut s, f) = rotated_frame_with_image();+ let before = s.execute("transform.info", &json!({"ids": [f]})).unwrap();+ assert!((before["rotation"].as_f64().unwrap() + 45.0).abs() < 1e-6 && (before["content"]["rotation"].as_f64().unwrap() + 45.0).abs() < 1e-6);+ // The tutorial's step: the image straightened inside its tilted frame.+ s.execute("transform.set", &json!({"rotation": 0})).unwrap();+ let after = s.execute("transform.info", &json!({"ids": [f]})).unwrap();+ assert!((after["rotation"].as_f64().unwrap() + 45.0).abs() < 1e-6, "the frame stays at -45: {after}");+ assert!(after["content"]["rotation"].as_f64().unwrap().abs() < 1e-6, "the image is upright: {after}");+ // Scale and position act on the image too.+ s.execute("transform.set", &json!({"scaleX": 50, "scaleY": 50})).unwrap();+ let info = s.execute("transform.info", &json!({"ids": [f]})).unwrap();+ assert!((info["content"]["scaleX"].as_f64().unwrap() - 50.0).abs() < 1e-6, "{info}");+ assert!((info["rotation"].as_f64().unwrap() + 45.0).abs() < 1e-6);+ // One undo step each.+ s.execute("edit.undo", &json!({})).unwrap();+ s.execute("edit.undo", &json!({})).unwrap();+ let undone = s.execute("transform.info", &json!({"ids": [f]})).unwrap();+ assert!((undone["content"]["rotation"].as_f64().unwrap() + 45.0).abs() < 1e-6, "{undone}");+ }++ #[test]+ fn with_the_graphic_selected_transform_info_reports_the_graphic() {+ let (mut s, f) = rotated_frame_with_image();+ s.execute("transform.set", &json!({"rotation": 0})).unwrap();+ // What the Control bar and Properties read: the graphic's 0, not the frame's -45, so a+ // spinner step from it gives 1, not -44.+ let info = s.execute("transform.info", &json!({})).unwrap();+ assert!(info["rotation"].as_f64().unwrap().abs() < 1e-6, "{info}");+ let rot = info["rotation"].as_f64().unwrap() + 1.0;+ s.execute("transform.set", &json!({"rotation": rot})).unwrap();+ let after = s.execute("transform.info", &json!({"ids": [f]})).unwrap();+ assert!((after["content"]["rotation"].as_f64().unwrap() - 1.0).abs() < 1e-6, "{after}");+ assert!((after["rotation"].as_f64().unwrap() + 45.0).abs() < 1e-6, "the frame stays: {after}");+ // `id` names the target explicitly, like `ids`: the frame.+ let by_id = s.execute("transform.info", &json!({"id": f})).unwrap();+ assert!((by_id["rotation"].as_f64().unwrap() + 45.0).abs() < 1e-6, "{by_id}");+ }++ #[test]+ fn a_locked_frame_records_no_undo_step() {+ let (mut s, f) = rotated_frame_with_image();+ s.execute("object.lock", &json!({"ids": [f]})).unwrap();+ s.execute("selection.set", &json!({"ids": [f], "content": true})).unwrap();+ let undo = s.doc().unwrap().history.undo.len();+ assert_eq!(s.execute("transform.set", &json!({"rotation": 0})).unwrap()["changed"], 0);+ assert_eq!(s.doc().unwrap().history.undo.len(), undo, "no empty undo step");+ }++ #[test]+ fn a_frame_selection_still_transforms_the_frame_and_an_empty_frame_has_no_content() {+ let (mut s, f) = rotated_frame_with_image();+ // `content: false` (or a frame selection) turns frame and image together.+ s.execute("transform.set", &json!({"rotation": 0, "content": false})).unwrap();+ let info = s.execute("transform.info", &json!({"ids": [f]})).unwrap();+ assert!(info["rotation"].as_f64().unwrap().abs() < 1e-6, "{info}");+ let e = s.execute("frame.create", &json!({"rect": [400, 100, 500, 200], "content": "graphic"})).unwrap()["id"].as_u64().unwrap();+ assert!(s.execute("transform.set", &json!({"ids": [e], "content": true, "rotation": 10})).is_err());+ }+}+++ #[cfg(test)]+ mod fill_tint_tests {+ use super::*;++ #[test]+ fn a_tint_alone_keeps_each_objects_own_swatch() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let a = s.execute("frame.create", &json!({"rect": [36, 36, 100, 100]})).unwrap()["id"].as_u64().unwrap();+ let b = s.execute("frame.create", &json!({"rect": [136, 36, 200, 100]})).unwrap()["id"].as_u64().unwrap();+ s.execute("object.fill", &json!({"ids": [a], "swatch": "C=100 M=0 Y=0 K=0"})).unwrap();+ s.execute("object.fill", &json!({"ids": [b], "swatch": "C=0 M=100 Y=0 K=0"})).unwrap();+ s.execute("object.fill", &json!({"ids": [a, b], "tint": 0.4})).unwrap();+ let fill_of = |s: &Session, id: u64| s.doc().unwrap().doc.item(ItemId(id)).unwrap().fill.clone();+ assert_eq!((fill_of(&s, a).swatch.as_str(), fill_of(&s, a).tint), ("C=100 M=0 Y=0 K=0", 0.4));+ assert_eq!((fill_of(&s, b).swatch.as_str(), fill_of(&s, b).tint), ("C=0 M=100 Y=0 K=0", 0.4));+ // A swatch without a tint is at 100 %, as before.+ s.execute("object.fill", &json!({"ids": [a], "swatch": "[Black]"})).unwrap();+ assert_eq!(fill_of(&s, a).tint, 1.0);+ // Neither, or a tint out of range: refused.+ assert!(s.execute("object.fill", &json!({"ids": [a]})).is_err());+ assert!(s.execute("object.fill", &json!({"ids": [a], "tint": 2})).is_err());+ assert!(s.execute("object.fill", &json!({"ids": [a], "tint": "x"})).is_err());+ // A stroke tint alone: stroked objects take it, an object without a stroke keeps none.+ s.execute("object.stroke", &json!({"ids": [a], "swatch": "C=100 M=0 Y=0 K=0", "weight": 2})).unwrap();+ s.execute("object.stroke", &json!({"ids": [b], "swatch": "[None]"})).unwrap();+ s.execute("object.stroke", &json!({"ids": [a, b], "tint": 0.5})).unwrap();+ let stroke_of = |s: &Session, id: u64| s.doc().unwrap().doc.item(ItemId(id)).unwrap().stroke.clone();+ assert_eq!((stroke_of(&s, a).swatch.as_str(), stroke_of(&s, a).tint, stroke_of(&s, a).weight), ("C=100 M=0 Y=0 K=0", 0.5, 2.0));+ assert!(stroke_of(&s, b).is_none());+ }+ }diff --cc crates/ui-egui/src/panels/mod.rsindex c8b597d8a,c88ae30a3..b84aa883d--- a/crates/ui-egui/src/panels/mod.rs+++ b/crates/ui-egui/src/panels/mod.rs@@@ -707,31 -787,88 +795,117 @@@ mod font_menu_ui_tests}}+#[cfg(test)]+mod content_selection_tests {+ use serde_json::json;++ /// With a placed graphic selected (Direct Selection), X/Y/W/H are the graphic's: what the+ /// Transform fields then set.+ #[test]+ fn a_selected_graphic_shows_its_own_bounds() {+ let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({})).unwrap();+ let f = app.run("frame.create", json!({"rect": [100, 100, 300, 300], "content": "graphic"})).unwrap()["id"].clone();+ let png = designcraft_render::Rendered { width: 400, height: 400, pixels: vec![200u8; 400 * 400 * 4] }.to_png();+ let b64 = designcraft_engine::cmd::base64_encode(&png);+ app.run("file.place", json!({"base64": b64, "name": "a.png", "frame": f})).unwrap();+ app.run("selection.set", json!({"ids": [f]})).unwrap();+ let frame = super::sel_info(&app).unwrap().page_rect;+ assert!((frame.width() - 200.0).abs() < 1e-6, "{frame:?}");+ app.run("selection.set", json!({"ids": [f], "content": true})).unwrap();+ // Placing fitted it to 50%: back to its own 400 pt.+ app.run("transform.set", json!({"scaleX": 100, "scaleY": 100})).unwrap();+ let g = super::sel_info(&app).unwrap().page_rect;+ assert!((g.width() - 400.0).abs() < 1e-6, "the graphic's width, not the frame's: {g:?}");+ // So a width typed from it scales the graphic by that ratio, not by half.+ app.run("transform.set", json!({"width": 401})).unwrap();+ let after = super::sel_info(&app).unwrap().page_rect;+ assert!((after.width() - 401.0).abs() < 1e-6, "{after:?}");+ }+}+++ #[cfg(test)]+ mod swatch_list_tests {+ use super::*;++ fn rects(shapes: &[egui::epaint::ClippedShape]) -> Vec<(egui::Rect, egui::Color32)> {+ fn walk(s: &egui::Shape, out: &mut Vec<(egui::Rect, egui::Color32)>) {+ match s {+ egui::Shape::Rect(r) => out.push((r.rect, r.fill)),+ egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),+ _ => {}+ }+ }+ let mut out = vec![];+ shapes.iter().for_each(|s| walk(&s.shape, &mut out));+ out+ }++ fn texts(shapes: &[egui::epaint::ClippedShape]) -> Vec<(String, egui::Rect)> {+ fn walk(s: &egui::Shape, out: &mut Vec<(String, egui::Rect)>) {+ match s {+ egui::Shape::Text(t) => out.push((t.galley.job.text.clone(), t.visual_bounding_rect())),+ egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),+ _ => {}+ }+ }+ let mut out = vec![];+ shapes.iter().for_each(|s| walk(&s.shape, &mut out));+ out+ }++ #[test]+ fn the_swatch_under_the_pointer_is_highlighted_and_names_clear_the_scroll_bar() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", serde_json::json!({})).unwrap();+ // A long name, as process swatches have.+ app.run("swatch.create", serde_json::json!({"name": "C=15 M=100 Y=100 K=0 Long Name", "color": {"c": 15, "m": 100, "y": 100, "k": 0}}))+ .unwrap();+ let long = "C=15 M=100 Y=100 K=0 Long Name";+ let ctx = egui::Context::default();+ crate::theme::install_fonts(&ctx, "");+ let tokens = Tokens::for_brightness(crate::theme::Brightness::MediumDark);+ crate::theme::apply(&ctx, &tokens);+ let mut time = 0.0;+ let mut frame = |app: &mut DesignApp, events: Vec<egui::Event>| {+ time += 0.1;+ let raw = egui::RawInput {+ screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 700.0))),+ time: Some(time),+ events,+ ..Default::default()+ };+ let mut out = ctx.run_ui(raw, |ui| swatch_picker(app, ui, "list", Some("[Black]".into()), |_, _| {}));+ out.textures_delta.clear();+ out.shapes+ };+ frame(&mut app, vec![]);+ let chip = egui::pos2(17.0, 17.0);+ for pressed in [true, false] {+ frame(+ &mut app,+ vec![+ egui::Event::PointerMoved(chip),+ egui::Event::PointerButton { pos: chip, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() },+ ],+ );+ }+ let shapes = frame(&mut app, vec![]);+ let (_, name) = texts(&shapes).into_iter().find(|(t, _)| t == "[Registration]").expect("the list is open");+ let pointer = name.center();+ frame(&mut app, vec![egui::Event::PointerMoved(pointer)]);+ let shapes = frame(&mut app, vec![]);+ let all = rects(&shapes);+ let (row, _) = *all.iter().find(|(r, c)| *c == tokens.accent_strong && r.contains(pointer)).expect("the hovered row is highlighted");+ let (list, _) = *all+ .iter()+ .filter(|(r, c)| *c == tokens.panel && r.contains_rect(row))+ .min_by(|a, b| a.0.area().total_cmp(&b.0.area()))+ .expect("the popup");+ let scroll = ctx.global_style().spacing.scroll;+ assert!(row.right() + scroll.bar_width <= list.right(), "rows {row:?} stop short of the scroll bar in {list:?}");+ let (_, long_rect) = texts(&shapes).into_iter().find(|(t, _)| t == long).unwrap();+ assert!(long_rect.right() <= row.right(), "the longest name {long_rect:?} fits its row {row:?}");+ assert!(texts(&shapes).iter().any(|(t, r)| t == "[Black]" && r.right() <= row.right()));+ }+ }