DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
T: scale/rotation/shear fields, absolute transform values, Transformations are Totals
Brandon Thomas240668e87d61
diff --git a/ROADMAP.md b/ROADMAP.mdindex c07ba6968..2f2fb6dca 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -35,6 +35,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- File ▸ Export Text (`file.exportText`): a story as Text Only or RTF (fonts, styles, alignment, indents, tables as tab-separated rows); Export EPUB now asks for a path in the UI.- Tagged PDF (`file.exportPdf {tagged}`, on by default from the UI): structure tree with stories as paragraphs in reading order, figures carrying their alt text, parent-page items and printer's marks as artifacts.- Global Light (`object.globalLight`, `globalLight` on drop/inner shadows; Use Global Light in the Effects panel) and Generate Static Caption (`object.caption`: template over name, path, alt text, label, effective ppi, dimensions, format; any side, offset, style).+- Control panel scale X/Y, rotation and shear fields (`transform.info`, absolute `transform.set {scaleX, scaleY, rotation, shear}` about the reference point) and Preferences › Transformations are Totals for nested objects and placed graphics.- Drag and drop text editing: drag selected text to move it (Alt copies) with its formatting (`text.release`).- Image Import Options: place any page of a multi-page PDF (`file.place {pdfPage}`; the app asks which page), shown on screen and embedded as that page in PDF export.- Define Lists: named numbered lists that continue across stories in page order (`list.define`, paragraph `listName` / `startAt`), round-tripped through IDML; `null` in `type.para` / `type.char` now removes an override.@@ -83,7 +84,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope## How far from full parity (estimate, 2026-10-02, updated)-**Breadth: ~83% weighted** (P0 core 99%, P1 82%, P2 19%) over the 275 features of the InDesign catalogue, scored+**Breadth: ~84% weighted** (P0 core 99%, P1 84%, P2 24%) over the 275 features of the InDesign catalogue, scoredrow by row in [docs/parity.md](docs/parity.md) (`cargo xtask parity` recomputes it). Many features scored done stilllack some of InDesign's options or dialog details, so **overall parity including depth is about 70%**.diff --git a/crates/engine/src/cmd/object.rs b/crates/engine/src/cmd/object.rsindex 03d0d0884..64a8581ab 100644--- a/crates/engine/src/cmd/object.rs+++ b/crates/engine/src/cmd/object.rs@@ -106,10 +106,11 @@ pub fn specs() -> Vec<CommandSpec> {"Transform Panel",[],None,- "{x?, y?, width?, height?, ref?: 0..8} — reference-point based geometry",+ "{x?, y?, width?, height?, scaleX? (%), scaleY? (%), rotation? (°), shear? (°), ref?: 0..8} — reference-point based geometry; rotation and shear are absolute (Transformations are Totals decides whether nested objects measure them on the pasteboard)",has_selection,transform_set),+ cmd!(query "transform.info", "Transform Values", [], None, "{ids?} → {scaleX, scaleY (%), rotation, shear (°), content?: the same for a placed graphic} of the first target", has_selection, transform_info),cmd!("object.arrange", "Arrange", ["Object", "Arrange"], None, "{to: front|forward|backward|back}", has_selection, arrange),cmd!("object.bringToFront", "Bring to Front", ["Object", "Arrange"], Some("Cmd+Shift+]"), "{}", has_selection, |s, _| s.execute("object.arrange", &json!({"to": "front"}))),@@ -837,8 +838,89 @@ fn transform_rotate(s: &mut Session, p: &Value) -> Result<Value> {apply_about_center(s, p, Affine::rotate(-a.to_radians()))}+/// The transform an item's panel values are measured from: its own (relative to its container)+/// or, with Transformations are Totals, the whole chain to the pasteboard.+fn measured_xf(d: &designcraft_doc::Document, id: ItemId, totals: bool) -> Option<(Affine, Affine)> {+ let loc = d.find(id)?;+ let it = d.item_at(&loc)?;+ let parent = if totals { d.parent_xf(&loc) } else { Affine::IDENTITY };+ Some((parent, parent * it.xf))+}++fn values_json(m: Affine) -> Value {+ let v = designcraft_geom::decompose::decompose(m);+ let r = |x: f64| (x * 1e4).round() / 1e4;+ json!({"scaleX": r(v.scale_x * 100.0), "scaleY": r(v.scale_y * 100.0), "rotation": r(v.rotation), "shear": r(v.shear)})+}++fn transform_info(s: &mut Session, p: &Value) -> Result<Value> {+ let ids = targets(s, p)?;+ let totals = s.prefs.transformations_are_totals;+ let d = &s.doc()?.doc;+ let id = *ids.first().ok_or_else(|| bad("transform.info", "nothing selected"))?;+ let (_, m) = measured_xf(d, id, totals).ok_or_else(|| bad("transform.info", "no such object"))?;+ let mut out = values_json(m);+ if let Some(g) = d.item(id).and_then(Item::graphic) {+ out["content"] = values_json(if totals { m * g.xf } else { g.xf });+ }+ Ok(out)+}++/// Absolute rotation / shear / scale from the Transform panel, about the reference point.+fn transform_values(s: &mut Session, p: &Value, ids: &[ItemId], rf: usize) -> Result<Value> {+ let totals = s.prefs.transformations_are_totals;+ let strokes = s.prefs.scale_strokes;+ let get = |k: &str| p.get(k).and_then(Value::as_f64);+ let (rot, shear, sx, sy) = (get("rotation"), get("shear").map(|v| v.clamp(-85.0, 85.0)), get("scaleX"), get("scaleY"));+ if [sx, sy].iter().flatten().any(|v| v.abs() < 0.01) {+ return Err(bad("transform.set", "scale too small"));+ }+ s.edit(|d, _| {+ for id in ids {+ let Some((parent, cur)) = measured_xf(d, *id, totals) else { continue };+ let Some(it) = d.item(*id) else { continue };+ // The reference point, on the pasteboard, then in the measuring space.+ let full = d.find(*id).map_or(Affine::IDENTITY, |l| d.parent_xf(&l));+ let spread_a = designcraft_geom::reference_point((full * it.xf).transform_rect_bbox(it.inner_bounds()), rf);+ let a = if totals { spread_a } else { full.inverse() * spread_a };+ let v = designcraft_geom::decompose::decompose(cur);+ let mut t = v;+ if let Some(r) = rot {+ t.rotation = r;+ }+ if let Some(k) = shear {+ t.shear = k;+ }+ let lin = |m: Affine| {+ let c = m.as_coeffs();+ Affine::new([c[0], c[1], c[2], c[3], 0.0, 0.0])+ };+ let delta = designcraft_geom::decompose::compose(&t) * lin(cur).inverse();+ // Δ in measuring space about `a`, brought into the item's container space.+ let m = parent.inverse() * Affine::translate(a.to_vec2()) * delta * Affine::translate(-a.to_vec2()) * parent;+ let it = d.item_mut(*id).expect("found");+ it.xf = m * it.xf;+ // Scale: relative to what is shown (frames show 100% — their scale lives in the geometry).+ if sx.is_some() || sy.is_some() {+ let (fx, fy) = (sx.map_or(1.0, |x| x / 100.0 / v.scale_x), sy.map_or(1.0, |y| y / 100.0 / v.scale_y));+ let m = Affine::translate(a.to_vec2()) * Affine::scale_non_uniform(fx, fy) * Affine::translate(-a.to_vec2());+ let m = parent.inverse() * m * parent;+ scale_item(it, m, (fx * fy).abs().sqrt(), strokes);+ }+ }+ ok()+ })+}+fn transform_set(s: &mut Session, p: &Value) -> Result<Value> {let ids = targets(s, p)?;+ if ["rotation", "shear", "scaleX", "scaleY"].iter().any(|k| p.get(*k).is_some()) {+ let rf = p.get("ref").and_then(Value::as_u64).unwrap_or(4) as usize;+ if !["x", "y", "width", "height"].iter().any(|k| p.get(*k).is_some()) {+ return transform_values(s, p, &ids, rf);+ }+ transform_values(s, p, &ids, rf)?;+ }let rf = p.get("ref").and_then(Value::as_u64).unwrap_or(0) as usize;let with_stroke = s.prefs.dimensions_include_stroke;s.edit(|d, _| {@@ -1537,3 +1619,39 @@ mod light_tests {assert_eq!(angle(&s), 45.0);}}++#[cfg(test)]+mod transform_values_tests {+ use super::*;++ #[test]+ fn absolute_rotation_shear_and_totals() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let a = s.execute("frame.create", &json!({"rect": [100, 100, 200, 150]})).unwrap()["id"].as_u64().unwrap();+ let info = |s: &mut Session, id: u64| s.execute("transform.info", &json!({"ids": [id]})).unwrap();+ let centre = |s: &Session| s.doc().unwrap().doc.item(ItemId(a)).unwrap().bounds().center();+ let c0 = centre(&s);+ s.execute("transform.set", &json!({"rotation": 30, "ids": [a]})).unwrap();+ s.execute("transform.set", &json!({"rotation": 30, "ids": [a]})).unwrap();+ assert_eq!(info(&mut s, a)["rotation"], 30.0, "absolute, not cumulative");+ assert!((centre(&s) - c0).hypot() < 1e-9, "about the centre reference point");+ s.execute("transform.set", &json!({"shear": 20, "ids": [a]})).unwrap();+ let i = info(&mut s, a);+ assert_eq!((i["rotation"].as_f64(), i["shear"].as_f64()), (Some(30.0), Some(20.0)));+ assert_eq!(i["scaleX"], 100.0);+ // Nested: a group rotated 10° around the rotated frame.+ let b = s.execute("frame.create", &json!({"rect": [300, 100, 350, 150]})).unwrap()["id"].as_u64().unwrap();+ let g = s.execute("object.group", &json!({"ids": [a, b]})).unwrap()["id"].as_u64().unwrap();+ s.execute("transform.rotate", &json!({"angle": 10, "ids": [g]})).unwrap();+ assert_eq!(info(&mut s, a)["rotation"], 40.0, "totals");+ s.execute("prefs.set", &json!({"transformationsAreTotals": false})).unwrap();+ assert_eq!(info(&mut s, a)["rotation"], 30.0, "relative to the group");+ s.execute("transform.set", &json!({"rotation": 0, "shear": 0, "ids": [a]})).unwrap();+ s.execute("prefs.set", &json!({"transformationsAreTotals": true})).unwrap();+ assert_eq!(info(&mut s, a)["rotation"], 10.0);+ // Scale is relative to what's shown: a frame always shows 100%.+ s.execute("transform.set", &json!({"scaleX": 200, "ids": [b]})).unwrap();+ assert_eq!(info(&mut s, b)["scaleX"], 100.0);+ }+}diff --git a/crates/engine/src/cmd/prefs.rs b/crates/engine/src/cmd/prefs.rsindex 141aab34b..b3011d8a9 100644--- a/crates/engine/src/cmd/prefs.rs+++ b/crates/engine/src/cmd/prefs.rs@@ -27,7 +27,7 @@ pub fn specs() -> Vec<CommandSpec> {"Preferences",[],None,- "{showHiddenCharacters?, typographersQuotes?, polygonSides?, starInset?, scaleStrokes?, dimensionsIncludeStroke?} → all application preferences",+ "{showHiddenCharacters?, typographersQuotes?, polygonSides?, starInset?, scaleStrokes?, dimensionsIncludeStroke?, transformationsAreTotals?} → all application preferences",super::always,|s, p| {let cur = serde_json::to_value(&s.prefs).map_err(|e| bad("prefs.set", e.to_string()))?;diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex b129ae5e0..b51fedab5 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -131,6 +131,10 @@ pub struct Prefs {pub scale_strokes: bool,/// X/Y/W/H in the Control and Properties panels measure the stroke's outer edge.pub dimensions_include_stroke: bool,+ /// Preferences › General › Transformations are Totals: rotation, shear and scale of nested+ /// objects (a graphic in a frame, objects in groups) are measured on the pasteboard rather+ /// than relative to their container.+ pub transformations_are_totals: bool,/// Preferences › Type › Smart Text Reflow: pages follow the primary text frame's story/// (added while it oversets, empty ones at the end removed).pub smart_text_reflow: bool,@@ -145,6 +149,7 @@ impl Default for Prefs {star_inset: 0.0,scale_strokes: true,dimensions_include_stroke: true,+ transformations_are_totals: true,smart_text_reflow: true,}}diff --git a/crates/geom/src/decompose.rs b/crates/geom/src/decompose.rsnew file mode 100644index 000000000..4c06a4261--- /dev/null+++ b/crates/geom/src/decompose.rs@@ -0,0 +1,53 @@+//! Transform panel values: an affine split into scale, rotation and shear the way InDesign shows+//! them (rotation counter-clockwise on screen, shear as an angle along x).++use kurbo::Affine;++/// `m`'s linear part as rotation · shear · scale.+#[derive(Clone, Copy, Debug, PartialEq)]+pub struct Decomposed {+ /// Scale factors (1 = 100%); `scale_y` is negative for a flipped transform.+ pub scale_x: f64,+ pub scale_y: f64,+ /// Degrees, counter-clockwise on screen, in (-180, 180].+ pub rotation: f64,+ /// Degrees (as `transform.shear` takes them).+ pub shear: f64,+}++pub fn decompose(m: Affine) -> Decomposed {+ let [a, b, c, d, _, _] = m.as_coeffs();+ let sx = a.hypot(b);+ if sx < 1e-12 {+ return Decomposed { scale_x: 0.0, scale_y: 0.0, rotation: 0.0, shear: 0.0 };+ }+ let det = a * d - b * c;+ let rotation = (-b).atan2(a).to_degrees();+ let rotation = if rotation <= -180.0 + 1e-9 { 180.0 } else { rotation };+ Decomposed { scale_x: sx, scale_y: det / sx, rotation, shear: ((a * c + b * d) / det).atan().to_degrees() }+}++/// The linear transform with these values (no translation); `decompose` inverts it.+pub fn compose(v: &Decomposed) -> Affine {+ Affine::rotate(-v.rotation.to_radians())+ * Affine::new([1.0, 0.0, v.shear.to_radians().tan(), 1.0, 0.0, 0.0])+ * Affine::scale_non_uniform(v.scale_x, v.scale_y)+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn round_trip() {+ for (sx, sy, r, k) in [(1.0, 1.0, 0.0, 0.0), (2.0, 0.5, 30.0, 0.0), (1.5, -1.0, -120.0, 20.0), (0.25, 3.0, 180.0, -45.0)] {+ let v = Decomposed { scale_x: sx, scale_y: sy, rotation: r, shear: k };+ let back = decompose(compose(&v));+ for (x, y) in [(back.scale_x, sx), (back.scale_y, sy), (back.rotation, r), (back.shear, k)] {+ assert!((x - y).abs() < 1e-9, "{v:?} → {back:?}");+ }+ }+ // transform.rotate's convention: rotate(-θ) is θ counter-clockwise.+ assert!((decompose(Affine::rotate(-0.5)).rotation - 0.5f64.to_degrees()).abs() < 1e-9);+ }+}diff --git a/crates/geom/src/lib.rs b/crates/geom/src/lib.rsindex e6520f417..02802a68d 100644--- a/crates/geom/src/lib.rs+++ b/crates/geom/src/lib.rs@@ -8,6 +8,7 @@#![forbid(unsafe_code)]pub mod corners;+pub mod decompose;pub mod edit_path;pub mod freehand;pub mod hit;diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rsindex 6d557efac..0c2dc9b54 100644--- a/crates/ui-egui/src/chrome.rs+++ b/crates/ui-egui/src/chrome.rs@@ -114,6 +114,13 @@ pub fn control_bar(app: &mut DesignApp, ui: &mut egui::Ui) {});}+/// A field label drawn as a tool icon (hover for its name).+fn icon_caption(ui: &mut egui::Ui, icon: &str, tip: &str) {+ let (r, resp) = ui.allocate_exact_size(vec2(16.0, 16.0), Sense::hover());+ icons::paint(ui.painter(), r, icon, Tokens::get(ui.ctx()).icon);+ resp.on_hover_text(tip);+}+fn control_object(app: &mut DesignApp, ui: &mut egui::Ui) {let units = app.session.active().map(|d| d.doc.settings.horizontal_units).unwrap_or(Unit::Picas);let info = panels::sel_info(app);@@ -147,6 +154,30 @@ fn control_object(app: &mut DesignApp, ui: &mut egui::Ui) {ui.end_row();});vsep(ui);+ // Scale, rotation and shear (absolute; see Transformations are Totals).+ let tv = if info.is_some() { app.session.execute("transform.info", &json!({})).ok() } else { None };+ let tv_get = |k: &str| tv.as_ref().and_then(|v| v[k].as_f64());+ egui::Grid::new("ctl_srs").num_columns(4).spacing(vec2(4.0, 4.0)).show(ui, |ui| {+ icon_caption(ui, "tool-scale", "Scale X Percentage");+ if let Some(v) = number(ui, "csx", tv_get("scaleX"), "%", 56.0, 1) {+ let _ = app.run("transform.set", json!({"scaleX": v}));+ }+ icon_caption(ui, "tool-rotate", "Rotation Angle");+ if let Some(v) = number(ui, "crot", tv_get("rotation"), "°", 50.0, 1) {+ let _ = app.run("transform.set", json!({"rotation": v}));+ }+ ui.end_row();+ icon_caption(ui, "tool-scale", "Scale Y Percentage");+ if let Some(v) = number(ui, "csy", tv_get("scaleY"), "%", 56.0, 1) {+ let _ = app.run("transform.set", json!({"scaleY": v}));+ }+ icon_caption(ui, "tool-shear", "Shear X Angle");+ if let Some(v) = number(ui, "cshr", tv_get("shear"), "°", 50.0, 1) {+ let _ = app.run("transform.set", json!({"shear": v}));+ }+ ui.end_row();+ });+ vsep(ui);// Rotate / flip.ui.vertical(|ui| {ui.horizontal(|ui| {diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex d7a7354b1..0542c6b4e 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -518,6 +518,7 @@ fn preferences(ui: &mut egui::Ui, d: &mut Dialog) {ui.add_space(6.0);ui.label(egui::RichText::new("Transform").font(semibold(12.0)));check(ui, d, "dimensionsIncludeStroke", "Dimensions Include Stroke Weight");+ check(ui, d, "transformationsAreTotals", "Transformations are Totals");}}});@@ -881,7 +882,7 @@ pub fn confirm(app: &mut DesignApp) -> Result<Value, String> {"preferences" => {app.run("prefs.set",- json!({"scaleStrokes": d.b("scaleStrokes"), "dimensionsIncludeStroke": d.b("dimensionsIncludeStroke"), "typographersQuotes": d.b("typographersQuotes"), "smartTextReflow": d.b("smartTextReflow")}),+ json!({"scaleStrokes": d.b("scaleStrokes"), "dimensionsIncludeStroke": d.b("dimensionsIncludeStroke"), "transformationsAreTotals": d.b("transformationsAreTotals"), "typographersQuotes": d.b("typographersQuotes"), "smartTextReflow": d.b("smartTextReflow")}),)?;let view = match d.s("displayQuality").as_str() {"fast" => "view.fastDisplay",diff --git a/docs/parity.md b/docs/parity.mdindex e89efc81a..1bb7241f7 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -5,12 +5,12 @@ The summary is generated by `cargo xtask parity` from the table at the bottom ofEach row of the InDesign feature catalogue is scored **D** (done), **P** (partial: works but lacks options or UI) or **M** (missing), weighted by priority (**P0** core = 3, **P1** = 2, **P2** = 1). Out-of-scope rows (Adobe cloud services, plug-ins, Typekit, Flash) are excluded.<!-- SUMMARY -->-**Weighted breadth parity: 83%** over 275 features.+**Weighted breadth parity: 84%** over 275 features.| Priority | Features | Done | Partial | Missing | Parity ||---|---|---|---|---|---|| P0 | 102 | 99 | 3 | 0 | 99% |-| P1 | 97 | 67 | 26 | 4 | 82% |+| P1 | 97 | 68 | 26 | 3 | 84% || P2 | 76 | 12 | 13 | 51 | 24% || Area | Parity |@@ -19,7 +19,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Documents, pages, spreads | 84% || Layers | 95% || Frames, shapes & paths | 88% |-| Transform | 93% |+| Transform | 100% || Fill, stroke, colour | 86% || Effects & transparency | 62% || Placing & links | 82% |@@ -134,7 +134,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t| Transform | Rotate, Scale, Shear tools + dialogs | P0 | D || Transform | Transform Again family | P1 | D || Transform | Clear Transformations | P1 | D |-| Transform | Transformations are Totals pref | P1 | M |+| Transform | Transformations are Totals pref | P1 | D || Transform | Scale strokes / content options | P0 | D || Transform | Align & Distribute | P0 | D || Transform | Dimensions Include Stroke Weight | P0 | D |