1use std::fmt;
4
5use f_office_warnings::Name;
6
7#[derive(Clone, Debug, PartialEq, Eq, Hash)]
11#[non_exhaustive]
12pub enum Warning {
13 InvalidValue {
18 element: Name,
20 attribute: Name,
22 },
23 InvalidChildren {
28 element: Name,
30 },
31 ValueNotSupported {
36 element: Name,
38 attribute: Name,
40 value: Name,
42 },
43 FeatureNotSupported {
46 feature: Feature,
48 },
49}
50
51#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
54#[non_exhaustive]
55pub enum Feature {
56 PictureFill,
59 PatternFill,
61 GroupFill,
63 GradientFill,
65 LineFill,
68 Turn,
71 ShapedPicture,
74 PictureLine,
77 PictureEffect,
81 ColorModifier,
85 ColorModel,
87 Shadow,
90 Glow,
92 SoftEdge,
94 Reflection,
96 OtherEffect,
100 ThreeD,
104 ThemeStyle,
110 LineDash,
113 LineEnd,
117 CompoundOutline,
121}
122
123impl Feature {
124 pub const ALL: [Self; 21] = [
126 Self::PictureFill,
127 Self::PatternFill,
128 Self::GroupFill,
129 Self::GradientFill,
130 Self::LineFill,
131 Self::Turn,
132 Self::ShapedPicture,
133 Self::PictureLine,
134 Self::PictureEffect,
135 Self::ColorModifier,
136 Self::ColorModel,
137 Self::Shadow,
138 Self::Glow,
139 Self::SoftEdge,
140 Self::Reflection,
141 Self::OtherEffect,
142 Self::ThreeD,
143 Self::ThemeStyle,
144 Self::LineDash,
145 Self::LineEnd,
146 Self::CompoundOutline,
147 ];
148
149 #[must_use]
151 pub fn kind(self) -> &'static str {
152 match self {
153 Self::PictureFill => "drawingml-picture-fill-not-supported",
154 Self::PatternFill => "drawingml-pattern-fill-not-supported",
155 Self::GroupFill => "drawingml-group-fill-not-supported",
156 Self::GradientFill => "drawingml-gradient-fill-not-supported",
157 Self::LineFill => "drawingml-line-fill-not-supported",
158 Self::Turn => "drawingml-turn-not-supported",
159 Self::ShapedPicture => "drawingml-shaped-picture-not-supported",
160 Self::PictureLine => "drawingml-picture-line-not-supported",
161 Self::PictureEffect => "drawingml-picture-effect-not-supported",
162 Self::ColorModifier => "drawingml-color-modifier-not-supported",
163 Self::ColorModel => "drawingml-color-model-not-supported",
164 Self::Shadow => "drawingml-shadow-not-supported",
165 Self::Glow => "drawingml-glow-not-supported",
166 Self::SoftEdge => "drawingml-soft-edge-not-supported",
167 Self::Reflection => "drawingml-reflection-not-supported",
168 Self::OtherEffect => "drawingml-other-effect-not-supported",
169 Self::ThreeD => "drawingml-three-d-not-supported",
170 Self::ThemeStyle => "drawingml-theme-style-not-supported",
171 Self::LineDash => "drawingml-line-dash-not-supported",
172 Self::LineEnd => "drawingml-line-end-not-supported",
173 Self::CompoundOutline => "drawingml-compound-outline-not-supported",
174 }
175 }
176}
177
178impl fmt::Display for Feature {
179 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
180 f.write_str(match self {
181 Self::PictureFill => "a picture fill is not supported here, and the area has no fill",
182 Self::PatternFill => "a pattern fill is not supported, and the area has no fill",
183 Self::GroupFill => "a group fill is not supported, and the area has no fill",
184 Self::GradientFill => {
185 "a gradient fill is not supported, and it takes the color of its first stop"
186 }
187 Self::LineFill => {
188 "a picture, pattern or group fill of a line is not supported, and the line takes \
189 the color of the shape's style or is not drawn"
190 }
191 Self::Turn => {
192 "a rotation other than a whole number of quarter turns is not supported, and \
193 the shape or picture is not drawn"
194 }
195 Self::ShapedPicture => {
196 "a picture in an outline other than a rectangle is not supported, and the \
197 picture fills its box"
198 }
199 Self::PictureLine => {
200 "a dashed, compound or shaded line around a picture is not supported, and is not \
201 drawn"
202 }
203 Self::PictureEffect => {
204 "a color effect of a picture other than its transparency or gray is not \
205 supported, and the picture keeps its own colors"
206 }
207 Self::ColorModifier => {
208 "a color modifier other than lumMod, lumOff, shade, tint and alpha is not \
209 supported, and the color is drawn without it"
210 }
211 Self::ColorModel => {
212 "a color in the HSL or scRGB model is not supported, and gives no color"
213 }
214 Self::Shadow => "a shadow is not supported, and is not drawn",
215 Self::Glow => "a glow is not supported, and is not drawn",
216 Self::SoftEdge => "a soft edge is not supported, and the edges are drawn hard",
217 Self::Reflection => "a reflection is not supported, and is not drawn",
218 Self::OtherEffect => {
219 "a blur, a fill overlay or a graph of effects is not supported, and is not \
220 drawn"
221 }
222 Self::ThreeD => "a 3-D look is not supported, and the shape is drawn flat",
223 Self::ThemeStyle => {
224 "a style of the theme other than a fill or a line of the reference's own color \
225 is not supported, and the shape takes only that color"
226 }
227 Self::LineDash => "a dash of a line is not supported, and the line is drawn solid",
228 Self::LineEnd => {
229 "an end of a line, such as an arrowhead, is not supported, and is not drawn"
230 }
231 Self::CompoundOutline => {
232 "a compound line on an outline other than a straight line is not supported, and \
233 the outline is drawn as one line of the full width"
234 }
235 })
236 }
237}
238
239impl Warning {
240 #[must_use]
243 pub fn kind(&self) -> &'static str {
244 match self {
245 Self::InvalidValue { .. } => "drawingml-invalid-value",
246 Self::InvalidChildren { .. } => "drawingml-invalid-children",
247 Self::ValueNotSupported { .. } => "drawingml-value-not-supported",
248 Self::FeatureNotSupported { feature } => feature.kind(),
249 }
250 }
251}
252
253impl fmt::Display for Warning {
254 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
255 match self {
256 Self::InvalidValue { element, attribute } => write!(
257 f,
258 "the value of attribute {attribute} of element {element} does not read and \
259 counts as missing"
260 ),
261 Self::InvalidChildren { element } => write!(
262 f,
263 "the children of element {element} do not read as the schema gives them, and \
264 the element counts as missing"
265 ),
266 Self::ValueNotSupported {
267 element,
268 attribute,
269 value,
270 } => write!(
271 f,
272 "the value {value} of attribute {attribute} of element {element} is drawn as \
273 another value or not at all"
274 ),
275 Self::FeatureNotSupported { feature } => feature.fmt(f),
276 }
277 }
278}
279
280#[cfg(test)]
281mod tests {
282 use std::collections::HashSet;
283
284 use super::{Feature, Warning};
285
286 const fn place_in_all(feature: Feature) -> usize {
289 match feature {
290 Feature::PictureFill => 0,
291 Feature::PatternFill => 1,
292 Feature::GroupFill => 2,
293 Feature::GradientFill => 3,
294 Feature::LineFill => 4,
295 Feature::Turn => 5,
296 Feature::ShapedPicture => 6,
297 Feature::PictureLine => 7,
298 Feature::PictureEffect => 8,
299 Feature::ColorModifier => 9,
300 Feature::ColorModel => 10,
301 Feature::Shadow => 11,
302 Feature::Glow => 12,
303 Feature::SoftEdge => 13,
304 Feature::Reflection => 14,
305 Feature::OtherEffect => 15,
306 Feature::ThreeD => 16,
307 Feature::ThemeStyle => 17,
308 Feature::LineDash => 18,
309 Feature::LineEnd => 19,
310 Feature::CompoundOutline => 20,
311 }
312 }
313
314 #[test]
315 fn lists_each_feature_once_in_its_place() {
316 for (index, feature) in Feature::ALL.into_iter().enumerate() {
317 assert_eq!(place_in_all(feature), index, "{feature:?}");
318 }
319 }
320
321 #[test]
322 fn gives_each_feature_a_kind_of_its_own_and_says_what_is_drawn_in_its_place() {
323 let mut kinds = HashSet::new();
324 for feature in Feature::ALL {
325 let warning = Warning::FeatureNotSupported { feature };
326 let kind = warning.kind();
327 assert_eq!(kind, feature.kind());
328 assert!(
329 kind.starts_with("drawingml-") && kind.ends_with("-not-supported"),
330 "{kind}"
331 );
332 assert!(kinds.insert(kind), "{kind}");
333 let text = warning.to_string();
334 assert_eq!(text, feature.to_string());
335 assert!(text.contains(" is not supported"), "{text}");
336 }
337 assert_eq!(
338 Warning::FeatureNotSupported {
339 feature: Feature::PatternFill
340 }
341 .to_string(),
342 "a pattern fill is not supported, and the area has no fill"
343 );
344 }
345}