From adc397f8716ed45edfde59d29b236a06b9bef3a7 Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Thu, 8 Oct 2026 00:32:07 +0000 Subject: [PATCH] feat: write cell and table style groups Groups (class 0xCA8B) listed by the root cell or table style group are written as CellStyleGroup or TableStyleGroup elements holding their styles, in the order of the group's children (objects.md). compare.py --exclude own/, trustworthy pairs: CellStyleGroup elements 0 -> 2 of 2 (4 values); no other change, no new extras, no conversion or schema failures. --- docs/format/objects.md | 6 +++++ src/idml/styles.rs | 56 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/docs/format/objects.md b/docs/format/objects.md index c741e62..4ba831f 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -1288,6 +1288,12 @@ children; chunk 0x28D2 a flag byte and the name. IDML names every group `$ID/` (20 of 21 groups), and a style inside groups is referenced as `ParagraphStyle/::` with `:` escaped as `%3a`. All 412 paragraph styles and 21 groups in the pairs match. +Cell style groups work the same way: the root cell style group's +children (chunk 0x2024E) include groups of class 0xCA8B, and IDML writes +each as `` holding its styles, in the order of the children (2 +groups with 6 cell styles in 1 trustworthy DOM 18 pair). No table style +group occurs in the pairs; the converter writes them the same way. **Style names.** Over the styles of the 489 trustworthy pairs, a style's IDML `Name` is its group path and its own name joined by `:` (1,170 diff --git a/src/idml/styles.rs b/src/idml/styles.rs index 13c4f3e..fd1bf98 100644 --- a/src/idml/styles.rs +++ b/src/idml/styles.rs @@ -287,18 +287,22 @@ impl Writer<'_> { } else { &doc.table_styles }; - // Styles listed in the root group first, then any others; the - // root style is written above. - let mut order: Vec = root.map_or(Vec::new(), |g| g.children.clone()); - order.extend(styles.keys().copied()); + // Styles and style groups listed in the root group first, then + // any other styles; the root style is written above. let mut seen = std::collections::HashSet::new(); - for uid in order { - let Some(s) = styles.get(&uid) else { continue }; - let is_root = s.builtin && s.based_on.is_none() && s.name == name; - if is_root || !seen.insert(self.table_style_ref(style, s)) { - continue; + if let Some(r) = styles + .values() + .find(|s| s.builtin && s.based_on.is_none() && s.name == name) + { + seen.insert(self.table_style_ref(style, r)); + } + if let Some(root) = root { + self.table_style_group_children(&mut x, root, style, styles, &mut seen); + } + for s in styles.values() { + if seen.insert(self.table_style_ref(style, s)) { + self.table_style_element(&mut x, style, s, styles); } - self.table_style_element(&mut x, style, s, styles); } x.end(); } @@ -657,6 +661,38 @@ impl Writer<'_> { node } + /// The cell or table styles and style groups of a style group, in + /// its order. `seen` holds the `Self` of the styles written: some + /// documents have two style objects with the same name, and the first + /// is written. + fn table_style_group_children( + &self, + x: &mut Xml, + g: &StyleGroup, + tag: &str, + styles: &BTreeMap, + seen: &mut std::collections::HashSet, + ) { + for &c in &g.children { + if let Some(sub) = self.doc.style_groups.get(&c) { + let sub_tag = format!("{tag}Group"); + let path = self.group_path.get(&sub.uid).cloned().unwrap_or_default(); + x.start(&sub_tag) + .attr( + "Self", + format!("{sub_tag}/$ID/{}", self_name(&path.join(":"))), + ) + .attr("Name", builtin_key(&sub.name)); + self.table_style_group_children(x, sub, tag, styles, seen); + x.end(); + } else if let Some(s) = styles.get(&c) + && seen.insert(self.table_style_ref(tag, s)) + { + self.table_style_element(x, tag, s, styles); + } + } + } + pub(super) fn style_group_children( &self, x: &mut Xml,