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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
//! What the readers of DrawingML read in another way than the file asks.
use std::fmt;
use f_office_warnings::Name;
/// What a reader of DrawingML read in another way than the file asks, while it went on with the
/// rest. A warning names the element and the attribute by the names of the schema, or a
/// [`Feature`], never content of the file. The format crate that calls the reader adds the part.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Warning {
/// A value of an attribute that does not read as its type, such as a line width with a
/// fraction, or an attribute that the schema requires and that is missing, such as the name
/// of a preset geometry: the element and the attribute that hold it. The reader reads it as
/// missing.
InvalidValue {
/// The element that has the attribute.
element: Name,
/// The attribute.
attribute: Name,
},
/// An element whose children do not read as the schema gives them: it lacks a child that
/// the schema requires, such as a custom geometry (`a:custGeom`) without its path list, or
/// holds a child that the schema does not allow there, such as a child of a custom path
/// (`a:path`) other than its steps. The reader reads the element as missing.
InvalidChildren {
/// The element.
element: Name,
},
/// A name of an enumeration that F-Office draws as the case of another name, or as
/// nothing, such as a preset shape other than the few that it draws: the element, the
/// attribute and the name as the schema spells it. Its count is the count of the values
/// that F-Office does not draw.
ValueNotSupported {
/// The element that has the attribute.
element: Name,
/// The attribute.
attribute: Name,
/// The name.
value: Name,
},
/// A feature of DrawingML that F-Office does not draw, which it draws in another way or
/// leaves out, such as a pattern fill.
FeatureNotSupported {
/// The feature.
feature: Feature,
},
}
/// A feature of DrawingML that F-Office does not draw, which [`Warning::FeatureNotSupported`]
/// names. Each says what F-Office draws in its place.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Feature {
/// A picture fill (`a:blipFill`) of an area whose reader does not draw it, such as a
/// shape of a SmartArt graphic or a chart area: the area has no fill.
PictureFill,
/// A pattern fill (`a:pattFill`) of an area: the area has no fill.
PatternFill,
/// A group fill (`a:grpFill`) of an area: the area has no fill.
GroupFill,
/// A gradient fill (`a:gradFill`) of an area or a line: the color of its first stop.
GradientFill,
/// A picture, pattern or group fill of a line (`a:ln`): the color of the line that the
/// shape's style refers to, or no line.
LineFill,
/// A rotation of a shape or a picture that is not a whole number of quarter turns (`rot`
/// of `a:xfrm`): the shape or the picture is not drawn.
Turn,
/// A picture, or a picture fill of a shape, whose outline is not a rectangle: a rounded
/// rectangle, an ellipse, a line or a custom geometry. The picture fills its whole box.
ShapedPicture,
/// A line around a picture (`a:ln` of `pic:spPr` with a fill) that is dashed, compound or
/// not of one color: no line.
PictureLine,
/// A color effect of a picture (a child of `a:blip`) other than its transparency
/// (`a:alphaModFix`) and gray (`a:grayscl`), such as `a:lum`, `a:duotone`, `a:biLevel` or
/// `a:clrChange`: the picture keeps its own colors.
PictureEffect,
/// A color modifier other than `a:lumMod`, `a:lumOff`, `a:satMod`, `a:shade`, `a:tint`,
/// `a:gamma`, `a:invGamma` and `a:alpha`, such as `a:hueOff` or `a:gray`, with a value
/// that changes the color: the color without it.
ColorModifier,
/// A color in the HSL or the scRGB model (`a:hslClr`, `a:scrgbClr`): no color.
ColorModel,
/// A shadow of a shape or a picture (`a:outerShdw`, `a:innerShdw` or `a:prstShdw` in
/// `a:effectLst`): no shadow.
Shadow,
/// A glow of a shape or a picture (`a:glow`): no glow.
Glow,
/// Soft edges of a shape or a picture (`a:softEdge`): hard edges.
SoftEdge,
/// A reflection of a shape or a picture (`a:reflection`): no reflection.
Reflection,
/// Another effect of a shape or a picture: a blur (`a:blur`) or a fill overlay
/// (`a:fillOverlay`) in `a:effectLst`, or effects in a graph (`a:effectDag`). It is
/// left out.
OtherEffect,
/// A 3-D look of a shape or a picture: a camera of `a:scene3d` other than the flat view
/// from the front, or a bevel, an extrusion or a contour of `a:sp3d`. The shape is drawn
/// flat.
ThreeD,
/// A style of the theme's format scheme (`a:fmtScheme`) that a style reference of a
/// shape's style names (`a:fillRef`, `a:lnRef`, `a:effectRef`) and that the shape takes,
/// other than a solid fill or a single line of the reference's own color and no effect,
/// such as a gradient fill, a color modifier of the style, a double line or a shadow: the
/// shape takes the reference's color, and no effect.
ThemeStyle,
/// A dash of a line (`a:prstDash` other than `solid`, or `a:custDash`), its own or of the
/// line style of the theme that it takes: the line is drawn solid.
LineDash,
/// An end of a line whose outline can be open, a line or a custom geometry (`a:headEnd` or
/// `a:tailEnd` of a `type` other than `none`), such as an arrowhead, its own or of the line
/// style of the theme that it takes: the end is not drawn.
LineEnd,
/// A compound line of a shape's own line (`cmpd` of `a:ln` other than `sng`) on an outline
/// other than a straight line, such as a rectangle, an ellipse or a custom geometry: the
/// outline is drawn as one line of the full width.
CompoundOutline,
}
impl Feature {
/// Every feature, in the order of their declaration.
pub const ALL: [Self; 21] = [
Self::PictureFill,
Self::PatternFill,
Self::GroupFill,
Self::GradientFill,
Self::LineFill,
Self::Turn,
Self::ShapedPicture,
Self::PictureLine,
Self::PictureEffect,
Self::ColorModifier,
Self::ColorModel,
Self::Shadow,
Self::Glow,
Self::SoftEdge,
Self::Reflection,
Self::OtherEffect,
Self::ThreeD,
Self::ThemeStyle,
Self::LineDash,
Self::LineEnd,
Self::CompoundOutline,
];
/// The kind of the warning of the feature, as [`Warning::kind`] gives it.
#[must_use]
pub fn kind(self) -> &'static str {
match self {
Self::PictureFill => "drawingml-picture-fill-not-supported",
Self::PatternFill => "drawingml-pattern-fill-not-supported",
Self::GroupFill => "drawingml-group-fill-not-supported",
Self::GradientFill => "drawingml-gradient-fill-not-supported",
Self::LineFill => "drawingml-line-fill-not-supported",
Self::Turn => "drawingml-turn-not-supported",
Self::ShapedPicture => "drawingml-shaped-picture-not-supported",
Self::PictureLine => "drawingml-picture-line-not-supported",
Self::PictureEffect => "drawingml-picture-effect-not-supported",
Self::ColorModifier => "drawingml-color-modifier-not-supported",
Self::ColorModel => "drawingml-color-model-not-supported",
Self::Shadow => "drawingml-shadow-not-supported",
Self::Glow => "drawingml-glow-not-supported",
Self::SoftEdge => "drawingml-soft-edge-not-supported",
Self::Reflection => "drawingml-reflection-not-supported",
Self::OtherEffect => "drawingml-other-effect-not-supported",
Self::ThreeD => "drawingml-three-d-not-supported",
Self::ThemeStyle => "drawingml-theme-style-not-supported",
Self::LineDash => "drawingml-line-dash-not-supported",
Self::LineEnd => "drawingml-line-end-not-supported",
Self::CompoundOutline => "drawingml-compound-outline-not-supported",
}
}
}
impl fmt::Display for Feature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::PictureFill => "a picture fill is not supported here, and the area has no fill",
Self::PatternFill => "a pattern fill is not supported, and the area has no fill",
Self::GroupFill => "a group fill is not supported, and the area has no fill",
Self::GradientFill => {
"a gradient fill is not supported, and it takes the color of its first stop"
}
Self::LineFill => {
"a picture, pattern or group fill of a line is not supported, and the line takes \
the color of the shape's style or is not drawn"
}
Self::Turn => {
"a rotation other than a whole number of quarter turns is not supported, and \
the shape or picture is not drawn"
}
Self::ShapedPicture => {
"a picture in an outline other than a rectangle is not supported, and the \
picture fills its box"
}
Self::PictureLine => {
"a dashed, compound or shaded line around a picture is not supported, and is not \
drawn"
}
Self::PictureEffect => {
"a color effect of a picture other than its transparency or gray is not \
supported, and the picture keeps its own colors"
}
Self::ColorModifier => {
"a color modifier other than lumMod, lumOff, shade, tint and alpha is not \
supported, and the color is drawn without it"
}
Self::ColorModel => {
"a color in the HSL or scRGB model is not supported, and gives no color"
}
Self::Shadow => "a shadow is not supported, and is not drawn",
Self::Glow => "a glow is not supported, and is not drawn",
Self::SoftEdge => "a soft edge is not supported, and the edges are drawn hard",
Self::Reflection => "a reflection is not supported, and is not drawn",
Self::OtherEffect => {
"a blur, a fill overlay or a graph of effects is not supported, and is not \
drawn"
}
Self::ThreeD => "a 3-D look is not supported, and the shape is drawn flat",
Self::ThemeStyle => {
"a style of the theme other than a fill or a line of the reference's own color \
is not supported, and the shape takes only that color"
}
Self::LineDash => "a dash of a line is not supported, and the line is drawn solid",
Self::LineEnd => {
"an end of a line, such as an arrowhead, is not supported, and is not drawn"
}
Self::CompoundOutline => {
"a compound line on an outline other than a straight line is not supported, and \
the outline is drawn as one line of the full width"
}
})
}
}
impl Warning {
/// The warning's kind, a short name that stays the same across versions, for a caller
/// that counts warnings.
#[must_use]
pub fn kind(&self) -> &'static str {
match self {
Self::InvalidValue { .. } => "drawingml-invalid-value",
Self::InvalidChildren { .. } => "drawingml-invalid-children",
Self::ValueNotSupported { .. } => "drawingml-value-not-supported",
Self::FeatureNotSupported { feature } => feature.kind(),
}
}
}
impl fmt::Display for Warning {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidValue { element, attribute } => write!(
f,
"the value of attribute {attribute} of element {element} does not read and \
counts as missing"
),
Self::InvalidChildren { element } => write!(
f,
"the children of element {element} do not read as the schema gives them, and \
the element counts as missing"
),
Self::ValueNotSupported {
element,
attribute,
value,
} => write!(
f,
"the value {value} of attribute {attribute} of element {element} is drawn as \
another value or not at all"
),
Self::FeatureNotSupported { feature } => feature.fmt(f),
}
}
}
#[cfg(test)]
mod tests {
use std::collections::HashSet;
use super::{Feature, Warning};
/// The place of `feature` in `Feature::ALL`. The match has no wildcard, so a new feature does
/// not compile until it is named here with the next place, which `Feature::ALL` must hold.
const fn place_in_all(feature: Feature) -> usize {
match feature {
Feature::PictureFill => 0,
Feature::PatternFill => 1,
Feature::GroupFill => 2,
Feature::GradientFill => 3,
Feature::LineFill => 4,
Feature::Turn => 5,
Feature::ShapedPicture => 6,
Feature::PictureLine => 7,
Feature::PictureEffect => 8,
Feature::ColorModifier => 9,
Feature::ColorModel => 10,
Feature::Shadow => 11,
Feature::Glow => 12,
Feature::SoftEdge => 13,
Feature::Reflection => 14,
Feature::OtherEffect => 15,
Feature::ThreeD => 16,
Feature::ThemeStyle => 17,
Feature::LineDash => 18,
Feature::LineEnd => 19,
Feature::CompoundOutline => 20,
}
}
#[test]
fn lists_each_feature_once_in_its_place() {
for (index, feature) in Feature::ALL.into_iter().enumerate() {
assert_eq!(place_in_all(feature), index, "{feature:?}");
}
}
#[test]
fn gives_each_feature_a_kind_of_its_own_and_says_what_is_drawn_in_its_place() {
let mut kinds = HashSet::new();
for feature in Feature::ALL {
let warning = Warning::FeatureNotSupported { feature };
let kind = warning.kind();
assert_eq!(kind, feature.kind());
assert!(
kind.starts_with("drawingml-") && kind.ends_with("-not-supported"),
"{kind}"
);
assert!(kinds.insert(kind), "{kind}");
let text = warning.to_string();
assert_eq!(text, feature.to_string());
assert!(text.contains(" is not supported"), "{text}");
}
assert_eq!(
Warning::FeatureNotSupported {
feature: Feature::PatternFill
}
.to_string(),
"a pattern fill is not supported, and the area has no fill"
);
}
}