Skip to main content

umya_spreadsheet/structs/drawing/
effect_style.rs

1use std::{
2    io::Cursor,
3    vec,
4};
5
6use quick_xml::{
7    Reader,
8    Writer,
9    events::{
10        BytesStart,
11        Event,
12    },
13};
14
15use super::{
16    EffectList,
17    Scene3DType,
18    Shape3DType,
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 EffectStyle {
30    effect_list:   Option<Box<EffectList>>,
31    scene_3d_type: Option<Box<Scene3DType>>,
32    shape_3d_type: Option<Box<Shape3DType>>,
33}
34
35impl EffectStyle {
36    #[inline]
37    #[must_use]
38    pub fn effect_list(&self) -> Option<&EffectList> {
39        self.effect_list.as_deref()
40    }
41
42    #[inline]
43    #[must_use]
44    #[deprecated(since = "3.0.0", note = "Use effect_list()")]
45    pub fn get_effect_list(&self) -> Option<&EffectList> {
46        self.effect_list()
47    }
48
49    #[inline]
50    pub fn effect_list_mut(&mut self) -> Option<&mut EffectList> {
51        self.effect_list.as_deref_mut()
52    }
53
54    #[inline]
55    #[deprecated(since = "3.0.0", note = "Use effect_list_mut()")]
56    pub fn get_effect_list_mut(&mut self) -> Option<&mut EffectList> {
57        self.effect_list_mut()
58    }
59
60    #[inline]
61    pub fn set_effect_list(&mut self, value: EffectList) -> &mut Self {
62        self.effect_list = Some(Box::new(value));
63        self
64    }
65
66    #[inline]
67    #[must_use]
68    pub fn scene_3d_type(&self) -> Option<&Scene3DType> {
69        self.scene_3d_type.as_deref()
70    }
71
72    #[inline]
73    #[must_use]
74    #[deprecated(since = "3.0.0", note = "Use scene_3d_type()")]
75    pub fn get_scene_3d_type(&self) -> Option<&Scene3DType> {
76        self.scene_3d_type()
77    }
78
79    #[inline]
80    pub fn scene_3d_type_mut(&mut self) -> Option<&mut Scene3DType> {
81        self.scene_3d_type.as_deref_mut()
82    }
83
84    #[inline]
85    #[deprecated(since = "3.0.0", note = "Use scene_3d_type_mut()")]
86    pub fn get_scene_3d_type_mut(&mut self) -> Option<&mut Scene3DType> {
87        self.scene_3d_type_mut()
88    }
89
90    #[inline]
91    pub fn set_scene_3d_type(&mut self, value: Scene3DType) -> &mut Self {
92        self.scene_3d_type = Some(Box::new(value));
93        self
94    }
95
96    #[inline]
97    #[must_use]
98    pub fn shape_3d_type(&self) -> Option<&Shape3DType> {
99        self.shape_3d_type.as_deref()
100    }
101
102    #[inline]
103    #[must_use]
104    #[deprecated(since = "3.0.0", note = "Use shape_3d_type()")]
105    pub fn get_shape_3d_type(&self) -> Option<&Shape3DType> {
106        self.shape_3d_type()
107    }
108
109    #[inline]
110    pub fn shape_3d_type_mut(&mut self) -> Option<&mut Shape3DType> {
111        self.shape_3d_type.as_deref_mut()
112    }
113
114    #[inline]
115    #[deprecated(since = "3.0.0", note = "Use shape_3d_type_mut()")]
116    pub fn get_shape_3d_type_mut(&mut self) -> Option<&mut Shape3DType> {
117        self.shape_3d_type_mut()
118    }
119
120    #[inline]
121    pub fn set_shape_3d_type(&mut self, value: Shape3DType) -> &mut Self {
122        self.shape_3d_type = Some(Box::new(value));
123        self
124    }
125
126    pub(crate) fn set_attributes<R: std::io::BufRead>(
127        &mut self,
128        reader: &mut Reader<R>,
129        _e: &BytesStart,
130    ) {
131        xml_read_loop!(
132            reader,
133            Event::Start(ref e) => {
134                match e.name().into_inner() {
135                b"a:effectLst" => {
136                    let mut obj = EffectList::default();
137                    obj.set_attributes(reader, e, false);
138                    self.effect_list = Some(Box::new(obj));
139                }
140                b"a:scene3d" => {
141                    let mut obj = Scene3DType::default();
142                    obj.set_attributes(reader, e);
143                    self.scene_3d_type = Some(Box::new(obj));
144                }
145                b"a:sp3d" => {
146                    let mut obj = Shape3DType::default();
147                    obj.set_attributes(reader, e);
148                    self.shape_3d_type = Some(Box::new(obj));
149                }
150                _ => (),
151                }
152            },
153            Event::Empty(ref e) => {
154                if e.name().into_inner() == b"a:effectLst" {
155                    let mut obj = EffectList::default();
156                    obj.set_attributes(reader, e, true);
157                    self.set_effect_list(obj);
158                }
159            },
160            Event::End(ref e) => {
161                if e.name().into_inner() == b"a:effectStyle" {
162                    return
163                }
164            },
165            Event::Eof => panic!("Error: Could not find {} end element", "a:effectStyle")
166        );
167    }
168
169    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
170        write_start_tag(writer, "a:effectStyle", vec![], false);
171
172        // a:effectLst
173        if let Some(v) = &self.effect_list {
174            v.write_to(writer);
175        }
176
177        // a:scene3d
178        if let Some(v) = &self.scene_3d_type {
179            v.write_to(writer);
180        }
181
182        // a:sp3d
183        if let Some(v) = &self.shape_3d_type {
184            v.write_to(writer);
185        }
186
187        write_end_tag(writer, "a:effectStyle");
188    }
189}