umya_spreadsheet/structs/drawing/
color_scheme.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::{
8 BytesStart,
9 Event,
10 },
11};
12
13use super::{
14 super::StringValue,
15 Color2Type,
16};
17use crate::{
18 reader::driver::{
19 get_attribute,
20 set_string_from_xml,
21 xml_read_loop,
22 },
23 writer::driver::{
24 write_end_tag,
25 write_start_tag,
26 },
27};
28
29#[derive(Clone, Default, Debug)]
30pub struct ColorScheme {
31 name: StringValue,
32 accent1: Color2Type,
33 accent2: Color2Type,
34 accent3: Color2Type,
35 accent4: Color2Type,
36 accent5: Color2Type,
37 accent6: Color2Type,
38 dk1: Color2Type,
39 dk2: Color2Type,
40 fol_hlink: Color2Type,
41 hlink: Color2Type,
42 lt1: Color2Type,
43 lt2: Color2Type,
44}
45
46impl ColorScheme {
47 #[inline]
48 #[must_use]
49 pub fn name(&self) -> &str {
50 self.name.value_str()
51 }
52
53 #[inline]
54 #[must_use]
55 #[deprecated(since = "3.0.0", note = "Use name()")]
56 pub fn get_name(&self) -> &str {
57 self.name()
58 }
59
60 #[inline]
61 pub fn set_name<S: Into<String>>(&mut self, value: S) -> &mut Self {
62 self.name.set_value(value);
63 self
64 }
65
66 #[inline]
67 #[must_use]
68 pub fn accent1(&self) -> &Color2Type {
69 &self.accent1
70 }
71
72 #[inline]
73 #[must_use]
74 #[deprecated(since = "3.0.0", note = "Use accent1()")]
75 pub fn get_accent1(&self) -> &Color2Type {
76 self.accent1()
77 }
78
79 #[inline]
80 pub fn accent1_mut(&mut self) -> &mut Color2Type {
81 &mut self.accent1
82 }
83
84 #[inline]
85 #[deprecated(since = "3.0.0", note = "Use accent1_mut()")]
86 pub fn get_accent1_mut(&mut self) -> &mut Color2Type {
87 self.accent1_mut()
88 }
89
90 #[inline]
91 pub fn set_accent1(&mut self, value: Color2Type) -> &mut Self {
92 self.accent1 = value;
93 self
94 }
95
96 #[inline]
97 #[must_use]
98 pub fn accent2(&self) -> &Color2Type {
99 &self.accent2
100 }
101
102 #[inline]
103 #[must_use]
104 #[deprecated(since = "3.0.0", note = "Use accent2()")]
105 pub fn get_accent2(&self) -> &Color2Type {
106 self.accent2()
107 }
108
109 #[inline]
110 pub fn accent2_mut(&mut self) -> &mut Color2Type {
111 &mut self.accent2
112 }
113
114 #[inline]
115 #[deprecated(since = "3.0.0", note = "Use accent2_mut()")]
116 pub fn get_accent2_mut(&mut self) -> &mut Color2Type {
117 self.accent2_mut()
118 }
119
120 #[inline]
121 pub fn set_accent2(&mut self, value: Color2Type) -> &mut Self {
122 self.accent2 = value;
123 self
124 }
125
126 #[inline]
127 #[must_use]
128 pub fn accent3(&self) -> &Color2Type {
129 &self.accent3
130 }
131
132 #[inline]
133 #[must_use]
134 #[deprecated(since = "3.0.0", note = "Use accent3()")]
135 pub fn get_accent3(&self) -> &Color2Type {
136 self.accent3()
137 }
138
139 #[inline]
140 pub fn accent3_mut(&mut self) -> &mut Color2Type {
141 &mut self.accent3
142 }
143
144 #[inline]
145 #[deprecated(since = "3.0.0", note = "Use accent3_mut()")]
146 pub fn get_accent3_mut(&mut self) -> &mut Color2Type {
147 self.accent3_mut()
148 }
149
150 #[inline]
151 pub fn set_accent3(&mut self, value: Color2Type) -> &mut Self {
152 self.accent3 = value;
153 self
154 }
155
156 #[inline]
157 #[must_use]
158 pub fn accent4(&self) -> &Color2Type {
159 &self.accent4
160 }
161
162 #[inline]
163 #[must_use]
164 #[deprecated(since = "3.0.0", note = "Use accent4()")]
165 pub fn get_accent4(&self) -> &Color2Type {
166 self.accent4()
167 }
168
169 #[inline]
170 pub fn accent4_mut(&mut self) -> &mut Color2Type {
171 &mut self.accent4
172 }
173
174 #[inline]
175 #[deprecated(since = "3.0.0", note = "Use accent4_mut()")]
176 pub fn get_accent4_mut(&mut self) -> &mut Color2Type {
177 self.accent4_mut()
178 }
179
180 #[inline]
181 pub fn set_accent4(&mut self, value: Color2Type) -> &mut Self {
182 self.accent4 = value;
183 self
184 }
185
186 #[inline]
187 #[must_use]
188 pub fn accent5(&self) -> &Color2Type {
189 &self.accent5
190 }
191
192 #[inline]
193 #[must_use]
194 #[deprecated(since = "3.0.0", note = "Use accent5()")]
195 pub fn get_accent5(&self) -> &Color2Type {
196 self.accent5()
197 }
198
199 #[inline]
200 pub fn accent5_mut(&mut self) -> &mut Color2Type {
201 &mut self.accent5
202 }
203
204 #[inline]
205 #[deprecated(since = "3.0.0", note = "Use accent5_mut()")]
206 pub fn get_accent5_mut(&mut self) -> &mut Color2Type {
207 self.accent5_mut()
208 }
209
210 #[inline]
211 pub fn set_accent5(&mut self, value: Color2Type) -> &mut Self {
212 self.accent5 = value;
213 self
214 }
215
216 #[inline]
217 #[must_use]
218 pub fn accent6(&self) -> &Color2Type {
219 &self.accent6
220 }
221
222 #[inline]
223 #[must_use]
224 #[deprecated(since = "3.0.0", note = "Use accent6()")]
225 pub fn get_accent6(&self) -> &Color2Type {
226 self.accent6()
227 }
228
229 #[inline]
230 pub fn accent6_mut(&mut self) -> &mut Color2Type {
231 &mut self.accent6
232 }
233
234 #[inline]
235 #[deprecated(since = "3.0.0", note = "Use accent6_mut()")]
236 pub fn get_accent6_mut(&mut self) -> &mut Color2Type {
237 self.accent6_mut()
238 }
239
240 #[inline]
241 pub fn set_accent6(&mut self, value: Color2Type) -> &mut Self {
242 self.accent6 = value;
243 self
244 }
245
246 #[inline]
247 #[must_use]
248 pub fn dk1(&self) -> &Color2Type {
249 &self.dk1
250 }
251
252 #[inline]
253 #[must_use]
254 #[deprecated(since = "3.0.0", note = "Use dk1()")]
255 pub fn get_dk1(&self) -> &Color2Type {
256 self.dk1()
257 }
258
259 #[inline]
260 pub fn dk1_mut(&mut self) -> &mut Color2Type {
261 &mut self.dk1
262 }
263
264 #[inline]
265 #[deprecated(since = "3.0.0", note = "Use dk1_mut()")]
266 pub fn get_dk1_mut(&mut self) -> &mut Color2Type {
267 self.dk1_mut()
268 }
269
270 #[inline]
271 pub fn set_dk1(&mut self, value: Color2Type) -> &mut Self {
272 self.dk1 = value;
273 self
274 }
275
276 #[inline]
277 #[must_use]
278 pub fn dk2(&self) -> &Color2Type {
279 &self.dk2
280 }
281
282 #[inline]
283 #[must_use]
284 #[deprecated(since = "3.0.0", note = "Use dk2()")]
285 pub fn get_dk2(&self) -> &Color2Type {
286 self.dk2()
287 }
288
289 #[inline]
290 pub fn dk2_mut(&mut self) -> &mut Color2Type {
291 &mut self.dk2
292 }
293
294 #[inline]
295 #[deprecated(since = "3.0.0", note = "Use dk2_mut()")]
296 pub fn get_dk2_mut(&mut self) -> &mut Color2Type {
297 self.dk2_mut()
298 }
299
300 #[inline]
301 pub fn set_dk2(&mut self, value: Color2Type) -> &mut Self {
302 self.dk2 = value;
303 self
304 }
305
306 #[inline]
307 #[must_use]
308 pub fn fol_hlink(&self) -> &Color2Type {
309 &self.fol_hlink
310 }
311
312 #[inline]
313 #[must_use]
314 #[deprecated(since = "3.0.0", note = "Use fol_hlink()")]
315 pub fn get_fol_hlink(&self) -> &Color2Type {
316 self.fol_hlink()
317 }
318
319 #[inline]
320 pub fn fol_hlink_mut(&mut self) -> &mut Color2Type {
321 &mut self.fol_hlink
322 }
323
324 #[inline]
325 #[deprecated(since = "3.0.0", note = "Use fol_hlink_mut()")]
326 pub fn get_fol_hlink_mut(&mut self) -> &mut Color2Type {
327 self.fol_hlink_mut()
328 }
329
330 #[inline]
331 pub fn set_fol_hlink(&mut self, value: Color2Type) -> &mut Self {
332 self.fol_hlink = value;
333 self
334 }
335
336 #[inline]
337 #[must_use]
338 pub fn hlink(&self) -> &Color2Type {
339 &self.hlink
340 }
341
342 #[inline]
343 #[must_use]
344 #[deprecated(since = "3.0.0", note = "Use hlink()")]
345 pub fn get_hlink(&self) -> &Color2Type {
346 self.hlink()
347 }
348
349 #[inline]
350 pub fn hlink_mut(&mut self) -> &mut Color2Type {
351 &mut self.hlink
352 }
353
354 #[inline]
355 #[deprecated(since = "3.0.0", note = "Use hlink_mut()")]
356 pub fn get_hlink_mut(&mut self) -> &mut Color2Type {
357 self.hlink_mut()
358 }
359
360 #[inline]
361 pub fn set_hlink(&mut self, value: Color2Type) -> &mut Self {
362 self.hlink = value;
363 self
364 }
365
366 #[inline]
367 #[must_use]
368 pub fn lt1(&self) -> &Color2Type {
369 &self.lt1
370 }
371
372 #[inline]
373 #[must_use]
374 #[deprecated(since = "3.0.0", note = "Use lt1()")]
375 pub fn get_lt1(&self) -> &Color2Type {
376 self.lt1()
377 }
378
379 #[inline]
380 pub fn lt1_mut(&mut self) -> &mut Color2Type {
381 &mut self.lt1
382 }
383
384 #[inline]
385 #[deprecated(since = "3.0.0", note = "Use lt1_mut()")]
386 pub fn get_lt1_mut(&mut self) -> &mut Color2Type {
387 self.lt1_mut()
388 }
389
390 #[inline]
391 pub fn set_lt1(&mut self, value: Color2Type) -> &mut Self {
392 self.lt1 = value;
393 self
394 }
395
396 #[inline]
397 #[must_use]
398 pub fn lt2(&self) -> &Color2Type {
399 &self.lt2
400 }
401
402 #[inline]
403 #[must_use]
404 #[deprecated(since = "3.0.0", note = "Use lt2()")]
405 pub fn get_lt2(&self) -> &Color2Type {
406 self.lt2()
407 }
408
409 #[inline]
410 pub fn lt2_mut(&mut self) -> &mut Color2Type {
411 &mut self.lt2
412 }
413
414 #[inline]
415 #[deprecated(since = "3.0.0", note = "Use lt2_mut()")]
416 pub fn get_lt2_mut(&mut self) -> &mut Color2Type {
417 self.lt2_mut()
418 }
419
420 #[inline]
421 pub fn set_lt2(&mut self, value: Color2Type) -> &mut Self {
422 self.lt2 = value;
423 self
424 }
425
426 #[inline]
427 #[must_use]
428 pub fn color_map(&self) -> Vec<String> {
429 vec![
430 self.lt1.val(),
431 self.dk1.val(),
432 self.lt2.val(),
433 self.dk2.val(),
434 self.accent1.val(),
435 self.accent2.val(),
436 self.accent3.val(),
437 self.accent4.val(),
438 self.accent5.val(),
439 self.accent6.val(),
440 self.hlink.val(),
441 self.fol_hlink.val(),
442 ]
443 }
444
445 #[inline]
446 #[must_use]
447 #[deprecated(since = "3.0.0", note = "Use color_map()")]
448 pub fn get_color_map(&self) -> Vec<String> {
449 self.color_map()
450 }
451
452 pub(crate) fn set_attributes<R: std::io::BufRead>(
453 &mut self,
454 reader: &mut Reader<R>,
455 e: &BytesStart,
456 ) {
457 set_string_from_xml!(self, e, name, "name");
458
459 xml_read_loop!(
460 reader,
461 Event::Start(ref e) => {
462 match e.name().into_inner() {
463 b"a:accent1" => {
464 self.accent1.set_attributes(reader, e);
465 }
466 b"a:accent2" => {
467 self.accent2.set_attributes(reader, e);
468 }
469 b"a:accent3" => {
470 self.accent3.set_attributes(reader, e);
471 }
472 b"a:accent4" => {
473 self.accent4.set_attributes(reader, e);
474 }
475 b"a:accent5" => {
476 self.accent5.set_attributes(reader, e);
477 }
478 b"a:accent6" => {
479 self.accent6.set_attributes(reader, e);
480 }
481 b"a:dk1" => {
482 self.dk1.set_attributes(reader, e);
483 }
484 b"a:dk2" => {
485 self.dk2.set_attributes(reader, e);
486 }
487 b"a:folHlink" => {
488 self.fol_hlink.set_attributes(reader, e);
489 }
490 b"a:hlink" => {
491 self.hlink.set_attributes(reader, e);
492 }
493 b"a:lt1" => {
494 self.lt1.set_attributes(reader, e);
495 }
496 b"a:lt2" => {
497 self.lt2.set_attributes(reader, e);
498 }
499 _ => (),
500 }
501 },
502 Event::End(ref e) => {
503 if e.name().into_inner() == b"a:clrScheme" {
504 return
505 }
506 },
507 Event::Eof => panic!("Error: Could not find {} end element", "a:clrScheme")
508 );
509 }
510
511 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
512 let mut attributes: crate::structs::AttrCollection = Vec::new();
514 if self.name.has_value() {
515 attributes.push(("name", self.name.value_str()).into());
516 }
517 write_start_tag(writer, "a:clrScheme", attributes, false);
518
519 self.dk1.write_to_dk1(writer);
521
522 self.lt1.write_to_lt1(writer);
524
525 self.dk2.write_to_dk2(writer);
527
528 self.lt2.write_to_lt2(writer);
530
531 self.accent1.write_to_accent1(writer);
533
534 self.accent2.write_to_accent2(writer);
536
537 self.accent3.write_to_accent3(writer);
539
540 self.accent4.write_to_accent4(writer);
542
543 self.accent5.write_to_accent5(writer);
545
546 self.accent6.write_to_accent6(writer);
548
549 self.hlink.write_to_hlink(writer);
551
552 self.fol_hlink.write_to_fol_hlink(writer);
554
555 write_end_tag(writer, "a:clrScheme");
556 }
557}