docx_reader/documents/
settings.rs

1use super::*;
2
3use crate::types::CharacterSpacingValues;
4
5use serde::Serialize;
6
7#[derive(Debug, Clone, PartialEq, Serialize)]
8#[serde(rename_all = "camelCase")]
9pub struct Settings {
10	default_tab_stop: DefaultTabStop,
11	zoom: Zoom,
12	doc_id: Option<DocId>,
13	doc_vars: Vec<DocVar>,
14	even_and_odd_headers: bool,
15	adjust_line_height_in_table: bool,
16	#[serde(skip_serializing_if = "Option::is_none")]
17	character_spacing_control: Option<CharacterSpacingValues>,
18}
19
20impl Settings {
21	pub fn new() -> Settings {
22		Default::default()
23	}
24
25	pub fn doc_id(mut self, id: impl Into<String>) -> Self {
26		self.doc_id = Some(DocId::new(id.into()));
27		self
28	}
29
30	pub fn default_tab_stop(mut self, tab_stop: usize) -> Self {
31		self.default_tab_stop = DefaultTabStop::new(tab_stop);
32		self
33	}
34
35	pub fn add_doc_var(mut self, name: impl Into<String>, val: impl Into<String>) -> Self {
36		self.doc_vars.push(DocVar::new(name, val));
37		self
38	}
39
40	pub fn even_and_odd_headers(mut self) -> Self {
41		self.even_and_odd_headers = true;
42		self
43	}
44
45	pub fn adjust_line_height_in_table(mut self) -> Self {
46		self.adjust_line_height_in_table = true;
47		self
48	}
49
50	pub fn character_spacing_control(mut self, val: CharacterSpacingValues) -> Self {
51		self.character_spacing_control = Some(val);
52		self
53	}
54}
55
56impl Default for Settings {
57	fn default() -> Self {
58		Self {
59			default_tab_stop: DefaultTabStop::new(840),
60			zoom: Zoom::new(100),
61			doc_id: None,
62			doc_vars: vec![],
63			even_and_odd_headers: false,
64			adjust_line_height_in_table: false,
65			character_spacing_control: None,
66		}
67	}
68}