diff --git a/docs/format/tables.md b/docs/format/tables.md index 47d873b..5425afd 100644 --- a/docs/format/tables.md +++ b/docs/format/tables.md @@ -88,8 +88,8 @@ flag-0 sets (one pair, 8 tables) could not be read before. Every grid position has an ID. A position whose attribute is 0xB666 starts a text cell (its ID is the cell ID); attribute 0x10469 starts a -graphic cell (22 cells, one stale pair; IDML -`CellType="GraphicTypeCell"`). Every other position is covered by a +graphic cell (45 cells in 6 pairs; IDML `CellType="GraphicTypeCell"`; +see "Graphic cells" below). Every other position is covered by a merged cell: attribute 0xB614 (779 positions in the pairs, no values), or no record at all, when a row record has fewer attribute records than the row has positions (80 positions; the missing ones are the last). @@ -143,6 +143,42 @@ DOM 16 pair, the last three rows of each table, which are overset. 11,097 cells of the trustworthy pairs) and on none before (0 of 453 cells of DOM 8 and 10). +### Graphic cells + +A graphic cell holds a page item instead of text. In IDML the item is +the only child of the `Cell`, written like an item nested in another +page item: with its own `ItemTransform` and children (`Image`, `Link` +and so on), without `Locked`. + +The 0x10469 record of the grid position has two values. The first +(ID 0xB6EF) is 76 bytes; the u32 at byte 70 is the UID of a graphic +cell object (class 0x1046B). The rest of the value is not used. The +graphic cell object has: + +| Chunk | Contents | +|---|---| +| 0x10466 | u32 own UID, u32 0, then a UID list: the cell's page items | +| 0x22E01 | u32 row, u32 column of the cell | +| 0x117 | u32 table UID | +| 0x22E12 | u32 (not identified) | + +The page item's chunk 0x15B names the graphic cell object as both its +spread and its parent. + +Evidence: 62 graphic cells in 11 files (6 with IDML, 5 without). Each has a 76-byte first value whose u32 at byte 70 names a +class 0x1046B object; its chunk 0x10466 starts with its own UID and 0 +and lists one item (62 of 62), of class 0x6201, whose chunk 0x15B names +the object twice (62 of 62). In the 6 pairs (45 cells: 13 in 3 trustworthy pairs, 32 in 3 stale +pairs) the listed item is the `Rectangle` child of the IDML `Cell` in 45 +of 45, chunk 0x22E01 is the cell's row and column (`Name`) in 45 of 45, +and chunk 0x117 is the table in 45 of 45. No `Locked` appears on the 45 +cell items. + +The `Cell` element of a graphic cell follows the rules of the other +cells: the text insets and `ClipContentToTextCell` in effect, the edges, +and the attributes of its attribute set ("Cell formatting" below). None +of the 45 IDML cells has graphic insets. The converter's `Cell` attributes equal the IDML ones on 45 of 45 cells. + ## Values in effect From DOM 11, IDML writes `TextTopInset`, `TextLeftInset`, diff --git a/docs/format/unknowns.md b/docs/format/unknowns.md index 4159045..dfdd3d9 100644 --- a/docs/format/unknowns.md +++ b/docs/format/unknowns.md @@ -82,7 +82,7 @@ Status values: | Unlinked images without chunk 0x8C23 | placed graphics | 25 pairs | open: no field found | IDML has `Contents` (362 values); the bytes were not located | `objects.md`, graphics pasted without a link | | EPS `Contents` that differ | placed graphics | – | open: not examined | 18 of 515 | `objects.md`, graphics pasted without a link | | Anchored settings of some nested items | `AnchoredObjectSetting` | 3 | open: not examined | 388 values | `objects.md`, items inside an anchored item | -| Graphic cells, `FlexObject`, story links, media posters | page items | 20–28 pairs | open: not decoded | structures not written | | +| `FlexObject`, story links, media posters | page items | 20–28 pairs | open: not decoded | structures not written | | | Export attributes of 10.0 files exported by 10.2 | `ObjectExportOption` | 4 | not needed | the attribute set follows the exporting version, which the INDD does not record | `idml-values.md`, export options | | `CustomImageSizeOption` | `ObjectExportOption` | 224 | not needed | IDML value not in the schema; left out on purpose | `idml-values.md`, export options | diff --git a/src/idml/attrs.rs b/src/idml/attrs.rs index 182104a..6563860 100644 --- a/src/idml/attrs.rs +++ b/src/idml/attrs.rs @@ -2143,6 +2143,7 @@ mod tests { kind: CellKind::Text, width: None, runs: Vec::new(), + items: Vec::new(), format: Some(0), }; let t = Table { diff --git a/src/idml/designmap.rs b/src/idml/designmap.rs index 4ff3b3b..1ddda11 100644 --- a/src/idml/designmap.rs +++ b/src/idml/designmap.rs @@ -946,7 +946,7 @@ impl Writer<'_> { } /// UIDs of the page items written: on spreads and master spreads, in - /// groups and anchored in stories. + /// groups, anchored in stories and in graphic cells. pub(super) fn written_items(&self) -> std::collections::HashSet { let doc = self.doc; let mut out = std::collections::HashSet::new(); @@ -960,6 +960,13 @@ impl Writer<'_> { .iter() .flat_map(|s| s.anchors.values().flatten()), ) + .chain( + doc.stories + .iter() + .flat_map(|s| s.tables.values()) + .flat_map(|t| &t.cells) + .flat_map(|c| &c.items), + ) .collect(); while let Some(item) = stack.pop() { out.insert(item.uid); diff --git a/src/idml/story.rs b/src/idml/story.rs index f49524f..c065e74 100644 --- a/src/idml/story.rs +++ b/src/idml/story.rs @@ -1069,6 +1069,11 @@ impl Writer<'_> { .attr("AppliedCellStylePriority", "0"); } self.story_ranges(x, &c.runs, story, &cell_id); + // IDML writes a graphic cell's item like a nested item, + // without `Locked` (tables.md). + for item in &c.items { + self.page_item(x, item, true, &Matrix::IDENTITY); + } // Deleted text owned by the cell's terminator, which no range // holds, ends the cell (objects.md, tracked changes). if let Some(r) = c.runs.last() diff --git a/src/model/table.rs b/src/model/table.rs index ae20764..4cf2a7b 100644 --- a/src/model/table.rs +++ b/src/model/table.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; -use super::{Attrs, Reader, TextRun, Value}; +use super::{Attrs, PageItem, Reader, TextRun, Value}; use crate::Error; use crate::audit::{List, Recorder}; use crate::object::{Cursor, Encoding}; @@ -15,6 +15,8 @@ pub mod class { pub const TABLE: u32 = 0xB608; /// Owns the cell strand (row groups with cell records). pub const CELL_STRAND_OWNER: u32 = 0xB606; + /// The content of a graphic cell. + pub const GRAPHIC_CELL: u32 = 0x1046B; } pub mod chunk { @@ -37,6 +39,8 @@ pub mod chunk { 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; + /// Page items of a graphic cell object: u32, u32, UID list. + pub const GRAPHIC_CELL_ITEMS: u32 = 0x10466; } /// Attribute IDs in table data. @@ -47,7 +51,8 @@ pub mod attr { /// A grid position that starts a text cell; its second value is the /// cell's layout record. pub const CELL: u32 = 0xB666; - /// A grid position that starts a graphic cell. + /// A grid position that starts a graphic cell; the u32 at byte 70 of + /// its first value is the graphic cell object. pub const GRAPHIC_CELL: u32 = 0x10469; /// A grid position covered by a merged cell. pub const COVERED: u32 = 0xB614; @@ -81,6 +86,8 @@ pub struct Cell { /// that was never laid out. pub width: Option, pub runs: Vec, + /// The page items of a graphic cell. + pub items: Vec, /// The cell's attribute set (index into `Table::formats`), if it has /// one. pub format: Option, @@ -242,6 +249,8 @@ struct Position { starts: Option, /// Text area width of the layout record of a text cell. width: Option, + /// The graphic cell object of a graphic cell. + content: Option, /// Attribute set, an index into the table's formats. format: Option, } @@ -353,7 +362,14 @@ impl Reader<'_> { }, ); - let cells = cells_from_grid(&grid); + let mut cells = cells_from_grid(&grid); + // Cells are in the order of the positions that start them. + let contents = grid.iter().flatten().filter(|p| p.starts.is_some()); + for (cell, pos) in cells.iter_mut().zip(contents) { + if let Some(content) = pos.content { + cell.items = self.graphic_cell_items(content)?; + } + } let grid = grid .into_iter() .map(|row| row.into_iter().map(|p| p.format).collect()) @@ -382,6 +398,19 @@ impl Reader<'_> { }) } + /// The page items of a graphic cell object (class 0x1046B), listed in + /// its chunk 0x10466 (tables.md). + fn graphic_cell_items(&self, content: u32) -> Result, Error> { + if self.class(content) != Some(class::GRAPHIC_CELL) { + return Ok(Vec::new()); + } + let mut items = Vec::new(); + for child in self.children(content, chunk::GRAPHIC_CELL_ITEMS)? { + items.extend(self.page_item(child, None)?); + } + Ok(items) + } + /// Grid positions by row, from the cell strand's row groups, and the /// attribute sets they refer to. #[allow(clippy::type_complexity)] @@ -462,7 +491,9 @@ impl Reader<'_> { .into_iter() .enumerate() .map(|(k, id)| { - let (aid, value) = raw.get(k).map_or((0, &[][..]), |(a, v)| (*a, v)); + let (aid, values) = + raw.get(k).map_or((0, &[][..]), |(a, v)| (*a, &v[..])); + let value = |i: usize| values.get(i).map_or(&[][..], Vec::as_slice); Position { id, starts: match aid { @@ -471,7 +502,10 @@ impl Reader<'_> { _ => None, }, width: (aid == attr::CELL) - .then(|| layout_width(self.enc(), value)) + .then(|| layout_width(self.enc(), value(1))) + .flatten(), + content: (aid == attr::GRAPHIC_CELL) + .then(|| self.enc().u32_at(value(0), 70)) .flatten(), format: formats.get(k).copied(), } @@ -485,8 +519,11 @@ impl Reader<'_> { } } -/// Attribute records keeping the raw payload of their second value. -fn raw_attrs(c: &mut Cursor, n: usize) -> Result)>, Error> { +/// An attribute ID and the raw payload of each of its values. +type RawAttr = (u32, Vec>); + +/// Attribute records keeping the raw payload of each value. +fn raw_attrs(c: &mut Cursor, n: usize) -> Result, Error> { let enc = c.encoding(); let mut out = Vec::with_capacity(n); for _ in 0..n { @@ -494,19 +531,16 @@ fn raw_attrs(c: &mut Cursor, n: usize) -> Result)>, Error> { let size = c.u16()? as usize; let payload = c.bytes(size)?; let mut p = enc.cursor(payload); - let mut second = Vec::new(); + let mut values = Vec::new(); if size >= 2 { let count = p.u16()?; - for i in 0..count { + for _ in 0..count { p.u32()?; let len = p.u16()? as usize; - let data = p.bytes(len)?; - if i == 1 { - second = data.to_vec(); - } + values.push(p.bytes(len)?.to_vec()); } } - out.push((id, second)); + out.push((id, values)); } Ok(out) } @@ -547,6 +581,7 @@ fn cells_from_grid(grid: &[Vec]) -> Vec { kind, width: pos.width, runs: Vec::new(), + items: Vec::new(), format: pos.format, }); } @@ -928,6 +963,7 @@ mod tests { id, starts: (id != 0).then_some(CellKind::Text), width, + content: None, format: None, }; // Cell 1 is 20 wide (two columns of 10) and covers the row below;