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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use anyhow::bail;
use quick_xml::events::BytesStart;
use crate::{
helper::{string_to_bool, string_to_int, string_to_unsignedint},
raw::drawing::st_types::{
STAngle, STPercentage, STPositiveAngle, STPositiveCoordinate, STPositivePercentage,
},
};
/// reflection (Reflection Effect)
///
/// This element specifies a reflection effect.
///
/// Example:
/// ```
/// <a:reflection blurRad="151308" stA="88815" endPos="65000" dist="402621"dir="5400000" sy="-100000" algn="bl" rotWithShape="0" />
/// ```
///
/// https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.drawing.reflection?view=openxml-3.0.1
#[derive(Debug, Clone, PartialEq)]
pub struct XlsxReflection {
/// attributes
/// Specifies shadow alignment; alignment happens first, effectively setting the origin for scale, skew, and offset.
/// Allowed values: https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.drawing.rectanglealignmentvalues?view=openxml-3.0.1
pub algn: Option<String>,
/// Specifies the blur radius
// tag: blurRad
pub blur_rad: Option<STPositiveCoordinate>,
/// Specifies the direction to offset the shadow as angle
pub dir: Option<STPositiveAngle>,
/// Specifies how far to offset the shadow
pub dist: Option<STPositiveCoordinate>,
/// Specifies the ending reflection opacity.
// endA (End Alpha)
pub end_a: Option<STPositivePercentage>,
/// Specifies the end position (along the alpha gradient ramp) of the end alpha value.
// endPos (End Position)
pub end_pos: Option<STPositivePercentage>,
///Specifies the direction to offset the reflection.
// fadeDir (Fade Direction)
pub fade_dir: Option<STPositiveAngle>,
/// Specifies the horizontal skew angle
pub kx: Option<STAngle>,
/// Specifies the vertical skew angle
pub ky: Option<STAngle>,
/// Specifies whether the shadow rotates with the shape if the shape is rotated
// tag: rotWithShape
pub rot_with_shape: Option<bool>,
/// starting reflection opacity.
// stA (Start Opacity)
pub st_a: Option<STPositivePercentage>,
/// Specifies the start position (along the alpha gradient ramp) of the start alpha value.
// stPos (Start Position)
pub st_pos: Option<STPositivePercentage>,
/// Specifies the horizontal scaling factor; negative scaling causes a flip.
pub sx: Option<STPercentage>,
/// Specifies the vertical scaling factor; negative scaling causes a flip.
pub sy: Option<STPercentage>,
}
impl XlsxReflection {
pub(crate) fn load(e: &BytesStart) -> anyhow::Result<Self> {
let attributes = e.attributes();
let mut reflection = Self {
algn: None,
blur_rad: None,
dir: None,
dist: None,
end_a: None,
end_pos: None,
fade_dir: None,
kx: None,
ky: None,
rot_with_shape: None,
st_a: None,
st_pos: None,
sx: None,
sy: 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"algn" => {
reflection.algn = Some(string_value);
}
b"blurRad" => {
reflection.blur_rad = string_to_unsignedint(&string_value);
}
b"dir" => {
reflection.dir = string_to_unsignedint(&string_value);
}
b"dist" => {
reflection.dist = string_to_unsignedint(&string_value);
}
b"endA" => {
reflection.end_a = string_to_unsignedint(&string_value);
}
b"endPos" => {
reflection.end_pos = string_to_unsignedint(&string_value);
}
b"fadeDir" => {
reflection.fade_dir = string_to_unsignedint(&string_value);
}
b"kx" => {
reflection.kx = string_to_int(&string_value);
}
b"ky" => {
reflection.ky = string_to_int(&string_value);
}
b"rotWithShape" => {
reflection.rot_with_shape = string_to_bool(&string_value);
}
b"stA" => {
reflection.st_a = string_to_unsignedint(&string_value);
}
b"stPos" => {
reflection.st_pos = string_to_unsignedint(&string_value);
}
b"sx" => {
reflection.sx = string_to_int(&string_value);
}
b"sy" => {
reflection.sy = string_to_int(&string_value);
}
_ => {}
}
}
Err(error) => {
bail!(error.to_string())
}
}
}
Ok(reflection)
}
}