feat: write PrimaryTextFrame of master spreads

Read master spread chunk 0x140A (u32 story) and write PrimaryTextFrame
as the last MasterSpread attribute from DOM 8: n without a story,
otherwise the spread's text frame of that story that has no previous
frame. Evidence in objects.md.

compare.py --exclude own/, trustworthy pairs: coverage 98.11 % ->
98.12 % (MasterSpread PrimaryTextFrame 0 -> 1,025 of 1,025), documents
>= 99 % 179 -> 182; all pairs 96.25 % -> 96.26 %, 1,521 of 1,521
values. Trustworthy extras unchanged (8,968); over all pairs +9, one
attribute on each of 9 master spreads that the stale IDMLs lack. No new
failures or warnings, schema failures 0 on pairs.

diff_outputs.py: 3,620 outputs differ, only in MasterSpreads/*.
This commit is contained in:
aiongg committed 2026-10-08 16:43:09 +00:00
1 parent 3a8718d9db
commit a958e55d82
6 files changed
+71 -1

No files matched your search

+11
View File
@@ -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`.
+1
View File
@@ -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![
+50 -1
View File
@@ -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<String> {
fn find(items: &[PageItem], story: u32) -> Option<u32> {
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 {
+2
View File
@@ -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.
+1
View File
@@ -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![
+6
View File
@@ -126,6 +126,9 @@ pub struct Spread {
pub flattener_resolution: Option<[f64; 2]>,
/// Master spreads: chunk 0x140D.
pub show_master_items: Option<u16>,
/// Master spreads: the story of the primary text frame (chunk
/// 0x140A); `None` without the chunk.
pub primary_story: Option<u32>,
}
/// 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)),
})
}