From 2eee577790b9f2be5bba618053bca34db0a9fa63 Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Mon, 12 Oct 2026 16:09:45 +0000 Subject: [PATCH] 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. --- src/idml/designmap.rs | 23 +++++++++++++++++------ src/idml/resources.rs | 33 +++++++++++++++++++++++++++++++++ src/model/prefs.rs | 30 +++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/src/idml/designmap.rs b/src/idml/designmap.rs index 3553a83..013537e 100644 --- a/src/idml/designmap.rs +++ b/src/idml/designmap.rs @@ -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) { diff --git a/src/idml/resources.rs b/src/idml/resources.rs index ae5345d..5bb507a 100644 --- a/src/idml/resources.rs +++ b/src/idml/resources.rs @@ -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); } diff --git a/src/model/prefs.rs b/src/model/prefs.rs index 237b6e7..6ccd0bd 100644 --- a/src/model/prefs.rs +++ b/src/model/prefs.rs @@ -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.