docx_reader/documents/elements/
level.rs

1use crate::documents::*;
2use crate::types::*;
3
4use serde::Serialize;
5
6#[derive(Debug, Clone, PartialEq, Serialize)]
7#[serde(rename_all = "camelCase")]
8pub struct Level {
9	pub level: usize,
10	pub start: Start,
11	pub format: NumberFormat,
12	pub text: LevelText,
13	pub jc: LevelJc,
14	pub paragraph_property: ParagraphProperty,
15	pub run_property: RunProperty,
16	pub suffix: LevelSuffixType,
17	pub pstyle: Option<String>,
18	pub level_restart: Option<LevelRestart>,
19	#[serde(skip_serializing_if = "Option::is_none")]
20	pub is_lgl: Option<IsLgl>,
21}
22
23impl Level {
24	pub fn new(
25		level: usize,
26		start: Start,
27		format: NumberFormat,
28		text: LevelText,
29		jc: LevelJc,
30	) -> Level {
31		Self {
32			level,
33			start,
34			format,
35			text,
36			jc,
37			paragraph_property: ParagraphProperty::new(),
38			run_property: RunProperty::new(),
39			suffix: LevelSuffixType::Tab,
40			pstyle: None,
41			level_restart: None,
42			is_lgl: None,
43		}
44	}
45
46	pub fn indent(
47		mut self,
48		left: Option<i32>,
49		special_indent: Option<SpecialIndentType>,
50		end: Option<i32>,
51		start_chars: Option<i32>,
52	) -> Self {
53		self.paragraph_property =
54			self.paragraph_property
55				.indent(left, special_indent, end, start_chars);
56		self
57	}
58
59	pub fn paragraph_style(mut self, style_id: impl Into<String>) -> Self {
60		self.pstyle = Some(style_id.into());
61		self
62	}
63
64	pub fn suffix(mut self, s: LevelSuffixType) -> Self {
65		self.suffix = s;
66		self
67	}
68
69	// run property
70	pub fn size(mut self, size: usize) -> Self {
71		self.run_property = self.run_property.size(size);
72		self
73	}
74
75	pub fn spacing(mut self, v: i32) -> Self {
76		self.run_property = self.run_property.spacing(v);
77		self
78	}
79
80	pub fn color(mut self, color: impl Into<String>) -> Self {
81		self.run_property = self.run_property.color(color);
82		self
83	}
84
85	pub fn highlight(mut self, color: impl Into<String>) -> Self {
86		self.run_property = self.run_property.highlight(color);
87		self
88	}
89
90	pub fn bold(mut self) -> Self {
91		self.run_property = self.run_property.bold();
92		self
93	}
94
95	pub fn italic(mut self) -> Self {
96		self.run_property = self.run_property.italic();
97		self
98	}
99
100	pub fn underline(mut self, line_type: impl Into<String>) -> Self {
101		self.run_property = self.run_property.underline(line_type);
102		self
103	}
104
105	pub fn vanish(mut self) -> Self {
106		self.run_property = self.run_property.vanish();
107		self
108	}
109
110	pub fn fonts(mut self, f: RunFonts) -> Self {
111		self.run_property = self.run_property.fonts(f);
112		self
113	}
114
115	pub fn level_restart(mut self, v: u32) -> Self {
116		self.level_restart = Some(LevelRestart::new(v));
117		self
118	}
119
120	pub fn is_lgl(mut self) -> Self {
121		self.is_lgl = Some(IsLgl::new());
122		self
123	}
124}