umya_spreadsheet/structs/drawing/
outer_shadow.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::{
8 BytesStart,
9 Event,
10 },
11};
12
13use super::{
14 PresetColor,
15 RgbColorModelHex,
16 SchemeColor,
17};
18use crate::{
19 StringValue,
20 reader::driver::{
21 get_attribute,
22 xml_read_loop,
23 },
24 writer::driver::{
25 write_end_tag,
26 write_start_tag,
27 },
28};
29
30#[derive(Clone, Default, Debug)]
31pub struct OuterShadow {
32 blur_radius: StringValue,
33 alignment: StringValue,
34 horizontal_ratio: StringValue,
35 vertical_ratio: StringValue,
36 direction: StringValue,
37 distance: StringValue,
38 rotate_with_shape: StringValue,
39 preset_color: Option<Box<PresetColor>>,
40 scheme_color: Option<Box<SchemeColor>>,
41 rgb_color_model_hex: Option<Box<RgbColorModelHex>>,
42}
43
44impl OuterShadow {
45 #[inline]
46 #[must_use]
47 pub fn blur_radius(&self) -> Option<&str> {
48 self.blur_radius.value()
49 }
50
51 #[inline]
52 #[must_use]
53 #[deprecated(since = "3.0.0", note = "Use blur_radius()")]
54 pub fn get_blur_radius(&self) -> Option<&str> {
55 self.blur_radius()
56 }
57
58 #[inline]
59 pub fn set_blur_radius<S: Into<String>>(&mut self, value: S) -> &mut Self {
60 self.blur_radius.set_value(value);
61 self
62 }
63
64 #[inline]
65 #[must_use]
66 pub fn horizontal_ratio(&self) -> Option<&str> {
67 self.horizontal_ratio.value()
68 }
69
70 #[inline]
71 #[must_use]
72 #[deprecated(since = "3.0.0", note = "Use horizontal_ratio()")]
73 pub fn get_horizontal_ratio(&self) -> Option<&str> {
74 self.horizontal_ratio()
75 }
76
77 #[inline]
78 pub fn set_horizontal_ratio<S: Into<String>>(&mut self, value: S) -> &mut Self {
79 self.horizontal_ratio.set_value(value);
80 self
81 }
82
83 #[inline]
84 #[must_use]
85 pub fn vertical_ratio(&self) -> Option<&str> {
86 self.vertical_ratio.value()
87 }
88
89 #[inline]
90 #[must_use]
91 #[deprecated(since = "3.0.0", note = "Use vertical_ratio()")]
92 pub fn get_vertical_ratio(&self) -> Option<&str> {
93 self.vertical_ratio()
94 }
95
96 #[inline]
97 pub fn set_vertical_ratio<S: Into<String>>(&mut self, value: S) -> &mut Self {
98 self.vertical_ratio.set_value(value);
99 self
100 }
101
102 #[inline]
103 #[must_use]
104 pub fn alignment(&self) -> Option<&str> {
105 self.alignment.value()
106 }
107
108 #[inline]
109 #[must_use]
110 #[deprecated(since = "3.0.0", note = "Use alignment()")]
111 pub fn get_alignment(&self) -> Option<&str> {
112 self.alignment()
113 }
114
115 #[inline]
116 pub fn set_alignment<S: Into<String>>(&mut self, value: S) -> &mut Self {
117 self.alignment.set_value(value);
118 self
119 }
120
121 #[inline]
122 #[must_use]
123 pub fn direction(&self) -> Option<&str> {
124 self.direction.value()
125 }
126
127 #[inline]
128 #[must_use]
129 #[deprecated(since = "3.0.0", note = "Use direction()")]
130 pub fn get_direction(&self) -> Option<&str> {
131 self.direction()
132 }
133
134 #[inline]
135 pub fn set_direction<S: Into<String>>(&mut self, value: S) -> &mut Self {
136 self.direction.set_value(value);
137 self
138 }
139
140 #[inline]
141 #[must_use]
142 pub fn distance(&self) -> Option<&str> {
143 self.distance.value()
144 }
145
146 #[inline]
147 #[must_use]
148 #[deprecated(since = "3.0.0", note = "Use distance()")]
149 pub fn get_distance(&self) -> Option<&str> {
150 self.distance()
151 }
152
153 #[inline]
154 pub fn set_distance<S: Into<String>>(&mut self, value: S) -> &mut Self {
155 self.distance.set_value(value);
156 self
157 }
158
159 #[must_use]
160 pub fn rotate_with_shape(&self) -> Option<&str> {
161 self.rotate_with_shape.value()
162 }
163
164 #[must_use]
165 #[deprecated(since = "3.0.0", note = "Use rotate_with_shape()")]
166 pub fn get_rotate_with_shape(&self) -> Option<&str> {
167 self.rotate_with_shape()
168 }
169
170 #[inline]
171 pub fn set_rotate_with_shape<S: Into<String>>(&mut self, value: S) -> &mut Self {
172 self.rotate_with_shape.set_value(value);
173 self
174 }
175
176 #[inline]
177 #[must_use]
178 pub fn preset_color(&self) -> Option<&PresetColor> {
179 self.preset_color.as_deref()
180 }
181
182 #[inline]
183 #[must_use]
184 #[deprecated(since = "3.0.0", note = "Use preset_color()")]
185 pub fn get_preset_color(&self) -> Option<&PresetColor> {
186 self.preset_color()
187 }
188
189 #[inline]
190 pub fn preset_color_mut(&mut self) -> Option<&mut PresetColor> {
191 self.preset_color.as_deref_mut()
192 }
193
194 #[inline]
195 #[deprecated(since = "3.0.0", note = "Use preset_color_mut()")]
196 pub fn get_preset_color_mut(&mut self) -> Option<&mut PresetColor> {
197 self.preset_color_mut()
198 }
199
200 #[inline]
201 pub fn set_preset_color(&mut self, value: PresetColor) -> &mut Self {
202 self.preset_color = Some(Box::new(value));
203 self
204 }
205
206 #[inline]
207 #[must_use]
208 pub fn scheme_color(&self) -> Option<&SchemeColor> {
209 self.scheme_color.as_deref()
210 }
211
212 #[inline]
213 #[must_use]
214 #[deprecated(since = "3.0.0", note = "Use scheme_color()")]
215 pub fn get_scheme_color(&self) -> Option<&SchemeColor> {
216 self.scheme_color()
217 }
218
219 #[inline]
220 pub fn scheme_color_mut(&mut self) -> Option<&mut SchemeColor> {
221 self.scheme_color.as_deref_mut()
222 }
223
224 #[inline]
225 #[deprecated(since = "3.0.0", note = "Use scheme_color_mut()")]
226 pub fn get_scheme_color_mut(&mut self) -> Option<&mut SchemeColor> {
227 self.scheme_color_mut()
228 }
229
230 #[inline]
231 pub fn set_scheme_color(&mut self, value: SchemeColor) -> &mut Self {
232 self.scheme_color = Some(Box::new(value));
233 self
234 }
235
236 #[inline]
237 #[must_use]
238 pub fn rgb_color_model_hex(&self) -> Option<&RgbColorModelHex> {
239 self.rgb_color_model_hex.as_deref()
240 }
241
242 #[inline]
243 #[must_use]
244 #[deprecated(since = "3.0.0", note = "Use rgb_color_model_hex()")]
245 pub fn get_rgb_color_model_hex(&self) -> Option<&RgbColorModelHex> {
246 self.rgb_color_model_hex()
247 }
248
249 #[inline]
250 pub fn rgb_color_model_hex_mut(&mut self) -> Option<&mut RgbColorModelHex> {
251 self.rgb_color_model_hex.as_deref_mut()
252 }
253
254 #[inline]
255 #[deprecated(since = "3.0.0", note = "Use rgb_color_model_hex_mut()")]
256 pub fn get_rgb_color_model_hex_mut(&mut self) -> Option<&mut RgbColorModelHex> {
257 self.rgb_color_model_hex_mut()
258 }
259
260 #[inline]
261 pub fn set_rgb_color_model_hex(&mut self, value: RgbColorModelHex) -> &mut Self {
262 self.rgb_color_model_hex = Some(Box::new(value));
263 self
264 }
265
266 pub(crate) fn set_attributes<R: std::io::BufRead>(
267 &mut self,
268 reader: &mut Reader<R>,
269 e: &BytesStart,
270 ) {
271 if let Some(v) = get_attribute(e, b"blurRad") {
272 self.set_blur_radius(v);
273 }
274 if let Some(v) = get_attribute(e, b"dist") {
275 self.set_distance(v);
276 }
277 if let Some(v) = get_attribute(e, b"dir") {
278 self.set_direction(v);
279 }
280 if let Some(v) = get_attribute(e, b"sx") {
281 self.set_horizontal_ratio(v);
282 }
283 if let Some(v) = get_attribute(e, b"sy") {
284 self.set_vertical_ratio(v);
285 }
286 if let Some(v) = get_attribute(e, b"algn") {
287 self.set_alignment(v);
288 }
289 if let Some(v) = get_attribute(e, b"rotWithShape") {
290 self.set_rotate_with_shape(v);
291 }
292
293 xml_read_loop!(
294 reader,
295 ref n @ (Event::Empty(ref e) | Event::Start(ref e)) => {
296 let is_empty = matches!(n, Event::Empty(_));
297 match e.name().into_inner() {
298 b"a:prstClr" => {
299 let mut obj = PresetColor::default();
300 obj.set_attributes(reader, e);
301 self.set_preset_color(obj);
302 }
303 b"a:schemeClr" => {
304 let mut obj = SchemeColor::default();
305 obj.set_attributes(reader, e, is_empty);
306 self.set_scheme_color(obj);
307 }
308 b"a:srgbClr" => {
309 let mut obj = RgbColorModelHex::default();
310 obj.set_attributes(reader, e, is_empty);
311 self.set_rgb_color_model_hex(obj);
312 }
313 _ => (),
314 }
315 },
316 Event::End(ref e) => {
317 if e.name().into_inner() == b"a:outerShdw" {
318 return
319 }
320 },
321 Event::Eof => panic!("Error: Could not find {} end element", "a:outerShdw")
322 );
323 }
324
325 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
326 let mut attributes: crate::structs::AttrCollection = Vec::new();
328 if let Some(v) = self.blur_radius.value() {
329 attributes.push(("blurRad", v).into());
330 }
331 if let Some(v) = self.distance.value() {
332 attributes.push(("dist", v).into());
333 }
334 if let Some(v) = self.direction.value() {
335 attributes.push(("dir", v).into());
336 }
337 if let Some(v) = self.horizontal_ratio.value() {
338 attributes.push(("sx", v).into());
339 }
340 if let Some(v) = self.vertical_ratio.value() {
341 attributes.push(("sy", v).into());
342 }
343 if let Some(v) = self.alignment.value() {
344 attributes.push(("algn", v).into());
345 }
346 if let Some(v) = self.rotate_with_shape.value() {
347 attributes.push(("rotWithShape", v).into());
348 }
349 write_start_tag(writer, "a:outerShdw", attributes, false);
350
351 if let Some(v) = &self.preset_color {
353 v.write_to(writer);
354 }
355
356 if let Some(v) = &self.scheme_color {
358 v.write_to(writer);
359 }
360
361 if let Some(v) = &self.rgb_color_model_hex {
363 v.write_to(writer);
364 }
365
366 write_end_tag(writer, "a:outerShdw");
367 }
368}