diff --git a/docs/format/objects.md b/docs/format/objects.md index 94e701d..0bf02e3 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -184,6 +184,7 @@ with every code. | 0x10833 | Flattener settings (below) | | 0x14580 | Tab orders: u32 count, then per page u32 page UID and a UID list (the page's `TabOrder`) | | 0x140D | Master spreads: u16, 0 = `ShowMasterItems="false"` | +| 0x140A | Master spreads: u32 story of the primary text frame (below) | Evidence, over the 5,129 spreads and 914 master spreads of the 495 trustworthy pairs: @@ -193,6 +194,16 @@ trustworthy pairs: all `false`. - `ShowMasterItems` of master spreads: 913 have no chunk 0x140D and are `true`; the one with the chunk (0) is `false`. +- `PrimaryTextFrame` of master spreads, over all pairs of the corpus of + 2026-10: IDML writes `n` when chunk 0x140A is absent (1,471 master + spreads) or holds 0 (6). Otherwise it names the text + frame on that master spread whose `ParentStory` is the chunk's story + and whose `PreviousTextFrame` is `n` (50 of 50; in 40 of them the + story has a second frame on the spread, which is not the primary + one). IDML of DOM 7 has no `PrimaryTextFrame` (9 master spreads). The + attribute is the last one of `MasterSpread`. The converter writes it + from DOM 8 and leaves it out when the spread has no such frame: 1,521 + of 1,521 values over all pairs with the same major version. - `TabOrder` of pages: the list for the page in its spread's chunk 0x14580 equals the IDML list for 9,367 of 9,367 pages (8 with a tab order); pages not in the chunk have an empty `TabOrder`. diff --git a/src/idml/pages.rs b/src/idml/pages.rs index 7289d86..7e5d45f 100644 --- a/src/idml/pages.rs +++ b/src/idml/pages.rs @@ -226,6 +226,7 @@ mod tests { shuffle: None, flattener_resolution: None, show_master_items: None, + primary_story: None, }], // Listed out of page order, as in some samples. sections: vec![ diff --git a/src/idml/spread.rs b/src/idml/spread.rs index c3a1e1f..3134a6a 100644 --- a/src/idml/spread.rs +++ b/src/idml/spread.rs @@ -830,6 +830,7 @@ impl Writer<'_> { .attr("Self", uref(Some(s.uid))) .attr("PageCount", s.pages.len().to_string()); let origin = spread_origin(&s.pages); + let major = self.doc.version.major; if !master { x.attr("BindingLocation", s.binding_location.to_string()); } @@ -863,6 +864,12 @@ impl Writer<'_> { } } x.attrs_missing(self.observed(kind).iter()); + if master + && major >= 8 + && let Some(f) = primary_text_frame(s) + { + x.attr("PrimaryTextFrame", f); + } // A master spread has the colour its pages share (objects.md). if master && let Some(first) = s.pages.first() @@ -875,7 +882,6 @@ impl Writer<'_> { n.write(&mut x); x.end(); } - let major = self.doc.version.major; if !master && let Some(mut fp) = values::element("Spread/FlattenerPreference", major) { // Without the flattener chunk, IDML has 400 and 400 after a // session of a Japanese or Chinese edition, otherwise 300 and @@ -968,10 +974,53 @@ impl Writer<'_> { } } +/// `PrimaryTextFrame` of a master spread: `n` without a primary story, +/// otherwise the spread's first text frame of that story; `None` if the +/// spread has no such frame (objects.md, primary text frame). +fn primary_text_frame(s: &Spread) -> Option { + fn find(items: &[PageItem], story: u32) -> Option { + items.iter().find_map(|i| match i.kind { + ItemKind::TextFrame { + story: Some(st), + previous: None, + .. + } if st == story => Some(i.uid), + _ => find(&i.children, story), + }) + } + match s.primary_story { + None | Some(0) => Some("n".into()), + Some(story) => find(&s.items, story).map(|u| uref(Some(u))), + } +} + #[cfg(test)] mod tests { use super::*; + #[test] + fn primary_text_frame_needs_a_first_frame_of_the_story() { + let mut s = Spread { + uid: 1, + master_name: None, + transform: Matrix::IDENTITY, + binding_location: 0, + pages: Vec::new(), + items: Vec::new(), + guides: Vec::new(), + shuffle: None, + flattener_resolution: None, + show_master_items: None, + primary_story: None, + }; + assert_eq!(primary_text_frame(&s).as_deref(), Some("n")); + s.primary_story = Some(0); + assert_eq!(primary_text_frame(&s).as_deref(), Some("n")); + // A story without a frame on the spread. + s.primary_story = Some(5); + assert_eq!(primary_text_frame(&s), None); + } + #[test] fn writes_wrap_offsets_by_side() { let wrap = TextWrap { diff --git a/src/model/ids.rs b/src/model/ids.rs index afba663..cc518b7 100644 --- a/src/model/ids.rs +++ b/src/model/ids.rs @@ -119,6 +119,8 @@ pub mod chunk { pub const SPREAD_TAB_ORDERS: u32 = 0x14580; /// u16 0 if a master spread hides the items of its own master. pub const MASTER_SHOW_ITEMS: u32 = 0x140D; + /// u32 story of a master spread's primary text frame. + pub const MASTER_PRIMARY_STORY: u32 = 0x140A; /// Overridden master page items: u32 count, two UID lists. pub const PAGE_OVERRIDES: u32 = 0x1404; /// Layout grid use: six bytes, the last u16 1 to use the master's. diff --git a/src/model/mod.rs b/src/model/mod.rs index decca10..bdf73f7 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -197,6 +197,7 @@ mod tests { shuffle: None, flattener_resolution: None, show_master_items: None, + primary_story: None, }; // Master B (pages listed right to left) is based on master A. let mut masters = vec![ diff --git a/src/model/spread.rs b/src/model/spread.rs index adc358d..2defab6 100644 --- a/src/model/spread.rs +++ b/src/model/spread.rs @@ -126,6 +126,9 @@ pub struct Spread { pub flattener_resolution: Option<[f64; 2]>, /// Master spreads: chunk 0x140D. pub show_master_items: Option, + /// Master spreads: the story of the primary text frame (chunk + /// 0x140A); `None` without the chunk. + pub primary_story: Option, } /// A ruler guide (class 0x3301, chunk 0x3308). See `docs/format/objects.md`. @@ -443,6 +446,9 @@ impl<'a> Reader<'a> { shuffle: short(chunk::SPREAD_SHUFFLE)?, flattener_resolution, show_master_items: short(chunk::MASTER_SHOW_ITEMS)?, + primary_story: self + .chunk(uid, chunk::MASTER_PRIMARY_STORY)? + .and_then(|d| self.enc().u32_at(&d, 0)), }) }