docx_reader/documents/elements/
style.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
use serde::Serialize;

use crate::types::*;
use crate::StyleType;

use super::*;

#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Style {
	pub style_id: String,
	pub name: Name,
	pub style_type: StyleType,
	pub run_property: RunProperty,
	pub paragraph_property: ParagraphProperty,
	pub table_property: TableProperty,
	pub table_cell_property: TableCellProperty,
	pub based_on: Option<BasedOn>,
	pub next: Option<Next>,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub link: Option<Link>,
}

impl Default for Style {
	fn default() -> Self {
		let name = Name::new("");
		let rpr = RunProperty::new();
		let ppr = ParagraphProperty::new();
		Style {
			style_id: "".to_owned(),
			style_type: StyleType::Paragraph,
			name,
			run_property: rpr,
			paragraph_property: ppr,
			table_property: TableProperty::new(),
			table_cell_property: TableCellProperty::new(),
			based_on: None,
			next: None,
			link: None,
		}
	}
}

impl Style {
	pub fn new(style_id: impl Into<String>, style_type: StyleType) -> Self {
		let default = Default::default();
		Style {
			style_id: style_id.into(),
			style_type,
			..default
		}
	}

	pub fn name(mut self, name: impl Into<String>) -> Self {
		self.name = Name::new(name);
		self
	}

	pub fn based_on(mut self, base: impl Into<String>) -> Self {
		self.based_on = Some(BasedOn::new(base));
		self
	}

	pub fn next(mut self, next: impl Into<String>) -> Self {
		self.next = Some(Next::new(next));
		self
	}

	pub fn link(mut self, link: impl Into<String>) -> Self {
		self.link = Some(Link::new(link));
		self
	}

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

	pub fn color(mut self, color: impl Into<String>) -> Self {
		self.run_property = self.run_property.color(color);
		self
	}

	pub fn highlight(mut self, color: impl Into<String>) -> Self {
		self.run_property = self.run_property.highlight(color);
		self
	}

	pub fn bold(mut self) -> Self {
		self.run_property = self.run_property.bold();
		self
	}

	pub fn italic(mut self) -> Self {
		self.run_property = self.run_property.italic();
		self
	}

	pub fn underline(mut self, line_type: impl Into<String>) -> Self {
		self.run_property = self.run_property.underline(line_type);
		self
	}

	pub fn vanish(mut self) -> Self {
		self.run_property = self.run_property.vanish();
		self
	}

	pub fn text_border(mut self, b: TextBorder) -> Self {
		self.run_property = self.run_property.text_border(b);
		self
	}

	pub fn fonts(mut self, f: RunFonts) -> Self {
		self.run_property = self.run_property.fonts(f);
		self
	}

	pub fn align(mut self, alignment_type: AlignmentType) -> Self {
		self.paragraph_property = self.paragraph_property.align(alignment_type);
		self
	}

	pub fn indent(
		mut self,
		left: Option<i32>,
		special_indent: Option<SpecialIndentType>,
		end: Option<i32>,
		start_chars: Option<i32>,
	) -> Self {
		self.paragraph_property =
			self.paragraph_property
				.indent(left, special_indent, end, start_chars);
		self
	}

	pub fn hanging_chars(mut self, chars: i32) -> Self {
		self.paragraph_property = self.paragraph_property.hanging_chars(chars);
		self
	}

	pub fn first_line_chars(mut self, chars: i32) -> Self {
		self.paragraph_property = self.paragraph_property.first_line_chars(chars);
		self
	}

	pub fn outline_lvl(mut self, l: usize) -> Self {
		self.paragraph_property = self.paragraph_property.outline_lvl(l);
		self
	}

	pub fn table_property(mut self, p: TableProperty) -> Self {
		self.table_property = p;
		self
	}

	pub fn table_indent(mut self, v: i32) -> Self {
		self.table_property = self.table_property.indent(v);
		self
	}

	pub fn table_align(mut self, v: TableAlignmentType) -> Self {
		self.table_property = self.table_property.align(v);
		self
	}

	pub fn style(mut self, s: impl Into<String>) -> Self {
		self.table_property = self.table_property.style(s);
		self
	}

	pub fn layout(mut self, t: TableLayoutType) -> Self {
		self.table_property = self.table_property.layout(t);
		self
	}

	pub fn width(mut self, w: usize, t: WidthType) -> Self {
		self.table_property = self.table_property.width(w, t);
		self
	}

	pub fn margins(mut self, margins: TableCellMargins) -> Self {
		self.table_property = self.table_property.set_margins(margins);
		self
	}

	pub fn set_borders(mut self, borders: TableBorders) -> Self {
		self.table_property = self.table_property.set_borders(borders);
		self
	}

	pub fn set_border(mut self, border: TableBorder) -> Self {
		self.table_property = self.table_property.set_border(border);
		self
	}

	pub fn clear_border(mut self, position: TableBorderPosition) -> Self {
		self.table_property = self.table_property.clear_border(position);
		self
	}

	pub fn clear_all_border(mut self) -> Self {
		self.table_property = self.table_property.clear_all_border();
		self
	}

	pub fn table_cell_property(mut self, p: TableCellProperty) -> Self {
		self.table_cell_property = p;
		self
	}
}