1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use anyhow::bail;
use quick_xml::events::BytesStart;
use std::io::Read;
use crate::excel::XmlReader;
use crate::{helper::string_to_int, raw::drawing::color::XlsxColorEnum};
/// prstShdw (Preset Shadow)
///
/// specifies that a preset shadow is to be used.
///
/// Each preset shadow is equivalent to a specific outer shadow effect.
/// For each preset shadow, the color element, direction attribute, and distance attribute represent the color, direction, and distance parameters of the corresponding outer shadow.
/// Additionally, the rotateWithShape attribute of corresponding outer shadow is always false. Other non-default parameters of the outer shadow are dependent on the prst attribute
///
/// Example:
/// ```
/// <a:prstShdw dir"90" dist="10" prst="shdw19">
/// <a:schemeClr val="phClr">
/// <a:lumMod val="99000" />
/// <a:satMod val="120000" />
/// a:shade val="78000" />
/// </a:schemeClr>
/// </a:prstShdw>
/// ```
///
/// https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.drawing.presetshadow?view=openxml-3.0.1
#[derive(Debug, Clone, PartialEq)]
pub struct XlsxPresetShadow {
// children
pub color: Option<XlsxColorEnum>,
// attribute
/// Specifies the direction to offset the shadow as angle
pub dir: Option<i64>,
/// Specifies how far to offset the shadow
pub dist: Option<i64>,
/// Specifies which preset shadow to use
/// allowed values: https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.drawing.presetshadowvalues?view=openxml-3.0.1
pub prst: Option<String>,
}
impl XlsxPresetShadow {
pub(crate) fn load(reader: &mut XmlReader<impl Read>, e: &BytesStart) -> anyhow::Result<Self> {
let attributes = e.attributes();
let mut shadow = Self {
color: None,
prst: None,
dir: None,
dist: None,
};
for a in attributes {
match a {
Ok(a) => {
let string_value = String::from_utf8(a.value.to_vec())?;
match a.key.local_name().as_ref() {
b"prst" => shadow.prst = Some(string_value),
b"dir" => {
shadow.dir = string_to_int(&string_value);
}
b"dist" => {
shadow.dist = string_to_int(&string_value);
}
_ => {}
}
}
Err(error) => {
bail!(error.to_string())
}
}
}
shadow.color = XlsxColorEnum::load(reader, b"prstShdw")?;
Ok(shadow)
}
}