diff --git a/docs/format/objects.md b/docs/format/objects.md index 155f76c..94e701d 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -45,8 +45,8 @@ are in `big-endian.md`. UTF-16 code units follow. A text of *n* code units is a sequence of segments adding up to *n*. Example: "WOMEN’S\r" is `05 40 "WOMEN" 01 80 19 20 02 40 "S\r"`. -- **In-object strings:** u8 2, u8 (usually 0, meaning unknown), u16 length - in code units, then segments. 4,135 occurrences in three sample files. +- **In-object strings:** u8 2, u8 (usually 0; a script code in some + strings, below), u16 length in code units, then segments. 4,135 occurrences in three sample files. In files from InDesign 2.0 the first byte is 1: in the four distinct 2.0 files, the pattern tag, 0, length *n*, 0, segment header 0x4000 + *n* occurs 154 to 353 times per file with tag 1 and never with tag 2. In @@ -84,6 +84,12 @@ users of a document have the same byte, except in one pair with users of bytes 0 and 7. The converter uses the byte of the last user to choose font family names (`fonts.md`, native family names). +Other in-object strings carry the same kind of byte, so a search for a +string must accept any second byte. In the 149 pairs typeset in +Japanese it is 1 for most user-made names, and 3, 5, 7, 0x19 and 0x1D +also occur, in style names, style GUIDs, layer names and ruby font +styles. Layer names and style GUIDs (below) rely on this. + **Document users.** IDML lists one `DocumentUser` per user in chunk 0xA443, `Self` being `dDocumentUser` and the index in hexadecimal (491 of 495 trustworthy pairs have as many users as the chunk; the other 4 are @@ -328,7 +334,12 @@ trustworthy pairs that layer is not written. It is usually named name (2), so the name does not identify it. In all 1,053 layers of the trustworthy pairs the name starts at offset 19, and each field above equals the IDML value for 1,053 of 1,053 layers (127 locked, 55 hidden, 59 not printable, 4 with locked guides, -1 without `UI`, 2 ignoring text wrap). `ShowGuides` and `Expendable` are +1 without `UI`, 2 ignoring text wrap). In the corpus of 2026-10, the +string at offset 19 gives the IDML `Name` of 1,683 of 1,683 layers in +all pairs, whatever its second byte (in the trustworthy pairs, 188 +layers have a byte other than 0, all with the IDML name). The converter reads the name at offset 19 when byte +19 is the string tag, and otherwise searches for a string from offset +18. `ShowGuides` and `Expendable` are true in every layer; the two fields that are 1 in every sample may hold them. The converter reads the fields only when the name starts at offset 19 (in all little-endian corpus pairs, 1,465 layers). @@ -1591,7 +1602,11 @@ is a 36-character in-object string after the name; where it is stored, IDML has it as `StyleUniqueId` in 2,769 of 2,793 styles (DOM 11 on; the other 24 have another GUID in IDML). Styles without a stored GUID (1,108 from DOM 11 on) have a `StyleUniqueId` in IDML that the INDD does -not hold, which the converter leaves out. +not hold, which the converter leaves out. The byte after the GUID's +string tag is not always 0. In the trustworthy pairs of the corpus of +2026-10, accepting any second byte gives 724 more styles (479 +paragraph, 245 character) the IDML `StyleUniqueId`; 4 more have another +GUID in IDML, as above. **Kind field.** The kind and the `Imported` u16 after it can be read as one u32 in most files, because the second u16 is 0. The InDesign 7.5 diff --git a/src/model/spread.rs b/src/model/spread.rs index 30d9136..adc358d 100644 --- a/src/model/spread.rs +++ b/src/model/spread.rs @@ -314,8 +314,12 @@ impl<'a> Reader<'a> { let locked = c.u16()? != 0; let visible = c.u16()? != 0; c.skip(14)?; - // A string follows; its position varies, so search for the tag. - let name = find_string(self.enc(), &data, 18)?; + // A string follows, at offset 19 in all corpus pairs; elsewhere + // search for the tag (objects.md, layers). + let name = match data.get(19) { + Some(2) if !self.enc().big_endian() => self.cursor(&data[19..]).string()?, + _ => find_string(self.enc(), &data, 18)?, + }; let settings = self.layer_settings(&data)?; Ok(Layer { uid, diff --git a/src/model/strings.rs b/src/model/strings.rs index 3439212..86d4ec1 100644 --- a/src/model/strings.rs +++ b/src/model/strings.rs @@ -30,7 +30,9 @@ pub(super) fn find_flagged_string( }) } -/// Find the first in-object string at or after `from`. +/// Find the first in-object string at or after `from`. The byte after +/// the tag can have any value (`docs/format/objects.md`, in-object +/// strings). pub(super) fn find_string(enc: Encoding, data: &[u8], from: usize) -> Result { if enc.big_endian() { // The tag (2), the byte before it in little-endian data, then the @@ -47,7 +49,7 @@ pub(super) fn find_string(enc: Encoding, data: &[u8], from: usize) -> Result 0 && i + 6 <= data.len() @@ -60,3 +62,17 @@ pub(super) fn find_string(enc: Encoding, data: &[u8], from: usize) -> Result Reader<'a> { } else { None }; - // A 36-character in-object string after the name: a GUID. - const GUID: [u8; 6] = [2, 0, 36, 0, 36, 0x40]; + // A 36-character in-object string after the name: a GUID. The + // byte after the tag can have any value (objects.md, styles). let unique_id = if self.enc().big_endian() { None } else { data[at..] - .windows(GUID.len()) - .position(|w| w == GUID) + .windows(6) + .position(|w| w[0] == 2 && w[2..] == [36, 0, 36, 0x40]) .and_then(|i| self.cursor(&data[at + i..]).string().ok()) }; let attrs = match self.chunk(uid, chunk::STYLE_ATTRS)? {