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 Event::Empty(ref e) => {
296 match e.name().into_inner() {
297 b"a:schemeClr" => {
298 let mut obj = SchemeColor::default();
299 obj.set_attributes(reader, e, true);
300 self.set_scheme_color(obj);
301 }
302 b"a:srgbClr" => {
303 let mut obj = RgbColorModelHex::default();
304 obj.set_attributes(reader, e, true);
305 self.set_rgb_color_model_hex(obj);
306 }
307 _ => (),
308 }
309 },
310 Event::Start(ref e) => {
311 match e.name().into_inner() {
312 b"a:prstClr" => {
313 let mut obj = PresetColor::default();
314 obj.set_attributes(reader, e);
315 self.set_preset_color(obj);
316 }
317 b"a:schemeClr" => {
318 let mut obj = SchemeColor::default();
319 obj.set_attributes(reader, e, false);
320 self.set_scheme_color(obj);
321 }
322 b"a:srgbClr" => {
323 let mut obj = RgbColorModelHex::default();
324 obj.set_attributes(reader, e, false);
325 self.set_rgb_color_model_hex(obj);
326 }
327 _ => (),
328 }
329 },
330 Event::End(ref e) => {
331 if e.name().into_inner() == b"a:outerShdw" {
332 return
333 }
334 },
335 Event::Eof => panic!("Error: Could not find {} end element", "a:outerShdw")
336 );
337 }
338
339 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
340 let mut attributes: crate::structs::AttrCollection = Vec::new();
342 if let Some(v) = self.blur_radius.value() {
343 attributes.push(("blurRad", v).into());
344 }
345 if let Some(v) = self.distance.value() {
346 attributes.push(("dist", v).into());
347 }
348 if let Some(v) = self.direction.value() {
349 attributes.push(("dir", v).into());
350 }
351 if let Some(v) = self.horizontal_ratio.value() {
352 attributes.push(("sx", v).into());
353 }
354 if let Some(v) = self.vertical_ratio.value() {
355 attributes.push(("sy", v).into());
356 }
357 if let Some(v) = self.alignment.value() {
358 attributes.push(("algn", v).into());
359 }
360 if let Some(v) = self.rotate_with_shape.value() {
361 attributes.push(("rotWithShape", v).into());
362 }
363 write_start_tag(writer, "a:outerShdw", attributes, false);
364
365 if let Some(v) = &self.preset_color {
367 v.write_to(writer);
368 }
369
370 if let Some(v) = &self.scheme_color {
372 v.write_to(writer);
373 }
374
375 if let Some(v) = &self.rgb_color_model_hex {
377 v.write_to(writer);
378 }
379
380 write_end_tag(writer, "a:outerShdw");
381 }
382}