1use super::*;
2use crate::documents::BuildXML;
3use crate::types::*;
4use crate::xml_builder::*;
5
6use serde::Serialize;
7
8#[derive(Debug, Clone, PartialEq, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Numberings {
11 pub abstract_nums: Vec<AbstractNumbering>,
12 pub numberings: Vec<Numbering>,
13}
14
15impl Numberings {
16 pub fn new() -> Self {
17 Default::default()
18 }
19
20 pub fn add_abstract_numbering(mut self, n: AbstractNumbering) -> Self {
21 self.abstract_nums.push(n);
22 self
23 }
24
25 pub fn add_numbering(mut self, n: Numbering) -> Self {
26 self.numberings.push(n);
27 self
28 }
29}
30
31impl Default for Numberings {
32 fn default() -> Self {
33 Self {
34 abstract_nums: vec![],
35 numberings: vec![],
36 }
37 }
38}
39
40impl BuildXML for Numberings {
41 fn build(&self) -> Vec<u8> {
42 let mut b = XMLBuilder::new().declaration(Some(true)).open_numbering();
43 b = b.add_child(&create_default_numbering());
44 for n in &self.abstract_nums {
45 b = b.add_child(n);
46 }
47 b = b.add_child(&Numbering::new(1, 1));
48 for n in &self.numberings {
49 b = b.add_child(n);
50 }
51 b.close().build()
52 }
53}
54
55fn create_default_numbering() -> AbstractNumbering {
56 AbstractNumbering::new(1)
57 .add_level(
58 Level::new(
59 0,
60 Start::new(1),
61 NumberFormat::new("decimal"),
62 LevelText::new("%1."),
63 LevelJc::new("left"),
64 )
65 .indent(Some(420), Some(SpecialIndentType::Hanging(420)), None, None),
66 )
67 .add_level(
68 Level::new(
69 1,
70 Start::new(1),
71 NumberFormat::new("decimal"),
72 LevelText::new("(%2)"),
73 LevelJc::new("left"),
74 )
75 .indent(Some(840), Some(SpecialIndentType::Hanging(420)), None, None),
76 )
77 .add_level(
78 Level::new(
79 2,
80 Start::new(1),
81 NumberFormat::new("decimalEnclosedCircle"),
82 LevelText::new("%3"),
83 LevelJc::new("left"),
84 )
85 .indent(
86 Some(1260),
87 Some(SpecialIndentType::Hanging(420)),
88 None,
89 None,
90 ),
91 )
92 .add_level(
93 Level::new(
94 3,
95 Start::new(1),
96 NumberFormat::new("decimal"),
97 LevelText::new("%4."),
98 LevelJc::new("left"),
99 )
100 .indent(
101 Some(1680),
102 Some(SpecialIndentType::Hanging(420)),
103 None,
104 None,
105 ),
106 )
107 .add_level(
108 Level::new(
109 4,
110 Start::new(1),
111 NumberFormat::new("decimal"),
112 LevelText::new("(%5)"),
113 LevelJc::new("left"),
114 )
115 .indent(
116 Some(2100),
117 Some(SpecialIndentType::Hanging(420)),
118 None,
119 None,
120 ),
121 )
122 .add_level(
123 Level::new(
124 5,
125 Start::new(1),
126 NumberFormat::new("decimalEnclosedCircle"),
127 LevelText::new("%6"),
128 LevelJc::new("left"),
129 )
130 .indent(
131 Some(2520),
132 Some(SpecialIndentType::Hanging(420)),
133 None,
134 None,
135 ),
136 )
137 .add_level(
138 Level::new(
139 6,
140 Start::new(1),
141 NumberFormat::new("decimal"),
142 LevelText::new("%7."),
143 LevelJc::new("left"),
144 )
145 .indent(
146 Some(2940),
147 Some(SpecialIndentType::Hanging(420)),
148 None,
149 None,
150 ),
151 )
152 .add_level(
153 Level::new(
154 7,
155 Start::new(1),
156 NumberFormat::new("decimal"),
157 LevelText::new("(%8)"),
158 LevelJc::new("left"),
159 )
160 .indent(
161 Some(3360),
162 Some(SpecialIndentType::Hanging(420)),
163 None,
164 None,
165 ),
166 )
167 .add_level(
168 Level::new(
169 8,
170 Start::new(1),
171 NumberFormat::new("decimalEnclosedCircle"),
172 LevelText::new("%9"),
173 LevelJc::new("left"),
174 )
175 .indent(
176 Some(3780),
177 Some(SpecialIndentType::Hanging(420)),
178 None,
179 None,
180 ),
181 )
182}