docx_reader/documents/elements/
style.rs

1use serde::Serialize;
2
3use crate::types::*;
4use crate::StyleType;
5
6use super::*;
7
8#[derive(Debug, Clone, PartialEq, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Style {
11	pub style_id: String,
12	pub name: Name,
13	pub style_type: StyleType,
14	pub run_property: RunProperty,
15	pub paragraph_property: ParagraphProperty,
16	pub table_property: TableProperty,
17	pub table_cell_property: TableCellProperty,
18	pub based_on: Option<BasedOn>,
19	pub next: Option<Next>,
20	#[serde(skip_serializing_if = "Option::is_none")]
21	pub link: Option<Link>,
22}
23
24impl Default for Style {
25	fn default() -> Self {
26		let name = Name::new("");
27		let rpr = RunProperty::new();
28		let ppr = ParagraphProperty::new();
29		Style {
30			style_id: "".to_owned(),
31			style_type: StyleType::Paragraph,
32			name,
33			run_property: rpr,
34			paragraph_property: ppr,
35			table_property: TableProperty::new(),
36			table_cell_property: TableCellProperty::new(),
37			based_on: None,
38			next: None,
39			link: None,
40		}
41	}
42}
43
44impl Style {
45	pub fn new(style_id: impl Into<String>, style_type: StyleType) -> Self {
46		let default = Default::default();
47		Style {
48			style_id: style_id.into(),
49			style_type,
50			..default
51		}
52	}
53
54	pub fn name(mut self, name: impl Into<String>) -> Self {
55		self.name = Name::new(name);
56		self
57	}
58
59	pub fn based_on(mut self, base: impl Into<String>) -> Self {
60		self.based_on = Some(BasedOn::new(base));
61		self
62	}
63
64	pub fn next(mut self, next: impl Into<String>) -> Self {
65		self.next = Some(Next::new(next));
66		self
67	}
68
69	pub fn link(mut self, link: impl Into<String>) -> Self {
70		self.link = Some(Link::new(link));
71		self
72	}
73
74	pub fn size(mut self, size: usize) -> Self {
75		self.run_property = self.run_property.size(size);
76		self
77	}
78
79	pub fn color(mut self, color: impl Into<String>) -> Self {
80		self.run_property = self.run_property.color(color);
81		self
82	}
83
84	pub fn highlight(mut self, color: impl Into<String>) -> Self {
85		self.run_property = self.run_property.highlight(color);
86		self
87	}
88
89	pub fn bold(mut self) -> Self {
90		self.run_property = self.run_property.bold();
91		self
92	}
93
94	pub fn italic(mut self) -> Self {
95		self.run_property = self.run_property.italic();
96		self
97	}
98
99	pub fn underline(mut self, line_type: impl Into<String>) -> Self {
100		self.run_property = self.run_property.underline(line_type);
101		self
102	}
103
104	pub fn vanish(mut self) -> Self {
105		self.run_property = self.run_property.vanish();
106		self
107	}
108
109	pub fn text_border(mut self, b: TextBorder) -> Self {
110		self.run_property = self.run_property.text_border(b);
111		self
112	}
113
114	pub fn fonts(mut self, f: RunFonts) -> Self {
115		self.run_property = self.run_property.fonts(f);
116		self
117	}
118
119	pub fn align(mut self, alignment_type: AlignmentType) -> Self {
120		self.paragraph_property = self.paragraph_property.align(alignment_type);
121		self
122	}
123
124	pub fn indent(
125		mut self,
126		left: Option<i32>,
127		special_indent: Option<SpecialIndentType>,
128		end: Option<i32>,
129		start_chars: Option<i32>,
130	) -> Self {
131		self.paragraph_property =
132			self.paragraph_property
133				.indent(left, special_indent, end, start_chars);
134		self
135	}
136
137	pub fn hanging_chars(mut self, chars: i32) -> Self {
138		self.paragraph_property = self.paragraph_property.hanging_chars(chars);
139		self
140	}
141
142	pub fn first_line_chars(mut self, chars: i32) -> Self {
143		self.paragraph_property = self.paragraph_property.first_line_chars(chars);
144		self
145	}
146
147	pub fn outline_lvl(mut self, l: usize) -> Self {
148		self.paragraph_property = self.paragraph_property.outline_lvl(l);
149		self
150	}
151
152	pub fn table_property(mut self, p: TableProperty) -> Self {
153		self.table_property = p;
154		self
155	}
156
157	pub fn table_indent(mut self, v: i32) -> Self {
158		self.table_property = self.table_property.indent(v);
159		self
160	}
161
162	pub fn table_align(mut self, v: TableAlignmentType) -> Self {
163		self.table_property = self.table_property.align(v);
164		self
165	}
166
167	pub fn style(mut self, s: impl Into<String>) -> Self {
168		self.table_property = self.table_property.style(s);
169		self
170	}
171
172	pub fn layout(mut self, t: TableLayoutType) -> Self {
173		self.table_property = self.table_property.layout(t);
174		self
175	}
176
177	pub fn width(mut self, w: usize, t: WidthType) -> Self {
178		self.table_property = self.table_property.width(w, t);
179		self
180	}
181
182	pub fn margins(mut self, margins: TableCellMargins) -> Self {
183		self.table_property = self.table_property.set_margins(margins);
184		self
185	}
186
187	pub fn set_borders(mut self, borders: TableBorders) -> Self {
188		self.table_property = self.table_property.set_borders(borders);
189		self
190	}
191
192	pub fn set_border(mut self, border: TableBorder) -> Self {
193		self.table_property = self.table_property.set_border(border);
194		self
195	}
196
197	pub fn clear_border(mut self, position: TableBorderPosition) -> Self {
198		self.table_property = self.table_property.clear_border(position);
199		self
200	}
201
202	pub fn clear_all_border(mut self) -> Self {
203		self.table_property = self.table_property.clear_all_border();
204		self
205	}
206
207	pub fn table_cell_property(mut self, p: TableCellProperty) -> Self {
208		self.table_cell_property = p;
209		self
210	}
211}