1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Document-level settings.
use crate::model::dimension::{Dimension, Twips};
use super::identifiers::RevisionSaveId;
#[derive(Clone, Debug)]
pub struct DocumentSettings {
/// Default tab stop interval (OOXML default: 720 twips = 0.5 inch).
pub default_tab_stop: Dimension<Twips>,
/// Whether even/odd headers/footers are enabled.
pub even_and_odd_headers: bool,
/// The rsid of the original editing session that created this document.
pub rsid_root: Option<RevisionSaveId>,
/// All revision save IDs recorded in this document's history.
pub rsids: Vec<RevisionSaveId>,
}
impl Default for DocumentSettings {
fn default() -> Self {
Self {
// §17.15.1.25: when `w:defaultTabStop` is omitted the default tab
// stop interval is 720 twips (0.5"). A derived `Default` would give
// 0 here — wrong per spec, and it would silently collapse default
// tabs for any consumer that reads this field.
default_tab_stop: Dimension::new(720),
even_and_odd_headers: false,
rsid_root: None,
rsids: Vec::new(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_tab_stop_is_720_twips_per_spec() {
// §17.15.1.25: an omitted `w:defaultTabStop` is 720 twips (0.5"), not
// the 0 a derived `Default` would produce. Guards against a "simplify
// to #[derive(Default)]" regression.
assert_eq!(DocumentSettings::default().default_tab_stop.raw(), 720);
}
#[test]
fn remaining_defaults() {
let s = DocumentSettings::default();
assert!(!s.even_and_odd_headers);
assert!(s.rsid_root.is_none());
assert!(s.rsids.is_empty());
}
}