docx_reader/documents/elements/
section_property.rs

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
use super::*;
use crate::types::*;
use crate::Footer;
use crate::Header;

use serde::Serialize;

#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SectionProperty {
	pub page_size: PageSize,
	pub page_margin: PageMargin,
	pub columns: usize,
	pub space: usize,
	pub title_pg: bool,
	pub text_direction: String,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub doc_grid: Option<DocGrid>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub header_reference: Option<HeaderReference>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub header: Option<Header>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub first_header_reference: Option<HeaderReference>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub first_header: Option<Header>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub even_header_reference: Option<HeaderReference>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub even_header: Option<Header>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub footer_reference: Option<FooterReference>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub footer: Option<Footer>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub first_footer_reference: Option<FooterReference>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub first_footer: Option<Footer>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub even_footer_reference: Option<FooterReference>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub even_footer: Option<Footer>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub section_type: Option<SectionType>,
}

impl SectionProperty {
	pub fn new() -> SectionProperty {
		Default::default()
	}

	pub fn page_size(mut self, size: PageSize) -> Self {
		self.page_size = size;
		self
	}

	pub fn page_margin(mut self, margin: PageMargin) -> Self {
		self.page_margin = margin;
		self
	}

	pub fn page_orient(mut self, o: PageOrientationType) -> Self {
		self.page_size = self.page_size.orient(o);
		self
	}

	pub fn doc_grid(mut self, doc_grid: DocGrid) -> Self {
		self.doc_grid = Some(doc_grid);
		self
	}

	pub fn text_direction(mut self, direction: String) -> Self {
		self.text_direction = direction;
		self
	}

	pub fn title_pg(mut self) -> Self {
		self.title_pg = true;
		self
	}

	pub fn header(mut self, h: Header, rid: &str) -> Self {
		self.header_reference = Some(HeaderReference::new("default", rid));
		self.header = Some(h);
		self
	}

	pub fn first_header(mut self, h: Header, rid: &str) -> Self {
		self.first_header_reference = Some(HeaderReference::new("first", rid));
		self.first_header = Some(h);
		self.title_pg = true;
		self
	}

	pub fn first_header_without_title_pg(mut self, h: Header, rid: &str) -> Self {
		self.first_header_reference = Some(HeaderReference::new("first", rid));
		self.first_header = Some(h);
		self
	}

	pub fn even_header(mut self, h: Header, rid: &str) -> Self {
		self.even_header_reference = Some(HeaderReference::new("even", rid));
		self.even_header = Some(h);
		self
	}

	pub fn footer(mut self, h: Footer, rid: &str) -> Self {
		self.footer_reference = Some(FooterReference::new("default", rid));
		self.footer = Some(h);
		self
	}

	pub fn first_footer(mut self, h: Footer, rid: &str) -> Self {
		self.first_footer_reference = Some(FooterReference::new("first", rid));
		self.first_footer = Some(h);
		self.title_pg = true;
		self
	}

	pub fn first_footer_without_title_pg(mut self, h: Footer, rid: &str) -> Self {
		self.first_footer_reference = Some(FooterReference::new("first", rid));
		self.first_footer = Some(h);
		self
	}

	pub fn even_footer(mut self, h: Footer, rid: &str) -> Self {
		self.even_footer_reference = Some(FooterReference::new("even", rid));
		self.even_footer = Some(h);
		self
	}

	pub fn get_headers(&self) -> Vec<&Header> {
		let mut headers = vec![];
		if let Some(ref header) = self.header {
			headers.push(header);
		}
		if let Some(ref header) = self.first_header {
			headers.push(header);
		}
		if let Some(ref header) = self.even_header {
			headers.push(header);
		}
		headers
	}

	pub fn get_footers(&self) -> Vec<&Footer> {
		let mut footers = vec![];
		if let Some(ref footer) = self.footer {
			footers.push(footer);
		}
		if let Some(ref footer) = self.first_footer {
			footers.push(footer);
		}
		if let Some(ref footer) = self.even_footer {
			footers.push(footer);
		}
		footers
	}
}

impl Default for SectionProperty {
	fn default() -> Self {
		Self {
			page_size: PageSize::new(),
			page_margin: PageMargin::new(),
			columns: 1,
			space: 425,
			title_pg: false,
			text_direction: "lrTb".to_string(),
			doc_grid: None,
			// headers
			header_reference: None,
			header: None,
			first_header_reference: None,
			first_header: None,
			even_header_reference: None,
			even_header: None,
			// footers
			footer_reference: None,
			footer: None,
			first_footer_reference: None,
			first_footer: None,
			even_footer_reference: None,
			even_footer: None,
			section_type: None,
		}
	}
}