feat: write documented defaults and the print page range

Preference, document and language values that no INDD field holds and
nearly every reference IDML has are written as defaults. The print
page range is read from the u16 at A+122 of the print settings.
This commit is contained in:
aiongg committed 2026-10-12 16:09:45 +00:00
1 parent 9f72881d5e
commit 2eee577790
3 files changed
+79 -7

No files matched your search

+17 -6
View File
@@ -96,11 +96,17 @@ const NO_SPELLING_VENDOR: &[&str] = &[
"uz_UZ",
];
/// Quotes that every IDML has for a language without chunk 0x2D26, where
/// the value files lack them because languages with the chunk differ
/// (idml-values.md, language quotes).
const QUOTES_WITHOUT_CHUNK: &[(&str, &str, &str)] =
&[("Romanian", "\u{201A}\u{2019}", "\u{201E}\u{201D}")];
/// Quotes of a language without chunk 0x2D26 that the value files lack.
/// Every Romanian language without the chunk has these, but those with it
/// differ (idml-values.md, language quotes). The others are defaults: a
/// few references have other quotes, which no stored field explains
/// (idml-values.md, defaults).
const QUOTES_WITHOUT_CHUNK: &[(&str, &str, &str)] = &[
("Romanian", "\u{201A}\u{2019}", "\u{201E}\u{201D}"),
("Korean", "''", "\"\""),
("Japanese", "''", "\"\""),
("Hebrew", "''", "\"\""),
];
impl Writer<'_> {
/// Values of designmap settings that follow the InDesign that saved the
@@ -177,6 +183,10 @@ impl Writer<'_> {
.attr("DOMVersion", &self.dom)
.attr("Self", "d")
.attr("StoryList", stories.join(" "));
// Defaults without a stored field (idml-values.md, defaults).
if self.dom_version().0 == 12 {
x.attr("UntitledDocumentCount", "1");
}
// `Name` from DOM 13 (idml-values.md, document attributes).
if doc.version.major >= 13 {
x.attr("Name", name);
@@ -195,7 +205,8 @@ impl Writer<'_> {
// (idml-values.md, document attributes).
let mathml = self.dom_version() >= (20, 0);
if mathml {
x.attr("AppliedMathMLRgbColor", "0 0 0")
x.attr("AppliedMathMLFontSize", "10")
.attr("AppliedMathMLRgbColor", "0 0 0")
.attr("TintValue", "100");
}
if self.dom_version() >= (20, 4) {
+33
View File
@@ -37,6 +37,29 @@ pub(super) const PREFERENCE_TAGS: &[&str] = &[
"EPubFixedLayoutExportPreference",
];
/// Preference values that no INDD field holds and nearly every reference
/// IDML has: (element, attribute, value, first DOM version). See
/// `docs/format/idml-values.md`, defaults.
const PREFERENCE_DEFAULTS: &[(&str, &str, &str, (u32, u32))] = &[
("PrintPreference", "TilingType", "Auto", (0, 0)),
("TextPreference", "HighlightKeeps", "false", (0, 0)),
(
"TextPreference",
"HighlightSubstitutedFonts",
"true",
(0, 0),
),
("ViewPreference", "GuideSnaptoZone", "4", (0, 0)),
("ViewPreference", "ShowNotes", "true", (0, 0)),
("XMLExportPreference", "ViewAfterExport", "false", (0, 0)),
(
"DocumentPreference",
"SpreadHiddenVisibility",
"false",
(20, 0),
),
];
/// A tree of preference values as a `Node`.
fn pref_node(n: &crate::model::prefs::PrefNode) -> Node {
Node {
@@ -1277,6 +1300,16 @@ impl Writer<'_> {
n.attrs.retain(|(k, _)| k != attr);
}
}
for &(tag, name, value, from) in PREFERENCE_DEFAULTS {
if self.dom_version() < from {
continue;
}
if let Some(n) = nodes.iter_mut().find(|n| n.tag == tag)
&& n.attr(name).is_none()
{
n.attrs.push((name.into(), value.into()));
}
}
for n in &nodes {
n.write(&mut x);
}
+29 -1
View File
@@ -602,7 +602,15 @@ fn print_prefs(
}
set("Copies", enc.cursor(&a[104..]).u32()?.to_string());
set_flag(&mut set, "PrintBlankPages", a[118]);
// The page range text; IDML writes `AllPages` whatever it holds.
// The page range: 0 at A+122 is `AllPages`; with 2 IDML has none,
// whatever the page range text holds.
if !booklet && enc.cursor(&a[122..]).u16()? == 0 {
props.push((
element,
"PageRange",
PrefProp::Text("enumeration", "AllPages".into()),
));
}
flagged(&mut c)?;
// Block B: spreads, colour output, composite screening.
@@ -2611,6 +2619,7 @@ mod tests {
let mut a = vec![0u8; 126];
a[84] = 1;
a[104] = 2;
let a_at = d.len();
d.extend(a);
fstr(&mut d, 1, "");
let mut b = vec![0u8; 30];
@@ -2706,6 +2715,10 @@ mod tests {
prop("Profile"),
Some(PrefProp::Text("enumeration", "PostScriptCMS".into()))
);
assert_eq!(
prop("PageRange"),
Some(PrefProp::Text("enumeration", "AllPages".into()))
);
assert_eq!(
records,
vec![
@@ -2727,6 +2740,21 @@ mod tests {
.unwrap();
assert!(!values.iter().any(|v| NOT_IN_BOOKLET.contains(&v.name)));
assert!(values.iter().any(|v| v.name == "ColorOutput"));
assert!(!props.iter().any(|p| p.1 == "PageRange"));
// Page range code 2: IDML has no `PageRange`.
d[a_at + 122] = 2;
let (mut values, mut props, mut records) = (Vec::new(), Vec::new(), Vec::new());
print_prefs(
enc,
&d,
"PrintPreference",
&mut values,
&mut props,
&mut records,
)
.unwrap();
assert!(!props.iter().any(|p| p.1 == "PageRange"));
}
/// A u32 length and single-byte text segments.