feat: write named grids and object style export options

designmap.xml gets the document's named grids with the layout grid
settings all its pages share. Object styles other than [None] get the
export options every IDML of their version has, now also before
InDesign 12.

Value coverage on trustworthy pairs: 86.72 % to 86.83 %.
This commit is contained in:
aiongg committed 2026-10-07 13:29:58 +00:00
1 parent 5344dc2148
commit 27cfef8fd7
4 files changed
+93 -2

No files matched your search

+5
View File
@@ -350,6 +350,11 @@ groups are tagged as artifacts with custom text. Their INDD objects hold
these settings in chunk 0x1E206 (its first u32 is 5 in items with the
usual values, 8 or 0 in those items), which is not decoded.
Object styles other than `[None]` (2,657 `ObjectExportOption`
elements) have 22 of the same values from DOM 9 on, `EpubType` from 10
and `EpubAriaRole` from 21; the converter writes them on those styles,
in addition to the object style values above.
The converter writes these values on every page item. From DOM 12 on it
adds the values that every object style other than `[None]` has in the
files the object style values were made from (above); all 6,151
+12
View File
@@ -225,6 +225,18 @@ 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).
## Named grids (0xCD12)
Chunk 0xCD28: u32, a flag byte (1 = built-in key) and the name
(`[Page Grid]`, IDML `$ID/[Page Grid]`). IDML writes a `NamedGrid` per
object, with a `GridDataInformation` that holds no INDD field of its
own: it equals the layout grid settings of the document pages (chunk
0xCD02, pages above) when all pages have the same, which is so in 494 of
the 495 trustworthy pairs; the named grid's settings match those in
493 of the 494. The converter writes the named grid with the pages'
settings when they agree, and without `GridDataInformation` otherwise.
Over the trustworthy pairs: 494 of 496 named grids, all names.
## Table of contents styles (0x11605)
Chunk 0x11605: a flag byte (1 = built-in key) and the name, three u32
+44 -2
View File
@@ -1198,6 +1198,29 @@ impl Writer<'_> {
n.write(x);
}
};
// Named grids. Their grid settings are those all document pages
// have (objects.md, named grids).
let grids: Vec<_> = doc
.spreads
.iter()
.flat_map(|s| &s.pages)
.filter_map(|p| p.grid.as_ref())
.collect();
let grid = grids.first().filter(|g| grids.iter().all(|h| h == *g));
for (builtin, name) in &doc.named_grids {
let name = if *builtin {
format!("$ID/{name}")
} else {
name.clone()
};
x.start("NamedGrid")
.attr("Self", format!("NamedGrid/{}", self_name(&name)))
.attr("Name", &name);
if let Some(g) = grid {
self.grid_data(&mut x, g);
}
x.end();
}
singleton(&mut x, "ConditionalTextPreference");
x.empty(
"idPkg:Preferences",
@@ -2600,7 +2623,20 @@ impl Writer<'_> {
let mut node = if root {
values::root_style("ObjectStyle", major)
} else {
values::object_style(major)
let mut n = values::object_style(major);
// The export options every object style of the version has,
// which also covers versions before 12 (idml-values.md).
if let Some(e) = values::element("ObjectStyle/ObjectExportOption", major) {
match n
.children
.iter_mut()
.find(|c| c.tag == "ObjectExportOption")
{
Some(c) => c.merge(&e),
None => n.children.push(e),
}
}
n
};
let mut attrs = self.item_attr_values(&os.attrs);
for (id, name) in [
@@ -3590,7 +3626,13 @@ impl Writer<'_> {
],
);
}
let Some(g) = &p.grid else { return };
if let Some(g) = &p.grid {
self.grid_data(x, g);
}
}
/// `GridDataInformation` of layout grid settings (chunk 0xCD02).
fn grid_data(&self, x: &mut Xml, g: &crate::model::GridData) {
x.start("GridDataInformation")
.attr("FontStyle", &g.font_style);
let [size, character_aki, line_aki, h_scale, v_scale] = g.numbers;
+32
View File
@@ -51,6 +51,7 @@ pub mod class {
pub const FONT_FAMILY: u32 = 0x3E03;
pub const LANGUAGE: u32 = 0x2D07;
pub const TOC_STYLE: u32 = 0x11605;
pub const NAMED_GRID: u32 = 0xCD12;
/// Holds an item anchored in text.
pub const ANCHOR: u32 = 0x262;
pub const TEXT_VARIABLE_INSTANCE: u32 = 0xCA64;
@@ -121,6 +122,7 @@ pub mod chunk {
/// The TOC style of a table of contents.
pub const TOC_STYLE_OF: u32 = 0x11613;
pub const TOC_STYLE: u32 = 0x11605;
pub const NAMED_GRID: u32 = 0xCD28;
pub const STRAND_DATA: u32 = 0x261;
pub const STRAND_RUNS: u32 = 0x262;
pub const STYLE_INFO: u32 = 0x230;
@@ -659,6 +661,9 @@ pub struct Document {
pub active_layer: Option<u32>,
/// Document users (chunk 0xA443): flag byte and name.
pub users: Vec<(u8, String)>,
/// Named grids (class 0xCD12, chunk 0xCD28: u32, a flag byte, 1 for
/// a built-in key, and the name), in UID order.
pub named_grids: Vec<(bool, String)>,
pub spreads: Vec<Spread>,
pub master_spreads: Vec<Spread>,
pub stories: Vec<Story>,
@@ -1361,6 +1366,7 @@ impl<'a> Reader<'a> {
languages,
language_list,
toc_styles: self.toc_styles(),
named_grids: self.named_grids(),
style_groups,
object_styles,
cell_styles,
@@ -2698,6 +2704,32 @@ impl<'a> Reader<'a> {
})
}
/// The named grids, in UID order.
fn named_grids(&self) -> Vec<(bool, String)> {
let mut out = Vec::new();
for &(uid, cls) in self.db.classes() {
if cls != class::NAMED_GRID {
continue;
}
let read = (|| -> Result<Option<(u32, bool, String)>, Error> {
let Some(d) = self.chunk(uid, chunk::NAMED_GRID)? else {
return Ok(None);
};
let mut c = Cursor::new(&d);
c.u32()?;
let builtin = c.flag()? == 1;
Ok(Some((uid, builtin, c.string()?)))
})();
match read {
Ok(Some(g)) => out.push(g),
Ok(None) => {}
Err(e) => self.warn(format!("named grid {uid} left out: {e}")),
}
}
out.sort_by_key(|g| g.0);
out.into_iter().map(|(_, b, n)| (b, n)).collect()
}
/// The table of contents styles, in UID order.
fn toc_styles(&self) -> Vec<TocStyle> {
let mut out = Vec::new();