mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-25 11:51:16 +01:00
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:
1 parent
5344dc2148
commit
27cfef8fd7
4 files changed
+93
-2
No files matched your search
+44
-2
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user