DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #541: Rotation, shear, scale, rotate and flip in Properties › Transform
aiongg30354c0a8840
diff --cc ROADMAP.mdindex f0d1df777,7b68df77c..f26bc6a19--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -129,37 -129,7 +129,38 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+ - **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** · 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-11** · The View menu follows InDesign's: proofing first, then zoom, Rotate Spread, Screen Mode, Display Performance, rulers, Extras, Grids & Guides and Structure; the view items that sat at the end of the Type menu moved there. No readiness percentage change.+- **2026-10-11** · Properties › Appearance's Fill and Stroke menus gain InDesign's Tint field and, for a text frame, Apply To: Frame / Text. No readiness percentage change.+- **2026-10-11** · `story.replaceRange`, `story.setText`, notes, footnotes, endnotes, type on a path and table cells read `\r` and `\r\n` as paragraph returns, as `frame.create` and `text.insert` already did. No readiness percentage change.+- **2026-10-11** · Corner Options keep curved sides curved and round every corner point, including where an arc meets a line (a Pathfinder quarter circle with rounded corners stayed a triangle). No readiness percentage change.+- **2026-10-11:** Type › Justification… (Cmd+Alt+Shift+J, also in the Paragraph panel menu) sets word and letter spacing, glyph scaling and the composer on the selected paragraphs, sharing the Paragraph Style Options section (#531). 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-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-11** · Japanese captions now cover print ranges, imported style handling and table+ row/column movement, including row-height distribution. Existing translation and RTL helpers+ handle the display; command IDs, stored option values and user-defined style names are unchanged.+- **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-11** · Live corners: the yellow widget on a selected rectangle frame shows corner+ diamonds; dragging one rounds the corners, Alt-click steps the corner shape (#186).+- **2026-10-11** · Optical kerning (#181): pairs are spaced from their outlines (ink gap per band,+ pulled towards the font's stem gap, bounded) instead of silently using the font's kern pairs.+- **2026-10-11** · New Document laid out like InDesign's (#325): Recent, Saved, Print, Web and+ Mobile preset tabs beside the preset's details; saved document presets live in the engine+ (`file.savePreset`, `file.deletePreset`, `file.new {preset}`); `file.new` takes intent, units,+ start page and per-edge bleed and slug.+- **2026-10-11** · macOS: fonts that font services and managers activate (Adobe Fonts,+ RightFont) are listed, read from the files CoreText has available (#261, #327).+- **2026-10-11:** Document pages take their parent page's margins and columns (left or right parent page by side) and follow its changes unless they have their own; parent ruler guides draw and snap on the pages based on it. IDML import marks a page margin preference that differs from its parent as the page's own. No readiness percentage change.+- **2026-10-11** · Document Setup laid out like InDesign's: Page Size, Margins (new: every+ page's, `layout.documentSetup {margins}`), Bleed and Slug with links, Adjust Layout.+- **2026-10-11** · IDML reads and writes a spread's view rotation (Rotate Spread) as the+ rotation part of the spread transform (#484).+- **2026-10-11** · The document grid is drawn (View ▸ Grids & Guides ▸ Show/Hide Document Grid,+ ⌘'), on the lines Snap to Document Grid uses, behind or in front of page items (#530).- **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.- **2026-10-10** · Version 0.6.0; releases add a Linux riscv64 tar.gz (cross-compiled, CLIsmoke-tested under QEMU).diff --cc crates/ui-egui/src/icons.rsindex eac798497,dba5a7a7a..a734dab70--- a/crates/ui-egui/src/icons.rs+++ b/crates/ui-egui/src/icons.rs@@@ -177,18 -176,31 +177,41 @@@ pub fn paint(p: &Painter, r: Rect, name}).collect();pen.line(&pts);- pen.line(&[(13.0, 4.0), (15.5, 6.0), (16.5, 2.8)]);+ pen.line(&[(10.0 + direction * 3.0, 4.0), (10.0 + direction * 5.5, 6.0), (10.0 + direction * 6.5, 2.8)]);+ }+ "flip-horizontal" => {+ pen.line(&[(10.0, 2.0), (10.0, 18.0)]);+ pen.fill(&[(3.0, 4.0), (8.0, 10.0), (3.0, 16.0)]);+ pen.closed(&[(17.0, 4.0), (12.0, 10.0), (17.0, 16.0)]);+ }+ "flip-vertical" => {+ pen.line(&[(2.0, 10.0), (18.0, 10.0)]);+ pen.fill(&[(4.0, 3.0), (10.0, 8.0), (16.0, 3.0)]);+ pen.closed(&[(4.0, 17.0), (10.0, 12.0), (16.0, 17.0)]);}+ // Properties › Transform: rotate a quarter turn (an arc over a square), flip (a shape and its+ // mirror image across a dashed axis).+ "rotate-cw" | "rotate-ccw" => {+ let m = |x: f32| if name == "rotate-ccw" { 20.0 - x } else { x };+ pen.rect(m(3.0).min(m(11.0)), 9.0, m(3.0).max(m(11.0)), 17.0);+ let pts: Vec<(f32, f32)> = (0..12)+ .map(|i| {+ let a = std::f32::consts::PI * (1.0 - i as f32 / 11.0);+ (m(11.0 + 5.0 * a.cos()), 9.0 - 5.0 * a.sin())+ })+ .collect();+ pen.line(&pts);+ pen.line(&[(m(14.0), 7.0), (m(16.0), 9.5), (m(18.0), 7.0)]);+ }+ "flip-h" | "flip-v" => {+ let t = |x: f32, y: f32| if name == "flip-v" { (y, x) } else { (x, y) };+ pen.fill(&[t(3.0, 16.0), t(8.5, 4.0), t(8.5, 16.0)]);+ pen.closed(&[t(11.5, 16.0), t(11.5, 4.0), t(17.0, 16.0)]);+ for k in 0..4 {+ let y0 = 2.5 + k as f32 * 4.0;+ pen.line(&[t(10.0, y0), t(10.0, y0 + 2.0)]);+ }+ }"tool-gradient" | "tool-gradient-feather" => {for i in 0..6 {let a = 30 + i * 35;diff --cc crates/ui-egui/src/panels/properties.rsindex 6860ed98a,17473fba0..56b884718--- a/crates/ui-egui/src/panels/properties.rs+++ b/crates/ui-egui/src/panels/properties.rs@@@ -482,8 -466,58 +483,58 @@@ fn transform_section(app: &mut DesignAp}}+ /// Properties › Transform, below X/Y/W/H as in InDesign: rotation and shear angles beside the+ /// X and Y scales (totals, as Transformations are Totals), then rotate a quarter turn and flip.+ fn transform_angles(app: &mut DesignApp, ui: &mut Ui, rp: u8) {+ let t = Tokens::get(ui.ctx());+ let lang = app.ui.language.clone();+ let tv = app.session.execute("transform.info", &json!({})).ok();+ let tv_get = |k: &str| tv.as_ref().and_then(|v| v[k].as_f64());+ ui.add_space(4.0);+ let b = block(ui, 2.0 * FIELD_H + 4.0);+ let mut set = serde_json::Map::new();+ let rows = [+ [("tool-rotate", "Rotation Angle", "rotation", "°", "p_rot"), ("tool-scale", "Scale X Percentage", "scaleX", "%", "p_sx")],+ [("tool-shear", "Shear X Angle", "shear", "°", "p_shear"), ("tool-scale", "Scale Y Percentage", "scaleY", "%", "p_sy")],+ ];+ for (row, cells) in rows.into_iter().enumerate() {+ let yy = row as f32 * 25.0;+ for (col, (icon, tip, key, suffix, id)) in cells.into_iter().enumerate() {+ let x = if col == 0 { 40.0 } else { 120.0 };+ let ir = sub(b, x, yy + 2.0, 17.0, 17.0);+ icons::paint(ui.painter(), ir, icon, t.icon);+ ui.interact(ir, ui.id().with(id), Sense::hover()).on_hover_text(crate::i18n::tr(&lang, tip));+ if let Some(v) = place(ui, sub(b, x + 19.0, yy, 54.0, FIELD_H), |ui| widgets::number(ui, id, tv_get(key), suffix, 54.0, 1)) {+ set.insert(key.into(), json!(v));+ }+ }+ }+ if !set.is_empty() {+ set.insert("ref".into(), json!(rp));+ let _ = app.run("transform.set", Value::Object(set));+ }+ ui.add_space(2.0);+ ui.horizontal(|ui| {+ ui.add_space(36.0);+ ui.spacing_mut().item_spacing.x = 10.0;+ for (icon, tip, cmd, params) in [+ ("rotate-cw", "Rotate 90° Clockwise", "transform.rotate", json!({"angle": -90})),+ ("rotate-ccw", "Rotate 90° Counterclockwise", "transform.rotate", json!({"angle": 90})),+ ("flip-h", "Flip Horizontal", "transform.flip", json!({"axis": "horizontal"})),+ ("flip-v", "Flip Vertical", "transform.flip", json!({"axis": "vertical"})),+ ] {+ let label = crate::i18n::tr(&lang, tip);+ let resp = icon_toggle(ui, icon, false, label);+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, label));+ if resp.clicked() {+ let _ = app.run(cmd, params);+ }+ }+ });+ }+/// A stroke-type preview dropdown (light box with the line style).-fn stroke_type_dropdown(app: &mut DesignApp, ui: &mut Ui, cur: &str, w: f32) {+pub(crate) fn stroke_type_dropdown(app: &mut DesignApp, ui: &mut Ui, cur: &str, w: f32) {const TYPES: &[(&str, &str)] = &[("Solid", "solid"),("Dashed", "dashed"),@@@ -2444,108 -2278,24 +2495,136 @@@ mod testsapp,);h.run_steps(3);+ h+ }++ #[test]+ fn several_shapes_show_pathfinder_and_intersect_combines_them() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({})).unwrap();+ let a = app.run("frame.create", json!({"rect": [100, 100, 300, 300], "shape": "ellipse"})).unwrap()["id"].clone();+ let b = app.run("frame.create", json!({"rect": [200, 100, 300, 200]})).unwrap()["id"].clone();+ // One shape: no Pathfinder section.+ app.run("selection.set", json!({"ids": [a]})).unwrap();+ let mut h = panel(app);+ assert!(h.query_by_label("Pathfinder").is_none());+ // Two: the section and its five buttons; Intersect leaves one shape, the ellipse's quarter.+ h.state_mut().run("selection.set", json!({"ids": [a, b]})).unwrap();+ h.run_steps(3);+ assert!(h.query_by_label("Pathfinder").is_some());+ for op in ["Add", "Subtract", "Intersect", "Exclude Overlap", "Minus Back"] {+ assert!(h.query_by_label(op).is_some(), "{op}");+ }+ h.get_by_label("Intersect").click();+ h.run_steps(3);+ let doc = &h.state().session.active().unwrap().doc;+ let items = &doc.spreads[0].items;+ assert_eq!(items.len(), 1, "one shape left");+ let r = items[0].bounds();+ assert!((r.x0 - 200.0).abs() < 0.5 && (r.y1 - 200.0).abs() < 0.5 && (r.x1 - 300.0).abs() < 0.5, "{r:?}");+ }++ const CYAN: &str = "C=100 M=0 Y=0 K=0";++ #[test]+ fn the_fill_menu_sets_a_tint() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({})).unwrap();+ let id = app.run("frame.create", json!({"rect": [72, 72, 300, 200]})).unwrap()["id"].as_u64().unwrap();+ app.run("object.fill", json!({"swatch": CYAN, "ids": [id]})).unwrap();+ app.run("selection.set", json!({"ids": [id]})).unwrap();+ let mut h = panel(app);+ h.get_by_label("Fill swatch").click();+ h.run_steps(3);+ // A frame that isn't a text frame: no Apply To.+ assert!(h.query_by_label("Apply To:").is_none());+ // The field on the Tint row (Opacity also reads 100%).+ let row = h.get_by_label("Tint:").rect();+ h.query_all_by(|n| n.role() == egui::accesskit::Role::TextInput && n.value().as_deref() == Some("100%"))+ .find(|n| (n.rect().center().y - row.center().y).abs() < 8.0)+ .expect("the Tint field")+ .click();+ h.run_steps(2);+ h.event(egui::Event::Key { key: egui::Key::A, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND });+ h.event(egui::Event::Text("25".into()));+ h.key_press(egui::Key::Enter);+ h.run_steps(3);+ let fill = h.state().session.active().unwrap().doc.item(designcraft_doc::ids::ItemId(id)).unwrap().fill.clone();+ assert_eq!((fill.swatch.as_str(), fill.tint), (CYAN, 0.25), "the tint, on the same swatch");+ }++ #[test]+ fn a_tint_on_several_objects_keeps_each_ones_swatch() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({})).unwrap();+ let a = app.run("frame.create", json!({"rect": [72, 72, 200, 200]})).unwrap()["id"].as_u64().unwrap();+ let b = app.run("frame.create", json!({"rect": [220, 72, 300, 200]})).unwrap()["id"].as_u64().unwrap();+ app.run("object.fill", json!({"swatch": CYAN, "ids": [a]})).unwrap();+ app.run("object.fill", json!({"swatch": "[Black]", "ids": [b]})).unwrap();+ app.run("selection.set", json!({"ids": [a, b]})).unwrap();+ let mut h = panel(app);+ h.get_by_label("Fill swatch").click();+ h.run_steps(3);+ let row = h.get_by_label("Tint:").rect();+ h.query_all_by(|n| n.role() == egui::accesskit::Role::TextInput && n.value().as_deref() == Some("100%"))+ .find(|n| (n.rect().center().y - row.center().y).abs() < 8.0)+ .expect("the Tint field")+ .click();+ h.run_steps(2);+ h.event(egui::Event::Key { key: egui::Key::A, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND });+ h.event(egui::Event::Text("25".into()));+ h.key_press(egui::Key::Enter);+ h.run_steps(3);+ let doc = &h.state().session.active().unwrap().doc;+ let fill = |id: u64| doc.item(designcraft_doc::ids::ItemId(id)).unwrap().fill.clone();+ assert_eq!((fill(a).swatch.as_str(), fill(a).tint), (CYAN, 0.25));+ assert_eq!((fill(b).swatch.as_str(), fill(b).tint), ("[Black]", 0.25), "the second keeps its own swatch");+ }++ #[test]+ fn apply_to_text_colours_a_text_frames_text_not_the_frame() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({})).unwrap();+ let r = app.run("frame.create", json!({"rect": [72, 72, 300, 200], "content": "text", "text": "Heading"})).unwrap();+ let (id, story) = (r["id"].as_u64().unwrap(), designcraft_doc::StoryId(r["story"].as_u64().unwrap()));+ app.run("selection.set", json!({"ids": [id]})).unwrap();+ let mut h = panel(app);+ h.get_by_label("Fill swatch").click();+ h.run_steps(3);+ h.get_by_label("Text").click();+ h.run_steps(3);+ h.get_by_label(CYAN).click();+ h.run_steps(3);+ let doc = &h.state().session.active().unwrap().doc;+ assert_eq!(doc.story(story).unwrap().char_format_at(0).over.fill.as_deref(), Some(CYAN), "the text is cyan");+ assert_eq!(doc.item(designcraft_doc::ids::ItemId(id)).unwrap().fill.swatch, "[None]", "the frame isn't");+ }++++ #[test]++ fn transform_flips_and_rotates_from_properties() {++ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());++ app.run("file.new", json!({})).unwrap();++ let id = app.run("frame.create", json!({"rect": [72, 72, 300, 200]})).unwrap()["id"].as_u64().unwrap();++ app.run("selection.set", json!({"ids": [id]})).unwrap();++ let mut h = panel(app);+ let xf = |h: &Harness<'_, DesignApp>| h.state().session.active().unwrap().doc.item(designcraft_doc::ids::ItemId(id)).unwrap().xf;+ // Flip Horizontal mirrors the frame (a negative determinant); Flip Vertical as well brings it+ // back to a half turn, as in the tutorial's petal.+ h.get_by_label("Flip Horizontal").click();+ h.run_steps(3);+ assert!(xf(&h).determinant() < 0.0, "{:?}", xf(&h));+ h.get_by_label("Flip Vertical").click();+ h.run_steps(3);+ let c = xf(&h).as_coeffs();+ assert!((c[0] + 1.0).abs() < 1e-9 && (c[3] + 1.0).abs() < 1e-9, "a half turn: {c:?}");+ let info = h.state_mut().session.execute("transform.info", &json!({})).unwrap();+ assert!((info["rotation"].as_f64().unwrap().abs() - 180.0).abs() < 1e-6, "{info}");+ // A quarter turn clockwise from there.+ h.get_by_label("Rotate 90° Clockwise").click();+ h.run_steps(3);+ let info = h.state_mut().session.execute("transform.info", &json!({})).unwrap();+ assert!((info["rotation"].as_f64().unwrap() - 90.0).abs() < 1e-6, "{info}");+ // The angle and scale fields are there.+ assert!(h.query_by(|n| n.role() == egui::accesskit::Role::TextInput && n.value().as_deref() == Some("90°")).is_some());+ }}