diff --git a/docs/format/objects.md b/docs/format/objects.md index e4eb473..5c6ea11 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -65,6 +65,13 @@ are in `big-endian.md`. | 0x222 | Two UID lists: the stories, then the XML backing story; IDML `StoryList` is both (`xml.md`) | | 0x4C01 | UID list: sections | | 0xA443 | Document users: u32 count, then per user a flag byte, the name as an in-object string, u32 colour | +| 0x1630B | Label: u16 0x7B7B, u32 count *n*, then *n* pairs of key and value, each a flag byte (1 for a built-in key) and an in-object string | + +**Document label.** IDML writes `Document/Properties/Label` with one +`KeyValuePair` (`Key`, `Value`) per stored pair, in stored order; the +`$ID/` rule of the flag applies. Without the chunk there is no `Label`. +Evidence: 436 of the 438 trustworthy pairs whose IDML has a document +label match (one differs, one has no chunk). **Script byte of the user names.** The second byte of each user name's in-object string (the byte after the string tag) is a script code: 0 @@ -598,6 +605,7 @@ IDML value is the default in the table. | 0x2C10 (groups: 0x418) | u8 1 if a built-in key, then an in-object string | `Name`: the string, or `$ID/` and the key | `$ID/` | | 0x2C32 | u16, 0 = hidden | `Visible` | `true` | | 0x2C2D | u32, 1 = locked | `Locked` | `false` | +| 0x142D | u32, 1 = overrides not allowed | `AllowOverrides` on items of master spreads (the spread in chunk 0x15B is a master spread): `false` for 1, else `true`; no item of a document spread and no placed graphic has it (11,791 of 11,791 trustworthy items) | `true` on master spreads | | 0x21D4E | u32 count *n*, *n* pairs of u32 | `ParentInterfaceChangeCount`: the numbers | empty | | 0x21D50 | same | `TargetInterfaceChangeCount` | empty | | 0x21D53 | same | `LastUpdatedInterfaceChangeCount` | empty | @@ -1384,6 +1392,19 @@ reproduced for 5,273 of 5,273 paragraph styles and 2,191 of 2,202 character styles. IDML has `ExtendedKeyboardShortcut` from DOM 15 on; the converter writes it from version 15. +**Export flags (chunk 0x28F0).** u32 count of export tag maps, the +maps, then u16 values: `SplitDocument`, `EmitCss` and, from DOM 13, +`IncludeClass` (1 `true`, 0 `false`); later versions add more u16 +values. The tag maps (`StyleExportTagMap`) are not decoded, so the +flags are read only when the count is 0. IDML has `SplitDocument` and +`EmitCss` from DOM 10 and `IncludeClass` from DOM 13 on paragraph and +character styles. Without the chunk the values are `false`, `true`, +`true`. Evidence (trustworthy pairs, styles other than the root +styles): every converted value equals the IDML (paragraph styles +`SplitDocument` 3,751, `IncludeClass` 3,098, `EmitCss` 3,865; character +styles 1,962, 1,717, 1,962). The styles with tag maps keep the observed +values or none. + **Empty nested, line and GREP styles.** Paragraph styles have `EmptyNestedStyles`, `EmptyLineStyles` and `EmptyGrepStyles` (DOM 8.1, and 10 on). Each is `false` when the style's list of nested styles diff --git a/src/idml/designmap.rs b/src/idml/designmap.rs index 28be76d..a62fedb 100644 --- a/src/idml/designmap.rs +++ b/src/idml/designmap.rs @@ -64,6 +64,14 @@ impl Writer<'_> { } // `false` in every corpus IDML (docs/format/idml-values.md). x.attr("AccurateLABSpots", "false"); + if !doc.label.is_empty() { + x.start("Properties").start("Label"); + for (k, v) in &doc.label { + x.empty("KeyValuePair", &[("Key", k.clone()), ("Value", v.clone())]); + } + x.end(); + x.end(); + } self.languages(&mut x); x.empty("idPkg:Graphic", &[("src", "Resources/Graphic.xml".into())]); x.empty("idPkg:Fonts", &[("src", "Resources/Fonts.xml".into())]); diff --git a/src/idml/graphic.rs b/src/idml/graphic.rs index bb0063c..3edac28 100644 --- a/src/idml/graphic.rs +++ b/src/idml/graphic.rs @@ -267,7 +267,12 @@ impl Writer<'_> { x.attr("AppliedObjectStyle", style); } x.attr("ItemTransform", matrix(&g.transform)); - self.settings(x, &g.props, None); + // IDML has no `AllowOverrides` on placed graphics. + let props = crate::model::ItemProps { + allow_overrides: None, + ..g.props.clone() + }; + self.settings(x, &props, None); if g.kind == GraphicKind::Image { for (name, v) in self.item_attr_values(&g.attrs) { if name == "FillColor" { diff --git a/src/idml/spread.rs b/src/idml/spread.rs index e79fdfa..cd7eeac 100644 --- a/src/idml/spread.rs +++ b/src/idml/spread.rs @@ -332,6 +332,9 @@ impl Writer<'_> { if let Some(l) = locked { x.attr("Locked", l.to_string()); } + if let Some(a) = p.allow_overrides { + x.attr("AllowOverrides", a.to_string()); + } if self.doc.version.major >= 8 { for (name, counts) in [ "ParentInterfaceChangeCount", diff --git a/src/idml/styles.rs b/src/idml/styles.rs index cc5d7a8..c37ee86 100644 --- a/src/idml/styles.rs +++ b/src/idml/styles.rs @@ -791,6 +791,9 @@ impl Writer<'_> { { x.attr("ExtendedKeyboardShortcut", e); } + for (name, value) in export_flags(s, v.major) { + x.attr(name, value); + } // 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()); @@ -818,3 +821,30 @@ impl Writer<'_> { x.end(); } } + +/// `SplitDocument`, `EmitCss` and `IncludeClass` of a paragraph or +/// character style: the first u16 values after the tag map count of +/// chunk 0x28F0, or `false`, `true`, `true` without the chunk. IDML has +/// the first two from DOM 10, the third from DOM 13 +/// (`docs/format/objects.md`, styles). +fn export_flags(s: &Style, major: u32) -> Vec<(&'static str, &'static str)> { + let need = match major { + 0..=9 => return Vec::new(), + 10..=12 => 2, + _ => 3, + }; + let values: Vec = match &s.export_flags { + Some(f) if f.len() >= need => f[..need].to_vec(), + Some(_) => return Vec::new(), + None => [0, 1, 1][..need].to_vec(), + }; + ["SplitDocument", "EmitCss", "IncludeClass"] + .into_iter() + .zip(values) + .filter_map(|(name, v)| match v { + 0 => Some((name, "false")), + 1 => Some((name, "true")), + _ => None, + }) + .collect() +} diff --git a/src/model/document.rs b/src/model/document.rs index c3b4e41..178f02c 100644 --- a/src/model/document.rs +++ b/src/model/document.rs @@ -22,6 +22,9 @@ pub struct Document { pub users: Vec<(u8, String)>, /// The script byte of the last document user's name. pub users_script: Option, + /// The document's label (chunk 0x1630B): key and value, as IDML + /// writes them. + pub label: Vec<(String, String)>, /// Index sort groups (preferences chunk 0x1307E), in order: name, /// include flag and header variant. pub index_groups: Vec<(String, bool, u16)>, @@ -182,6 +185,10 @@ impl<'a> Reader<'a> { let constant_shade = self.constant_shade(); let assignments = self.assignments(); let users_script = self.users_script(DOC); + let label = self.label(DOC).unwrap_or_else(|e| { + self.warn(format!("document label left out: {e}")); + Vec::new() + }); let users = self.users(DOC).unwrap_or_else(|e| { self.warn(format!("document users left out: {e}")); Vec::new() @@ -240,6 +247,7 @@ impl<'a> Reader<'a> { table_styles: objects.table_styles, users, users_script, + label, sections, text_variables: objects.text_variables, hyperlinks: objects.hyperlinks, diff --git a/src/model/ids.rs b/src/model/ids.rs index fd0f551..f6e693b 100644 --- a/src/model/ids.rs +++ b/src/model/ids.rs @@ -87,6 +87,8 @@ pub mod chunk { /// Document users: u32 count, then per user a flag byte, the name /// and u32 colour. pub const DOC_USERS: u32 = 0xA443; + /// Document label: u16 0x7B7B, u32 count, flagged key and value strings. + pub const DOC_LABEL: u32 = 0x1630B; pub const SPREAD_CHILDREN: u32 = 0x503; pub const SPREAD_TRANSFORM: u32 = 0x56E; pub const SPREAD_BINDING: u32 = 0x1B8; @@ -124,6 +126,8 @@ pub mod chunk { pub const ITEM_CONTENT: u32 = 0x1623; pub const ITEM_PATHS: u32 = 0x162B; pub const ITEM_HIERARCHY: u32 = 0x15B; + /// u32: 1 when a master page item cannot be overridden. + pub const ITEM_ALLOW_OVERRIDES: u32 = 0x142D; pub const COLUMN_FRAME_LIST: u32 = 0x220; pub const FRAME_LIST_FRAMES: u32 = 0x205; pub const STORY_STRANDS: u32 = 0x223; @@ -138,6 +142,8 @@ pub mod chunk { pub const STYLE_INFO: u32 = 0x230; pub const ITEM_ATTRS: u32 = 0x6E03; pub const STYLE_ATTRS: u32 = 0x23F; + /// Style export settings: tag maps, then u16 flags. + pub const STYLE_EXPORT: u32 = 0x28F0; pub const LANGUAGE_NAME: u32 = 0x2D0F; pub const ANCHOR_CHILDREN: u32 = 0x2C8; /// Anchored object settings, of an anchor or an object style. diff --git a/src/model/item.rs b/src/model/item.rs index 92da41f..f89910d 100644 --- a/src/model/item.rs +++ b/src/model/item.rs @@ -128,6 +128,9 @@ pub struct ItemProps { pub hidden: bool, /// Chunk 0x2C2D is 1. pub locked: bool, + /// `AllowOverrides`, for items of master spreads only: `false` when + /// chunk 0x142D is 1 (`docs/format/objects.md`). + pub allow_overrides: Option, /// Layout constraint flags (chunk 0x22228). pub layout_constraints: Option, /// The parent, target and last updated interface change counts @@ -506,8 +509,22 @@ impl<'a> Reader<'a> { } None => None, }; + let on_master = self + .chunk(uid, chunk::ITEM_HIERARCHY)? + .and_then(|d| self.enc().u32_at(&d, 0)) + .is_some_and(|s| self.class(s) == Some(class::MASTER_SPREAD)); + let allow_overrides = if on_master { + Some( + self.chunk(uid, chunk::ITEM_ALLOW_OVERRIDES)? + .and_then(|d| self.enc().u32_at(&d, 0)) + != Some(1), + ) + } else { + None + }; Ok(ItemProps { name, + allow_overrides, hidden: self .chunk(uid, chunk::ITEM_VISIBLE)? .is_some_and(|d| d.len() >= 2 && self.cursor(&d).u16().ok() == Some(0)), diff --git a/src/model/settings.rs b/src/model/settings.rs index f387ae2..007b090 100644 --- a/src/model/settings.rs +++ b/src/model/settings.rs @@ -173,6 +173,26 @@ impl<'a> Reader<'a> { .collect() } + /// The label of an object (chunk 0x1630B of the document): u16 0x7B7B, + /// u32 count, then key and value of each pair as a flag byte (1 for a + /// built-in key) and an in-object string. See `docs/format/objects.md`. + pub(super) fn label(&self, uid: u32) -> Result, Error> { + let Some(d) = self.chunk(uid, chunk::DOC_LABEL)? else { + return Ok(Vec::new()); + }; + let mut c = self.cursor(&d); + if c.u16()? != 0x7B7B { + return Err(Error::Corrupt("label of unknown layout".into())); + } + let n = c.u32()? as usize; + if n > d.len() / 8 { + return Err(Error::Corrupt(format!("{n} label pairs"))); + } + (0..n) + .map(|_| Ok((c.name()?.idml(), c.name()?.idml()))) + .collect() + } + /// The script byte of the last document user's name: the second byte /// of its in-object string (`objects.md`, document users). Only read /// in little-endian files. diff --git a/src/model/style.rs b/src/model/style.rs index 9e4cf00..983a66b 100644 --- a/src/model/style.rs +++ b/src/model/style.rs @@ -22,6 +22,12 @@ pub struct Style { /// Keyboard shortcut: u32 key 10 bytes before the name's flag byte, /// then the two bytes 6 and 5 before it (`docs/format/objects.md`). pub shortcut: Option<(u32, u8, u8)>, + /// The u16 values after the tag map count of the export settings + /// (chunk 0x28F0): `SplitDocument`, `EmitCss` and, from InDesign 13, + /// `IncludeClass` (`docs/format/objects.md`, styles). Empty when the + /// chunk has tag maps, whose layout is not known; `None` without the + /// chunk. + pub export_flags: Option>, } /// A table of contents style (class 0x11605), from chunk 0x11605: a flag @@ -175,6 +181,17 @@ impl<'a> Reader<'a> { } _ => Attrs::default(), }; + // Export settings: u32 count of tag maps, the maps, then u16 flags. + let export_flags = self.chunk(uid, chunk::STYLE_EXPORT)?.map(|d| { + if self.enc().u32_at(&d, 0) == Some(0) { + (4..d.len().saturating_sub(1)) + .step_by(2) + .filter_map(|o| self.enc().u16_at(&d, o)) + .collect() + } else { + Vec::new() + } + }); Ok(Some(Style { uid, name, @@ -186,6 +203,7 @@ impl<'a> Reader<'a> { imported, unique_id, shortcut, + export_flags, })) }