feat: write table direction and the row group attributes

Chunk 0x50F65 gives TableDirection (written on every table); the row
group attributes 0xB69F, 0x10407 and 0xB6A1 give AutoGrow (now also
true), StartRow and KeepWithNextRow (tables.md).

compare.py --exclude own/, trustworthy pairs: value coverage 92.50 % ->
92.51 %; Table TableDirection 0 -> 326 of 326, Row AutoGrow 63 -> 1,128
of 1,128, StartRow 10 of 10, KeepWithNextRow 8 of 8. No new extras in
trustworthy pairs; 7 in one stale pair's table that the reference lacks.
This commit is contained in:
aiongg committed 2026-10-07 23:00:13 +00:00
1 parent 758a12a92e
commit e9a6a3cdf7
4 files changed
+50 -12

No files matched your search

+14 -3
View File
@@ -47,9 +47,20 @@ the table out.
rows (columns), u16, u16 attribute count, text attribute records (see
`attributes.md`), 8 bytes.
Row attribute 0xB69F is `AutoGrow`: 0 in all 32 rows of the pairs that
have it, and those rows have `AutoGrow="false"`; the 182 rows without it
have no `AutoGrow` in IDML. The converter writes `false` for 0 only.
**Row attributes.** IDML writes on a `Row` exactly the attributes its
row group has (presence matches for all three IDs below in the pairs):
| ID | IDML | Encoding | Evidence |
|---|---|---|---|
| 0xB69F | `AutoGrow` | 0 `false`, 1 `true` | 1,065 rows with 1, 63 with 0 |
| 0x10407 | `StartRow` | 0 `Anywhere`, 2 `NextColumn` | 10 rows (3 files) |
| 0xB6A1 | `KeepWithNextRow` | 0 `false` | 8 rows |
**Table direction.** Chunk 0x50F65 of the table object is a u16: 0 for
`TableDirection="LeftToRightDirection"`, 1 for `RightToLeftDirection`.
All 396 tables of the pairs (all versions) have it; 395 have 0 and are
left to right in IDML, the one table with 1 (DOM 21.5) is right to left.
IDML writes `TableDirection` on every table of every version.
## Cells
+12
View File
@@ -623,6 +623,18 @@ pub(super) const TABLE_ATTRS: &[(u32, &str, Kind)] = &[
(0x10454, "RightColumnRegionCellStyle", Kind::CellStyle),
];
/// Row group attributes: ID, IDML attribute, kind.
/// See `docs/format/tables.md`.
pub(super) const ROW_ATTRS: &[(u32, &str, Kind)] = &[
(0xB69F, "AutoGrow", Kind::Bool),
(
0x10407,
"StartRow",
Kind::Enum(&[(0, "Anywhere"), (2, "NextColumn")]),
),
(0xB6A1, "KeepWithNextRow", Kind::Enum(&[(0, "false")])),
];
/// Paragraph style of a cell style.
pub(super) const CELL_STYLE_PARAGRAPH_STYLE: u32 = 0x10463;
+10 -2
View File
@@ -343,6 +343,14 @@ impl Writer<'_> {
if let Some(st) = t.style.and_then(|u| self.doc.table_styles.get(&u)) {
x.attr("AppliedTableStyle", self.table_style_ref("TableStyle", st));
}
x.attr(
"TableDirection",
if t.right_to_left {
"RightToLeftDirection"
} else {
"LeftToRightDirection"
},
);
for (name, v) in self.table_attrs(&t.attrs) {
x.attr(name, v);
}
@@ -356,8 +364,8 @@ impl Writer<'_> {
if let Some(h) = r.min_height {
x.attr("MinimumHeight", num(h));
}
if r.auto_grow == Some(0) {
x.attr("AutoGrow", "false");
for (name, v) in self.attr_values(&r.attrs, ROW_ATTRS) {
x.attr(name, v);
}
x.end();
}
+14 -7
View File
@@ -33,6 +33,8 @@ pub mod chunk {
pub const CELL_STYLE_ROOT_CHILDREN: u32 = 0x2024E;
/// Children of the root table style group: u32, u32, UID list.
pub const TABLE_STYLE_ROOT_CHILDREN: u32 = 0x104E5;
/// u16 table direction: 0 left to right, 1 right to left.
pub const TABLE_DIRECTION: u32 = 0x50F65;
}
/// Attribute IDs in table data.
@@ -40,8 +42,6 @@ pub mod attr {
pub const COLUMN_WIDTH: u32 = 0xB60D;
pub const ROW_HEIGHT: u32 = 0xB60C;
pub const ROW_MIN_HEIGHT: u32 = 0xB66E;
/// 0 = `AutoGrow="false"`.
pub const ROW_AUTO_GROW: u32 = 0xB69F;
/// A grid position that starts a cell; its value holds cell geometry.
pub const CELL: u32 = 0xB666;
/// A grid position covered by a merged cell.
@@ -52,8 +52,8 @@ pub mod attr {
pub struct Row {
pub height: Option<f64>,
pub min_height: Option<f64>,
/// Stored auto-grow value (0 in every sample, `AutoGrow="false"`).
pub auto_grow: Option<u32>,
/// The row group's attributes (`AutoGrow`, `StartRow`, ...).
pub attrs: Attrs,
}
#[derive(Debug, Clone, PartialEq)]
@@ -98,6 +98,8 @@ pub struct Table {
pub style: Option<u32>,
/// Local table attributes.
pub attrs: Attrs,
/// Right to left (chunk 0x50F65 is 1).
pub right_to_left: bool,
pub header_rows: u32,
pub footer_rows: u32,
pub rows: Vec<Row>,
@@ -233,7 +235,7 @@ impl Reader<'_> {
let row = Row {
height: f64_attr(&a, attr::ROW_HEIGHT),
min_height: f64_attr(&a, attr::ROW_MIN_HEIGHT),
auto_grow: a.get(attr::ROW_AUTO_GROW).and_then(Value::as_u32),
attrs: a,
};
let count = count.min(nrows - rows.len());
rows.extend(std::iter::repeat_n(row, count));
@@ -243,7 +245,7 @@ impl Reader<'_> {
Row {
height: None,
min_height: None,
auto_grow: None,
attrs: Attrs::default(),
},
);
@@ -253,10 +255,15 @@ impl Reader<'_> {
None => None,
};
let attrs = self.counted_attrs(uid, chunk::TABLE_ATTRS)?;
let right_to_left = match self.chunk(uid, chunk::TABLE_DIRECTION)? {
Some(d) => self.cursor(&d).u16()? == 1,
None => false,
};
Ok(Table {
uid,
style,
attrs,
right_to_left,
header_rows,
footer_rows,
rows,
@@ -620,7 +627,7 @@ mod tests {
let row = |h| Row {
height: Some(h),
min_height: None,
auto_grow: None,
attrs: Attrs::default(),
};
let cells = cells_from_grid(&grid, &[row(20.0), row(20.0)], &[10.0; 4]);
let spans: Vec<_> = cells