umya_spreadsheet/structs/drawing/
outer_shadow.rs1use super::PresetColor;
3use super::RgbColorModelHex;
4use super::SchemeColor;
5use crate::reader::driver::*;
6use crate::writer::driver::*;
7use crate::StringValue;
8use quick_xml::events::{BytesStart, Event};
9use quick_xml::Reader;
10use quick_xml::Writer;
11use std::io::Cursor;
12
13#[derive(Clone, Default, Debug)]
14pub struct OuterShadow {
15    blur_radius: StringValue,
16    alignment: StringValue,
17    horizontal_ratio: StringValue,
18    vertical_ratio: StringValue,
19    direction: StringValue,
20    distance: StringValue,
21    rotate_with_shape: StringValue,
22    preset_color: Option<Box<PresetColor>>,
23    scheme_color: Option<Box<SchemeColor>>,
24    rgb_color_model_hex: Option<Box<RgbColorModelHex>>,
25}
26
27impl OuterShadow {
28    #[inline]
29    pub fn get_blur_radius(&self) -> Option<&str> {
30        self.blur_radius.get_value()
31    }
32
33    #[inline]
34    pub fn set_blur_radius<S: Into<String>>(&mut self, value: S) -> &mut Self {
35        self.blur_radius.set_value(value);
36        self
37    }
38
39    #[inline]
40    pub fn get_horizontal_ratio(&self) -> Option<&str> {
41        self.horizontal_ratio.get_value()
42    }
43
44    #[inline]
45    pub fn set_horizontal_ratio<S: Into<String>>(&mut self, value: S) -> &mut Self {
46        self.horizontal_ratio.set_value(value);
47        self
48    }
49
50    #[inline]
51    pub fn get_vertical_ratio(&self) -> Option<&str> {
52        self.vertical_ratio.get_value()
53    }
54
55    #[inline]
56    pub fn set_vertical_ratio<S: Into<String>>(&mut self, value: S) -> &mut Self {
57        self.vertical_ratio.set_value(value);
58        self
59    }
60
61    #[inline]
62    pub fn get_alignment(&self) -> Option<&str> {
63        self.alignment.get_value()
64    }
65
66    #[inline]
67    pub fn set_alignment<S: Into<String>>(&mut self, value: S) -> &mut Self {
68        self.alignment.set_value(value);
69        self
70    }
71
72    #[inline]
73    pub fn get_direction(&self) -> Option<&str> {
74        self.direction.get_value()
75    }
76
77    #[inline]
78    pub fn set_direction<S: Into<String>>(&mut self, value: S) -> &mut Self {
79        self.direction.set_value(value);
80        self
81    }
82
83    #[inline]
84    pub fn get_distance(&self) -> Option<&str> {
85        self.distance.get_value()
86    }
87
88    #[inline]
89    pub fn set_distance<S: Into<String>>(&mut self, value: S) -> &mut Self {
90        self.distance.set_value(value);
91        self
92    }
93
94    pub fn get_rotate_with_shape(&self) -> Option<&str> {
95        self.rotate_with_shape.get_value()
96    }
97
98    #[inline]
99    pub fn set_rotate_with_shape<S: Into<String>>(&mut self, value: S) -> &mut Self {
100        self.rotate_with_shape.set_value(value);
101        self
102    }
103
104    #[inline]
105    pub fn get_preset_color(&self) -> Option<&PresetColor> {
106        self.preset_color.as_deref()
107    }
108
109    #[inline]
110    pub fn get_preset_color_mut(&mut self) -> Option<&mut PresetColor> {
111        self.preset_color.as_deref_mut()
112    }
113
114    #[inline]
115    pub fn set_preset_color(&mut self, value: PresetColor) -> &mut Self {
116        self.preset_color = Some(Box::new(value));
117        self
118    }
119
120    #[inline]
121    pub fn get_scheme_color(&self) -> Option<&SchemeColor> {
122        self.scheme_color.as_deref()
123    }
124
125    #[inline]
126    pub fn get_scheme_color_mut(&mut self) -> Option<&mut SchemeColor> {
127        self.scheme_color.as_deref_mut()
128    }
129
130    #[inline]
131    pub fn set_scheme_color(&mut self, value: SchemeColor) -> &mut Self {
132        self.scheme_color = Some(Box::new(value));
133        self
134    }
135
136    #[inline]
137    pub fn get_rgb_color_model_hex(&self) -> Option<&RgbColorModelHex> {
138        self.rgb_color_model_hex.as_deref()
139    }
140
141    #[inline]
142    pub fn get_rgb_color_model_hex_mut(&mut self) -> Option<&mut RgbColorModelHex> {
143        self.rgb_color_model_hex.as_deref_mut()
144    }
145
146    #[inline]
147    pub fn set_rgb_color_model_hex(&mut self, value: RgbColorModelHex) -> &mut Self {
148        self.rgb_color_model_hex = Some(Box::new(value));
149        self
150    }
151
152    pub(crate) fn set_attributes<R: std::io::BufRead>(
153        &mut self,
154        reader: &mut Reader<R>,
155        e: &BytesStart,
156    ) {
157        if let Some(v) = get_attribute(e, b"blurRad") {
158            self.set_blur_radius(v);
159        }
160        if let Some(v) = get_attribute(e, b"dist") {
161            self.set_distance(v);
162        }
163        if let Some(v) = get_attribute(e, b"dir") {
164            self.set_direction(v);
165        }
166        if let Some(v) = get_attribute(e, b"sx") {
167            self.set_horizontal_ratio(v);
168        }
169        if let Some(v) = get_attribute(e, b"sy") {
170            self.set_vertical_ratio(v);
171        }
172        if let Some(v) = get_attribute(e, b"algn") {
173            self.set_alignment(v);
174        }
175        if let Some(v) = get_attribute(e, b"rotWithShape") {
176            self.set_rotate_with_shape(v);
177        }
178
179        xml_read_loop!(
180            reader,
181            Event::Empty(ref e) => {
182                match e.name().into_inner() {
183                    b"a:schemeClr" => {
184                        let mut obj = SchemeColor::default();
185                        obj.set_attributes(reader, e, true);
186                        self.set_scheme_color(obj);
187                    }
188                    b"a:srgbClr" => {
189                        let mut obj = RgbColorModelHex::default();
190                        obj.set_attributes(reader, e, true);
191                        self.set_rgb_color_model_hex(obj);
192                    }
193                    _ => (),
194                }
195            },
196            Event::Start(ref e) => {
197                match e.name().into_inner() {
198                    b"a:prstClr" => {
199                        let mut obj = PresetColor::default();
200                        obj.set_attributes(reader, e);
201                        self.set_preset_color(obj);
202                    }
203                    b"a:schemeClr" => {
204                        let mut obj = SchemeColor::default();
205                        obj.set_attributes(reader, e, false);
206                        self.set_scheme_color(obj);
207                    }
208                    b"a:srgbClr" => {
209                        let mut obj = RgbColorModelHex::default();
210                        obj.set_attributes(reader, e, false);
211                        self.set_rgb_color_model_hex(obj);
212                    }
213                    _ => (),
214                }
215            },
216            Event::End(ref e) => {
217                if e.name().into_inner() == b"a:outerShdw" {
218                    return
219                }
220            },
221            Event::Eof => panic!("Error: Could not find {} end element", "a:outerShdw")
222        );
223    }
224
225    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
226        let mut attributes: Vec<(&str, &str)> = Vec::new();
228        if let Some(v) = self.blur_radius.get_value() {
229            attributes.push(("blurRad", v));
230        }
231        if let Some(v) = self.distance.get_value() {
232            attributes.push(("dist", v));
233        }
234        if let Some(v) = self.direction.get_value() {
235            attributes.push(("dir", v));
236        }
237        if let Some(v) = self.horizontal_ratio.get_value() {
238            attributes.push(("sx", v));
239        }
240        if let Some(v) = self.vertical_ratio.get_value() {
241            attributes.push(("sy", v));
242        }
243        if let Some(v) = self.alignment.get_value() {
244            attributes.push(("algn", v));
245        }
246        if let Some(v) = self.rotate_with_shape.get_value() {
247            attributes.push(("rotWithShape", v));
248        }
249        write_start_tag(writer, "a:outerShdw", attributes, false);
250
251        if let Some(v) = &self.preset_color {
253            v.write_to(writer);
254        }
255
256        if let Some(v) = &self.scheme_color {
258            v.write_to(writer);
259        }
260
261        if let Some(v) = &self.rgb_color_model_hex {
263            v.write_to(writer);
264        }
265
266        write_end_tag(writer, "a:outerShdw");
267    }
268}