diff --git a/ROADMAP.md b/ROADMAP.md index 4727979cd..b5c966c27 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -454,6 +454,7 @@ Newest first. - **2026-10-26** · Inner Shadow, Inner Glow (from the edges) and Bevel and Emboss on a frame holding an image follow what the image paints: a transparent part is outside the object, so the effect lines the image's opaque edge, not the frame (#1622). Satin and a centred Inner Glow still follow the frame. No readiness percentage change. - **2026-10-25** · Duplicate Layer (`layer.duplicate`; the layer's context menu in the Layers panel, or a layer dropped on Create New Layer) adds a copy named after the layer with " copy" added ("Art copy" for Art) above the layer, with its settings, a copy of every object on it and copies of its ruler guides, on document and parent pages, in one undo step. Copied frames stay threaded to the copies of frames on the same layer and are not threaded to frames on other layers. A copied override of a parent item overrides that item's copy, and pages hide the copy where they hide the parent item. Hyperlinks on copied objects and text get copies that go to the same destinations. No readiness percentage change. - **2026-10-24** · Column rules run from the top line's ascent to the bottom line's descent, as InDesign draws them, instead of from the top to the bottom of the columns, on screen, in PDF and in PowerPoint export. The top and bottom insets shorten the rule from those lines. Existing documents draw their column rules at the new length. No readiness percentage change. +- **2026-10-24** · Table › Cell Options › Diagonal Lines… (`table.setCell` `diagonal`, `table.getCellDiagonal`): as in InDesign, a cell can carry a diagonal line from the top left corner to the bottom right, from the top right to the bottom left, or both, with the weight, type, color, tint, gap color and gap tint that cell edges take, drawn in front of the cell's contents or behind them. The lines draw on screen and in PDF and are saved in the native format. No readiness percentage change. - **2026-10-20** · Edit › Keyboard Shortcuts is craft-keymap's shared dialog: commands grouped by menu with Show and Filter, recording that asks before taking a key from another command, undo and redo, named shortcut sets (edits of Default become Custom; an imported set becomes a set of its own), an on-screen US keyboard, InDesign Show Set files reviewed before they apply, JSON export and an HTML summary. ui.json keeps the `shortcuts` map earlier versions read, for the active set. No readiness percentage change. - **2026-10-19** · Import InDesign Set… runs on craft-keymap's importer: a set's Window menu panel items (Layers F7, Pages F12, Swatches F5) and Tools items set the panel and tool shortcuts, all of an item's Default keys apply, and the report adds numeric keypad keys read as main keys and likely commands for unmatched items (`window.importShortcuts`). On InDesign's Windows defaults it matches 366 of 1,629 items (was 233) and changes 23 commands. No readiness percentage change. - **2026-10-19** · Keyboard shortcuts run on the shared craft-keymap crate. Panels take shortcuts, with InDesign's defaults where the key is free (Swatches F5, Color F6, Layers F7, Info F8, Stroke F10, Paragraph Styles F11, Character Styles Shift+F11, Pages F12, Align Shift+F7); tool keys are editable in Edit › Keyboard Shortcuts and `window.setShortcut`, and tools sharing a key take turns (B). Saved shortcuts load unchanged. No readiness percentage change. diff --git a/crates/compose/src/table.rs b/crates/compose/src/table.rs index 0190aad05..341a116b6 100644 --- a/crates/compose/src/table.rs +++ b/crates/compose/src/table.rs @@ -34,6 +34,10 @@ pub struct PlacedCell { pub repeated: bool, /// Graphic cell content (drawn at `clip`'s top left, clipped to it). pub graphic: Option, + /// The cell's diagonal lines (Cell Options › Diagonal Lines), corner to corner of `rect`. + pub diagonals: Vec, + /// Whether the diagonals are drawn over the cell's contents (otherwise under them). + pub diagonals_in_front: bool, } /// One cell edge (or the table border) to stroke. @@ -91,6 +95,10 @@ impl TableFrag { c.rect = c.rect + v; c.clip = c.clip + v; c.origin += v; + for s in &mut c.diagonals { + s.a += v; + s.b += v; + } } for r in &mut self.rows { r.1 += dy; @@ -474,6 +482,14 @@ fn emit( overset, repeated, graphic: cell.graphic.clone(), + diagonals: cell + .diagonal + .segments(rect) + .into_iter() + .filter(|_| cell.diagonal.stroke.is_visible()) + .map(|(a, b)| StrokeSeg { a, b, stroke: cell.diagonal.stroke.clone() }) + .collect(), + diagonals_in_front: cell.diagonal.in_front, }); } } diff --git a/crates/compose/src/table/border_tests.rs b/crates/compose/src/table/border_tests.rs index 5a28d7274..336b0803d 100644 --- a/crates/compose/src/table/border_tests.rs +++ b/crates/compose/src/table/border_tests.rs @@ -31,6 +31,42 @@ fn explicit_cell_edges_override_table_border_without_changing_native_defaults() assert_eq!(right.stroke.weight, 2.0, "unoverridden right edge keeps the table border"); } +#[test] +fn diagonal_lines_cross_the_placed_cell_corner_to_corner() { + let mut table = Table::new(77, 2, 2, 0, 0, 100.0); + let stroke = CellStroke { weight: 3.0, ..Default::default() }; + let cell = table.cell_mut(0, 0).unwrap(); + cell.col_span = 2; + cell.diagonal = designcraft_doc::CellDiagonal { lines: designcraft_doc::DiagonalLines::Crossed, stroke: stroke.clone(), in_front: false }; + table.cell_mut(1, 0).unwrap().diagonal.lines = designcraft_doc::DiagonalLines::TopLeft; + table.cell_mut(1, 0).unwrap().diagonal.stroke.color = designcraft_color::swatch::NONE.into(); + let composed = compose_table(table); + let fragment = &composed.frames[0].tables[0]; + let merged = fragment.cells.iter().find(|c| (c.row, c.col) == (0, 0)).unwrap(); + let r = merged.rect; + let ends: Vec<_> = merged.diagonals.iter().map(|s| (s.a, s.b)).collect(); + assert_eq!(ends, [(Point::new(r.x0, r.y0), Point::new(r.x1, r.y1)), (Point::new(r.x1, r.y0), Point::new(r.x0, r.y1))], "across the merged cell"); + assert!(merged.diagonals.iter().all(|s| s.stroke == stroke) && !merged.diagonals_in_front); + assert!(fragment.cells.iter().filter(|c| c.row == 1).all(|c| c.diagonals.is_empty()), "none, or an invisible stroke, draws nothing"); + assert!(fragment.strokes.iter().all(|s| s.a.x == s.b.x || s.a.y == s.b.y), "the edges stay edges"); +} + +#[test] +fn diagonal_lines_move_with_their_cell_in_a_bottom_justified_frame() { + let mut table = Table::new(77, 1, 1, 0, 0, 100.0); + table.cell_mut(0, 0).unwrap().diagonal.lines = designcraft_doc::DiagonalLines::TopLeft; + let mut doc = Document::new(&NewDocument::default()); + let layer = doc.default_layer(); + let (fid, sid) = doc.add_text_frame(SpreadRef::Doc(0), Rect::new(0.0, 0.0, 200.0, 300.0), layer, "", ParaFormat::default()).unwrap(); + doc.item_mut(fid).unwrap().text_frame_mut().unwrap().options.vertical_justification = VerticalJustification::Bottom; + doc.story_mut(sid).unwrap().insert_table(0, table); + let composed = crate::compose_story(&doc, sid, &ComposeOptions::default()); + let cell = &composed.frames[0].tables[0].cells[0]; + assert!(cell.rect.y0 > 100.0, "the table sits at the bottom: {:?}", cell.rect); + let s = &cell.diagonals[0]; + assert_eq!((s.a, s.b), (Point::new(cell.rect.x0, cell.rect.y0), Point::new(cell.rect.x1, cell.rect.y1))); +} + #[test] fn merged_cell_keeps_explicit_border_suppression() { let mut table = Table::new(77, 2, 2, 0, 0, 100.0); diff --git a/crates/doc/src/swatch_refs.rs b/crates/doc/src/swatch_refs.rs index b3a885f89..2c9af65b8 100644 --- a/crates/doc/src/swatch_refs.rs +++ b/crates/doc/src/swatch_refs.rs @@ -174,6 +174,7 @@ impl Names<'_> { for s in &mut c.strokes { self.cell_stroke(s); } + self.cell_stroke(&mut c.diagonal.stroke); } } /// One story's own text, objects and tables (cell and note text are visited separately). @@ -239,8 +240,8 @@ impl Document { /// Point every reference to swatch `from` at `to`: tints based on it, colour groups, inks, /// styles, page items (fills, strokes, gaps, effects, column rules, the swatch an image is /// coloured with), text, kenten and ruby colours, rules, shading, borders and border gaps, - /// tables (with stroke gaps and cell images), footnotes, gradient stops, endnotes and the - /// footnote rule. The swatch itself is renamed by the caller. + /// tables (with stroke gaps, diagonal lines and cell images), footnotes, gradient stops, + /// endnotes and the footnote rule. The swatch itself is renamed by the caller. pub fn rename_swatch_refs(&mut self, from: &str, to: &str) { if from == to { return; diff --git a/crates/doc/src/table.rs b/crates/doc/src/table.rs index 4c726b743..1926cf1df 100644 --- a/crates/doc/src/table.rs +++ b/crates/doc/src/table.rs @@ -22,7 +22,7 @@ mod grid; mod merge; mod story; -pub use cell::{AltFills, AltStrokes, Cell, CellStroke, Column, Row, RowHeightMode, RowKind, TableOptions}; +pub use cell::{AltFills, AltStrokes, Cell, CellDiagonal, CellStroke, Column, DiagonalLines, Row, RowHeightMode, RowKind, TableOptions}; pub use grid::CellRange; /// Most rows a table holds, as InDesign allows. @@ -366,4 +366,27 @@ mod tests { assert_eq!(back, explicit); assert_eq!(back.blank_like().border_overrides, explicit.border_overrides); } + + #[test] + fn cell_diagonal_lines_roundtrip_and_run_corner_to_corner() { + let plain = serde_json::to_value(Cell::default()).unwrap(); + assert!(plain.get("diagonal").is_none(), "a cell without diagonal lines saves none"); + let diagonal = CellDiagonal { lines: DiagonalLines::Crossed, stroke: CellStroke { weight: 2.0, ..Default::default() }, in_front: false }; + let cell = Cell { diagonal: diagonal.clone(), ..Cell::default() }; + let back: Cell = serde_json::from_str(&serde_json::to_string(&cell).unwrap()).unwrap(); + assert_eq!(back.diagonal, diagonal); + assert_eq!(back.blank_like().diagonal, diagonal, "new cells take the cell's formatting"); + let r = designcraft_geom::Rect::new(10.0, 20.0, 110.0, 70.0); + let p = designcraft_geom::Point::new; + let down = (p(10.0, 20.0), p(110.0, 70.0)); + let up = (p(110.0, 20.0), p(10.0, 70.0)); + for (lines, want) in [ + (DiagonalLines::None, vec![]), + (DiagonalLines::TopLeft, vec![down]), + (DiagonalLines::TopRight, vec![up]), + (DiagonalLines::Crossed, vec![down, up]), + ] { + assert_eq!(CellDiagonal { lines, ..Default::default() }.segments(r), want, "{lines:?}"); + } + } } diff --git a/crates/doc/src/table/cell.rs b/crates/doc/src/table/cell.rs index ac022a7a8..628892af6 100644 --- a/crates/doc/src/table/cell.rs +++ b/crates/doc/src/table/cell.rs @@ -74,6 +74,55 @@ impl Default for CellStroke { } } +/// Cell Options › Diagonal Lines: the diagonals drawn across a cell. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum DiagonalLines { + #[default] + None, + /// From the top left corner to the bottom right corner. + TopLeft, + /// From the top right corner to the bottom left corner. + TopRight, + /// Both diagonals. + Crossed, +} + +/// A cell's diagonal lines, their stroke, and whether they are drawn in front of the cell's +/// contents (Draw › Diagonal In Front) or behind them (Content In Front). +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase", default)] +pub struct CellDiagonal { + pub lines: DiagonalLines, + pub stroke: CellStroke, + pub in_front: bool, +} + +impl Default for CellDiagonal { + fn default() -> Self { + CellDiagonal { lines: DiagonalLines::None, stroke: CellStroke::default(), in_front: true } + } +} + +impl CellDiagonal { + pub fn is_default(&self) -> bool { + *self == CellDiagonal::default() + } + + /// The diagonals' ends in the cell rectangle `r`, as (start, end) pairs. + pub fn segments(&self, r: designcraft_geom::Rect) -> Vec<(designcraft_geom::Point, designcraft_geom::Point)> { + use designcraft_geom::Point; + let down = (Point::new(r.x0, r.y0), Point::new(r.x1, r.y1)); + let up = (Point::new(r.x1, r.y0), Point::new(r.x0, r.y1)); + match self.lines { + DiagonalLines::None => vec![], + DiagonalLines::TopLeft => vec![down], + DiagonalLines::TopRight => vec![up], + DiagonalLines::Crossed => vec![down, up], + } + } +} + impl CellStroke { pub fn none() -> Self { CellStroke { weight: 0.0, ..Default::default() } @@ -207,6 +256,9 @@ pub struct Cell { /// content box, origin at the box's top left). #[serde(default, skip_serializing_if = "Option::is_none")] pub graphic: Option, + /// Cell Options › Diagonal Lines. + #[serde(default, skip_serializing_if = "CellDiagonal::is_default")] + pub diagonal: CellDiagonal, } impl Default for Cell { @@ -228,6 +280,7 @@ impl Default for Cell { stroke_defined: [false; 4], style: String::new(), graphic: None, + diagonal: CellDiagonal::default(), } } } diff --git a/crates/engine/src/cmd/export/formats.rs b/crates/engine/src/cmd/export/formats.rs index 915954cff..2f9d9f88e 100644 --- a/crates/engine/src/cmd/export/formats.rs +++ b/crates/engine/src/cmd/export/formats.rs @@ -438,6 +438,36 @@ mod pptx_tests { assert!(s.execute("file.exportPptx", &json!({"pages": [9]})).is_err()); } + #[test] + fn cell_diagonal_lines_export_as_cell_diagonal_borders() { + let mut s = Session::new(); + s.execute("file.new", &json!({})).unwrap(); + let r = s.execute("frame.create", &json!({"rect": [72, 72, 500, 400], "content": "text", "text": ""})).unwrap(); + s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 0})).unwrap(); + s.execute("table.insert", &json!({"rows": 2, "cols": 2})).unwrap(); + for (row, col, lines) in [(0, 0, "topLeft"), (0, 1, "topRight"), (1, 0, "crossed")] { + s.execute("table.setCell", &json!({"row": row, "col": col, "diagonal": {"lines": lines, "weight": 3}})).unwrap(); + } + let r = s.execute("file.exportPptx", &json!({})).unwrap(); + let x = read(&mut unzip(r["base64"].as_str().unwrap()), "ppt/slides/slide1.xml"); + let cells: Vec<&str> = x.split("").filter(|c| c.contains(" = cells.iter().map(|c| has(c)).collect(); + assert_eq!(got, [(true, false), (false, true), (true, true), (false, false)], "{x}"); + // The diagonals follow the four edges and come before the cell's fill, in the schema's order. + let c = cells[2]; + let at = |tag: &str| c.find(tag).unwrap_or(usize::MAX); + assert!(at(" at(", + stroke: StrokeEdit, + in_front: Option, +} + +impl DiagonalEdit { + fn parse(doc: &Document, v: &Value, cmd: &str) -> Result { + if !v.is_object() { + return Err(bad(cmd, "diagonal must be an object")); + } + let lines = match v.get("lines").filter(|l| !l.is_null()) { + Some(Value::String(name)) => match name.as_str() { + "none" => Some(DiagonalLines::None), + "topLeft" => Some(DiagonalLines::TopLeft), + "topRight" => Some(DiagonalLines::TopRight), + "crossed" => Some(DiagonalLines::Crossed), + other => return Err(bad(cmd, format!("unknown diagonal lines `{other}`: none, topLeft, topRight or crossed"))), + }, + Some(other) => return Err(bad(cmd, format!("diagonal lines must be a string, not {other}"))), + None => None, + }; + let in_front = match v.get("inFront").filter(|f| !f.is_null()) { + Some(Value::Bool(b)) => Some(*b), + Some(other) => return Err(bad(cmd, format!("inFront must be true or false, not {other}"))), + None => None, + }; + Ok(DiagonalEdit { lines, stroke: StrokeEdit::parse(doc, v, cmd)?, in_front }) + } + + fn apply(&self, d: &mut designcraft_doc::CellDiagonal) { + if let Some(l) = self.lines { + d.lines = l; + } + d.stroke = self.stroke.apply(d.stroke.clone()); + if let Some(f) = self.in_front { + d.in_front = f; + } + } +} + /// The stroke drawn on side `side` of the owner cell at `(r, c)` (where that side meets its /// first neighbour), as rendering resolves it; the cell's own copy if the side has no stretch. fn drawn_side(t: &Table, owners: &[(usize, usize)], (r, c): (usize, usize), side: usize) -> Option { @@ -247,6 +292,10 @@ pub(super) fn set_cell(s: &mut Session, p: &Value) -> Result { Some(sv) => Some((StrokeEdit::parse(doc, sv, ID)?, EdgeSel::parse(sv.get("edges"), ID)?)), None => None, }; + let diagonal = match p.get("diagonal").filter(|v| !v.is_null()) { + Some(dv) => Some(DiagonalEdit::parse(doc, dv, ID)?), + None => None, + }; let apply = |t: &mut Table| { let owners = t.owners(); let nc = t.ncols(); @@ -323,6 +372,9 @@ pub(super) fn set_cell(s: &mut Session, p: &Value) -> Result { let len = cell.text.len(); cell.text.replace(0..len, tx); } + if let Some(edit) = &diagonal { + edit.apply(&mut cell.diagonal); + } if let Some((edit, _)) = &stroke { for i in 0..4 { if let Some(base) = bases.remove(&(r, c, i)) { @@ -412,6 +464,40 @@ pub(super) fn get_cell_stroke(s: &mut Session, p: &Value) -> Result { Ok(Value::Object(out)) } +/// The diagonal lines of the target cells and their stroke; values that differ are null. The +/// result also names the target cells (`story`, `table`, `rows`, `cols`). +pub(super) fn get_cell_diagonal(s: &mut Session, p: &Value) -> Result { + const ID: &str = "table.getCellDiagonal"; + let g = target(s, p, ID)?; + let st = s.doc()?; + let t = st.doc.story(g.story).and_then(|x| x.tables.get(&g.table)).ok_or_else(|| bad(ID, "no table"))?; + let keys = ["lines", "weight", "color", "tint", "type", "gapColor", "gapTint", "inFront"]; + let mut slots: [Option; 8] = Default::default(); + for (r, c) in t.selected_owners(g.range) { + let Some(cell) = t.cell(r, c) else { continue }; + let d = &cell.diagonal; + let e = &d.stroke; + let values = + [json!(d.lines), json!(e.weight), json!(e.color), json!(e.tint), json!(e.kind), json!(e.gap_color), json!(e.gap_tint), json!(d.in_front)]; + for (slot, v) in slots.iter_mut().zip(values) { + match slot { + None => *slot = Some(v), + Some(cur) if *cur != v => *cur = Value::Null, + _ => {} + } + } + } + let mut out = serde_json::Map::new(); + for (k, v) in keys.iter().zip(slots) { + out.insert((*k).into(), v.unwrap_or(Value::Null)); + } + out.insert("story".into(), json!(g.story.0)); + out.insert("table".into(), json!(g.table)); + out.insert("rows".into(), json!([g.range.r0, g.range.r1])); + out.insert("cols".into(), json!([g.range.c0, g.range.c1])); + Ok(Value::Object(out)) +} + /// Only saturation needs rebasing. Preserve every distinct priority's order and keep /// zero/negative priorities untouched; the work is bounded by the table's edges. fn next_cell_stroke_priority(t: &mut Table) -> i32 { diff --git a/crates/engine/src/cmd/table/options.rs b/crates/engine/src/cmd/table/options.rs index 867c7b87d..95038baf5 100644 --- a/crates/engine/src/cmd/table/options.rs +++ b/crates/engine/src/cmd/table/options.rs @@ -83,7 +83,7 @@ pub(super) fn get(s: &mut Session, p: &Value) -> Result { .filter_map(|(r, c)| { let cell = t.cell(r, c)?; Some(json!({"row": r, "col": c, "rowSpan": cell.row_span, "colSpan": cell.col_span, "text": cell.text.text, "fill": cell.fill, - "insets": cell.insets, "vj": cell.vj, "firstBaseline": cell.first_baseline, "firstBaselineMin": cell.first_baseline_min, "rotation": cell.rotation, "style": cell.style})) + "insets": cell.insets, "vj": cell.vj, "firstBaseline": cell.first_baseline, "firstBaselineMin": cell.first_baseline_min, "rotation": cell.rotation, "style": cell.style, "diagonal": cell.diagonal})) }) .collect(); out["cells"] = json!(cells); diff --git a/crates/engine/src/cmd/table/registry.rs b/crates/engine/src/cmd/table/registry.rs index 0c27e498d..be0d2fc0b 100644 --- a/crates/engine/src/cmd/table/registry.rs +++ b/crates/engine/src/cmd/table/registry.rs @@ -1,4 +1,4 @@ -use super::cell::{get_cell_stroke, set_cell}; +use super::cell::{get_cell_diagonal, get_cell_stroke, set_cell}; use super::content::{drop_cells, place_graphic, sort_rows}; use super::options::{get, options}; use super::selection::{go_to_row, move_rc, select, step_cell, toggle_selection}; @@ -292,7 +292,7 @@ fn table_specs() -> Vec { "Cell Options", [], None, - "{fill?: swatch, tint?: 0..1, insets?: n | [t,l,b,r], vj? | verticalJustification?: top|center|bottom|justify, firstBaseline?: ascent|capHeight|leading|xHeight|fixed|emboxHeight, firstBaselineMin?: pt, rotation?: 0|90|180|270 (Cell Options › Text › Rotation; kept and written back to IDML, composed horizontally for now), text?, stroke?: {weight?, color?: swatch, tint?: 0..1, type?: solid|dashed|dotted|thickThin|thinThick|thinThin|thickThick|thinThickThin|thickThinThick|wavy|hashed | {kind:…}, gapColor?: swatch, gapTint?: 0..1, edges?: name | [names] (all|outer|inner|top|left|bottom|right|innerHorizontal|innerVertical; default all)}, story?, table?, rows?: [a, b] | row?, cols?: [a, b] | col? (the target cells; default: the selection)} — top/left/bottom/right are the target range's outer sides, innerHorizontal/innerVertical the lines between its rows/columns", + "{fill?: swatch, tint?: 0..1, insets?: n | [t,l,b,r], vj? | verticalJustification?: top|center|bottom|justify, firstBaseline?: ascent|capHeight|leading|xHeight|fixed|emboxHeight, firstBaselineMin?: pt, rotation?: 0|90|180|270 (Cell Options › Text › Rotation; kept and written back to IDML, composed horizontally for now), text?, stroke?: {weight?, color?: swatch, tint?: 0..1, type?: solid|dashed|dotted|thickThin|thinThick|thinThin|thickThick|thinThickThin|thickThinThick|wavy|hashed | {kind:…}, gapColor?: swatch, gapTint?: 0..1, edges?: name | [names] (all|outer|inner|top|left|bottom|right|innerHorizontal|innerVertical; default all)}, diagonal?: {lines?: none|topLeft|topRight|crossed (Cell Options › Diagonal Lines: top left to bottom right, top right to bottom left, or both), weight?, color?, tint?, type?, gapColor?, gapTint? (as stroke), inFront?: bool (true: Diagonal In Front, false: Content In Front)}, story?, table?, rows?: [a, b] | row?, cols?: [a, b] | col? (the target cells; default: the selection)} — top/left/bottom/right are the target range's outer sides, innerHorizontal/innerVertical the lines between its rows/columns", in_table, set_cell ), @@ -305,6 +305,15 @@ fn table_specs() -> Vec { in_table_or_ids, get_cell_stroke ), + cmd!( + query "table.getCellDiagonal", + "Get Cell Diagonal Lines", + [], + None, + "{story?, table?, rows?, cols?} → {lines, weight, color, tint, type, gapColor, gapTint, inFront} of the target cells' diagonal lines (a value that differs between them is null), with story, table, rows: [a, b] and cols: [a, b] naming the target cells", + in_table_or_ids, + get_cell_diagonal + ), cmd!( "table.setRowHeight", "Row Height", diff --git a/crates/engine/src/cmd/table/styles.rs b/crates/engine/src/cmd/table/styles.rs index 046904fef..008b8f00f 100644 --- a/crates/engine/src/cmd/table/styles.rs +++ b/crates/engine/src/cmd/table/styles.rs @@ -300,6 +300,54 @@ mod style_tests { assert_eq!(t.cell(1, 0).unwrap().first_baseline, designcraft_doc::FirstBaseline::Ascent); } + #[test] + fn diagonal_lines_are_a_cell_option_of_the_target_cells() { + use designcraft_doc::DiagonalLines; + let mut s = Session::new(); + s.execute("file.new", &json!({})).unwrap(); + let r = s.execute("frame.create", &json!({"rect": [72, 72, 500, 400], "content": "text", "text": ""})).unwrap(); + let sid = designcraft_doc::StoryId(r["story"].as_u64().unwrap()); + s.execute("text.select", &json!({"story": sid.0, "anchor": 0, "focus": 0})).unwrap(); + s.execute("table.insert", &json!({"rows": 2, "cols": 2})).unwrap(); + let fresh = s.execute("table.getCellDiagonal", &json!({})).unwrap(); + assert_eq!((&fresh["lines"], &fresh["weight"], &fresh["inFront"]), (&json!("none"), &json!(1.0), &json!(true))); + let p = json!({"rows": [0, 0], "cols": [0, 1], "diagonal": {"lines": "crossed", "weight": 2, "color": "[Paper]", "type": "dotted", "inFront": false}}); + s.execute("table.setCell", &p).unwrap(); + let cell = |s: &Session, r: usize, c: usize| { + s.doc().unwrap().doc.story(sid).unwrap().tables.values().next().unwrap().cell(r, c).unwrap().diagonal.clone() + }; + let d = cell(&s, 0, 1); + assert_eq!( + (d.lines, d.stroke.weight, d.stroke.color.as_str(), &d.stroke.kind, d.in_front), + (DiagonalLines::Crossed, 2.0, "[Paper]", &designcraft_doc::StrokeType::Dotted, false) + ); + assert!(cell(&s, 1, 0).is_default(), "other cells keep none"); + // Only the attributes given change. + s.execute("table.setCell", &json!({"row": 0, "col": 0, "diagonal": {"lines": "topRight"}})).unwrap(); + let d = cell(&s, 0, 0); + assert_eq!((d.lines, d.stroke.weight, d.in_front), (DiagonalLines::TopRight, 2.0, false)); + let got = s.execute("table.getCellDiagonal", &json!({"rows": [0, 0], "cols": [0, 1]})).unwrap(); + assert_eq!( + (&got["lines"], &got["weight"], &got["color"], &got["inFront"]), + (&serde_json::Value::Null, &json!(2.0), &json!("[Paper]"), &json!(false)), + "{got}" + ); + let tid = s.doc().unwrap().doc.story(sid).unwrap().tables.keys().next().copied().unwrap(); + assert_eq!( + (&got["story"], &got["table"], &got["rows"], &got["cols"]), + (&json!(sid.0), &json!(tid), &json!([0, 0]), &json!([0, 1])), + "the result names the target cells" + ); + let shown = s.execute("table.get", &json!({})).unwrap()["cells"][1]["diagonal"].clone(); + assert_eq!((&shown["lines"], &shown["inFront"]), (&json!("crossed"), &json!(false))); + for bad in [json!({"lines": "x"}), json!({"lines": 1}), json!({"inFront": "yes"}), json!({"weight": -1}), json!("crossed")] { + assert!(s.execute("table.setCell", &json!({"row": 0, "col": 0, "diagonal": bad})).is_err(), "{bad}"); + } + assert_eq!(cell(&s, 0, 0).lines, DiagonalLines::TopRight, "a refused edit changes nothing"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(cell(&s, 0, 0).lines, DiagonalLines::Crossed, "one undo step per edit"); + } + #[test] fn cell_and_table_styles_apply_and_follow_edits() { let mut s = Session::new(); diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rs index a851fcf8d..45090648a 100644 --- a/crates/pdf/src/tests.rs +++ b/crates/pdf/src/tests.rs @@ -267,6 +267,29 @@ fn tables_export_cell_text() { } } +#[test] +fn cell_diagonal_lines_export_in_front_of_or_behind_the_cell_text() { + let export = |lines, in_front| { + let mut d = Document::new(&NewDocument::default()); + let lid = d.default_layer(); + let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(36.0, 36.0, 336.0, 400.0), lid, "", ParaFormat::default()).unwrap(); + let mut t = designcraft_doc::Table::new(9, 1, 1, 0, 0, 200.0); + let cell = t.cell_mut(0, 0).unwrap(); + cell.text.insert(0, "Ink"); + let stroke = designcraft_doc::CellStroke { weight: 3.0, ..Default::default() }; + cell.diagonal = designcraft_doc::CellDiagonal { lines, stroke, in_front }; + d.story_mut(sid).unwrap().insert_table(0, t); + let bytes = export_pdf(&d, &Cache::new(), &PdfOptions::default()).unwrap(); + // The table's edges are 1 pt; the diagonals are the 3 pt strokes. + paint_order(&bytes).into_iter().filter(|(op, w)| op.ends_with("text") || *w == 3.0).map(|(op, _)| op).collect::>() + }; + use designcraft_doc::DiagonalLines; + let (text, line) = ("fill text".to_string(), "stroke path".to_string()); + assert_eq!(export(DiagonalLines::None, true), [text.clone(), text.clone(), text.clone()]); + assert_eq!(export(DiagonalLines::Crossed, true), [text.clone(), text.clone(), text.clone(), line.clone(), line.clone()], "Diagonal In Front"); + assert_eq!(export(DiagonalLines::TopLeft, false), [line.clone(), text.clone(), text.clone(), text.clone()], "Content In Front"); +} + #[test] fn drop_cap_text_extracts_in_order() { let mut d = Document::new(&NewDocument::default()); diff --git a/crates/pdf/src/text.rs b/crates/pdf/src/text.rs index bf32f1f3b..315291c1c 100644 --- a/crates/pdf/src/text.rs +++ b/crates/pdf/src/text.rs @@ -370,72 +370,88 @@ impl Exporter<'_> { } } for c in &t.cells { + if !c.diagonals_in_front { + self.cell_diagonals(s, c); + } self.table_cell(s, c); + if c.diagonals_in_front { + self.cell_diagonals(s, c); + } } for seg in &t.strokes { - let st = &seg.stroke; - let Some(col) = self.swatch_color(&st.color, st.tint) else { continue }; - let kind = self.doc.stroke_kind(&st.kind); - let mut bp = BezPath::new(); - bp.move_to(seg.a); - bp.line_to(seg.b); - let Some(p) = to_path(&bp) else { continue }; - // Butt-ended fills close the table's corners the way square caps do. - let (ca, cb) = t.corner_capped(seg); - let mut capped = BezPath::new(); - capped.move_to(ca); - capped.line_to(cb); - let Some(cp) = to_path(&capped) else { continue }; - // Gap colour under dashes, dots and stripes: the whole edge, solid. - if !matches!(kind, designcraft_doc::StrokeType::Solid) - && st.gap_color != designcraft_color::swatch::NONE - && let Some(gap) = self.swatch_color(&st.gap_color, st.gap_tint) - { - s.set_fill(None); - s.set_stroke(Some(Stroke { - paint: gap.into(), - width: st.weight as f32, - line_cap: krilla::paint::LineCap::Butt, - ..Default::default() - })); - s.draw_path(&cp); - s.set_stroke(None); - } - // Stripes, wavy and hash types are fills along the edge. - if let Some(o) = kind.outline(&capped, st.weight, 0.05) - && let Some(op) = to_path(&o) - { - s.set_stroke(None); - s.set_fill(Some(solid_fill(col, 1.0))); - s.draw_path(&op); - s.set_fill(None); - continue; - } - let (cap, dash) = match &kind { - designcraft_doc::StrokeType::Dashed { pattern } - if designcraft_doc::StrokeType::expandable_dashes(pattern, seg.a.distance(seg.b)) => - { - let mut pat: Vec = pattern.iter().map(|v| v.max(0.0) as f32).collect(); - if pat.len() % 2 == 1 { - pat.extend(pat.clone()); - } - (krilla::paint::LineCap::Butt, Some(krilla::paint::StrokeDash { array: pat, offset: 0.0 })) - } - designcraft_doc::StrokeType::Dotted - if designcraft_doc::StrokeType::expandable_dashes(&[0.0, st.weight * 2.0], seg.a.distance(seg.b)) => - { - (krilla::paint::LineCap::Round, Some(krilla::paint::StrokeDash { array: vec![0.0, (st.weight * 2.0) as f32], offset: 0.0 })) - } - _ => (krilla::paint::LineCap::Square, None), - }; - s.set_fill(None); - s.set_stroke(Some(Stroke { paint: col.into(), width: st.weight as f32, line_cap: cap, dash, ..Default::default() })); - s.draw_path(&p); - s.set_stroke(None); + self.cell_stroke(s, seg, t.corner_capped(seg)); } } } + /// A cell's diagonal lines, clipped to the cell so their caps stay inside it. + fn cell_diagonals(&mut self, s: &mut Surface, c: &designcraft_compose::PlacedCell) { + if c.diagonals.is_empty() { + return; + } + let Some(clip) = to_path(&c.rect.to_path(0.1)) else { return }; + s.push_clip_path(&clip, &krilla::paint::FillRule::NonZero); + for seg in &c.diagonals { + self.cell_stroke(s, seg, (seg.a, seg.b)); + } + s.pop(); + } + + /// One cell edge or diagonal: the gap color, then the stroke type. `capped` holds the ends the + /// butt-ended fills (stripes, wavy, hash, the gap color) run between. + fn cell_stroke(&mut self, s: &mut Surface, seg: &designcraft_compose::StrokeSeg, capped: (designcraft_geom::Point, designcraft_geom::Point)) { + let st = &seg.stroke; + let Some(col) = self.swatch_color(&st.color, st.tint) else { return }; + let kind = self.doc.stroke_kind(&st.kind); + let mut bp = BezPath::new(); + bp.move_to(seg.a); + bp.line_to(seg.b); + let Some(p) = to_path(&bp) else { return }; + // Butt-ended fills close the table's corners the way square caps do. + let (ca, cb) = capped; + let mut capped = BezPath::new(); + capped.move_to(ca); + capped.line_to(cb); + let Some(cp) = to_path(&capped) else { return }; + // Gap colour under dashes, dots and stripes: the whole edge, solid. + if !matches!(kind, designcraft_doc::StrokeType::Solid) + && st.gap_color != designcraft_color::swatch::NONE + && let Some(gap) = self.swatch_color(&st.gap_color, st.gap_tint) + { + s.set_fill(None); + s.set_stroke(Some(Stroke { paint: gap.into(), width: st.weight as f32, line_cap: krilla::paint::LineCap::Butt, ..Default::default() })); + s.draw_path(&cp); + s.set_stroke(None); + } + // Stripes, wavy and hash types are fills along the edge. + if let Some(o) = kind.outline(&capped, st.weight, 0.05) + && let Some(op) = to_path(&o) + { + s.set_stroke(None); + s.set_fill(Some(solid_fill(col, 1.0))); + s.draw_path(&op); + s.set_fill(None); + return; + } + let (cap, dash) = match &kind { + designcraft_doc::StrokeType::Dashed { pattern } if designcraft_doc::StrokeType::expandable_dashes(pattern, seg.a.distance(seg.b)) => { + let mut pat: Vec = pattern.iter().map(|v| v.max(0.0) as f32).collect(); + if pat.len() % 2 == 1 { + pat.extend(pat.clone()); + } + (krilla::paint::LineCap::Butt, Some(krilla::paint::StrokeDash { array: pat, offset: 0.0 })) + } + designcraft_doc::StrokeType::Dotted if designcraft_doc::StrokeType::expandable_dashes(&[0.0, st.weight * 2.0], seg.a.distance(seg.b)) => { + (krilla::paint::LineCap::Round, Some(krilla::paint::StrokeDash { array: vec![0.0, (st.weight * 2.0) as f32], offset: 0.0 })) + } + _ => (krilla::paint::LineCap::Square, None), + }; + s.set_fill(None); + s.set_stroke(Some(Stroke { paint: col.into(), width: st.weight as f32, line_cap: cap, dash, ..Default::default() })); + s.draw_path(&p); + s.set_stroke(None); + } + fn fill_rect(&self, s: &mut Surface, r: Rect, c: krilla::color::Color) { self.fill_path(s, &r.to_path(0.1), c); } diff --git a/crates/pptx/src/table.rs b/crates/pptx/src/table.rs index 108cdb66f..ecb196fab 100644 --- a/crates/pptx/src/table.rs +++ b/crates/pptx/src/table.rs @@ -167,6 +167,9 @@ fn table(ex: &mut Exporter, t: &TableFrag, m: Affine, k: f64, opacity: f32) { if t.cells.iter().any(|c| c.graphic.is_some()) { ex.warn("graphic cells are exported empty"); } + if t.cells.iter().any(|c| !c.diagonals.is_empty() && !c.diagonals_in_front) { + ex.warn("diagonal lines drawn behind cell contents are exported without that drawing order"); + } let edges_of = EdgeIndex::new(&t.strokes); let id = ex.id(); let mut model = craft_pptx::table::Table { @@ -223,6 +226,10 @@ fn table(ex: &mut Exporter, t: &TableFrag, m: Affine, k: f64, opacity: f32) { edges_of.stroke(a, b) }; cell.borders = ['L', 'R', 'T', 'B'].map(|side| Some(model_border(ex, edge(side), k, opacity))); + // Cell Options › Diagonal Lines. + let diagonal = |down: bool| placed.diagonals.iter().find(|s| ((s.a.x < s.b.x) == (s.a.y < s.b.y)) == down); + cell.diag_down = diagonal(true).map(|seg| model_border(ex, Some(seg), k, opacity)); + cell.diag_up = diagonal(false).map(|seg| model_border(ex, Some(seg), k, opacity)); } } ex.native_shapes.push(craft_pptx::Shape { diff --git a/crates/render/src/tests.rs b/crates/render/src/tests.rs index 4d5ad4926..a07f03a7b 100644 --- a/crates/render/src/tests.rs +++ b/crates/render/src/tests.rs @@ -547,6 +547,55 @@ fn table_edges_paint_gap_colour_between_dashes_and_stripes() { assert!(column.iter().any(|p| ink(*p)) && column.iter().any(|p| cyan(*p)), "stripes and gap: {column:?}"); } +#[test] +fn cell_diagonal_lines_draw_in_front_of_or_behind_the_cell_text() { + let render = |lines, in_front| { + let mut d = Document::new(&NewDocument::default()); + let lid = d.default_layer(); + let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(36.0, 36.0, 336.0, 400.0), lid, "", ParaFormat::default()).unwrap(); + let mut t = designcraft_doc::Table::new(1, 1, 1, 0, 0, 200.0); + t.rows[0].height = 60.0; + t.rows[0].mode = designcraft_doc::RowHeightMode::Exactly; + let cell = t.cell_mut(0, 0).unwrap(); + cell.text.insert(0, "WWWWWWWWWWWWWWWWWWWW"); + cell.text.format_chars(0..20, |f| f.over.size = Some(30.0)); + let stroke = designcraft_doc::CellStroke { weight: 6.0, color: "C=100 M=0 Y=0 K=0".into(), ..Default::default() }; + cell.diagonal = designcraft_doc::CellDiagonal { lines, stroke, in_front }; + d.story_mut(sid).unwrap().insert_table(0, t); + let cache = Cache::new(); + let rect = cache.get(&d, sid, None).frames[0].tables[0].cell(0, 0).unwrap().rect; + let mut r = Renderer::new(); + r.threads = 0; + let img = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap(); + let cyan = |p: [u8; 4]| p[0] < 80 && p[2] > 150; + let inside = |x: f64, y: f64| x > rect.x0 + 4.0 && x < rect.x1 - 4.0 && y > rect.y0 + 4.0 && y < rect.y1 - 4.0; + let count = |a: (f64, f64), b: (f64, f64)| { + (0..=200) + .map(|i| (a.0 + (b.0 - a.0) * i as f64 / 200.0, a.1 + (b.1 - a.1) * i as f64 / 200.0)) + .filter(|&(x, y)| inside(x, y) && cyan(img.pixel(x as u32, y as u32))) + .count() + }; + let down = count((rect.x0, rect.y0), (rect.x1, rect.y1)); + let up = count((rect.x1, rect.y0), (rect.x0, rect.y1)); + // Just past the corner, outside the cell. + let outside = img.pixel((rect.x1 + 2.0) as u32, (rect.y1 + 2.0) as u32); + (down, up, cyan(outside)) + }; + use designcraft_doc::DiagonalLines; + assert_eq!(render(DiagonalLines::None, true), (0, 0, false)); + let (down, up, outside) = render(DiagonalLines::Crossed, true); + assert!(down > 150 && up > 150 && !outside, "crossed: {down} {up} {outside}"); + let (down, up, _) = render(DiagonalLines::TopLeft, true); + // The other diagonal meets this one only where they cross, near the middle. + assert!(down > 150 && up < 40, "top left to bottom right: {down} {up}"); + let (down, up, _) = render(DiagonalLines::TopRight, true); + assert!(down < 40 && up > 150, "top right to bottom left: {down} {up}"); + // The text covers part of the line drawn behind it. + let (behind, _, _) = render(DiagonalLines::TopLeft, false); + let (front, _, _) = render(DiagonalLines::TopLeft, true); + assert!(behind + 10 < front, "content in front: {behind} vs {front}"); +} + #[test] fn degenerate_dash_patterns_draw_solid_and_fill_types_close_table_corners() { let fine = designcraft_doc::StrokeType::Dashed { pattern: vec![1e-6, 1e-6] }; diff --git a/crates/render/src/text.rs b/crates/render/src/text.rs index 52d49a505..f656b1f2b 100644 --- a/crates/render/src/text.rs +++ b/crates/render/src/text.rs @@ -498,6 +498,9 @@ impl Renderer { } } for c in &t.cells { + if !c.diagonals_in_front { + draw_cell_diagonals(ctx, f, xf, c); + } if let Some(g) = &c.graphic { ctx.set_transform(f.view * xf); ctx.push_clip_layer(&c.clip.to_path(0.1)); @@ -507,36 +510,58 @@ impl Renderer { } else if let Some(cft) = c.text.frames.first() { self.draw_text(ctx, f, &c.text, cft, xf * Affine::translate(c.origin.to_vec2())); } + if c.diagonals_in_front { + draw_cell_diagonals(ctx, f, xf, c); + } } ctx.set_transform(f.view * xf); for s in &t.strokes { - let Some(col) = doc.resolve_color(&s.stroke.color, s.stroke.tint) else { continue }; - let kind = doc.stroke_kind(&s.stroke.kind); - let line = kurbo::Line::new(s.a, s.b).to_path(0.1); - // Butt-ended fills close the table's corners the way square caps do. - let (ca, cb) = t.corner_capped(s); - let capped = kurbo::Line::new(ca, cb).to_path(0.1); - // Gap colour under dashes, dots and stripes: the whole edge, solid. - if !matches!(kind, designcraft_doc::StrokeType::Solid) - && let Some(gap) = doc.resolve_color(&s.stroke.gap_color, s.stroke.gap_tint) - { - ctx.set_paint(color_of(&gap, 1.0)); - ctx.set_stroke(kurbo::Stroke::new(s.stroke.weight).with_caps(kurbo::Cap::Butt)); - ctx.stroke_path(&capped); - } - ctx.set_paint(color_of(&col, 1.0)); - // Stripes, wavy and hash types are fills along the edge. - if let Some(o) = kind.outline(&capped, s.stroke.weight, 0.05 * f.px) { - ctx.fill_path(&o); - continue; - } - ctx.set_stroke(cell_stroke(&kind, s.stroke.weight, s.a.distance(s.b))); - ctx.stroke_path(&line); + draw_cell_stroke(ctx, f, s, t.corner_capped(s)); } } } } +/// A cell's diagonal lines, clipped to the cell so their caps stay inside it. +fn draw_cell_diagonals(ctx: &mut RenderContext, f: &Frame, xf: Affine, c: &designcraft_compose::PlacedCell) { + if c.diagonals.is_empty() { + return; + } + ctx.set_transform(f.view * xf); + ctx.push_clip_layer(&c.rect.to_path(0.1)); + for s in &c.diagonals { + draw_cell_stroke(ctx, f, s, (s.a, s.b)); + } + ctx.pop_layer(); +} + +/// One cell edge or diagonal: the gap color, then the stroke type. `capped` holds the ends the +/// butt-ended fills (stripes, wavy, hash, the gap color) run between. +fn draw_cell_stroke(ctx: &mut RenderContext, f: &Frame, s: &designcraft_compose::StrokeSeg, capped: (kurbo::Point, kurbo::Point)) { + let doc = f.doc; + let Some(col) = doc.resolve_color(&s.stroke.color, s.stroke.tint) else { return }; + let kind = doc.stroke_kind(&s.stroke.kind); + let line = kurbo::Line::new(s.a, s.b).to_path(0.1); + // Butt-ended fills close the table's corners the way square caps do. + let capped = kurbo::Line::new(capped.0, capped.1).to_path(0.1); + // Gap colour under dashes, dots and stripes: the whole edge, solid. + if !matches!(kind, designcraft_doc::StrokeType::Solid) + && let Some(gap) = doc.resolve_color(&s.stroke.gap_color, s.stroke.gap_tint) + { + ctx.set_paint(color_of(&gap, 1.0)); + ctx.set_stroke(kurbo::Stroke::new(s.stroke.weight).with_caps(kurbo::Cap::Butt)); + ctx.stroke_path(&capped); + } + ctx.set_paint(color_of(&col, 1.0)); + // Stripes, wavy and hash types are fills along the edge. + if let Some(o) = kind.outline(&capped, s.stroke.weight, 0.05 * f.px) { + ctx.fill_path(&o); + return; + } + ctx.set_stroke(cell_stroke(&kind, s.stroke.weight, s.a.distance(s.b))); + ctx.stroke_path(&line); +} + /// A run's stroke colour, if it has one. fn stroke_of(doc: &designcraft_doc::Document, st: &designcraft_compose::RunStyle) -> Option { if st.stroke == designcraft_color::swatch::NONE { diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index edc5e1812..0b69db95f 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -408,6 +408,11 @@ fn handle_request(app: &mut DesignApp, ctx: &egui::Context, req: &ControlRequest let fields = p.get("fields").cloned().unwrap_or(Value::Null); let d = match id { "frameSize" => crate::dialogs::frame_size_dialog(app, fields), + // Bound to the target cells and document, as Table › Cell Options › Diagonal Lines… opens it. + "diagonalLines" => match crate::dialogs::diagonal_lines_dialog(app, fields) { + Ok(d) => d, + Err(e) => return err(e), + }, "contactSheet" => crate::dialogs::contact_sheet_dialog(app, fields), "fittingOptions" => { let mut d = crate::dialogs::Dialog::new(id, fields); @@ -543,6 +548,25 @@ mod automation_contract_tests { app.run("style.paragraph.edit", json!({"name":designcraft_doc::BASIC_PARAGRAPH,"chars":{"size":18}})).unwrap(); assert_eq!(app.session.doc().unwrap().history.undo.len(), history + 1); } + #[test] + fn diagonal_lines_opened_through_the_control_channel_applies_to_its_target_cells() { + let mut app = app(); + let ctx = egui::Context::default(); + app.run("frame.create", json!({"rect": [72, 72, 400, 400], "content": "text", "caret": true})).unwrap(); + let tid = app.run("table.insert", json!({"rows": 2, "cols": 2})).unwrap()["table"].as_u64().unwrap(); + app.run("table.select", json!({"rows": [0, 0], "cols": [0, 0]})).unwrap(); + let response = call(&mut app, &ctx, "ui.dialog.open", json!({"id": "diagonalLines", "fields": {"lines": "crossed"}})); + assert_eq!(response["ok"], true, "{response}"); + app.run("table.select", json!({"rows": [1, 1], "cols": [1, 1]})).unwrap(); + let response = call(&mut app, &ctx, "ui.dialog.confirm", json!({})); + assert_eq!(response["ok"], true, "{response}"); + let st = app.session.active().unwrap(); + let t = st.doc.stories.values().find_map(|s| s.tables.get(&tid)).unwrap(); + let lines: Vec<_> = t.cells.iter().map(|c| c.diagonal.lines).collect(); + use designcraft_doc::DiagonalLines::{Crossed, None as No}; + assert_eq!(lines, [Crossed, No, No, No]); + } + /// `ui.dialog.open` opens Place Contact Sheet as the menu does: bare numbers are in the /// document's ruler unit, so `1` on an inch document is an inch, not a pica. #[test] diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 327a4623b..336cf6409 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -26,6 +26,10 @@ pub struct Dialog { /// from when it opened, so a bare `50` means what it did then. `None` falls back to `unit`. #[serde(skip)] pub vertical_unit: Option, + /// The document contents the dialog opened with (Diagonal Lines), held while it is open: an + /// edit replaces them, so a dialog whose document holds other contents knows it was edited. + #[serde(skip)] + pub contents: Option>, } impl Dialog { @@ -86,7 +90,7 @@ impl Dialog { if id == "ruby" { fields.entry("section".to_string()).or_insert(json!("cjk.rubyPlacement")); } - Dialog { id: id.into(), fields, unit: Unit::Picas, vertical_unit: None } + Dialog { id: id.into(), fields, unit: Unit::Picas, vertical_unit: None, contents: None } } /// Set a field and report a genuine Find domain/mode transition to the caller. pub(crate) fn set_field(&mut self, key: &str, value: Value) -> bool { @@ -3272,7 +3276,7 @@ pub fn show(app: &mut DesignApp, ctx: &egui::Context) { // The menu items' translations (every language has them), without the ellipsis. "convertTextToTable" => crate::i18n::tr(&app.ui.language, "Convert Text to Table…").trim_end_matches('…').trim_end(), "convertTableToText" => crate::i18n::tr(&app.ui.language, "Convert Table to Text…").trim_end_matches('…').trim_end(), - "cellOptions" => crate::i18n::tr(&app.ui.language, "Cell Options"), + "cellOptions" | "diagonalLines" => crate::i18n::tr(&app.ui.language, "Cell Options"), "createGuides" => crate::i18n::tr(&app.ui.language, "Create Guides"), "marginsAndColumns" => crate::i18n::tr(&app.ui.language, "Margins and Columns"), "textFrameOptions" => crate::i18n::tr(&app.ui.language, "Text Frame Options"), @@ -4161,6 +4165,7 @@ pub fn show(app: &mut DesignApp, ctx: &egui::Context) { "insertTable" => insert_table_dialog(app, ui, &mut d), "convertTextToTable" | "convertTableToText" => convert_table_dialog(app, ui, &mut d), "cellOptions" => cell_options(app, ui, &mut d), + "diagonalLines" => diagonal_lines(app, ui, &mut d), "createGuides" => create_guides_dialog(app, ui, &mut d), "marginsAndColumns" => margins_and_columns_dialog(app, ui, &mut d), "textFrameOptions" => { @@ -4362,7 +4367,7 @@ fn cell_options_edges_changed(app: &mut DesignApp, d: &mut Dialog, edges: &crate let v = cur.get(k).cloned().unwrap_or(Value::Null); // Null shows mixed values; the user can't type it. let field = d.fields.get(k).filter(|f| !f.is_null()); - if field.is_none() || field == seed.get(k) { + if field.is_none_or(|f| same_cell_value(seed.get(k), k, f)) { d.fields.insert(k.into(), v.clone()); } seed.insert(k.into(), v); @@ -4370,13 +4375,19 @@ fn cell_options_edges_changed(app: &mut DesignApp, d: &mut Dialog, edges: &crate d.fields.insert("seed".into(), Value::Object(seed)); } +/// Whether the dialog field `k` holds the cells' value `seed`. The Type list picks a stroke type +/// by name (`"solid"`), and the cells' value is the type itself (`{"kind": "solid"}`). +fn same_cell_value(seed: Option<&Value>, k: &str, v: &Value) -> bool { + seed == Some(v) || (k == "type" && v.as_str().is_some_and(|name| seed == Some(&json!({"kind": name})))) +} + /// Apply the Cell Options fields that differ from the cells' values, as one `table.setCell`. fn confirm_cell_options(app: &mut DesignApp, d: &Dialog) -> Result { let seed = d.fields.get("seed").cloned().unwrap_or(Value::Null); let mut stroke = Map::new(); let mut params = Map::new(); for (k, is_stroke) in CELL_OPTION_KEYS { - let Some(v) = d.fields.get(k).filter(|v| !v.is_null() && seed.get(k) != Some(*v)) else { continue }; + let Some(v) = d.fields.get(k).filter(|v| !v.is_null() && !same_cell_value(seed.get(k), k, v)) else { continue }; match (is_stroke, k) { (true, _) => { stroke.insert(k.into(), v.clone()); @@ -4399,6 +4410,170 @@ fn confirm_cell_options(app: &mut DesignApp, d: &Dialog) -> Result Result { + app.ui.dialog = Some(diagonal_lines_dialog(app, Value::Null)?); + Ok(Value::Null) +} + +/// The Diagonal Lines dialog for the target cells, with the `DIAGONAL_KEYS` values in `params` +/// (from `ui.dialog.open`) entered in place of the cells' values. +pub fn diagonal_lines_dialog(app: &mut DesignApp, params: Value) -> Result { + let cur = app.session.execute("table.getCellDiagonal", &json!({})).map_err(|e| e.to_string())?; + let st = app.session.active().ok_or("no document open")?; + let document = json!({"uid": st.uid, "epoch": st.identity_epoch}); + let contents = st.doc.clone(); + let mut fields = Map::new(); + for k in DIAGONAL_KEYS { + fields.insert(k.into(), cur[k].clone()); + } + fields.insert("seed".into(), Value::Object(fields.clone())); + for k in DIAGONAL_KEYS { + if let Some(v) = params.get(k) { + fields.insert(k.into(), v.clone()); + } + } + fields.insert("document".into(), document); + fields.insert("cells".into(), json!({"story": cur["story"], "table": cur["table"], "rows": cur["rows"], "cols": cur["cols"]})); + let mut d = Dialog::new("diagonalLines", Value::Object(fields)); + d.contents = Some(contents); + Ok(d) +} + +/// Where the document a Diagonal Lines dialog opened in is now. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +enum DiagonalLinesDocument { + /// Active and unchanged since the dialog opened. + Ready, + /// Open, but another document is active. + Inactive, + /// Active, but edited since the dialog opened: the saved cell range may name other cells. + Changed, + /// Closed or reverted. + Gone, +} + +/// An edit gives the document new contents, and a selection change keeps them. The dialog holds +/// the contents it opened with, so no new contents can take their address while it is open. +fn diagonal_lines_document(app: &DesignApp, d: &Dialog) -> DiagonalLinesDocument { + let saved = d.fields.get("document"); + let get = |k: &str| saved.and_then(|s| s.get(k)).and_then(Value::as_u64); + let (Some(uid), Some(epoch), Some(contents)) = (get("uid"), get("epoch"), d.contents.as_ref()) else { + return DiagonalLinesDocument::Gone; + }; + let Some(i) = app.session.documents().iter().position(|st| st.uid == uid && st.identity_epoch == epoch) else { + return DiagonalLinesDocument::Gone; + }; + if app.session.active_index() != Some(i) { + DiagonalLinesDocument::Inactive + } else if !std::sync::Arc::ptr_eq(&app.session.documents()[i].doc, contents) { + DiagonalLinesDocument::Changed + } else { + DiagonalLinesDocument::Ready + } +} + +/// Cell Options › Diagonal Lines: the four line buttons, the Line Stroke fields and Draw. +fn diagonal_lines(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog) { + let lang = app.ui.language.clone(); + let t = crate::theme::Tokens::get(ui.ctx()); + ui.horizontal(|ui| { + for (name, label) in DIAGONAL_LINES { + let on = d.fields.get("lines").and_then(Value::as_str) == Some(name); + let text = crate::i18n::tr(&lang, label).to_string(); + let (r, resp) = ui.allocate_exact_size(egui::vec2(32.0, 32.0), egui::Sense::click()); + resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, on, &text)); + let resp = resp.on_hover_text(&text); + if resp.clicked() { + d.fields.insert("lines".into(), json!(name)); + } + // Enter on a focused line button picks that line and leaves the dialog open. + if resp.has_focus() { + ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Enter)); + } + let p = ui.painter(); + p.rect_filled(r, 2.0, if resp.hovered() { t.hover } else { t.input }); + let cell = r.shrink(7.0); + p.rect_stroke(cell, 0.0, egui::Stroke::new(1.0, t.text_dim), egui::StrokeKind::Inside); + let ink = egui::Stroke::new(1.5, if on { t.accent } else { t.icon }); + if matches!(name, "topLeft" | "crossed") { + p.line_segment([cell.left_top(), cell.right_bottom()], ink); + } + if matches!(name, "topRight" | "crossed") { + p.line_segment([cell.right_top(), cell.left_bottom()], ink); + } + let rim = if on { egui::Stroke::new(2.0, t.accent) } else { egui::Stroke::new(1.0, t.field_border) }; + p.rect_stroke(r, 2.0, rim, egui::StrokeKind::Inside); + } + }); + ui.add_space(10.0); + crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&lang, "Line Stroke")).font(semibold(12.0))); + let values = Value::Object(d.fields.clone()); + if let Some((k, v)) = crate::panels::cell_stroke::stroke_fields(app, ui, "diagonal_lines", &values) { + d.fields.insert(k.into(), v); + } + ui.add_space(10.0); + egui::Grid::new("diagonal_draw").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| { + crate::rtl::label(ui, crate::i18n::tr(&lang, "Draw:")); + let shown = match d.fields.get("inFront").and_then(Value::as_bool) { + Some(true) => crate::i18n::tr(&lang, "Diagonal In Front"), + Some(false) => crate::i18n::tr(&lang, "Content In Front"), + None => "", + } + .to_string(); + craft_ui::ComboBox::from_id_salt("diagonal_draw_order").selected_text(crate::rtl::widget(ui, &shown)).width(140.0).show_ui(ui, |ui| { + for (front, label) in [(true, "Diagonal In Front"), (false, "Content In Front")] { + let text = crate::i18n::tr(&lang, label); + if ui.selectable_label(shown == text, crate::rtl::widget(ui, text)).clicked() { + d.fields.insert("inFront".into(), json!(front)); + } + } + }); + ui.end_row(); + }); +} + +/// Apply the Diagonal Lines fields that differ from the cells' values, as one `table.setCell` +/// on the cells the dialog opened for, in the document it opened in. +fn confirm_diagonal_lines(app: &mut DesignApp, d: &Dialog) -> Result { + match diagonal_lines_document(app, d) { + DiagonalLinesDocument::Ready => {} + DiagonalLinesDocument::Inactive => return Err("Diagonal Lines: the document the dialog opened in is not the active document".into()), + DiagonalLinesDocument::Changed => return Err("Diagonal Lines: the document changed while the dialog was open".into()), + DiagonalLinesDocument::Gone => return Err("Diagonal Lines: the document the dialog opened in was closed or reverted".into()), + } + let Some(Value::Object(cells)) = d.fields.get("cells") else { + return Err("Diagonal Lines: the dialog has no target cells".into()); + }; + let seed = d.fields.get("seed").cloned().unwrap_or(Value::Null); + let mut diagonal = Map::new(); + for k in DIAGONAL_KEYS { + if let Some(v) = d.fields.get(k).filter(|v| !v.is_null() && !same_cell_value(seed.get(k), k, v)) { + diagonal.insert(k.into(), v.clone()); + } + } + if diagonal.is_empty() { + return Ok(Value::Null); + } + let mut params = cells.clone(); + params.insert("diagonal".into(), Value::Object(diagonal)); + app.run("table.setCell", Value::Object(params)) +} + /// Delete absolute pages `pages` as the Pages panel and Layout › Pages › Delete Page do: when /// they hold objects, InDesign's warning asks first, unless it was told not to. pub fn delete_pages(app: &mut DesignApp, pages: Vec) -> Result { @@ -4578,6 +4753,7 @@ fn format_settings(app: &mut DesignApp, ctx: &egui::Context, d: &mut Dialog) { fields: d.fields.get(FORMAT_EDIT).and_then(Value::as_object).cloned().unwrap_or_default(), unit: d.unit, vertical_unit: None, + contents: None, }; let base = json!({}); let cf = CharFields { base: &base, sparse: true }; @@ -4865,6 +5041,18 @@ fn confirm_part1(app: &mut DesignApp, d: Dialog) -> Result { } r } + "diagonalLines" => { + // On an error the dialog stays open to be corrected, unless the document it opened + // in was closed, reverted or edited. + let r = confirm_diagonal_lines(app, &d); + if let Err(e) = &r { + app.status(e.clone()); + if matches!(diagonal_lines_document(app, &d), DiagonalLinesDocument::Ready | DiagonalLinesDocument::Inactive) { + app.ui.dialog = Some(d); + } + } + r + } "textFrameOptions" => { // On an error the dialog stays open to be corrected. let mut d = d; diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs index a7a6e67aa..e432ad07c 100644 --- a/crates/ui-egui/src/dialogs/tests.rs +++ b/crates/ui-egui/src/dialogs/tests.rs @@ -413,6 +413,46 @@ fn cell_options_dialog_draws_and_applies_only_changed_values_to_the_chosen_edges assert!(t.cells.iter().all(|c| c.strokes.iter().all(|e| e.weight == 1.0)), "unchanged values are not applied"); } +#[test] +fn cell_options_ok_edits_nothing_when_the_picked_stroke_type_is_the_cells() { + let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({})).unwrap(); + app.run("frame.create", json!({"rect": [72, 72, 400, 400], "content": "text", "caret": true})).unwrap(); + app.run("table.insert", json!({"rows": 2, "cols": 2})).unwrap(); + app.run("table.select", json!({"what": "table"})).unwrap(); + app.run("app.cellOptionsDialog", json!({})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + assert_eq!(d.fields["seed"]["type"], json!({"kind": "solid"})); + // The Type list picks a stroke type by name. + d.fields.insert("type".into(), json!("solid")); + let (undo, revision) = { + let st = app.session.active().unwrap(); + (st.history.undo.len(), st.revision) + }; + confirm(&mut app).unwrap(); + let st = app.session.active().unwrap(); + assert_eq!((st.history.undo.len(), st.revision), (undo, revision), "no edit and no undo step"); +} + +#[test] +fn cell_options_edge_change_reseeds_a_picked_stroke_type_that_was_the_cells() { + let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({})).unwrap(); + app.run("frame.create", json!({"rect": [72, 72, 400, 400], "content": "text", "caret": true})).unwrap(); + app.run("table.insert", json!({"rows": 2, "cols": 2})).unwrap(); + app.run("table.select", json!({"what": "table"})).unwrap(); + app.run("table.setCell", json!({"stroke": {"type": "dotted", "edges": "innerHorizontal"}})).unwrap(); + app.run("app.cellOptionsDialog", json!({})).unwrap(); + let mut d = app.ui.dialog.take().unwrap(); + cell_options_edges_changed(&mut app, &mut d, &[true, true, true, true, false, false]); + assert_eq!(d.fields["seed"]["type"], json!({"kind": "solid"})); + // Solid picked by name for the outer edges is what they show; the inner horizontal edges + // chosen next show their own type. + d.fields.insert("type".into(), json!("solid")); + cell_options_edges_changed(&mut app, &mut d, &[false, false, false, false, true, false]); + assert_eq!(d.fields["type"], json!({"kind": "dotted"})); +} + #[test] fn cell_options_edge_changes_reseed_every_stroke_field_and_survive_a_bad_seed() { let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); @@ -440,6 +480,222 @@ fn cell_options_edge_changes_reseed_every_stroke_field_and_survive_a_bad_seed() assert_eq!([t.cell(0, 0).unwrap().strokes[2].weight, t.cell(1, 1).unwrap().strokes[0].weight], [1.0; 2]); } +#[test] +fn diagonal_lines_dialog_draws_and_applies_its_values_but_not_a_mixed_one() { + let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({})).unwrap(); + app.run("frame.create", json!({"rect": [72, 72, 400, 400], "content": "text", "caret": true})).unwrap(); + let tid = app.run("table.insert", json!({"rows": 2, "cols": 2})).unwrap()["table"].as_u64().unwrap(); + app.run("table.setCell", json!({"row": 0, "col": 0, "diagonal": {"color": "[Paper]"}})).unwrap(); + app.run("table.select", json!({"what": "table"})).unwrap(); + app.run("app.diagonalLinesDialog", json!({})).unwrap(); + let ctx = dialog_context(""); + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 700.0)); + // The first frame sizes the window without painting it. + dialog_frame(&mut app, &ctx, screen, vec![]); + let labels = dialog_frame(&mut app, &ctx, screen, vec![]); + for shown in ["Line Stroke", "Weight:", "Draw:", "Diagonal In Front"] { + visible_label(&labels, screen, shown); + } + let d = app.ui.dialog.as_ref().unwrap(); + assert_eq!(d.id, "diagonalLines"); + assert_eq!((&d.fields["lines"], &d.fields["color"], &d.fields["inFront"]), (&json!("none"), &Value::Null, &json!(true))); + // The fourth line button, in the row above Line Stroke, is Crossed Diagonal Lines. + let caption = visible_label(&labels, screen, "Line Stroke"); + let gap = ctx.global_style().spacing.item_spacing; + let crossed = egui::pos2(caption.left() + 3.0 * (32.0 + gap.x) + 16.0, caption.top() - 10.0 - gap.y - 16.0); + click_dialog(&mut app, &ctx, screen, crossed); + let d = app.ui.dialog.as_mut().unwrap(); + assert_eq!(d.fields["lines"], json!("crossed")); + d.fields.insert("inFront".into(), json!(false)); + d.fields.insert("weight".into(), json!(0.5)); + confirm(&mut app).unwrap(); + let st = app.session.active().unwrap(); + let t = st.doc.stories.values().find_map(|s| s.tables.get(&tid)).unwrap(); + assert!( + t.cells + .iter() + .all(|c| c.diagonal.lines == designcraft_doc::DiagonalLines::Crossed && !c.diagonal.in_front && c.diagonal.stroke.weight == 0.5) + ); + let colors: Vec<_> = t.cells.iter().map(|c| c.diagonal.stroke.color.as_str()).collect(); + assert_eq!(colors, ["[Paper]", "[Black]", "[Black]", "[Black]"], "a mixed value is left as it is"); +} + +#[test] +fn cell_options_menu_items_need_a_table_target() { + let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({})).unwrap(); + app.run("frame.create", json!({"rect": [72, 72, 400, 400], "content": "text", "caret": true})).unwrap(); + let items = ["app.cellOptionsDialog", "app.diagonalLinesDialog"]; + for id in items { + assert!(!crate::menus::menu_enabled(&app, id), "{id} without a table"); + } + app.run("table.insert", json!({"rows": 2, "cols": 2})).unwrap(); + for id in items { + assert!(crate::menus::menu_enabled(&app, id), "{id} in a table"); + } +} + +#[test] +fn enter_on_a_diagonal_line_button_picks_it_and_leaves_the_dialog_open() { + let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({})).unwrap(); + app.run("frame.create", json!({"rect": [72, 72, 400, 400], "content": "text", "caret": true})).unwrap(); + let tid = app.run("table.insert", json!({"rows": 2, "cols": 2})).unwrap()["table"].as_u64().unwrap(); + app.run("table.select", json!({"what": "table"})).unwrap(); + app.run("app.diagonalLinesDialog", json!({})).unwrap(); + let ctx = dialog_context(""); + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 700.0)); + dialog_frame(&mut app, &ctx, screen, vec![]); + dialog_frame(&mut app, &ctx, screen, vec![]); + let key = |key| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; + // Tab past the title bar and the first line button to Diagonal Line from Top Left to Bottom + // Right, then press Enter. + for _ in 0..3 { + dialog_frame(&mut app, &ctx, screen, vec![key(egui::Key::Tab)]); + dialog_frame(&mut app, &ctx, screen, vec![]); + } + dialog_frame(&mut app, &ctx, screen, vec![key(egui::Key::Enter)]); + dialog_frame(&mut app, &ctx, screen, vec![]); + let d = app.ui.dialog.as_ref().expect("Enter on a line button leaves the dialog open"); + assert_eq!(d.fields["lines"], json!("topLeft")); + let st = app.session.active().unwrap(); + let t = st.doc.stories.values().find_map(|s| s.tables.get(&tid)).unwrap(); + assert!(t.cells.iter().all(|c| c.diagonal.lines == designcraft_doc::DiagonalLines::None), "nothing is applied yet"); + // Enter with no line button focused still confirms. + ctx.memory_mut(|m| { + if let Some(id) = m.focused() { + m.surrender_focus(id); + } + }); + dialog_frame(&mut app, &ctx, screen, vec![key(egui::Key::Enter)]); + assert!(app.ui.dialog.is_none()); + let st = app.session.active().unwrap(); + let t = st.doc.stories.values().find_map(|s| s.tables.get(&tid)).unwrap(); + assert!(t.cells.iter().all(|c| c.diagonal.lines == designcraft_doc::DiagonalLines::TopLeft)); +} + +/// A document holding a 2×2 table with cell (0, 0) selected; returns the table id. +fn table_document_for_diagonals(app: &mut DesignApp) -> u64 { + app.run("file.new", json!({})).unwrap(); + app.run("frame.create", json!({"rect": [72, 72, 400, 400], "content": "text", "caret": true})).unwrap(); + let tid = app.run("table.insert", json!({"rows": 2, "cols": 2})).unwrap()["table"].as_u64().unwrap(); + app.run("table.select", json!({"rows": [0, 0], "cols": [0, 0]})).unwrap(); + tid +} + +/// The diagonal lines of the cells of table `tid` in document `doc`, row by row. +fn diagonal_lines_of(app: &DesignApp, doc: usize, tid: u64) -> Vec { + let st = &app.session.documents()[doc]; + let t = st.doc.stories.values().find_map(|s| s.tables.get(&tid)).unwrap(); + t.cells.iter().map(|c| c.diagonal.lines).collect() +} + +#[test] +fn diagonal_lines_dialog_applies_to_the_cells_and_document_it_opened_for() { + use designcraft_doc::DiagonalLines::{Crossed, None as No, TopRight}; + let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); + let a = table_document_for_diagonals(&mut app); + // The selection moves to another cell while the dialog is open: OK still edits cell (0, 0). + app.run("app.diagonalLinesDialog", json!({})).unwrap(); + app.run("table.select", json!({"rows": [1, 1], "cols": [1, 1]})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("lines".into(), json!("crossed")); + confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!(diagonal_lines_of(&app, 0, a), [Crossed, No, No, No]); + // Another document with a table selection becomes active: OK is refused and changes neither + // document, and the dialog stays open. + app.run("table.select", json!({"rows": [0, 0], "cols": [0, 0]})).unwrap(); + app.run("app.diagonalLinesDialog", json!({})).unwrap(); + let b = table_document_for_diagonals(&mut app); + app.ui.dialog.as_mut().unwrap().fields.insert("lines".into(), json!("topRight")); + assert!(confirm(&mut app).is_err()); + assert!(app.ui.dialog.is_some(), "the dialog stays open while its document is open"); + assert_eq!(diagonal_lines_of(&app, 1, b), [No; 4]); + assert_eq!(diagonal_lines_of(&app, 0, a), [Crossed, No, No, No]); + // Back in the first document, OK applies there. + app.run("file.activate", json!({"index": 0})).unwrap(); + confirm(&mut app).unwrap(); + assert_eq!(diagonal_lines_of(&app, 0, a), [TopRight, No, No, No]); + // A row is added above the target cell while the dialog is open: the document changed and the + // saved range would name another cell, so OK is refused, nothing changes and the dialog closes. + app.run("app.diagonalLinesDialog", json!({})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("lines".into(), json!("crossed")); + app.run("table.insertRowAbove", json!({})).unwrap(); + assert!(confirm(&mut app).is_err()); + assert!(app.ui.dialog.is_none(), "a dialog whose table changed closes"); + // The new row takes the formatting of the row below it. + assert_eq!(diagonal_lines_of(&app, 0, a), [TopRight, No, TopRight, No, No, No]); + // The first document is closed while the dialog is open: OK is refused and the dialog closes. + app.run("app.diagonalLinesDialog", json!({})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("lines".into(), json!("crossed")); + app.run("file.close", json!({"index": 0})).unwrap(); + assert!(confirm(&mut app).is_err()); + assert!(app.ui.dialog.is_none(), "a dialog whose document was closed closes"); + assert_eq!(diagonal_lines_of(&app, 0, b), [No; 4]); +} + +#[test] +fn diagonal_lines_dialog_is_refused_when_new_contents_reuse_the_old_address() { + use designcraft_doc::DiagonalLines::None as No; + let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); + let tid = table_document_for_diagonals(&mut app); + app.run("app.diagonalLinesDialog", json!({})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("lines".into(), json!("crossed")); + // A row is added above the target cell, and the edit is undone: the contents the dialog + // opened with are back, and the undo stack no longer holds them. + app.run("table.insertRowAbove", json!({})).unwrap(); + let edited = (*app.session.active().unwrap().doc).clone(); + app.session.execute("edit.undo", &json!({})).unwrap(); + // The edited contents are written in place when nothing else holds the old contents, at the + // address an allocation that reuses freed memory would give them. The saved cell range now + // names the new row. + let st = app.session.active_mut().unwrap(); + *std::sync::Arc::make_mut(&mut st.doc) = edited; + assert!(confirm(&mut app).is_err()); + assert!(app.ui.dialog.is_none(), "a dialog whose table changed closes"); + assert_eq!(diagonal_lines_of(&app, 0, tid), [No; 6]); +} + +#[test] +fn diagonal_lines_dialog_ok_edits_nothing_when_the_picked_stroke_type_is_the_cells() { + let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); + table_document_for_diagonals(&mut app); + app.run("app.diagonalLinesDialog", json!({})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + assert_eq!(d.fields["seed"]["type"], json!({"kind": "solid"})); + // The Type list picks a stroke type by name. + d.fields.insert("type".into(), json!("solid")); + let (undo, revision) = { + let st = app.session.active().unwrap(); + (st.history.undo.len(), st.revision) + }; + confirm(&mut app).unwrap(); + let st = app.session.active().unwrap(); + assert_eq!((st.history.undo.len(), st.revision), (undo, revision), "no edit and no undo step"); +} + +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn diagonal_lines_dialog_is_refused_after_its_document_is_reverted() { + use designcraft_doc::DiagonalLines::None as No; + let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); + let tid = table_document_for_diagonals(&mut app); + let dir = tempfile::tempdir().unwrap(); + app.run("file.saveAs", json!({"path": dir.path().join("diagonal.designcraft")})).unwrap(); + app.run("table.setCell", json!({"row": 1, "col": 1, "text": "unsaved"})).unwrap(); + app.run("app.diagonalLinesDialog", json!({})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("lines".into(), json!("crossed")); + app.session.execute("file.revert", &json!({})).unwrap(); + // The reverted document holds the same table; a selection in it does not let OK through. + let story = app.session.active().unwrap().doc.stories.iter().find(|(_, s)| s.tables.contains_key(&tid)).map(|(k, _)| k.0).unwrap(); + app.run("text.select", json!({"story": story, "anchor": 0, "focus": 0})).unwrap(); + app.run("table.select", json!({"rows": [0, 0], "cols": [0, 0]})).unwrap(); + assert!(confirm(&mut app).is_err()); + assert!(app.ui.dialog.is_none(), "a dialog whose document was reverted closes"); + assert_eq!(diagonal_lines_of(&app, 0, tid), [No; 4]); +} + #[test] fn preferences_ok_saves_a_story_editor_size_that_loads_back() { // `ui.dialog.set` takes any value; a size that isn't finite is saved as `null`. diff --git a/crates/ui-egui/src/i18n/ar.rs b/crates/ui-egui/src/i18n/ar.rs index b9b10c93c..d6d4a5475 100644 --- a/crates/ui-egui/src/i18n/ar.rs +++ b/crates/ui-egui/src/i18n/ar.rs @@ -1948,6 +1948,15 @@ pub(super) const TABLE: &[(&str, &str)] = &[ ("Continue from Previous Number", "المتابعة من الرقم السابق"), ("Start At", "البدء عند"), ("Strokes and Fills…", "الحدود والتعبئة…"), + ("Diagonal Lines…", "الخطوط القطرية…"), + ("No Diagonal Lines", "بلا خطوط قطرية"), + ("Diagonal Line from Top Left to Bottom Right", "خط قطري من أعلى اليسار إلى أسفل اليمين"), + ("Diagonal Line from Top Right to Bottom Left", "خط قطري من أعلى اليمين إلى أسفل اليسار"), + ("Crossed Diagonal Lines", "خطوط قطرية متقاطعة"), + ("Line Stroke", "حد الخط"), + ("Draw:", "الرسم:"), + ("Diagonal In Front", "القطري في الأمام"), + ("Content In Front", "المحتوى في الأمام"), ("Cell Stroke", "حد الخلية"), ("Cell Fill", "تعبئة الخلية"), ("Cell edges", "حواف الخلية"), diff --git a/crates/ui-egui/src/i18n/de.rs b/crates/ui-egui/src/i18n/de.rs index 1430d8d9b..0b8b29745 100644 --- a/crates/ui-egui/src/i18n/de.rs +++ b/crates/ui-egui/src/i18n/de.rs @@ -1962,6 +1962,15 @@ pub(super) const TABLE: &[(&str, &str)] = &[ ("Fancy", "Verziert"), ("Gap Tint:", "Lückenfarbton:"), ("Strokes and Fills…", "Konturen und Flächen …"), + ("Diagonal Lines…", "Diagonale Linien …"), + ("No Diagonal Lines", "Keine diagonalen Linien"), + ("Diagonal Line from Top Left to Bottom Right", "Diagonale Linie von links oben nach rechts unten"), + ("Diagonal Line from Top Right to Bottom Left", "Diagonale Linie von rechts oben nach links unten"), + ("Crossed Diagonal Lines", "Gekreuzte diagonale Linien"), + ("Line Stroke", "Linienkontur"), + ("Draw:", "Zeichnen:"), + ("Diagonal In Front", "Diagonale im Vordergrund"), + ("Content In Front", "Inhalt im Vordergrund"), ("Cell Stroke", "Zellkontur"), ("Cell Fill", "Zellfläche"), ("Cell edges", "Zellkanten"), diff --git a/crates/ui-egui/src/i18n/fr.rs b/crates/ui-egui/src/i18n/fr.rs index 8a7c537ce..cdeaa2ab4 100644 --- a/crates/ui-egui/src/i18n/fr.rs +++ b/crates/ui-egui/src/i18n/fr.rs @@ -142,6 +142,7 @@ pub(super) const TABLE: &[(&str, &str)] = &[ ("Generate Index", "Générer l'index"), ("Generate Live Caption", "Générer une légende dynamique"), ("Get Cell Stroke", "Obtenir le contour de cellule"), + ("Get Cell Diagonal Lines", "Obtenir les lignes diagonales de cellule"), ("Get Tabs", "Obtenir les tabulations"), ("Global Light", "Lumière globale"), ("Grab bag", "Liste"), diff --git a/crates/ui-egui/src/i18n/it.rs b/crates/ui-egui/src/i18n/it.rs index ae9aac01a..ed5364b0e 100644 --- a/crates/ui-egui/src/i18n/it.rs +++ b/crates/ui-egui/src/i18n/it.rs @@ -2008,6 +2008,15 @@ pub(super) const TABLE: &[(&str, &str)] = &[ ("Continue from Previous Number", "Continua dal numero precedente"), ("Start At", "Inizia da"), ("Strokes and Fills…", "Tracce e riempimenti…"), + ("Diagonal Lines…", "Linee diagonali…"), + ("No Diagonal Lines", "Nessuna linea diagonale"), + ("Diagonal Line from Top Left to Bottom Right", "Linea diagonale dall'angolo superiore sinistro a quello inferiore destro"), + ("Diagonal Line from Top Right to Bottom Left", "Linea diagonale dall'angolo superiore destro a quello inferiore sinistro"), + ("Crossed Diagonal Lines", "Linee diagonali incrociate"), + ("Line Stroke", "Traccia linea"), + ("Draw:", "Disegna:"), + ("Diagonal In Front", "Diagonale in primo piano"), + ("Content In Front", "Contenuto in primo piano"), ("Cell Stroke", "Traccia cella"), ("Cell Fill", "Riempimento cella"), ("Cell edges", "Bordi cella"), diff --git a/crates/ui-egui/src/i18n/ja.rs b/crates/ui-egui/src/i18n/ja.rs index 1737da58c..b201306b7 100644 --- a/crates/ui-egui/src/i18n/ja.rs +++ b/crates/ui-egui/src/i18n/ja.rs @@ -2171,6 +2171,15 @@ pub(super) const TABLE: &[(&str, &str)] = &[ ("Bounding Box (Visible Layers Only)", "バウンディングボックス(表示レイヤーのみ)"), ("Bounding Box (All Layers)", "バウンディングボックス(すべてのレイヤー)"), ("Strokes and Fills…", "線と塗り…"), + ("Diagonal Lines…", "斜線…"), + ("No Diagonal Lines", "斜線なし"), + ("Diagonal Line from Top Left to Bottom Right", "左上から右下への斜線"), + ("Diagonal Line from Top Right to Bottom Left", "右上から左下への斜線"), + ("Crossed Diagonal Lines", "交差する斜線"), + ("Line Stroke", "斜線の線"), + ("Draw:", "描画:"), + ("Diagonal In Front", "斜線を前面へ"), + ("Content In Front", "内容を前面へ"), ("Cell Stroke", "セルの線"), ("Cell Fill", "セルの塗り"), ("Cell edges", "セルの境界線"), diff --git a/crates/ui-egui/src/i18n/ka.rs b/crates/ui-egui/src/i18n/ka.rs index f3006244c..ed7369ac4 100644 --- a/crates/ui-egui/src/i18n/ka.rs +++ b/crates/ui-egui/src/i18n/ka.rs @@ -2066,6 +2066,7 @@ pub(super) const TABLE: &[(&str, &str)] = &[ ("Clear Recent Files", "ბოლო ფაილების სიის გასუფთავება"), ("Transparency…", "გამჭვირვალობა…"), ("Strokes and Fills…", "კონტურები და შევსებები…"), + ("Diagonal Lines…", "დიაგონალური ხაზები…"), ("Show/Hide Document Grid", "დოკუმენტის ბადის ჩვენება/დამალვა"), ("% of all commits", "ყველა კომიტის %"), ("(Paragraph Font)", "(აბზაცის შრიფტი)"), diff --git a/crates/ui-egui/src/i18n/pt_br.rs b/crates/ui-egui/src/i18n/pt_br.rs index 6af0c888b..1f822b749 100644 --- a/crates/ui-egui/src/i18n/pt_br.rs +++ b/crates/ui-egui/src/i18n/pt_br.rs @@ -1554,6 +1554,15 @@ pub(super) const TABLE: &[(&str, &str)] = &[ ("Continue from Previous Number", "Continuar do número anterior"), ("Start At", "Iniciar em"), ("Strokes and Fills…", "Traçados e preenchimentos…"), + ("Diagonal Lines…", "Linhas diagonais…"), + ("No Diagonal Lines", "Sem linhas diagonais"), + ("Diagonal Line from Top Left to Bottom Right", "Linha diagonal do canto superior esquerdo ao inferior direito"), + ("Diagonal Line from Top Right to Bottom Left", "Linha diagonal do canto superior direito ao inferior esquerdo"), + ("Crossed Diagonal Lines", "Linhas diagonais cruzadas"), + ("Line Stroke", "Traçado da linha"), + ("Draw:", "Desenhar:"), + ("Diagonal In Front", "Diagonal à frente"), + ("Content In Front", "Conteúdo à frente"), ("Cell Stroke", "Traçado da célula"), ("Cell Fill", "Preenchimento da célula"), ("Cell edges", "Bordas da célula"), diff --git a/crates/ui-egui/src/i18n/sv.rs b/crates/ui-egui/src/i18n/sv.rs index a59a99b62..906f7aab0 100644 --- a/crates/ui-egui/src/i18n/sv.rs +++ b/crates/ui-egui/src/i18n/sv.rs @@ -2050,6 +2050,15 @@ pub(super) const TABLE: &[(&str, &str)] = &[ ("Fancy", "Dekorativ"), ("Gap Tint:", "Färgton för mellanrum:"), ("Strokes and Fills…", "Konturer och fyllningar…"), + ("Diagonal Lines…", "Diagonala linjer…"), + ("No Diagonal Lines", "Inga diagonala linjer"), + ("Diagonal Line from Top Left to Bottom Right", "Diagonal linje från övre vänstra till nedre högra hörnet"), + ("Diagonal Line from Top Right to Bottom Left", "Diagonal linje från övre högra till nedre vänstra hörnet"), + ("Crossed Diagonal Lines", "Korsade diagonala linjer"), + ("Line Stroke", "Linjekontur"), + ("Draw:", "Rita:"), + ("Diagonal In Front", "Diagonal i förgrunden"), + ("Content In Front", "Innehåll i förgrunden"), ("Cell Stroke", "Cellkontur"), ("Cell Fill", "Cellfyllning"), ("Cell edges", "Cellkanter"), diff --git a/crates/ui-egui/src/i18n/table.rs b/crates/ui-egui/src/i18n/table.rs index 1671f3fdf..c25cf5be1 100644 --- a/crates/ui-egui/src/i18n/table.rs +++ b/crates/ui-egui/src/i18n/table.rs @@ -4843,6 +4843,36 @@ pub(super) const TABLE: &[(&str, [&str; 5])] = &[ ("Start At", ["Beginnen bei", "Commencer à", "Empezar en", "開始番号", "起始编号"]), // Cell strokes. ("Strokes and Fills…", ["Konturen und Flächen …", "Contours et fonds…", "Trazos y rellenos…", "線と塗り…", "描边和填色…"]), + ("Diagonal Lines…", ["Diagonale Linien …", "Lignes diagonales…", "Líneas diagonales…", "斜線…", "对角线…"]), + ("No Diagonal Lines", ["Keine diagonalen Linien", "Aucune ligne diagonale", "Sin líneas diagonales", "斜線なし", "无对角线"]), + ( + "Diagonal Line from Top Left to Bottom Right", + [ + "Diagonale Linie von links oben nach rechts unten", + "Ligne diagonale du coin supérieur gauche au coin inférieur droit", + "Línea diagonal de la esquina superior izquierda a la inferior derecha", + "左上から右下への斜線", + "从左上到右下的对角线", + ], + ), + ( + "Diagonal Line from Top Right to Bottom Left", + [ + "Diagonale Linie von rechts oben nach links unten", + "Ligne diagonale du coin supérieur droit au coin inférieur gauche", + "Línea diagonal de la esquina superior derecha a la inferior izquierda", + "右上から左下への斜線", + "从右上到左下的对角线", + ], + ), + ( + "Crossed Diagonal Lines", + ["Gekreuzte diagonale Linien", "Lignes diagonales croisées", "Líneas diagonales cruzadas", "交差する斜線", "交叉对角线"], + ), + ("Line Stroke", ["Linienkontur", "Contour de ligne", "Trazo de línea", "斜線の線", "线条描边"]), + ("Draw:", ["Zeichnen:", "Dessin :", "Dibujar:", "描画:", "绘制:"]), + ("Diagonal In Front", ["Diagonale im Vordergrund", "Diagonale au premier plan", "Diagonal delante", "斜線を前面へ", "对角线置前"]), + ("Content In Front", ["Inhalt im Vordergrund", "Contenu au premier plan", "Contenido delante", "内容を前面へ", "内容置前"]), ("Cell Stroke", ["Zellkontur", "Contour de cellule", "Trazo de celda", "セルの線", "单元格描边"]), ("Cell Fill", ["Zellfläche", "Fond de cellule", "Relleno de celda", "セルの塗り", "单元格填色"]), ("Cell edges", ["Zellkanten", "Bords de cellule", "Bordes de celda", "セルの境界線", "单元格边缘"]), diff --git a/crates/ui-egui/src/i18n/uk.rs b/crates/ui-egui/src/i18n/uk.rs index f738549b6..79966a83f 100644 --- a/crates/ui-egui/src/i18n/uk.rs +++ b/crates/ui-egui/src/i18n/uk.rs @@ -1976,6 +1976,15 @@ pub(super) const TABLE: &[(&str, &str)] = &[ ("Continue from Previous Number", "Продовжити з попереднього номера"), ("Start At", "Почати з"), ("Strokes and Fills…", "Обведення та заливки…"), + ("Diagonal Lines…", "Діагональні лінії…"), + ("No Diagonal Lines", "Без діагональних ліній"), + ("Diagonal Line from Top Left to Bottom Right", "Діагональна лінія з верхнього лівого кута в нижній правий"), + ("Diagonal Line from Top Right to Bottom Left", "Діагональна лінія з верхнього правого кута в нижній лівий"), + ("Crossed Diagonal Lines", "Перехресні діагональні лінії"), + ("Line Stroke", "Обведення лінії"), + ("Draw:", "Малювати:"), + ("Diagonal In Front", "Діагональ попереду"), + ("Content In Front", "Вміст попереду"), ("Cell Stroke", "Обведення клітинки"), ("Cell Fill", "Заливка клітинки"), ("Cell edges", "Краї клітинки"), diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rs index 103f5db84..7bf2265ca 100644 --- a/crates/ui-egui/src/menus/run.rs +++ b/crates/ui-egui/src/menus/run.rs @@ -244,6 +244,7 @@ fn run_ui_part1(app: &mut DesignApp, id: &str, p: &Value) -> Option crate::dialogs::open_cell_options(app), + "app.diagonalLinesDialog" => crate::dialogs::open_diagonal_lines(app), "window.hideMenuItem" => { let Some(item) = p.get("item").and_then(Value::as_str) else { return Some(Err("missing item".into())) }; let hide = p.get("hidden").and_then(Value::as_bool).unwrap_or(true); diff --git a/crates/ui-egui/src/menus/state.rs b/crates/ui-egui/src/menus/state.rs index 7578fb023..564858222 100644 --- a/crates/ui-egui/src/menus/state.rs +++ b/crates/ui-egui/src/menus/state.rs @@ -184,6 +184,9 @@ pub fn menu_enabled(app: &DesignApp, id: &str) -> bool { if matches!(id, "app.justificationDialog" | "app.hyphenationDialog") { return enabled(app, "type.para"); } + if matches!(id, "app.cellOptionsDialog" | "app.diagonalLinesDialog") { + return enabled(app, "table.setCell"); + } if id == "app.graphicCell" { return enabled(app, "table.placeGraphic"); } diff --git a/crates/ui-egui/src/menus/tables.rs b/crates/ui-egui/src/menus/tables.rs index bebc31fb1..94638aae1 100644 --- a/crates/ui-egui/src/menus/tables.rs +++ b/crates/ui-egui/src/menus/tables.rs @@ -437,6 +437,7 @@ pub const MENUS: &[(&str, &[&str])] = &[ "-", ">Cell Options", "ui:app.cellOptionsDialog", + "ui:app.diagonalLinesDialog", "<", "-", ">Insert", diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index f4da6e11b..323a82934 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -146,6 +146,12 @@ pub const UI_COMMANDS: &[(&str, &str, Option<&str>, &str)] = &[ None, "{} — Cell Options › Strokes and Fills of the target cells: edge proxy, stroke weight, type, colour, tint, gap colour, gap tint, and cell fill (table.setCell)", ), + ( + "app.diagonalLinesDialog", + "Diagonal Lines…", + None, + "{} — Cell Options › Diagonal Lines of the target cells: the line type, its weight, type, color, tint, gap color and gap tint, and Draw (table.setCell {diagonal})", + ), ("app.footnoteOptionsDialog", "Document Footnote Options…", None, "{} — numbering, formatting and layout of footnotes"), ("app.rubyDialog", "Ruby…", None, "{} — the reading set over the selected text"), ( diff --git a/docs/gaps.md b/docs/gaps.md index 99d1ddab9..e555d5730 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -147,8 +147,8 @@ Kind: **F** feature · **U** UI/UX · **T** typography · **FF** file format · ### 12. Tables in depth (F) - **Missing:** anchored objects in cells not drawn (#163); Table ▸ Table Options and Cell Options - submenus as InDesign lays them out, Diagonal Lines, Edit Header/Footer; general reliability - (#20). + submenus as InDesign lays them out, diagonal lines in IDML, Edit Header/Footer; general + reliability (#20). - **Estimate:** 25–40 h. ### 13. Hyphenation and spelling languages (T, L) diff --git a/docs/roadmap.md b/docs/roadmap.md index bf90fb519..c34282727 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -63,7 +63,7 @@ set exists; depth gaps are in gaps.md. | M5 | Graphics & links | ✅ core; EPS preview only | | M6 | Files & export (native, IDML, PDF, PNG/JPEG) | IDML ✅, PDF ✅ (X-4, A-2b, tagged); INDD read ✅ (via indd-utils); PDF/X-1a ✅; PDF/X-3 and presets ✗ | | M7 | Long documents (sections, TOC, index, footnotes, books) | ✅ except Books (shallow) | -| M8 | Tables | ✅ core (table/cell styles, rotation); diagonal lines, anchored objects in cells (#163) | +| M8 | Tables | ✅ core (table/cell styles, rotation); diagonal lines in IDML, anchored objects in cells (#163) | | M9 | Performance (MT composition, tiles) | in progress: parallel compose 6.7×, damage regions; incremental composition next | | M10 | Find/Change, spelling, Preflight | ✅ (spelling English only) | | M11 | Layout power features (liquid/alternate layouts, data merge) | present, shallow; Flex Layout (new in InDesign 2026) ✗ | diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index cea4cb050..9440d64ef 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -213,7 +213,7 @@ table is the one summed. | Type & text frames | 99% | 45% | 40–60 | Primary Text Frame pages users can't delete (alpha blocker, #165); autoflow sets new frames on following pages instead of flowing into their primary text frame; caret formatting discarded (#289); Notes/Track Changes menus; frame grids | | Typography | 100% | 45% | (typography dimension) | see [typography-parity.md](typography-parity.md) | | Styles | 100% | 60% | 15–25 | Paragraph Styles edit/delete reported failing (#169); style options depth | -| Tables | 100% | 55% | 25–40 | anchored objects in cells not drawn (#163); Table ▸ Table Options submenus, Diagonal Lines, Edit Header/Footer | +| Tables | 100% | 55% | 25–40 | anchored objects in cells not drawn (#163); Table ▸ Table Options submenus, Edit Header/Footer | | Long documents | 100% | 45% | 30–50 | Books are shallow (sync, book pagination, book PDF/TOC/index); Table of Contents Styles | | Interactivity & digital | 100% | 40% | 30–50 | HTML export basic (#314); fixed-layout EPUB is page images; no animation, timing, media playback | | Output & production | 92% | 55% | 40–70 | PDF/X-4 only (no X-1a/X-3), with visible unembedded font detection (below); no PDF/print presets or `.joboptions`, print via craft-print (CUPS/Windows), no trapping; Output Preview panel | @@ -375,6 +375,7 @@ It is evidence of breadth: each item exists. It is not a claim of InDesign-level - Track Changes: per-change Accept / Reject (`changes.accept`, `changes.reject`) and a Track Changes panel listing every change. - Move table rows and columns (`table.moveRow`, `table.moveColumn`, Table panel buttons; with whole rows or columns selected, drag them with the Type tool — `table.dropCells`). - Cell strokes: with cells selected (or the cursor in a cell) the Stroke panel edits the chosen cell edges, picked on a drawn edge proxy (top, bottom, left, right, inner horizontal, inner vertical); Table › Cell Options › Strokes and Fills… does the same with the cell fill. Weight, every stroke type, colour, tint, gap colour and gap tint draw on screen and in PDF and round-trip through IDML (`table.setCell` `stroke.edges`, `table.getCellStroke`). +- Diagonal lines in cells: Table › Cell Options › Diagonal Lines… draws a line from the top left corner to the bottom right, from the top right to the bottom left, or both, with the same weight, type, color, tint, gap color and gap tint as cell edges, in front of the cell's contents or behind them (Draw: Diagonal In Front or Content In Front). They draw on screen, in PDF and in PowerPoint export and are saved in the native format; IDML import and export do not carry them (`table.setCell` `diagonal`, `table.getCellDiagonal`). - Distribute Rows Evenly (`table.distributeRows`, Table menu and panel): selected rows receive equal fixed heights preserving their composed total height, with undo/redo. Row-spanning merges and rows outside the composed frames are rejected; shrinking tall cells can overset their text. - Object States (`states.create/show/rename/release/list`, Object States panel): multi-state objects show one state on screen and in PDF. - Buttons (`button.set/clear/list`, Buttons and Forms panel): go to page / next / previous / first / last / URL as PDF link annotations. Form fields too (`form.set/clear/list`: text fields, check boxes, combo and list boxes, signature fields; required, multiline, defaults) exported as AcroForm widgets through an incremental update (not in PDF/X or PDF/A).