Skip to main content

umya_spreadsheet/structs/drawing/
list_style.rs

1// a:lstStyle
2use std::{
3    collections::HashMap,
4    io::Cursor,
5};
6
7use quick_xml::{
8    Reader,
9    Writer,
10    events::{
11        BytesStart,
12        Event,
13    },
14};
15
16use super::{
17    EffectList,
18    TextParagraphPropertiesType,
19};
20use crate::{
21    reader::driver::xml_read_loop,
22    writer::driver::{
23        write_end_tag,
24        write_start_tag,
25    },
26};
27
28#[derive(Clone, Default, Debug)]
29pub struct ListStyle {
30    effect_list:                    Option<Box<EffectList>>,
31    text_paragraph_properties_type: HashMap<Box<str>, Box<TextParagraphPropertiesType>>,
32}
33
34impl ListStyle {
35    #[inline]
36    #[must_use]
37    pub fn effect_list(&self) -> Option<&EffectList> {
38        self.effect_list.as_deref()
39    }
40
41    #[inline]
42    #[must_use]
43    #[deprecated(since = "3.0.0", note = "Use effect_list()")]
44    pub fn get_effect_list(&self) -> Option<&EffectList> {
45        self.effect_list()
46    }
47
48    #[inline]
49    pub fn effect_list_mut(&mut self) -> Option<&mut EffectList> {
50        self.effect_list.as_deref_mut()
51    }
52
53    #[inline]
54    #[deprecated(since = "3.0.0", note = "Use effect_list_mut()")]
55    pub fn get_effect_list_mut(&mut self) -> Option<&mut EffectList> {
56        self.effect_list_mut()
57    }
58
59    #[inline]
60    pub fn set_effect_list(&mut self, value: EffectList) -> &mut Self {
61        self.effect_list = Some(Box::new(value));
62        self
63    }
64
65    #[inline]
66    pub fn default_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
67        self.text_paragraph_properties_type
68            .get("def")
69            .map(Box::as_ref)
70    }
71
72    #[inline]
73    #[must_use]
74    #[deprecated(since = "3.0.0", note = "Use default_paragraph_properties()")]
75    pub fn get_default_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
76        self.default_paragraph_properties()
77    }
78
79    #[inline]
80    pub fn default_paragraph_properties_mut(&mut self) -> Option<&mut TextParagraphPropertiesType> {
81        self.text_paragraph_properties_type
82            .get_mut("def")
83            .map(Box::as_mut)
84    }
85
86    #[inline]
87    #[deprecated(since = "3.0.0", note = "Use default_paragraph_properties_mut()")]
88    pub fn get_default_paragraph_properties_mut(
89        &mut self,
90    ) -> Option<&mut TextParagraphPropertiesType> {
91        self.default_paragraph_properties_mut()
92    }
93
94    #[inline]
95    pub fn set_default_paragraph_properties(
96        &mut self,
97        value: TextParagraphPropertiesType,
98    ) -> &mut Self {
99        self.text_paragraph_properties_type
100            .insert(String::from("def").into_boxed_str(), Box::new(value));
101        self
102    }
103
104    #[inline]
105    pub fn level1_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
106        self.text_paragraph_properties_type
107            .get("lv1")
108            .map(Box::as_ref)
109    }
110
111    #[inline]
112    #[must_use]
113    #[deprecated(since = "3.0.0", note = "Use level1_paragraph_properties()")]
114    pub fn get_level1_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
115        self.level1_paragraph_properties()
116    }
117
118    #[inline]
119    pub fn level1_paragraph_properties_mut(&mut self) -> Option<&mut TextParagraphPropertiesType> {
120        self.text_paragraph_properties_type
121            .get_mut("lv1")
122            .map(Box::as_mut)
123    }
124
125    #[inline]
126    #[deprecated(since = "3.0.0", note = "Use level1_paragraph_properties_mut()")]
127    pub fn get_level1_paragraph_properties_mut(
128        &mut self,
129    ) -> Option<&mut TextParagraphPropertiesType> {
130        self.level1_paragraph_properties_mut()
131    }
132
133    #[inline]
134    pub fn set_level1_paragraph_properties(
135        &mut self,
136        value: TextParagraphPropertiesType,
137    ) -> &mut Self {
138        self.text_paragraph_properties_type
139            .insert(String::from("lv1").into_boxed_str(), Box::new(value));
140        self
141    }
142
143    #[inline]
144    pub fn level2_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
145        self.text_paragraph_properties_type
146            .get("lv2")
147            .map(Box::as_ref)
148    }
149
150    #[inline]
151    #[must_use]
152    #[deprecated(since = "3.0.0", note = "Use level2_paragraph_properties()")]
153    pub fn get_level2_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
154        self.level2_paragraph_properties()
155    }
156
157    #[inline]
158    pub fn level2_paragraph_properties_mut(&mut self) -> Option<&mut TextParagraphPropertiesType> {
159        self.text_paragraph_properties_type
160            .get_mut("lv2")
161            .map(Box::as_mut)
162    }
163
164    #[inline]
165    #[deprecated(since = "3.0.0", note = "Use level2_paragraph_properties_mut()")]
166    pub fn get_level2_paragraph_properties_mut(
167        &mut self,
168    ) -> Option<&mut TextParagraphPropertiesType> {
169        self.level2_paragraph_properties_mut()
170    }
171
172    #[inline]
173    pub fn set_level2_paragraph_properties(
174        &mut self,
175        value: TextParagraphPropertiesType,
176    ) -> &mut Self {
177        self.text_paragraph_properties_type
178            .insert(String::from("lv2").into_boxed_str(), Box::new(value));
179        self
180    }
181
182    #[inline]
183    pub fn level3_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
184        self.text_paragraph_properties_type
185            .get("lv3")
186            .map(Box::as_ref)
187    }
188
189    #[inline]
190    #[must_use]
191    #[deprecated(since = "3.0.0", note = "Use level3_paragraph_properties()")]
192    pub fn get_level3_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
193        self.level3_paragraph_properties()
194    }
195
196    #[inline]
197    pub fn level3_paragraph_properties_mut(&mut self) -> Option<&mut TextParagraphPropertiesType> {
198        self.text_paragraph_properties_type
199            .get_mut("lv3")
200            .map(Box::as_mut)
201    }
202
203    #[inline]
204    #[deprecated(since = "3.0.0", note = "Use level3_paragraph_properties_mut()")]
205    pub fn get_level3_paragraph_properties_mut(
206        &mut self,
207    ) -> Option<&mut TextParagraphPropertiesType> {
208        self.level3_paragraph_properties_mut()
209    }
210
211    #[inline]
212    pub fn set_level3_paragraph_properties(
213        &mut self,
214        value: TextParagraphPropertiesType,
215    ) -> &mut Self {
216        self.text_paragraph_properties_type
217            .insert(String::from("lv3").into_boxed_str(), Box::new(value));
218        self
219    }
220
221    #[inline]
222    pub fn level4_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
223        self.text_paragraph_properties_type
224            .get("lv4")
225            .map(Box::as_ref)
226    }
227
228    #[inline]
229    #[must_use]
230    #[deprecated(since = "3.0.0", note = "Use level4_paragraph_properties()")]
231    pub fn get_level4_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
232        self.level4_paragraph_properties()
233    }
234
235    #[inline]
236    pub fn level4_paragraph_properties_mut(&mut self) -> Option<&mut TextParagraphPropertiesType> {
237        self.text_paragraph_properties_type
238            .get_mut("lv4")
239            .map(Box::as_mut)
240    }
241
242    #[inline]
243    #[deprecated(since = "3.0.0", note = "Use level4_paragraph_properties_mut()")]
244    pub fn get_level4_paragraph_properties_mut(
245        &mut self,
246    ) -> Option<&mut TextParagraphPropertiesType> {
247        self.level4_paragraph_properties_mut()
248    }
249
250    #[inline]
251    pub fn set_level4_paragraph_properties(
252        &mut self,
253        value: TextParagraphPropertiesType,
254    ) -> &mut Self {
255        self.text_paragraph_properties_type
256            .insert(String::from("lv4").into_boxed_str(), Box::new(value));
257        self
258    }
259
260    #[inline]
261    pub fn level5_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
262        self.text_paragraph_properties_type
263            .get("lv5")
264            .map(Box::as_ref)
265    }
266
267    #[inline]
268    #[must_use]
269    #[deprecated(since = "3.0.0", note = "Use level5_paragraph_properties()")]
270    pub fn get_level5_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
271        self.level5_paragraph_properties()
272    }
273
274    #[inline]
275    pub fn level5_paragraph_properties_mut(&mut self) -> Option<&mut TextParagraphPropertiesType> {
276        self.text_paragraph_properties_type
277            .get_mut("lv5")
278            .map(Box::as_mut)
279    }
280
281    #[inline]
282    #[deprecated(since = "3.0.0", note = "Use level5_paragraph_properties_mut()")]
283    pub fn get_level5_paragraph_properties_mut(
284        &mut self,
285    ) -> Option<&mut TextParagraphPropertiesType> {
286        self.level5_paragraph_properties_mut()
287    }
288
289    #[inline]
290    pub fn set_level5_paragraph_properties(
291        &mut self,
292        value: TextParagraphPropertiesType,
293    ) -> &mut Self {
294        self.text_paragraph_properties_type
295            .insert(String::from("lv5").into_boxed_str(), Box::new(value));
296        self
297    }
298
299    #[inline]
300    pub fn level6_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
301        self.text_paragraph_properties_type
302            .get("lv6")
303            .map(Box::as_ref)
304    }
305
306    #[inline]
307    #[must_use]
308    #[deprecated(since = "3.0.0", note = "Use level6_paragraph_properties()")]
309    pub fn get_level6_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
310        self.level6_paragraph_properties()
311    }
312
313    #[inline]
314    pub fn level6_paragraph_properties_mut(&mut self) -> Option<&mut TextParagraphPropertiesType> {
315        self.text_paragraph_properties_type
316            .get_mut("lv6")
317            .map(Box::as_mut)
318    }
319
320    #[inline]
321    #[deprecated(since = "3.0.0", note = "Use level6_paragraph_properties_mut()")]
322    pub fn get_level6_paragraph_properties_mut(
323        &mut self,
324    ) -> Option<&mut TextParagraphPropertiesType> {
325        self.level6_paragraph_properties_mut()
326    }
327
328    #[inline]
329    pub fn set_level6_paragraph_properties(
330        &mut self,
331        value: TextParagraphPropertiesType,
332    ) -> &mut Self {
333        self.text_paragraph_properties_type
334            .insert(String::from("lv6").into_boxed_str(), Box::new(value));
335        self
336    }
337
338    #[inline]
339    pub fn level7_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
340        self.text_paragraph_properties_type
341            .get("lv7")
342            .map(Box::as_ref)
343    }
344
345    #[inline]
346    #[must_use]
347    #[deprecated(since = "3.0.0", note = "Use level7_paragraph_properties()")]
348    pub fn get_level7_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
349        self.level7_paragraph_properties()
350    }
351
352    #[inline]
353    pub fn level7_paragraph_properties_mut(&mut self) -> Option<&mut TextParagraphPropertiesType> {
354        self.text_paragraph_properties_type
355            .get_mut("lv7")
356            .map(Box::as_mut)
357    }
358
359    #[inline]
360    #[deprecated(since = "3.0.0", note = "Use level7_paragraph_properties_mut()")]
361    pub fn get_level7_paragraph_properties_mut(
362        &mut self,
363    ) -> Option<&mut TextParagraphPropertiesType> {
364        self.level7_paragraph_properties_mut()
365    }
366
367    #[inline]
368    pub fn set_level7_paragraph_properties(
369        &mut self,
370        value: TextParagraphPropertiesType,
371    ) -> &mut Self {
372        self.text_paragraph_properties_type
373            .insert(String::from("lv7").into_boxed_str(), Box::new(value));
374        self
375    }
376
377    #[inline]
378    pub fn level8_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
379        self.text_paragraph_properties_type
380            .get("lv8")
381            .map(Box::as_ref)
382    }
383
384    #[inline]
385    #[must_use]
386    #[deprecated(since = "3.0.0", note = "Use level8_paragraph_properties()")]
387    pub fn get_level8_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
388        self.level8_paragraph_properties()
389    }
390
391    #[inline]
392    pub fn level8_paragraph_properties_mut(&mut self) -> Option<&mut TextParagraphPropertiesType> {
393        self.text_paragraph_properties_type
394            .get_mut("lv8")
395            .map(Box::as_mut)
396    }
397
398    #[inline]
399    #[deprecated(since = "3.0.0", note = "Use level8_paragraph_properties_mut()")]
400    pub fn get_level8_paragraph_properties_mut(
401        &mut self,
402    ) -> Option<&mut TextParagraphPropertiesType> {
403        self.level8_paragraph_properties_mut()
404    }
405
406    #[inline]
407    pub fn set_level8_paragraph_properties(
408        &mut self,
409        value: TextParagraphPropertiesType,
410    ) -> &mut Self {
411        self.text_paragraph_properties_type
412            .insert(String::from("lv8").into_boxed_str(), Box::new(value));
413        self
414    }
415
416    #[inline]
417    pub fn level9_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
418        self.text_paragraph_properties_type
419            .get("lv9")
420            .map(Box::as_ref)
421    }
422
423    #[inline]
424    #[must_use]
425    #[deprecated(since = "3.0.0", note = "Use level9_paragraph_properties()")]
426    pub fn get_level9_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
427        self.level9_paragraph_properties()
428    }
429
430    #[inline]
431    pub fn level9_paragraph_properties_mut(&mut self) -> Option<&mut TextParagraphPropertiesType> {
432        self.text_paragraph_properties_type
433            .get_mut("lv9")
434            .map(Box::as_mut)
435    }
436
437    #[inline]
438    #[deprecated(since = "3.0.0", note = "Use level9_paragraph_properties_mut()")]
439    pub fn get_level9_paragraph_properties_mut(
440        &mut self,
441    ) -> Option<&mut TextParagraphPropertiesType> {
442        self.level9_paragraph_properties_mut()
443    }
444
445    #[inline]
446    pub fn set_level9_paragraph_properties(
447        &mut self,
448        value: TextParagraphPropertiesType,
449    ) -> &mut Self {
450        self.text_paragraph_properties_type
451            .insert(String::from("lv9").into_boxed_str(), Box::new(value));
452        self
453    }
454
455    pub(crate) fn set_attributes<R: std::io::BufRead>(
456        &mut self,
457        reader: &mut Reader<R>,
458        _e: &BytesStart,
459    ) {
460        xml_read_loop!(
461            reader,
462            Event::Start(ref e) => {
463                match e.name().into_inner() {
464                    b"a:effectLst" => {
465                        let obj = EffectList::default();
466                        self.set_effect_list(obj);
467                    }
468                    b"a:defPPr" => {
469                        let mut obj = TextParagraphPropertiesType::default();
470                        obj.set_attributes(reader, e);
471                        self.set_default_paragraph_properties(obj);
472                    }
473                    b"a:lvl1pPr" => {
474                        let mut obj = TextParagraphPropertiesType::default();
475                        obj.set_attributes(reader, e);
476                        self.set_level1_paragraph_properties(obj);
477                    }
478                    b"a:lvl2pPr" => {
479                        let mut obj = TextParagraphPropertiesType::default();
480                        obj.set_attributes(reader, e);
481                        self.set_level2_paragraph_properties(obj);
482                    }
483                    b"a:lvl3pPr" => {
484                        let mut obj = TextParagraphPropertiesType::default();
485                        obj.set_attributes(reader, e);
486                        self.set_level3_paragraph_properties(obj);
487                    }
488                    b"a:lvl4pPr" => {
489                        let mut obj = TextParagraphPropertiesType::default();
490                        obj.set_attributes(reader, e);
491                        self.set_level4_paragraph_properties(obj);
492                    }
493                    b"a:lvl5pPr" => {
494                        let mut obj = TextParagraphPropertiesType::default();
495                        obj.set_attributes(reader, e);
496                        self.set_level5_paragraph_properties(obj);
497                    }
498                    b"a:lvl6pPr" => {
499                        let mut obj = TextParagraphPropertiesType::default();
500                        obj.set_attributes(reader, e);
501                        self.set_level6_paragraph_properties(obj);
502                    }
503                    b"a:lvl7pPr" => {
504                        let mut obj = TextParagraphPropertiesType::default();
505                        obj.set_attributes(reader, e);
506                        self.set_level7_paragraph_properties(obj);
507                    }
508                    b"a:lvl8pPr" => {
509                        let mut obj = TextParagraphPropertiesType::default();
510                        obj.set_attributes(reader, e);
511                        self.set_level8_paragraph_properties(obj);
512                    }
513                    b"a:lvl9pPr" => {
514                        let mut obj = TextParagraphPropertiesType::default();
515                        obj.set_attributes(reader, e);
516                        self.set_level9_paragraph_properties(obj);
517                    }
518                    _ => (),
519                }
520            },
521            Event::End(ref e) => {
522                if e.name().into_inner() == b"a:lstStyle" {
523                    return;
524                }
525            },
526            Event::Eof => panic!("Error: Could not find {} end element", "a:lstStyle")
527        );
528    }
529
530    #[inline]
531    fn is_empty(&self) -> bool {
532        self.effect_list.is_none() && self.text_paragraph_properties_type.is_empty()
533    }
534
535    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
536        // a:lstStyle
537        let is_empty = self.is_empty();
538        write_start_tag(writer, "a:lstStyle", vec![], is_empty);
539
540        // a:defPPr
541        if let Some(v) = &self.text_paragraph_properties_type.get("def") {
542            v.write_to_default(writer);
543        }
544
545        // a:lvl1pPr
546        if let Some(v) = &self.text_paragraph_properties_type.get("lv1") {
547            v.write_to_lvl1(writer);
548        }
549
550        // a:lvl2pPr
551        if let Some(v) = &self.text_paragraph_properties_type.get("lv2") {
552            v.write_to_lvl2(writer);
553        }
554
555        // a:lvl3pPr
556        if let Some(v) = &self.text_paragraph_properties_type.get("lv3") {
557            v.write_to_lvl3(writer);
558        }
559
560        // a:lvl4pPr
561        if let Some(v) = &self.text_paragraph_properties_type.get("lv4") {
562            v.write_to_lvl4(writer);
563        }
564
565        // a:lvl5pPr
566        if let Some(v) = &self.text_paragraph_properties_type.get("lv5") {
567            v.write_to_lvl5(writer);
568        }
569
570        // a:lvl6pPr
571        if let Some(v) = &self.text_paragraph_properties_type.get("lv6") {
572            v.write_to_lvl6(writer);
573        }
574
575        // a:lvl7pPr
576        if let Some(v) = &self.text_paragraph_properties_type.get("lv7") {
577            v.write_to_lvl7(writer);
578        }
579
580        // a:lvl8pPr
581        if let Some(v) = &self.text_paragraph_properties_type.get("lv8") {
582            v.write_to_lvl8(writer);
583        }
584
585        // a:lvl9pPr
586        if let Some(v) = &self.text_paragraph_properties_type.get("lv9") {
587            v.write_to_lvl9(writer);
588        }
589
590        if !is_empty {
591            write_end_tag(writer, "a:lstStyle");
592        }
593    }
594}