From 15d6af5eeebd46d06bff6fd81df8926dcad10fce Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Fri, 9 Oct 2026 18:51:48 +0000 Subject: [PATCH] feat: write the grid starting point, TOC story direction and object style optical margin - Page GridStartingPoint from the u32 at 0 of chunk 0xCD04 (0 TopOutside, 4 CenterVertical; other codes are in no pair and are left out). - TOCStyle SetStoryDirection from the first u16 field of chunk 0x11605 (0 Horizontal, 1 Vertical). It is no longer a WHEN_WRITTEN key of element_values.py (the regenerated file is unchanged). - ObjectStyle StoryPreference OpticalMarginSize and OpticalMarginAlignment from the f64 at 2 and u16 at 12 of chunk 0x285B, as in the story chunk 0x2EE. Evidence in objects.md. compare.py --exclude own/, trustworthy pairs: coverage 98.32 % -> 98.41 % (Page GridStartingPoint 10,080 missing -> 0, TOCStyle SetStoryDirection 620 missing -> 0, object style OpticalMarginSize 261 and OpticalMarginAlignment 4 wrong -> 0), documents >= 99 % 225 -> 268; all pairs 96.46 % -> 96.54 %. Extras unchanged on trustworthy pairs (8,968); over all pairs +182, the new attribute on pages of stale pairs that the reference does not have. No new failures. --- docs/format/idml-values.md | 4 ++-- docs/format/objects.md | 32 ++++++++++++++++++++++++++++---- src/idml/designmap.rs | 9 +++++++++ src/idml/spread.rs | 11 +++++++++++ src/idml/styles.rs | 6 ++++++ src/model/ids.rs | 3 ++- src/model/spread.rs | 5 +++++ src/model/style.rs | 7 ++++++- tools/element_values.py | 1 - 9 files changed, 69 insertions(+), 9 deletions(-) diff --git a/docs/format/idml-values.md b/docs/format/idml-values.md index ceb85a3..d927310 100644 --- a/docs/format/idml-values.md +++ b/docs/format/idml-values.md @@ -365,8 +365,8 @@ character styles in the IDML files): | `SplitDocument="false"` where written | character | 10 on | TOC styles (851 in the IDML files) all have `RunIn="false"` and -`IncludeHidden="false"`. `SetStoryDirection` is left out: 3 styles have -`Vertical`. +`IncludeHidden="false"`. `SetStoryDirection` varies and is read from +the INDD (`objects.md`, table of contents styles). The paragraph styles' `SplitDocument` and `IncludeClass` are left out: a few styles have other values, whose INDD field was not found. Keyboard diff --git a/docs/format/objects.md b/docs/format/objects.md index e009dd3..93f7454 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -508,7 +508,8 @@ of a named grid of the document; otherwise it leaves the attribute out. Chunk 0x11605: a flag byte (1 = built-in key) and the name, three u32 (the third the UID of the title's paragraph style), a flag byte and the -title, a flag byte and a string not identified, then u16 fields: at 2 +title, a flag byte and a string not identified, then u16 fields: at 0 +`SetStoryDirection` (0 `Horizontal`, 1 `Vertical`), at 2 `NumberedParagraphs` (0 `IncludeFullParagraph`, 2 `ExcludeNumbers`), at 4 `MakeAnchor` and at 6 `RemoveForcedLineBreak` (1 = true; the chunk of older files ends before the fields IDML does not have yet), then the @@ -520,13 +521,19 @@ that style as the story's `AppliedTOCStyle`, and `n` for other stories. Evidence over the trustworthy pairs: the 511 TOC styles the converter writes match on `Name`, `Title` and `TitleStyle` (511 of 511), -`NumberedParagraphs` (511, one `ExcludeNumbers`), `MakeAnchor` (445 of +`NumberedParagraphs` (511, one `ExcludeNumbers`), `SetStoryDirection` +(620 of 620 in the corpus of 2026-10; over all its pairs 823 of 824, 2 +`Vertical` in two pairs of version 18), `MakeAnchor` (445 of 445 from DOM 9 on, 4 true) and `RemoveForcedLineBreak` (340 of 340 from DOM 13 on, 4 true); `AppliedTOCStyle` matches for 18,923 of 18,923 stories (21 made by a table of contents). `CreateBookmarks` (false in 1 of 676 IDML styles) and `IncludeBookDocuments` (true in 8) were not found, and the entries (`TOCStyleEntry`, 130 in all corpus IDML files) are not decoded: the converter writes the styles without them. +Two TOC styles of the corpus pairs have another value at the +`SetStoryDirection` field: 0x40 with no `SetStoryDirection` in the IDML +(version 15.0) and 0xF6FC with `Horizontal` (a stale pair of version +12.0). The converter writes the attribute for 0 and 1 only. ## Languages (0x2D07) @@ -606,7 +613,7 @@ chunks 0x151 and 0x154, and chunk 0x140F has no matrix | Chunk | Contents | IDML | Without the chunk | |---|---|---|---| | 0x1404 | u32 count; if not 0, a UID list of master page items and a UID list of their overrides | `OverrideList`: each item and its override (`n` for 0) | empty | -| 0xCD04 | 6 bytes, the last u16 | `UseMasterGrid` (1 = true) | | +| 0xCD04 | 6 bytes: u32 at 0, then u16 | `GridStartingPoint` (u32: 0 `TopOutside`, 4 `CenterVertical`; below), `UseMasterGrid` (u16, 1 = true) | | | 0x563 | u32, u32 code: 1 `Recenter`, 2 `ObjectBased`, 3 `Scale`, 4 `GuideBased`, 5 `UseMaster` | `LayoutRule` | `Off` | | 0x5FF | u32: 0 `Nothing`, 1 `UseMasterColor`, else an interface colour | `PageColor` | `UseMasterColor` | @@ -619,6 +626,15 @@ and `Off`, 4,117 `UseMaster`, 92 `ObjectBased`, 24 `GuideBased`, 3 `Recenter` and 1 `Scale`; 9,260 have no chunk 0x5FF, 44 code 1, 5 code 0 and 58 an interface colour. `LayoutRule` is in IDML from DOM 8 on (no page of the DOM 7 files has it). + +**Layout grid starting point.** The u32 at 0 of chunk 0xCD04 is +`GridStartingPoint`. Over all pairs of the corpus of 2026-10, 13,458 of +13,458 pages that the converter writes match (10,080 of 10,080 in the +trustworthy pairs): 13,430 have 0 and `TopOutside`, 28 have 4 and +`CenterVertical` (master pages in 14 pairs of version 18.4). Every page +in the corpus has the chunk. Codes 1, 5 and 6 occur only in files +without an IDML (versions 3, 6, 19 and 21), so their values are not +shown; the converter leaves the attribute out for them. | 0x51A | Margins: four f64 (left, top, right, bottom), u16 own-margins flag | | 0x528 | Columns: u32 count *n*, *n* f64 column edges, f64 gutter, u16 own-columns flag, u16, u16 column direction (1 vertical, 0 horizontal) | | 0xCD02 | Layout grid (`GridDataInformation`, below) | @@ -1805,7 +1821,7 @@ counts are matches of 337 unless stated. | 0x1B92B | Attribute list, u16 count, page item records (`attributes.md`) | `FillColor`, `StrokeColor`, `StrokeWeight`, `StrokeType`, `CornerOption`, `CornerRadius`, `GradientFillAngle` (0x551E), `GradientStrokeAngle` (0x5524) | | 0x1B956 | Attribute list, frame fitting (see frame fitting) | `FrameFittingOption` | | 0x1B924 | Text frame settings (below) | `TextFramePreference`, `TextFrameFootnoteOptionsObject` | -| 0x285B | u16 story orientation at 0, f64 12 at 2, u16 frame type at 14 | `StoryPreference` | +| 0x285B | u16 story orientation at 0, f64 at 2, u16 at 12, u16 frame type at 14 | `StoryPreference` (`OpticalMarginSize` from the f64, `OpticalMarginAlignment` from the u16 at 12: 0 `false`, 1 `true`) | | 0x50F28 | u16 story direction | `StoryPreference/StoryDirection` | | 0x3776, 0x3777 | Text wrap, as chunks 0x3703 and 0x373D of page items | `TextWrapPreference` | | 0x1B92E | u32 count, IDs of the categories the style turns on | `Enable…` attributes (below) | @@ -1818,6 +1834,14 @@ angles are told apart by one style with −90 and 0. Each corner radius and corner option has its own ID, as in page items (`attributes.md`, corners), and the converter writes each corner from its ID. +**Optical margin (chunk 0x285B).** The f64 at 2 is `OpticalMarginSize` +and the u16 at 12 `OpticalMarginAlignment` (1 = true), as in the story +chunk 0x2EE (stories). Over all pairs of the corpus of 2026-10, both +match in 3,515 of 3,515 object styles (2,661 of 2,661 in the trustworthy +pairs). The IDML sizes are 12 (3,172 styles), 9.2126 (336), 8 (4) and +9.9213 (3); 4 styles have `OpticalMarginAlignment="true"`. The u16 at 10 +is not identified. + **Text frame settings (chunk 0x1B924).** 222 bytes; 162, 142 or 106 in files from older versions (942, 48, 66 and 61 object styles in the little-endian corpus). The converter reads it only with these sizes. diff --git a/src/idml/designmap.rs b/src/idml/designmap.rs index 37f1446..456b7c9 100644 --- a/src/idml/designmap.rs +++ b/src/idml/designmap.rs @@ -408,6 +408,15 @@ impl Writer<'_> { .attr("Name", &name); let major = self.doc.version.major; let flag = |i: usize| t.flags.get(i).copied(); + match flag(0) { + Some(0) => { + x.attr("SetStoryDirection", "Horizontal"); + } + Some(1) => { + x.attr("SetStoryDirection", "Vertical"); + } + _ => {} + } match flag(1) { Some(0) => { x.attr("NumberedParagraphs", "IncludeFullParagraph"); diff --git a/src/idml/spread.rs b/src/idml/spread.rs index 20e4dc2..06dce01 100644 --- a/src/idml/spread.rs +++ b/src/idml/spread.rs @@ -723,6 +723,17 @@ impl Writer<'_> { .flat_map(|&(item, with)| [uref(Some(item)), uref((with != 0).then_some(with))]) .collect(); x.attr("OverrideList", overrides.join(" ")); + // Codes 0 and 4 only; the others are in no pair (objects.md, page + // settings). + match st.grid_start { + Some(0) => { + x.attr("GridStartingPoint", "TopOutside"); + } + Some(4) => { + x.attr("GridStartingPoint", "CenterVertical"); + } + _ => {} + } if let Some(v) = st.use_master_grid { x.attr("UseMasterGrid", v.to_string()); } diff --git a/src/idml/styles.rs b/src/idml/styles.rs index 2ba9fe9..ff294b5 100644 --- a/src/idml/styles.rs +++ b/src/idml/styles.rs @@ -642,6 +642,12 @@ impl Writer<'_> { 1 => story.push(("StoryOrientation", "Horizontal".to_string())), _ => {} } + story.push(("OpticalMarginSize", num(st.optical_size))); + match st.optical_alignment { + 0 => story.push(("OpticalMarginAlignment", "false".to_string())), + 1 => story.push(("OpticalMarginAlignment", "true".to_string())), + _ => {} + } } match os.direction { Some(1) => story.push(("StoryDirection", "LeftToRightDirection".into())), diff --git a/src/model/ids.rs b/src/model/ids.rs index 9000cf8..0684dfc 100644 --- a/src/model/ids.rs +++ b/src/model/ids.rs @@ -123,7 +123,8 @@ pub mod chunk { 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. + /// Layout grid use: six bytes, u32 grid starting point code, then + /// u16 1 to use the master's grid. pub const PAGE_GRID_USE: u32 = 0xCD04; /// Layout rule: u32, then u32 code. pub const PAGE_LAYOUT_RULE: u32 = 0x563; diff --git a/src/model/spread.rs b/src/model/spread.rs index 0badac5..8113928 100644 --- a/src/model/spread.rs +++ b/src/model/spread.rs @@ -69,6 +69,8 @@ pub struct PageSettings { pub overrides: Vec<(u32, u32)>, /// Chunk 0xCD04: whether the page uses its master's layout grid. pub use_master_grid: Option, + /// Chunk 0xCD04: the layout grid starting point code (u32 at 0). + pub grid_start: Option, /// Layout rule code (chunk 0x563); `None` without the chunk. pub layout_rule: Option, pub color: UiColorRef, @@ -604,6 +606,9 @@ impl<'a> Reader<'a> { .chunk(uid, chunk::PAGE_GRID_USE)? .and_then(|d| self.enc().u16_at(&d, 4)) .map(|v| v != 0), + grid_start: self + .chunk(uid, chunk::PAGE_GRID_USE)? + .and_then(|d| self.enc().u32_at(&d, 0)), layout_rule: self .chunk(uid, chunk::PAGE_LAYOUT_RULE)? .and_then(|d| self.enc().u32_at(&d, 4)), diff --git a/src/model/style.rs b/src/model/style.rs index 744ce09..1bacbd1 100644 --- a/src/model/style.rs +++ b/src/model/style.rs @@ -476,10 +476,13 @@ impl ObjectStyleFrame { } /// Story settings of an object style (chunk 0x285B), if the chunk has 16 -/// bytes: u16 story orientation at 0 and u16 frame type at 14. +/// bytes: u16 story orientation at 0, f64 optical margin size at 2, u16 +/// optical margin alignment at 12 and u16 frame type at 14. #[derive(Debug, Clone, Copy, PartialEq)] pub struct StorySettings { pub orientation: u16, + pub optical_size: f64, + pub optical_alignment: u16, pub frame_type: u16, } @@ -487,6 +490,8 @@ impl StorySettings { pub(super) fn read(enc: Encoding, d: &[u8]) -> Option { Some(StorySettings { orientation: enc.u16_at(d, 0)?, + optical_size: enc.f64_at(d, 2)?, + optical_alignment: enc.u16_at(d, 12)?, frame_type: enc.u16_at(d, 14)?, }) } diff --git a/tools/element_values.py b/tools/element_values.py index 7379c4d..53dafdf 100644 --- a/tools/element_values.py +++ b/tools/element_values.py @@ -134,7 +134,6 @@ WHEN_WRITTEN = { "ParagraphStyle": ["EmitCss"], "Story": ["UserText"], "XmlStory": ["UserText"], - "TOCStyle": ["SetStoryDirection"], "CharacterStyle": ["EmitCss", "SplitDocument"], } # Elements the converter writes only for one value of an attribute that