feat: decode style export flags, AllowOverrides and the document label

- Paragraph and character styles: SplitDocument, EmitCss and
  IncludeClass from the u16 values after the tag map count of chunk
  0x28F0 (when the style has no tag maps); false, true, true without
  the chunk.
- Page items of master spreads: AllowOverrides from chunk 0x142D
  (1 false, else true). Placed graphics and items of document spreads
  have none.
- Document/Properties/Label from document chunk 0x1630B.

compare.py --exclude own/:
- trustworthy value coverage 97.48% -> 97.64% (+18,499 values); all
  pairs 95.46% -> 95.61% (+22,885)
- AllowOverrides 11,791 of 11,791; paragraph style SplitDocument +3,403
  and IncludeClass +2,869; document label 436 of 438
- extra values +3 (ParagraphStyle SplitDocument); no key lost values
- compare.py --all with schemas: 0 schema failures on pairs; files
  without a reference as before
This commit is contained in:
aiongg committed 2026-10-08 07:25:44 +00:00
1 parent f0bd7f1e3b
commit 53746658d9
10 files changed
+137 -1

No files matched your search

+21
View File
@@ -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
+8
View File
@@ -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())]);
+6 -1
View File
@@ -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" {
+3
View File
@@ -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",
+30
View File
@@ -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<u16> = 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()
}
+8
View File
@@ -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<u8>,
/// 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,
+6
View File
@@ -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.
+17
View File
@@ -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<bool>,
/// Layout constraint flags (chunk 0x22228).
pub layout_constraints: Option<u8>,
/// 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)),
+20
View File
@@ -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<Vec<(String, String)>, 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.
+18
View File
@@ -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<Vec<u16>>,
}
/// 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,
}))
}