umya_spreadsheet/structs/drawing/
color_scheme.rs1use super::super::StringValue;
3use super::Color2Type;
4use crate::reader::driver::*;
5use crate::writer::driver::*;
6use quick_xml::events::{BytesStart, Event};
7use quick_xml::Reader;
8use quick_xml::Writer;
9use std::io::Cursor;
10
11#[derive(Clone, Default, Debug)]
12pub struct ColorScheme {
13 name: StringValue,
14 accent1: Color2Type,
15 accent2: Color2Type,
16 accent3: Color2Type,
17 accent4: Color2Type,
18 accent5: Color2Type,
19 accent6: Color2Type,
20 dk1: Color2Type,
21 dk2: Color2Type,
22 fol_hlink: Color2Type,
23 hlink: Color2Type,
24 lt1: Color2Type,
25 lt2: Color2Type,
26}
27
28impl ColorScheme {
29 #[inline]
30 pub fn get_name(&self) -> &str {
31 self.name.get_value_str()
32 }
33
34 #[inline]
35 pub fn set_name<S: Into<String>>(&mut self, value: S) -> &mut Self {
36 self.name.set_value(value);
37 self
38 }
39
40 #[inline]
41 pub fn set_accent1(&mut self, value: Color2Type) {
42 self.accent1 = value;
43 }
44
45 #[inline]
46 pub fn get_accent1(&self) -> &Color2Type {
47 &self.accent1
48 }
49
50 #[inline]
51 pub fn get_accent1_mut(&mut self) -> &mut Color2Type {
52 &mut self.accent1
53 }
54
55 #[inline]
56 pub fn set_accent2(&mut self, value: Color2Type) {
57 self.accent2 = value;
58 }
59
60 #[inline]
61 pub fn get_accent2(&self) -> &Color2Type {
62 &self.accent2
63 }
64
65 #[inline]
66 pub fn get_accent2_mut(&mut self) -> &mut Color2Type {
67 &mut self.accent2
68 }
69
70 #[inline]
71 pub fn set_accent3(&mut self, value: Color2Type) {
72 self.accent3 = value;
73 }
74
75 #[inline]
76 pub fn get_accent3(&self) -> &Color2Type {
77 &self.accent3
78 }
79
80 #[inline]
81 pub fn get_accent3_mut(&mut self) -> &mut Color2Type {
82 &mut self.accent3
83 }
84
85 #[inline]
86 pub fn set_accent4(&mut self, value: Color2Type) {
87 self.accent4 = value;
88 }
89
90 #[inline]
91 pub fn get_accent4(&self) -> &Color2Type {
92 &self.accent4
93 }
94
95 #[inline]
96 pub fn get_accent4_mut(&mut self) -> &mut Color2Type {
97 &mut self.accent4
98 }
99
100 #[inline]
101 pub fn set_accent5(&mut self, value: Color2Type) {
102 self.accent5 = value;
103 }
104
105 #[inline]
106 pub fn get_accent5(&self) -> &Color2Type {
107 &self.accent5
108 }
109
110 #[inline]
111 pub fn get_accent5_mut(&mut self) -> &mut Color2Type {
112 &mut self.accent5
113 }
114
115 #[inline]
116 pub fn set_accent6(&mut self, value: Color2Type) {
117 self.accent6 = value;
118 }
119
120 #[inline]
121 pub fn get_accent6(&self) -> &Color2Type {
122 &self.accent6
123 }
124
125 #[inline]
126 pub fn get_accent6_mut(&mut self) -> &mut Color2Type {
127 &mut self.accent6
128 }
129
130 #[inline]
131 pub fn set_dk1(&mut self, value: Color2Type) {
132 self.dk1 = value;
133 }
134
135 #[inline]
136 pub fn get_dk1(&self) -> &Color2Type {
137 &self.dk1
138 }
139
140 #[inline]
141 pub fn get_dk1_mut(&mut self) -> &mut Color2Type {
142 &mut self.dk1
143 }
144
145 #[inline]
146 pub fn set_dk2(&mut self, value: Color2Type) {
147 self.dk2 = value;
148 }
149
150 #[inline]
151 pub fn get_dk2(&self) -> &Color2Type {
152 &self.dk2
153 }
154
155 #[inline]
156 pub fn get_dk2_mut(&mut self) -> &mut Color2Type {
157 &mut self.dk2
158 }
159
160 #[inline]
161 pub fn set_fol_hlink(&mut self, value: Color2Type) {
162 self.fol_hlink = value;
163 }
164
165 #[inline]
166 pub fn get_fol_hlink(&self) -> &Color2Type {
167 &self.fol_hlink
168 }
169
170 #[inline]
171 pub fn get_fol_hlink_mut(&mut self) -> &mut Color2Type {
172 &mut self.fol_hlink
173 }
174
175 #[inline]
176 pub fn set_hlink(&mut self, value: Color2Type) {
177 self.hlink = value;
178 }
179
180 #[inline]
181 pub fn get_hlink(&self) -> &Color2Type {
182 &self.hlink
183 }
184
185 #[inline]
186 pub fn get_hlink_mut(&mut self) -> &mut Color2Type {
187 &mut self.hlink
188 }
189
190 #[inline]
191 pub fn set_lt1(&mut self, value: Color2Type) {
192 self.lt1 = value;
193 }
194
195 #[inline]
196 pub fn get_lt1(&self) -> &Color2Type {
197 &self.lt1
198 }
199
200 #[inline]
201 pub fn get_lt1_mut(&mut self) -> &mut Color2Type {
202 &mut self.lt1
203 }
204
205 #[inline]
206 pub fn set_lt2(&mut self, value: Color2Type) {
207 self.lt2 = value;
208 }
209
210 #[inline]
211 pub fn get_lt2(&self) -> &Color2Type {
212 &self.lt2
213 }
214
215 #[inline]
216 pub fn get_lt2_mut(&mut self) -> &mut Color2Type {
217 &mut self.lt2
218 }
219
220 #[inline]
221 pub fn get_color_map(&self) -> Vec<String> {
222 vec![
223 self.lt1.get_val(),
224 self.dk1.get_val(),
225 self.lt2.get_val(),
226 self.dk2.get_val(),
227 self.accent1.get_val(),
228 self.accent2.get_val(),
229 self.accent3.get_val(),
230 self.accent4.get_val(),
231 self.accent5.get_val(),
232 self.accent6.get_val(),
233 self.hlink.get_val(),
234 self.fol_hlink.get_val(),
235 ]
236 }
237
238 pub(crate) fn set_attributes<R: std::io::BufRead>(
239 &mut self,
240 reader: &mut Reader<R>,
241 e: &BytesStart,
242 ) {
243 set_string_from_xml!(self, e, name, "name");
244
245 xml_read_loop!(
246 reader,
247 Event::Start(ref e) => {
248 match e.name().into_inner() {
249 b"a:accent1" => {
250 self.accent1.set_attributes(reader, e);
251 }
252 b"a:accent2" => {
253 self.accent2.set_attributes(reader, e);
254 }
255 b"a:accent3" => {
256 self.accent3.set_attributes(reader, e);
257 }
258 b"a:accent4" => {
259 self.accent4.set_attributes(reader, e);
260 }
261 b"a:accent5" => {
262 self.accent5.set_attributes(reader, e);
263 }
264 b"a:accent6" => {
265 self.accent6.set_attributes(reader, e);
266 }
267 b"a:dk1" => {
268 self.dk1.set_attributes(reader, e);
269 }
270 b"a:dk2" => {
271 self.dk2.set_attributes(reader, e);
272 }
273 b"a:folHlink" => {
274 self.fol_hlink.set_attributes(reader, e);
275 }
276 b"a:hlink" => {
277 self.hlink.set_attributes(reader, e);
278 }
279 b"a:lt1" => {
280 self.lt1.set_attributes(reader, e);
281 }
282 b"a:lt2" => {
283 self.lt2.set_attributes(reader, e);
284 }
285 _ => (),
286 }
287 },
288 Event::End(ref e) => {
289 if e.name().into_inner() == b"a:clrScheme" {
290 return
291 }
292 },
293 Event::Eof => panic!("Error: Could not find {} end element", "a:clrScheme")
294 );
295 }
296
297 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
298 let mut attributes: Vec<(&str, &str)> = Vec::new();
300 if self.name.has_value() {
301 attributes.push(("name", self.name.get_value_str()));
302 }
303 write_start_tag(writer, "a:clrScheme", attributes, false);
304
305 self.dk1.write_to_dk1(writer);
307
308 self.lt1.write_to_lt1(writer);
310
311 self.dk2.write_to_dk2(writer);
313
314 self.lt2.write_to_lt2(writer);
316
317 self.accent1.write_to_accent1(writer);
319
320 self.accent2.write_to_accent2(writer);
322
323 self.accent3.write_to_accent3(writer);
325
326 self.accent4.write_to_accent4(writer);
328
329 self.accent5.write_to_accent5(writer);
331
332 self.accent6.write_to_accent6(writer);
334
335 self.hlink.write_to_hlink(writer);
337
338 self.fol_hlink.write_to_fol_hlink(writer);
340
341 write_end_tag(writer, "a:clrScheme");
342 }
343}