diff --git a/docs/format/idml-values.md b/docs/format/idml-values.md index 05999df..710f8b7 100644 --- a/docs/format/idml-values.md +++ b/docs/format/idml-values.md @@ -265,6 +265,26 @@ same value, in at least 3 files (a `Keyed` block of the values file): 63 languages. Romanian and Japanese have two variants each and are left out. +### Paragraph and character styles + +The styles other than the root styles (5,505 paragraph and 2,284 +character styles in the IDML files): + +| Values kept | Styles | Versions | +|---|---|---| +| `PreviewColor` `Nothing` | paragraph and character | 7 on | +| `EpubAriaRole=""` | paragraph and character | 21 on | +| `IncludeClass="true"` | character | 13 on | +| `ExtendedKeyboardShortcut="0 0 0"` | character | 15 on | +| `EmitCss="true"` where written | paragraph and character | 10 on | +| `SplitDocument="false"` where written | character | 10 on | + +`KeyboardShortcut` and the paragraph styles' `ExtendedKeyboardShortcut`, +`SplitDocument` and `IncludeClass` are left out: a few styles have +other values (keyboard shortcuts such as `16 82`), whose INDD field was +not found. `Imported` and `StyleUniqueId` come from the INDD +(`objects.md`, styles). + ### Swatches | Element | Values kept | diff --git a/docs/format/objects.md b/docs/format/objects.md index 80324ab..16cea44 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -788,14 +788,24 @@ last paragraph return of a story is not written to IDML. Paragraph and character styles share the class. Chunk 0x230: u32 next style (0 = itself), u32 based-on style, fields not yet identified, u16 1 -for paragraph styles or 0 for character styles, u16 not identified, u8 1 -if the name is a built-in key (`$ID/` in IDML), the name as an in-object -string, then a GUID string in newer files. The name's offset varies (23–26 +for paragraph styles or 0 for character styles, u16 `Imported` (1 = +true), u8 1 if the name is a built-in key (`$ID/` in IDML), the name as +an in-object string, then, in newer files, a GUID string +(`StyleUniqueId`). The name's offset varies (23–26 bytes), so the converter locates it as a flag byte followed by a valid in-object string. All 486 style names and 291 `NextStyle` values in the pairs match. -**Kind field.** The kind and the unidentified u16 after it can be read +**Imported and unique ID.** Over the 4,694 paragraph and character +styles of the trustworthy pairs whose IDML style has the same name, the +u16 after the kind equals `Imported` in 4,694 (180 imported). The GUID +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. + +**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 template fixture `scml-template/scml.indt` (no IDML) has 1 there in 600 of its styles: 151 have `00 00 01 00` before the flag and 449 have diff --git a/src/idml/element_values.xml b/src/idml/element_values.xml index f8b375c..2d53ae9 100644 --- a/src/idml/element_values.xml +++ b/src/idml/element_values.xml @@ -35,6 +35,16 @@ tools/element_values.py; evidence in docs/format/idml-values.md. + + + Nothing + + + + + Nothing + + @@ -145,6 +155,7 @@ tools/element_values.py; evidence in docs/format/idml-values.md. + @@ -162,6 +173,9 @@ tools/element_values.py; evidence in docs/format/idml-values.md. + + + @@ -190,6 +204,8 @@ tools/element_values.py; evidence in docs/format/idml-values.md. + + @@ -201,6 +217,10 @@ tools/element_values.py; evidence in docs/format/idml-values.md. + + + + diff --git a/src/idml/mod.rs b/src/idml/mod.rs index e8069ac..9476454 100644 --- a/src/idml/mod.rs +++ b/src/idml/mod.rs @@ -2817,6 +2817,10 @@ impl Writer<'_> { for (k, v) in &plain { x.attr(k, v); } + x.attr("Imported", s.imported.to_string()); + if let Some(id) = &s.unique_id { + x.attr("StyleUniqueId", id); + } // Root styles also get the values every exported IDML has on them; // values read from the INDD take precedence. let mut extra = Vec::new(); @@ -2824,9 +2828,18 @@ impl Writer<'_> { let written: Vec<&str> = plain.iter().map(|(k, _)| *k).collect(); let (attrs, more, _) = self.root_values(tag, &written, &props); for (k, v) in &attrs { - x.attr(k, v); + if !x.has_attr(k) { + x.attr(k, v); + } } extra = more; + } else if let Some(n) = values::element(tag, doc.version.major) { + // Other styles get the values every IDML has on them. + x.attrs_missing(n.attrs.iter()); + x.attrs_missing(values::when_written(tag, doc.version.major).iter()); + if let Some(p) = n.child("Properties") { + extra = p.children.clone(); + } } if let Some(base) = s.based_on.and_then(|b| doc.styles.get(&b)) { // The root "[No ... style]" is written as a string. diff --git a/src/model/mod.rs b/src/model/mod.rs index a75d48b..0a95b78 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -537,6 +537,10 @@ pub struct Style { pub based_on: Option, pub next: Option, pub attrs: Attrs, + /// The u16 after the kind, before the name (IDML `Imported`). + pub imported: bool, + /// The GUID string after the name in newer files (`StyleUniqueId`). + pub unique_id: Option, } /// A stretch of story text with one paragraph style and one character style. @@ -2377,6 +2381,17 @@ impl<'a> Reader<'a> { return Err(Error::Corrupt(format!("style {uid}: no name"))); }; let paragraph = Cursor::new(&data[at - 4..]).u16()? != 0; + let imported = Cursor::new(&data[at - 2..]).u16()? != 0; + // A 36-character in-object string after the name: a GUID. + const GUID: [u8; 6] = [2, 0, 36, 0, 36, 0x40]; + let unique_id = if crate::object::big_endian() { + None + } else { + data[at..] + .windows(GUID.len()) + .position(|w| w == GUID) + .and_then(|i| Cursor::new(&data[at + i..]).string().ok()) + }; let attrs = match self.chunk(uid, chunk::STYLE_ATTRS)? { Some(d) if d.len() >= 2 => { let mut c = Cursor::new(&d); @@ -2393,6 +2408,8 @@ impl<'a> Reader<'a> { based_on: uid_or_none(based_on), next: uid_or_none(next), attrs, + imported, + unique_id, })) } diff --git a/tests/fixtures.rs b/tests/fixtures.rs index 489ca1a..32f9c78 100644 --- a/tests/fixtures.rs +++ b/tests/fixtures.rs @@ -186,7 +186,8 @@ fn little_endian_fixtures_convert() { } /// The InDesign 7.5 template has character styles whose kind field is -/// followed by a non-zero u16 (`docs/format/objects.md`, Styles). +/// followed by a non-zero u16, the imported flag +/// (`docs/format/objects.md`, Styles). #[test] fn style_kind_is_a_u16() { let Some(root) = fixtures() else { @@ -196,7 +197,9 @@ fn style_kind_is_a_u16() { let mut out = Vec::new(); indd::convert(&bytes, "test.indd", &mut out).unwrap(); let text = String::from_utf8_lossy(&out); - assert!(text.contains(r#""#)); + assert!(text.contains(r#" reason, as recorded in docs/format/idml-values.md. EXPLAINED = {} EXPLAINED_SHARE = 0.995 +# The root styles, whose values tools/root_values.py collects; they are +# left out of the style paths here. +ROOT_STYLES = { + "ParagraphStyle/$ID/[No paragraph style]", + "CharacterStyle/$ID/[No character style]", + "ObjectStyle/$ID/[None]", + "CellStyle/$ID/[None]", + "TableStyle/$ID/[No table style]", +} # Attributes that are names or references of the element itself, or # written by the converter from the document structure. SKIP = {"Self", "Name"} @@ -168,7 +180,7 @@ def scan(arg): lists["keyed:" + el.tag].append(dict(el.attrib)) if el.get("Self") is None: continue - if el.tag in wanted: + if el.tag in wanted and el.get("Self") not in ROOT_STYLES: found[el.tag].append(flatten(el)) for ch in el: path = f"{el.tag}/{ch.tag}"