DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
I: IDML — nested and GREP styles, cell and table styles, type on a path (TextPath)
Brandon Thomas6b362c5f71df
diff --git a/ROADMAP.md b/ROADMAP.mdindex acd6c1e87..1e3085cc2 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -31,13 +31,13 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- Color panel (fill/stroke proxy, CMYK/RGB/Lab sliders with channel ramps, tint slider for swatches, spectrum ramp, Add to Swatches) and Color Picker (double-click the proxy); mixed colours are unnamed (not listed in Swatches until added); `object.color`, `swatch.addToSwatches`, `swatch.addUnnamed`.- Place text files: Word (.docx: styles by name with their attributes, bold/italic/underline/size/font, footnotes, tables, tabs, breaks), RTF and plain text, into the insertion point, the selected frame or a new frame; autoflow adds pages and threaded frames until the text fits; Remove Styles option (`designcraft-textimport`).- View › Overprint Preview (⌥⇧⌘Y): overprinting fills, strokes and 100% [Black] text mix with what's beneath on screen.-- Type on a Path (⇧T tool, `type.onPath`): a story along any line, curve or shape on screen and in PDF; Type on a Path Options (start, flip, baseline/ascender/descender/centre) and Delete Type from Path. On-path caret drawing and IDML TextPath are still to come.+- Type on a Path (⇧T tool, `type.onPath`): a story along any line, curve or shape on screen and in PDF; Type on a Path Options (start, flip, baseline/ascender/descender/centre) and Delete Type from Path. Round-trips through IDML as TextPath; on-path caret drawing is still to come.- Preferences › Appearance of Black: 100% K on screen accurately (dark grey) or as rich black (`window.richBlack`); the printing/export side is still to come.- Spreads of up to 10 pages: Add to Previous Spread and Allow Spread to Shuffle (Pages panel; `layout.pages.toSpread`, `layout.spreadShuffle`); inserted pages go around kept spreads.- Page tool (⇧P) and `layout.pageSize`: pages of their own size (or a preset); the spine stays put and objects keep their place on their page.- File › Print (⌘P): printer, copies, page range, spreads, marks, bleed; printed as PDF through the system spooler (`file.print`, `file.printers`, `dryRun` for agents). Shortcuts now act like choosing the menu item (dialogs open), and UI commands win shortcut ties (⌘N opens New Document).-- Nested styles (through/up to N sentences, words, characters, letters, digits, tabs, breaks, spaces or given characters) and GREP styles (regex → character style), edited in Paragraph Style Options and composed under local formatting; `ui.dialog.open` for agents. Nested line styles and their IDML mapping are still to come.-- Table and cell styles: cell styles (fill, insets, vertical justification, strokes, paragraph style) and table styles (region cell styles, border, alternating rows, spacing); apply from the Table panel, edits re-apply to every user; `style.cell.*`, `style.table.*`. IDML mapping is still to come.+- Nested styles (through/up to N sentences, words, characters, letters, digits, tabs, breaks, spaces or given characters) and GREP styles (regex → character style), edited in Paragraph Style Options and composed under local formatting; `ui.dialog.open` for agents. Nested line styles are still to come; nested and GREP styles round-trip through IDML.+- Table and cell styles (round-trip through IDML): cell styles (fill, insets, vertical justification, strokes, paragraph style) and table styles (region cell styles, border, alternating rows, spacing); apply from the Table panel, edits re-apply to every user; `style.cell.*`, `style.table.*`.- Style groups: paragraph and character styles shown in group folders, Move to Group (new, existing, none); `style.group` renames every use (styles, stories, table cells, footnotes, object styles).- Scrubby zoom: drag the Zoom tool left or right to zoom continuously around the press point.- Guides belong to the active layer: hidden with it (or with its Show Guides off) and locked with it.diff --git a/crates/engine/src/tests_idml.rs b/crates/engine/src/tests_idml.rsindex 11a5a46c3..cd84917d2 100644--- a/crates/engine/src/tests_idml.rs+++ b/crates/engine/src/tests_idml.rs@@ -182,3 +182,56 @@ fn underline_options_render_and_round_trip() {assert_eq!(f.over.underline_offset, Some(Some(4.0)));assert_eq!(f.over.underline_color.as_deref(), Some("C=100 M=0 Y=0 K=0"));}++#[test]+fn newer_features_round_trip_through_idml() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ // Nested and GREP styles on a paragraph style.+ s.execute("style.character.create", &json!({"name": "Lead", "chars": {"fontStyle": "Bold"}})).unwrap();+ s.execute(+ "style.paragraph.create",+ &json!({"name": "Intro", "para": {+ "nestedStyles": [{"style": "Lead", "through": false, "count": 2, "until": {"kind": "chars", "chars": ":"}}],+ "grepStyles": [{"style": "Lead", "pattern": "\\d+"}]+ }}),+ )+ .unwrap();+ // Cell and table styles on a table.+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 500, 300], "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, "headerRows": 1})).unwrap();+ s.execute("style.cell.create", &json!({"name": "Head", "fill": "[Black]", "insets": 5, "paragraphStyle": "Intro"})).unwrap();+ s.execute("style.table.create", &json!({"name": "Grid", "header": "Head", "border": {"weight": 3, "color": "[Black]"}})).unwrap();+ s.execute("style.table.apply", &json!({"name": "Grid"})).unwrap();+ // Type on a path.+ let line = s.execute("line.create", &json!({"a": [100, 500], "b": [400, 500]})).unwrap()["id"].as_u64().unwrap();+ s.execute("type.onPath", &json!({"id": line, "text": "On the line", "start": 12, "flip": true, "align": "center"})).unwrap();+ let d = s.doc().unwrap().doc.clone();+ let back = designcraft_idml::import_idml(&designcraft_idml::export_idml(&d)).unwrap();+ let intro = back.styles.para("Intro").unwrap();+ let ns = intro.para.nested_styles.clone().unwrap();+ assert_eq!(ns[0].style, "Lead");+ assert_eq!((ns[0].through, ns[0].count), (false, 2));+ assert_eq!(ns[0].until, designcraft_doc::NestedUntil::Chars(":".into()));+ assert_eq!(intro.para.grep_styles.clone().unwrap()[0].pattern, "\\d+");+ let head = back.styles.cell.iter().find(|c| c.name == "Head").unwrap();+ assert_eq!((head.fill.as_deref(), head.insets, head.paragraph_style.as_deref()), (Some("[Black]"), Some([5.0; 4]), Some("Intro")));+ let grid = back.styles.table.iter().find(|t| t.name == "Grid").unwrap();+ assert_eq!(grid.header.as_deref(), Some("Head"));+ assert_eq!(grid.border.as_ref().unwrap().weight, 3.0);+ let t = back.stories.values().flat_map(|st| st.tables.values()).next().unwrap();+ assert_eq!(t.style, "Grid");+ assert_eq!(t.cell(0, 0).unwrap().style, "Head");+ let pt = back+ .spreads+ .iter()+ .flat_map(|sp| sp.items.iter())+ .find_map(|it| match &it.content {+ designcraft_doc::Content::Text(tf) => tf.options.path.clone().map(|p| (p, tf.story)),+ _ => None,+ })+ .expect("type on a path");+ assert_eq!((pt.0.start, pt.0.flip, pt.0.align), (12.0, true, designcraft_doc::PathAlign::Center));+ assert_eq!(back.story(pt.1).unwrap().text, "On the line");+}diff --git a/crates/idml/src/export.rs b/crates/idml/src/export.rsindex cec20a400..f4be2b874 100644--- a/crates/idml/src/export.rs+++ b/crates/idml/src/export.rs@@ -743,21 +743,83 @@ impl<'a> Ex<'a> {pg.emit(&mut rp, "ParagraphStyleGroup", "");root.push(rp);- // Cell and table styles (built-ins only).- root.push(- El::new("RootCellStyleGroup").attr("Self", self.fresh()).child(- El::new("CellStyle").attr("Self", "CellStyle/$ID/[None]").attr("AppliedParagraphStyle", NO_PARA_ID).attr("Name", "$ID/[None]"),- ),- );- root.push(- El::new("RootTableStyleGroup")- .attr("Self", self.fresh())- .child(El::new("TableStyle").attr("Self", "TableStyle/$ID/[No table style]").attr("Name", "$ID/[No table style]"))- .child(with_props(- El::new("TableStyle").attr("Self", "TableStyle/$ID/[Basic Table]").attr("Name", "$ID/[Basic Table]"),- vec![p("BasedOn", "string", "$ID/[No table style]")],- )),- );+ // Cell and table styles.+ let mut cells = El::new("RootCellStyleGroup")+ .attr("Self", self.fresh())+ .child(El::new("CellStyle").attr("Self", "CellStyle/$ID/[None]").attr("AppliedParagraphStyle", NO_PARA_ID).attr("Name", "$ID/[None]"));+ for cs in styles.cell.iter().filter(|c| c.name != designcraft_doc::NO_CELL_STYLE) {+ let mut el = El::new("CellStyle")+ .attr("Self", names::style_self("CellStyle", names::CELL_BUILTINS, &cs.name))+ .attr("Name", names::style_name_out(names::CELL_BUILTINS, &cs.name));+ if let Some(f) = &cs.fill {+ el.set("FillColor", self.sw(f));+ }+ if let Some(t) = cs.fill_tint {+ el.set("FillTint", pct(t as f64));+ }+ if let Some(i) = cs.insets {+ for (k, v) in ["TopInset", "LeftInset", "BottomInset", "RightInset"].iter().zip(i) {+ el.set(k, num(v));+ }+ }+ if let Some(vj) = cs.vj {+ el.set("VerticalJustification", names::vj_out(vj));+ }+ if let Some(st) = &cs.stroke {+ for side in ["TopEdge", "LeftEdge", "BottomEdge", "RightEdge"] {+ self.cell_stroke_attrs(&mut el, side, st);+ }+ }+ if let Some(ps) = &cs.paragraph_style {+ el.set("AppliedParagraphStyle", names::style_self("ParagraphStyle", PARA_BUILTINS, ps));+ }+ cells = cells.child(with_props(el, vec![p("BasedOn", "string", "$ID/[None]")]));+ }+ root.push(cells);+ let mut tables = El::new("RootTableStyleGroup")+ .attr("Self", self.fresh())+ .child(El::new("TableStyle").attr("Self", "TableStyle/$ID/[No table style]").attr("Name", "$ID/[No table style]"))+ .child(with_props(+ El::new("TableStyle").attr("Self", "TableStyle/$ID/[Basic Table]").attr("Name", "$ID/[Basic Table]"),+ vec![p("BasedOn", "string", "$ID/[No table style]")],+ ));+ for ts in styles.table.iter().filter(|t| t.name != designcraft_doc::BASIC_TABLE) {+ let mut el = El::new("TableStyle")+ .attr("Self", names::style_self("TableStyle", names::TABLE_BUILTINS, &ts.name))+ .attr("Name", names::style_name_out(names::TABLE_BUILTINS, &ts.name));+ for (k, v) in [+ ("HeaderRegionCellStyle", &ts.header),+ ("BodyRegionCellStyle", &ts.body),+ ("FooterRegionCellStyle", &ts.footer),+ ("LeftColumnRegionCellStyle", &ts.left_column),+ ("RightColumnRegionCellStyle", &ts.right_column),+ ] {+ if let Some(n) = v {+ el.set(k, names::style_self("CellStyle", names::CELL_BUILTINS, n));+ }+ }+ if let Some(b) = &ts.border {+ for side in ["Top", "Left", "Bottom", "Right"] {+ self.cell_stroke_attrs(&mut el, &format!("{side}Border"), b);+ }+ }+ if let Some(a) = &ts.alt_rows {+ el.set("StartRowFillColor", self.sw(&a.first_color));+ el.set("StartRowFillCount", a.first);+ el.set("StartRowFillTint", pct(a.first_tint as f64));+ el.set("EndRowFillColor", self.sw(&a.next_color));+ el.set("EndRowFillCount", a.next);+ el.set("EndRowFillTint", pct(a.next_tint as f64));+ }+ if let Some(v) = ts.space_before {+ el.set("SpaceBefore", num(v));+ }+ if let Some(v) = ts.space_after {+ el.set("SpaceAfter", num(v));+ }+ tables = tables.child(with_props(el, vec![p("BasedOn", "string", "$ID/[Basic Table]")]));+ }+ root.push(tables);// Object styles.let mut og = Group::default();@@ -911,6 +973,34 @@ impl<'a> Ex<'a> {}fn para_attrs(&mut self, el: &mut El, props: &mut Vec<El>, a: &ParaAttrs) {+ // Nested and GREP styles: property lists of records.+ if let Some(list) = &a.nested_styles {+ let mut l = El::new("AllNestedStyles").attr("type", "list");+ for ns in list {+ let (ty, delim) = names::nested_until_out(&ns.until);+ l = l.child(+ El::new("ListItem")+ .attr("type", "record")+ .child(p("AppliedCharacterStyle", "object", names::style_self("CharacterStyle", CHAR_BUILTINS, &ns.style)))+ .child(p("Delimiter", ty, delim))+ .child(p("Repetition", "long", ns.count.to_string()))+ .child(p("Inclusive", "boolean", bool_s(ns.through))),+ );+ }+ props.push(l);+ }+ if let Some(list) = &a.grep_styles {+ let mut l = El::new("AllGREPStyles").attr("type", "list");+ for g in list {+ l = l.child(+ El::new("ListItem")+ .attr("type", "record")+ .child(p("AppliedCharacterStyle", "object", names::style_self("CharacterStyle", CHAR_BUILTINS, &g.style)))+ .child(p("GrepExpression", "string", g.pattern.clone())),+ );+ }+ props.push(l);+ }macro_rules! n {($f:ident, $k:literal) => {if let Some(v) = a.$f {@@ -1132,7 +1222,14 @@ impl<'a> Ex<'a> {fn item_el(&mut self, it: &Item, xf: Affine) -> El {let d = self.d;+ let path_text = matches!(&it.content, Content::Text(t) if t.options.path.is_some());let tag = match (&it.content, it.shape) {+ (Content::Text(_), _) if path_text => match it.shape {+ Shape::GraphicLine => "GraphicLine",+ Shape::Oval => "Oval",+ Shape::Rectangle => "Rectangle",+ _ => "Polygon",+ },(Content::Text(_), _) => "TextFrame",(Content::Group { .. }, Shape::Group) => "Group",(_, Shape::Oval) => "Oval",@@ -1141,7 +1238,25 @@ impl<'a> Ex<'a> {_ => "Rectangle",};let mut el = El::new(tag).attr("Self", uid(it.id.0));- if let Content::Text(t) = &it.content {+ if let Content::Text(t) = &it.content+ && let Some(pt) = &t.options.path+ {+ // Type on a path: a TextPath child holds the story.+ let len = designcraft_geom::warp::PathWarp::new(&it.path.to_bezpath(), false).length();+ el.push(+ El::new("TextPath")+ .attr("Self", format!("{}tp", uid(it.id.0)))+ .attr("ParentStory", uid(t.story.0))+ .attr("PreviousTextFrame", "n")+ .attr("NextTextFrame", "n")+ .attr("PathEffect", "RainbowPathEffect")+ .attr("PathAlignment", "CenterPathAlignment")+ .attr("TextAlignment", names::path_align_out(pt.align))+ .attr("FlipPathEffect", if pt.flip { "Flipped" } else { "NotFlipped" })+ .attr("StartBracket", num(pt.start))+ .attr("EndBracket", num(len)),+ );+ } else if let Content::Text(t) = &it.content {let (prev, next) = self.threads.get(&it.id.0).copied().unwrap_or((None, None));el.set("ParentStory", uid(t.story.0));el.set("PreviousTextFrame", prev.map(uid).unwrap_or_else(|| "n".into()));@@ -1672,7 +1787,10 @@ impl<'a> Ex<'a> {.attr("FooterRowCount", f).attr("BodyRowCount", t.nrows() - h - f).attr("ColumnCount", t.ncols())- .attr("AppliedTableStyle", "TableStyle/$ID/[Basic Table]")+ .attr(+ "AppliedTableStyle",+ names::style_self("TableStyle", names::TABLE_BUILTINS, if t.style.is_empty() { designcraft_doc::BASIC_TABLE } else { &t.style }),+ ).attr("TableDirection", "LeftToRightDirection").attr("SpaceBefore", num(t.options.space_before)).attr("SpaceAfter", num(t.options.space_after))@@ -1725,7 +1843,14 @@ impl<'a> Ex<'a> {.attr("Name", format!("{c}:{r}")).attr("RowSpan", cell.row_span).attr("ColumnSpan", cell.col_span)- .attr("AppliedCellStyle", "CellStyle/$ID/[None]")+ .attr(+ "AppliedCellStyle",+ names::style_self(+ "CellStyle",+ names::CELL_BUILTINS,+ if cell.style.is_empty() { designcraft_doc::NO_CELL_STYLE } else { &cell.style },+ ),+ ).attr("FillColor", self.sw(&cell.fill)).attr("FillTint", pct(cell.fill_tint as f64)).attr("TopInset", num(cell.insets[0]))diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rsindex 4c3387b5f..b05a56985 100644--- a/crates/idml/src/import.rs+++ b/crates/idml/src/import.rs@@ -598,6 +598,8 @@ impl<'r> Importer<'r> {let mut paras: Vec<(String, El)> = Vec::new();let mut chars: Vec<(String, El)> = Vec::new();let mut objects: Vec<(String, El)> = Vec::new();+ let mut cell_styles: Vec<(String, El)> = Vec::new();+ let mut table_styles: Vec<(String, El)> = Vec::new();fn walk(e: &El, style: &str, group: &str, out: &mut Vec<(String, El)>) {for c in e.elements() {if c.local() == style {@@ -612,6 +614,8 @@ impl<'r> Importer<'r> {"RootParagraphStyleGroup" => walk(e, "ParagraphStyle", "ParagraphStyleGroup", &mut paras),"RootCharacterStyleGroup" => walk(e, "CharacterStyle", "CharacterStyleGroup", &mut chars),"RootObjectStyleGroup" => walk(e, "ObjectStyle", "ObjectStyleGroup", &mut objects),+ "RootCellStyleGroup" => walk(e, "CellStyle", "CellStyleGroup", &mut cell_styles),+ "RootTableStyleGroup" => walk(e, "TableStyle", "TableStyleGroup", &mut table_styles),_ => {}}}@@ -650,6 +654,77 @@ impl<'r> Importer<'r> {None => self.styles.character.push(s),}}+ // Cell and table styles (the built-ins stay as they are).+ let cell_ref = |r: &str| names::style_name_in(names::CELL_BUILTINS, &unescape_id(r.trim_start_matches("CellStyle/")));+ for (_, e) in &cell_styles {+ let name = names::style_name_in(names::CELL_BUILTINS, e.get("Name").unwrap_or(""));+ if name == designcraft_doc::NO_CELL_STYLE {+ continue;+ }+ let mut cs = designcraft_doc::CellStyle { name: name.clone(), ..Default::default() };+ cs.fill = e.get("FillColor").map(|c| self.swatch_ref(c));+ cs.fill_tint = e.num("FillTint").and_then(|v| tint(Some(v)));+ let ins: Vec<Option<f64>> = ["TopInset", "LeftInset", "BottomInset", "RightInset"].iter().map(|k| e.num(k)).collect();+ if ins.iter().all(Option::is_some) {+ cs.insets = Some([ins[0].unwrap_or(0.0), ins[1].unwrap_or(0.0), ins[2].unwrap_or(0.0), ins[3].unwrap_or(0.0)]);+ }+ cs.vj = e.get("VerticalJustification").map(names::vj_in);+ if e.get("TopEdgeStrokeWeight").is_some() || e.get("TopEdgeStrokeColor").is_some() {+ let mut st = CellStroke::default();+ if let Some(w) = e.num("TopEdgeStrokeWeight") {+ st.weight = w.max(0.0);+ }+ if let Some(c) = e.get("TopEdgeStrokeColor") {+ st.color = self.swatch_ref(c);+ }+ cs.stroke = Some(st);+ }+ cs.paragraph_style = e.get("AppliedParagraphStyle").map(|r| self.para_style_ref(r)).filter(|n| n != designcraft_doc::NO_PARA_STYLE);+ match self.styles.cell.iter_mut().find(|c| c.name == name) {+ Some(slot) => *slot = cs,+ None => self.styles.cell.push(cs),+ }+ }+ for (_, e) in &table_styles {+ let name = names::style_name_in(names::TABLE_BUILTINS, e.get("Name").unwrap_or(""));+ if name == designcraft_doc::BASIC_TABLE || name == "[No table style]" {+ continue;+ }+ let mut ts = designcraft_doc::TableStyle { name: name.clone(), ..Default::default() };+ ts.header = e.get("HeaderRegionCellStyle").map(cell_ref).filter(|n| n != designcraft_doc::NO_CELL_STYLE);+ ts.body = e.get("BodyRegionCellStyle").map(cell_ref).filter(|n| n != designcraft_doc::NO_CELL_STYLE);+ ts.footer = e.get("FooterRegionCellStyle").map(cell_ref).filter(|n| n != designcraft_doc::NO_CELL_STYLE);+ ts.left_column = e.get("LeftColumnRegionCellStyle").map(cell_ref).filter(|n| n != designcraft_doc::NO_CELL_STYLE);+ ts.right_column = e.get("RightColumnRegionCellStyle").map(cell_ref).filter(|n| n != designcraft_doc::NO_CELL_STYLE);+ if e.get("TopBorderStrokeWeight").is_some() {+ let mut b = CellStroke::default();+ if let Some(w) = e.num("TopBorderStrokeWeight") {+ b.weight = w.max(0.0);+ }+ if let Some(c) = e.get("TopBorderStrokeColor") {+ b.color = self.swatch_ref(c);+ }+ ts.border = Some(b);+ }+ if let Some(first) = e.num("StartRowFillCount").filter(|n| *n > 0.0) {+ ts.alt_rows = Some(AltFills {+ first: first as u32,+ first_color: e.get("StartRowFillColor").map(|c| self.swatch_ref(c)).unwrap_or_else(|| swatch::NONE.into()),+ first_tint: tint(e.num("StartRowFillTint")).unwrap_or(1.0),+ next: e.num("EndRowFillCount").unwrap_or(1.0) as u32,+ next_color: e.get("EndRowFillColor").map(|c| self.swatch_ref(c)).unwrap_or_else(|| swatch::NONE.into()),+ next_tint: tint(e.num("EndRowFillTint")).unwrap_or(1.0),+ skip_first: 0,+ skip_last: 0,+ });+ }+ ts.space_before = e.num("SpaceBefore");+ ts.space_after = e.num("SpaceAfter");+ match self.styles.table.iter_mut().find(|c| c.name == name) {+ Some(slot) => *slot = ts,+ None => self.styles.table.push(ts),+ }+ }for (_, e) in &objects {let name = names::style_name_in(OBJECT_BUILTINS, e.get("Name").unwrap_or(""));let based_on = e.prop("BasedOn").map(|b| {@@ -913,6 +988,33 @@ impl<'r> Importer<'r> {a.first_line_indent = e.num("FirstLineIndent");a.last_line_indent = e.num("LastLineIndent");a.space_before = e.num("SpaceBefore");+ // Nested and GREP styles.+ if let Some(l) = e.prop_el("AllNestedStyles") {+ let v: Vec<designcraft_doc::NestedStyle> = l+ .find_all("ListItem")+ .map(|it| {+ let t = |k: &str| it.find(k).map(|x| x.text_content()).unwrap_or_default();+ let d = it.find("Delimiter");+ designcraft_doc::NestedStyle {+ style: self.char_style_ref(t("AppliedCharacterStyle").trim()),+ through: t("Inclusive").trim() != "false",+ count: t("Repetition").trim().parse().unwrap_or(1),+ until: names::nested_until_in(d.and_then(|d| d.get("type")).unwrap_or("enumeration"), &t("Delimiter")),+ }+ })+ .collect();+ a.nested_styles = Some(v);+ }+ if let Some(l) = e.prop_el("AllGREPStyles") {+ let v: Vec<designcraft_doc::GrepStyle> = l+ .find_all("ListItem")+ .map(|it| {+ let t = |k: &str| it.find(k).map(|x| x.text_content()).unwrap_or_default();+ designcraft_doc::GrepStyle { style: self.char_style_ref(t("AppliedCharacterStyle").trim()), pattern: t("GrepExpression") }+ })+ .collect();+ a.grep_styles = Some(v);+ }a.space_after = e.num("SpaceAfter");a.drop_cap_lines = u("DropCapLines");a.drop_cap_chars = u("DropCapCharacters");@@ -1145,6 +1247,11 @@ impl<'r> Importer<'r> {t.options.alt_cols = Some(alt);}}+ t.style = e+ .get("AppliedTableStyle")+ .map(|r| names::style_name_in(names::TABLE_BUILTINS, &unescape_id(r.trim_start_matches("TableStyle/"))))+ .filter(|n| n != designcraft_doc::BASIC_TABLE && n != "[No table style]")+ .unwrap_or_default();let mut regions = Vec::new();for ce in e.find_all("Cell") {let Some((c, r)) =@@ -1159,6 +1266,11 @@ impl<'r> Importer<'r> {let cs = ce.num("ColumnSpan").unwrap_or(1.0).max(1.0) as usize;let text = self.story(StoryId(0), ce);let mut cell = Cell { text, ..Default::default() };+ cell.style = ce+ .get("AppliedCellStyle")+ .map(|r| names::style_name_in(names::CELL_BUILTINS, &unescape_id(r.trim_start_matches("CellStyle/"))))+ .filter(|n| n != designcraft_doc::NO_CELL_STYLE)+ .unwrap_or_default();if let Some(fc) = ce.get("FillColor") {cell.fill = self.swatch_ref(fc);}@@ -1610,6 +1722,24 @@ impl<'r> Importer<'r> {}it.wrap = tw;}+ // Type on a path.+ if tag != "TextFrame"+ && let Some(tp) = e.find("TextPath")+ {+ let story_self = tp.get("ParentStory").unwrap_or("n").to_string();+ if let Some(story) = self.story_ids.get(&story_self).copied() {+ let options = TextFrameOptions {+ path: Some(designcraft_doc::PathType {+ start: tp.num("StartBracket").unwrap_or(0.0).max(0.0),+ flip: tp.get("FlipPathEffect") == Some("Flipped"),+ align: names::path_align_in(tp.get("TextAlignment").unwrap_or("")),+ }),+ ..Default::default()+ };+ it.content = Content::Text(TextFrame { story, options });+ self.ctx.threads.push((id, story_self, "n".into(), "n".into()));+ }+ }// Content.match tag {"TextFrame" => {diff --git a/crates/idml/src/names.rs b/crates/idml/src/names.rsindex 878c84103..b9517008c 100644--- a/crates/idml/src/names.rs+++ b/crates/idml/src/names.rs@@ -19,6 +19,8 @@ pub fn unescape_id(s: &str) -> String {/// Built-in style names: (ours, IDML `Name`).pub const PARA_BUILTINS: &[(&str, &str)] = &[("[No Paragraph Style]", "$ID/[No paragraph style]"), ("[Basic Paragraph]", "$ID/NormalParagraphStyle")];pub const CHAR_BUILTINS: &[(&str, &str)] = &[("[None]", "$ID/[No character style]")];+pub const CELL_BUILTINS: &[(&str, &str)] = &[("[None]", "$ID/[None]")];+pub const TABLE_BUILTINS: &[(&str, &str)] = &[("[Basic Table]", "$ID/[Basic Table]")];pub const OBJECT_BUILTINS: &[(&str, &str)] =&[("[None]", "$ID/[None]"), ("[Basic Graphics Frame]", "$ID/[Normal Graphics Frame]"), ("[Basic Text Frame]", "$ID/[Normal Text Frame]")];@@ -506,3 +508,57 @@ pub fn note_marker_in(s: &str) -> Position {_ => Position::Normal,}}++/// Nested-style delimiter → (property type, value).+pub fn nested_until_out(u: &designcraft_doc::NestedUntil) -> (&'static str, String) {+ use designcraft_doc::NestedUntil as N;+ let e = |v: &str| ("enumeration", v.to_string());+ match u {+ N::Sentences => e("Sentence"),+ N::Words => e("AnyWord"),+ N::Characters => e("AnyCharacter"),+ N::Letters => e("Letters"),+ N::Digits => e("Digits"),+ N::Tab => e("Tabs"),+ N::ForcedLineBreak => e("ForcedLineBreak"),+ N::EmSpace => e("EmSpaces"),+ N::EnSpace => e("EnSpaces"),+ N::Chars(c) => ("string", c.clone()),+ }+}++pub fn nested_until_in(ty: &str, v: &str) -> designcraft_doc::NestedUntil {+ use designcraft_doc::NestedUntil as N;+ if ty == "string" {+ return N::Chars(v.to_string());+ }+ match v.trim() {+ "Sentence" => N::Sentences,+ "AnyCharacter" => N::Characters,+ "Letters" => N::Letters,+ "Digits" => N::Digits,+ "Tabs" => N::Tab,+ "ForcedLineBreak" => N::ForcedLineBreak,+ "EmSpaces" => N::EmSpace,+ "EnSpaces" => N::EnSpace,+ _ => N::Words,+ }+}++pub fn path_align_out(a: designcraft_doc::PathAlign) -> &'static str {+ match a {+ designcraft_doc::PathAlign::Baseline => "BaselineAlignment",+ designcraft_doc::PathAlign::Ascender => "AscenderAlignment",+ designcraft_doc::PathAlign::Descender => "DescenderAlignment",+ designcraft_doc::PathAlign::Center => "CenterAlignment",+ }+}++pub fn path_align_in(v: &str) -> designcraft_doc::PathAlign {+ match v {+ "AscenderAlignment" => designcraft_doc::PathAlign::Ascender,+ "DescenderAlignment" => designcraft_doc::PathAlign::Descender,+ "CenterAlignment" => designcraft_doc::PathAlign::Center,+ _ => designcraft_doc::PathAlign::Baseline,+ }+}