From e1286924ff69816baf35521063b2b6e983b7fdfb Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Sat, 10 Oct 2026 03:22:50 +0000 Subject: [PATCH] fix: read four more page number styles and index topics with cross references Section page number styles 0x4C1A SingleLeadingZeros, 0x4C13 DoubleLeadingZeros, 0x4C19 LowerLetters and 0x4C16 UpperRoman, from pairs that had warned about them (89 sections with an IDML section, no contradiction). Pages of these sections get names in that style; in the page Descriptor of a SingleLeadingZeros section IDML writes the section prefix as a string in place of the style (1,249 of 1,249 descriptors). An index topic record ends with a u32 count of cross references, their UIDs and a u32, not with 8 fixed bytes. 29 pairs whose topic has one cross reference lost the whole index section with a warning; their topics are now written. CrossReference elements are not written yet. Also documents the colour model code 3 (mixed inks, written by IDML as MixedInk elements) and the 104-byte object style frame settings of InDesign 4.0 to 6.0 (no pair), which stay unconverted. compare.py --exclude own/, trustworthy pairs: +727 values before the descriptor rule (Section PageNumberStyle 1,257 -> 1,344 of 1,344, Page Name 645 -> 553 wrong, 29 Topic elements), 0 lost on any key; with the rule, the page descriptors of the subsets checked are all reproduced. --- docs/format/index.md | 17 +++++++++++++++- docs/format/objects.md | 44 +++++++++++++++++++++++++++++++++++------- src/idml/pages.rs | 32 ++++++++++++++++++++++++++++-- src/idml/spread.rs | 8 +++++++- src/model/ids.rs | 4 ++++ src/model/index.rs | 19 +++++++++++++++++- src/model/spread.rs | 18 +++++++++++++---- 7 files changed, 126 insertions(+), 16 deletions(-) diff --git a/docs/format/index.md b/docs/format/index.md index 2a02bbf..d9377da 100644 --- a/docs/format/index.md +++ b/docs/format/index.md @@ -41,7 +41,8 @@ Topic record: | u32 string | Topic text | `Name` | | u32 string | Sort order (empty in every sample) | `SortOrder` | | u32 *m*, *m* UIDs | The page references (class 0x13006) of this topic | their `ReferencedTopic` | -| 8 bytes | 0 in every sample | | +| u32 *k*, *k* UIDs | The topic's cross references (class 0x13007), below | `CrossReference` children | +| u32 | 0 in every sample | | - IDML writes the topics as `Topic` children of `Index`, a subtopic as a child of its topic: sections in the order of chunk 0x13005, records in @@ -54,6 +55,20 @@ Topic record: one trustworthy pair the INDD has 3 more topics, and 3 more page references, than its IDML (below). +**Cross references.** In the corpus after 2026-10, 29 pairs (InDesign +13.0 and 13.1, from one set of tutorial files) have a topic with *k* = 1. +Read with a fixed 8 bytes after the page references, these sections +ended 4 bytes early and were left out. The UID is that of the topic's +IDML `CrossReference` (`Self="u…"`). The cross reference object has +chunk 0x1300B (u16 4 for `CrossReferenceType="SeeAlsoHerein"`, u32 UID +of a class 0x13008 object, u32 0) and chunk 0x13008 (u16 2, u32 the +section). The class 0x13008 object (chunk 0x1300C) holds the UID of +the section of the referenced topic, the topic's position in it (1) and +the cross reference's UID. Every topic of the pairs before 2026-10 has +*k* = 0. The converter reads the list so that the section's topics are +written; it does not write `CrossReference` elements, as one sample +shows one type code. + ## Page references (class 0x13006) A page reference is owned by a U+FEFF in the story text (owned items, diff --git a/docs/format/objects.md b/docs/format/objects.md index 5d9be73..c798ce7 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -1917,7 +1917,9 @@ is not identified. files from older versions (942, 48, 66 and 61 object styles in the little-endian corpus). The converter reads it only with these sizes. The InDesign 4.0 file has 104 bytes, with another layout; the converter -leaves it out with a warning (`big-endian.md`). +leaves it out with a warning (`big-endian.md`). In the corpus after +2026-10, 1,129 object styles in 263 files of InDesign 4.0 to 6.0 have 104 +bytes; none of these files has an IDML, so the layout cannot be checked. | Offset | Contents | Attribute | |---|---|---| @@ -2055,7 +2057,7 @@ Section chunk 0x4C02: | u8, string | `Marker` | | u32 | First page of the section; 0 for the section that starts at the document's first page | | u32 | Page number start (`PageNumberStart`) | -| u32 | Page number style: 0x4C15 = `Arabic`, 0x4C17 = `LowerRoman`, 0x4C12 = `Kanji` | +| u32 | Page number style: 0x4C15 = `Arabic`, 0x4C17 = `LowerRoman`, 0x4C12 = `Kanji`, 0x4C13 = `DoubleLeadingZeros`, 0x4C16 = `UpperRoman`, 0x4C19 = `LowerLetters`, 0x4C1A = `SingleLeadingZeros` (below) | | u32 | Continue numbering (1 = true, `ContinueNumbering`) | | u32 | Not identified | | u8 flag, string | `AlternateLayout`: the string, with `$ID/` before it if the flag is 1 | @@ -2114,15 +2116,35 @@ Evidence: show the style. `Kanji` is the only value of the schema's `PageNumberStyle` enumeration that uses such numerals. -The converter writes `PageNumberStyle` for these three codes and leaves -it out (with a warning) for other codes. +Pairs of the corpus after 2026-10 show four more codes. Over every +valid distinct file, each section whose code the converter did not know +was matched with the IDML `Section` of the same UID: + +| Code | IDML `PageNumberStyle` | Sections with an IDML section | Sections without | +|---|---|---|---| +| 0x4C1A | `SingleLeadingZeros` | 51 | 30 | +| 0x4C13 | `DoubleLeadingZeros` | 21 | 3 | +| 0x4C19 | `LowerLetters` | 14 | 2 | +| 0x4C16 | `UpperRoman` | 3 | 10 | + +No section has another value for these codes. In the `Descriptor` of a +page, whose second item is the section's style, IDML writes a page of a +`SingleLeadingZeros` section with a string there, the section prefix +again: 1,249 descriptors in the IDML files of the corpus (1,223 with an +empty prefix), none with the enumeration value. 0x4C18 (one section) and +0x4C06 (InDesign 2.0 and 3.0 files) occur only in files without IDML. +The converter writes `PageNumberStyle` for the seven codes and leaves it +out (with a warning) for other codes. The converter names document pages by their number in their section, counting on from the previous section when numbering continues. In a section with style 0x4C17 it writes the number in lower-case Roman (i, ii, iii), as in the PDF labels above, and in a section with style 0x4C12 in Chinese digits, as the folios show. No pair shows IDML page names in -such sections. +such sections. It writes upper-case Roman numerals for 0x4C16, two and +three digits with leading zeros for 0x4C1A and 0x4C13, and the letters a +to z for 0x4C19 (later numbers as Arabic numbers); the page names of the +pairs above measure these. ## Document preferences (class 0x2202) @@ -2545,8 +2567,16 @@ writes is written (783 of 783 `Gradient` elements). colours with chunk 0x1F09: 12,814 with code 0, 250 with code 2 (one `Registration` colour per file) and 3 with code 1. Two of the three are copies of one colour in two pairs, and their IDML has `Model="Spot"`; -the third is in a file without an IDML. No file has another code, so -the converter leaves `Model` out, with a warning, for any other code. +the third is in a file without an IDML. The converter leaves `Model` +out, with a warning, for any other code. + +**Code 3: mixed inks.** The corpus after 2026-10 has 47 colours with +code 3 in 27 files, 16 of them pairs (InDesign 12.1 to 17.0, typeset in +Korean). Their IDML has no `Color` element for them; it lists +`MixedInk` elements in `Resources/Graphic.xml` (`Model="Mixedinkmodel"`, +`Space="MixedInk"`, `InkList`, `InkPercentages`, `BaseColor` and the +spot colour lists). The fields of the ink list are not decoded, so the +converter writes neither element for these colours. **Tints** are objects of the same class without chunks 0x1F10 and 0x1F01. Chunk 0x117 is the UID of the base colour, and chunk 0x1F24 holds diff --git a/src/idml/pages.rs b/src/idml/pages.rs index b5ccc34..64d9cf5 100644 --- a/src/idml/pages.rs +++ b/src/idml/pages.rs @@ -93,6 +93,10 @@ pub(super) fn number_style(code: u32) -> Option<&'static str> { numbering::ARABIC => Some("Arabic"), numbering::LOWER_ROMAN => Some("LowerRoman"), numbering::KANJI => Some("Kanji"), + numbering::DOUBLE_LEADING_ZEROS => Some("DoubleLeadingZeros"), + numbering::UPPER_ROMAN => Some("UpperRoman"), + numbering::LOWER_LETTERS => Some("LowerLetters"), + numbering::SINGLE_LEADING_ZEROS => Some("SingleLeadingZeros"), _ => None, } } @@ -124,6 +128,27 @@ pub(super) fn lower_roman(mut n: u32) -> String { out } +fn upper_roman(n: u32) -> String { + lower_roman(n).to_uppercase() +} + +fn single_leading_zeros(n: u32) -> String { + format!("{n:02}") +} + +fn double_leading_zeros(n: u32) -> String { + format!("{n:03}") +} + +/// The letter of `n` from 1 to 26; other numbers as Arabic numbers, as no +/// sample shows them. +fn lower_letter(n: u32) -> String { + match n { + 1..=26 => char::from(b'a' + (n - 1) as u8).to_string(), + _ => n.to_string(), + } +} + /// Chinese numeral of `n`, digit by digit (10 is 一〇), as the folios of /// a sample with that style show. pub(super) fn kanji_digits(n: u32) -> String { @@ -135,8 +160,7 @@ pub(super) fn kanji_digits(n: u32) -> String { } /// The name of each document page: its number (see `page_numbers`) in -/// its section's style. Styles other than lower-case Roman and Kanji are -/// written as Arabic numbers. +/// its section's style (objects.md, master spread names and sections). pub(super) fn page_names(doc: &Document) -> Vec { let numbers = page_numbers(doc); let mut out: Vec = numbers.iter().map(u32::to_string).collect(); @@ -144,6 +168,10 @@ pub(super) fn page_names(doc: &Document) -> Vec { let name: fn(u32) -> String = match s.style { numbering::LOWER_ROMAN => lower_roman, numbering::KANJI => kanji_digits, + numbering::UPPER_ROMAN => upper_roman, + numbering::SINGLE_LEADING_ZEROS => single_leading_zeros, + numbering::DOUBLE_LEADING_ZEROS => double_leading_zeros, + numbering::LOWER_LETTERS => lower_letter, _ => continue, }; for i in (first..first + length).filter(|&i| numbers[i] > 0) { diff --git a/src/idml/spread.rs b/src/idml/spread.rs index 44fbf54..4b31b6a 100644 --- a/src/idml/spread.rs +++ b/src/idml/spread.rs @@ -932,7 +932,13 @@ impl Writer<'_> { }; let mut items = vec![ item("string", s.prefix.clone()), - item("enumeration", style.into()), + // IDML writes the prefix again in place of this style + // (objects.md, master spread names and sections). + if s.style == crate::model::numbering::SINGLE_LEADING_ZEROS { + item("string", s.prefix.clone()) + } else { + item("enumeration", style.into()) + }, item("boolean", s.continue_numbering.to_string()), item("boolean", "false".into()), item("long", number.to_string()), diff --git a/src/model/ids.rs b/src/model/ids.rs index 0512733..4faa074 100644 --- a/src/model/ids.rs +++ b/src/model/ids.rs @@ -333,4 +333,8 @@ pub mod numbering { pub const LOWER_ROMAN: u32 = 0x4C17; /// Chinese numerals, written digit by digit. pub const KANJI: u32 = 0x4C12; + pub const DOUBLE_LEADING_ZEROS: u32 = 0x4C13; + pub const UPPER_ROMAN: u32 = 0x4C16; + pub const LOWER_LETTERS: u32 = 0x4C19; + pub const SINGLE_LEADING_ZEROS: u32 = 0x4C1A; } diff --git a/src/model/index.rs b/src/model/index.rs index 8e6f68b..b7090bc 100644 --- a/src/model/index.rs +++ b/src/model/index.rs @@ -80,7 +80,12 @@ fn read_topics(c: &mut Cursor) -> Result, Error> { return Err(Error::Corrupt(format!("{m} page references"))); } let refs = (0..m).map(|_| c.u32()).collect::>()?; - c.skip(8)?; + // The cross references of the topic (class 0x13007), then a u32. + let k = c.u32()? as usize; + if k > c.remaining() / 4 { + return Err(Error::Corrupt(format!("{k} cross references"))); + } + c.skip(4 * k + 4)?; close(&mut stack, &mut out, level - 1); stack.push(Topic { name, @@ -181,6 +186,18 @@ mod tests { assert_eq!((t[0].name.as_str(), &t[0].refs[..]), ("a", &[7][..])); assert_eq!(t[0].children[0].children[0].refs, vec![8, 9]); assert_eq!(t[1].name, "d"); + // A topic with a cross reference: u32 1, its UID, u32 0. + let mut x = Vec::new(); + x.extend(1u32.to_le_bytes()); + x.extend(0u16.to_le_bytes()); + x.extend(1u32.to_le_bytes()); + record(&mut x, 1, 0, "s", &[]); + x.truncate(x.len() - 8); + x.extend(1u32.to_le_bytes()); + x.extend(0xC6Du32.to_le_bytes()); + x.extend(0u32.to_le_bytes()); + let t = read_topics(&mut enc.cursor(&x)).unwrap(); + assert_eq!(t[0].name, "s"); // A level that skips one is an error. let mut bad = d[..10].to_vec(); bad[6..10].copy_from_slice(&1u32.to_le_bytes()); diff --git a/src/model/spread.rs b/src/model/spread.rs index 4b42127..224fe32 100644 --- a/src/model/spread.rs +++ b/src/model/spread.rs @@ -332,7 +332,17 @@ impl<'a> Reader<'a> { .ok(); } } - if ![numbering::ARABIC, numbering::LOWER_ROMAN, numbering::KANJI].contains(§ion.style) { + if ![ + numbering::ARABIC, + numbering::LOWER_ROMAN, + numbering::KANJI, + numbering::DOUBLE_LEADING_ZEROS, + numbering::UPPER_ROMAN, + numbering::LOWER_LETTERS, + numbering::SINGLE_LEADING_ZEROS, + ] + .contains(§ion.style) + { self.warn(format!( "section {uid}: page number style {:#x} is not known; left out", section.style @@ -467,9 +477,9 @@ impl<'a> Reader<'a> { let short = |id: u32| -> Result, Error> { Ok(self.chunk(uid, id)?.and_then(|d| self.enc().u16_at(&d, 0))) }; - let transition = self.chunk(uid, chunk::SPREAD_TRANSITION)?.and_then(|d| { - Some((self.enc().u32_at(&d, 0)?, self.enc().u32_at(&d, 8)?)) - }); + let transition = self + .chunk(uid, chunk::SPREAD_TRANSITION)? + .and_then(|d| Some((self.enc().u32_at(&d, 0)?, self.enc().u32_at(&d, 8)?))); Ok(Spread { transition, uid,