diff --git a/docs/format/objects.md b/docs/format/objects.md index c88b6f5..f1fbb74 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -1455,6 +1455,30 @@ Japanese (DOM 12, 13 and 18). Another frame type value leaves `FrameType` out. For another orientation value the converter uses the orientation of the story's frames (text orientation, below). +**Frame grids.** Over all pairs of the corpus of 2026-10: + +- Chunk 0xCD41 of a text frame's multi-column frame object (class + 0x263, the child that the frame's chunk 0x15B lists) is `00 00` for a + plain frame (23,537 of 23,537) and starts with u16 1 for a frame grid + (248 of 248; 100, 146, 192 or 238 bytes). IDML writes an empty + `GridDataInformation` in the `TextFrame` for exactly these 248 frames, + after `Properties`, with `GridView="GridViewEnum"`, + `CharacterCountLocation="BottomAlign"` and `CharacterCountSize` equal + to the `CharacterCountSize` of the document's story grid preference + (chunk 0xCD2E, `preferences.md`): 248 of 248 in 39 documents. The rest + of the chunk is not decoded. +- The stories of these frames are the frame grid stories of chunk 0x2EE + (above): 57 of 57. They have chunk 0xCD02 in the story object, with + the layout of the page chunk (layout grid, below), and IDML writes a + `GridDataInformation` in the `Story`, after `StoryPreference` and + before `InCopyExportOption`, with the same values: 57 of 57 for every + attribute. 223 other stories have the chunk but are not frame grid + stories, and IDML writes no `GridDataInformation` for them. One frame + grid story in the trustworthy pairs has the IDML element but no + chunk. + +The converter writes both elements by these rules. + **Owned items (run kind 0x209).** Each record: u32 run length, u16 count, then that many (u32 class, u32 UID) pairs, the objects owned by the text position at the start of the run. An item anchored in text has diff --git a/src/idml/spread.rs b/src/idml/spread.rs index f91ce5d..20e4dc2 100644 --- a/src/idml/spread.rs +++ b/src/idml/spread.rs @@ -520,6 +520,31 @@ impl Writer<'_> { }; x.attrs_missing(self.observed(observed).iter()); Self::path_geometry(x, &item.paths); + // A frame grid (objects.md, frame grids). + if let ItemKind::TextFrame { + preferences: Some(p), + .. + } = &item.kind + && p.frame_grid + { + let count = self + .doc + .prefs + .grids + .iter() + .find(|(tag, ..)| *tag == "StoryGridDataInformation") + .and_then(|(_, _, c)| *c); + if let Some(c) = count { + x.empty( + "GridDataInformation", + &[ + ("GridView", "GridViewEnum".into()), + ("CharacterCountLocation", "BottomAlign".into()), + ("CharacterCountSize", num(c)), + ], + ); + } + } for t in &item.text_paths { self.text_path(x, t); } diff --git a/src/idml/story.rs b/src/idml/story.rs index bc8ebaf..0829e98 100644 --- a/src/idml/story.rs +++ b/src/idml/story.rs @@ -120,6 +120,12 @@ impl Writer<'_> { } x.attrs_missing(self.observed("Story/StoryPreference").iter()); x.end(); + // The layout grid of a frame grid story (objects.md, frame grids). + if frame_type == Some("FrameGridType") + && let Some(g) = &s.settings.grid + { + self.grid_data(&mut x, g); + } x.start("InCopyExportOption"); x.attrs_missing(self.observed("Story/InCopyExportOption").iter()); x.end(); diff --git a/src/model/ids.rs b/src/model/ids.rs index cc518b7..ebc8566 100644 --- a/src/model/ids.rs +++ b/src/model/ids.rs @@ -228,6 +228,8 @@ pub mod chunk { pub const FRAME_COLUMN_RULE_OVERRIDE: u32 = 0x2265A; pub const FRAME_FOOTNOTES: u32 = 0x22608; pub const FRAME_IGNORE_WRAP: u32 = 0x3730; + /// Frame grid of a multi-column frame: u16 1 at 0 for a frame grid. + pub const FRAME_GRID: u32 = 0xCD41; /// Inset spacing of a text frame (on the frame, not its columns). pub const FRAME_INSET: u32 = 0x3723; pub const FRAME_JUSTIFICATION: u32 = 0x2CE; diff --git a/src/model/item.rs b/src/model/item.rs index d7bd657..9875e0b 100644 --- a/src/model/item.rs +++ b/src/model/item.rs @@ -360,6 +360,8 @@ pub struct TextFramePreferences { pub footnotes: Option<[f64; 2]>, /// Inset spacing (the frame's chunk 0x3723): top, left, bottom, right. pub inset: [f64; 4], + /// A frame grid (chunk 0xCD41 starts with u16 1). + pub frame_grid: bool, } /// Groups nested deeper than this are left out, with a warning, so that a @@ -527,6 +529,10 @@ impl<'a> Reader<'a> { .map(|d| d.iter().any(|&b| b != 0)), footnotes, inset, + frame_grid: self + .chunk(mcf, chunk::FRAME_GRID)? + .and_then(|d| self.enc().u16_at(&d, 0)) + == Some(1), })) } diff --git a/src/model/story.rs b/src/model/story.rs index a0cbcbe..50d0f7a 100644 --- a/src/model/story.rs +++ b/src/model/story.rs @@ -93,6 +93,8 @@ pub struct StoryChunks { /// Chunk 0x2EE: the text orientation u16 at 0 and the frame type u16 /// at 14. pub layout: Option<(u16, u16)>, + /// Chunk 0xCD02: the layout grid of a frame grid story. + pub grid: Option, } /// A footnote: its text runs, at their offsets in the story text, which @@ -799,6 +801,10 @@ impl<'a> Reader<'a> { layout: margin .as_ref() .and_then(|d| Some((self.enc().u16_at(d, 0)?, self.enc().u16_at(d, 14)?))), + grid: match self.chunk(uid, chunk::PAGE_GRID)? { + Some(d) => Some(GridData::read(&mut self.cursor(&d))?), + None => None, + }, }, toc_style: match self .chunk(uid, chunk::STORY_TOC)?