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.
This commit is contained in:
aiongg committed 2026-10-08 00:32:07 +00:00
1 parent 01113d1c21
commit adc397f871
2 files changed
+52 -10

No files matched your search

+6
View File
@@ -1288,6 +1288,12 @@ children; chunk 0x28D2 a flag byte and the name. IDML names every group
`$ID/<name>` (20 of 21 groups), and a style inside groups is referenced as
`ParagraphStyle/<group>:<group>:<name>` 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 `<CellStyleGroup Self="CellStyleGroup/$ID/<group>"
Name="$ID/<group>">` 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
+46 -10
View File
@@ -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<u32> = 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<u32, crate::model::TableStyle>,
seen: &mut std::collections::HashSet<String>,
) {
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,