f-office-drawingml 0.3.0

DrawingML shapes, pictures, fills, lines, themes and colors.
Documentation
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
//! What a theme gives shapes: its color scheme, the widths of its line styles, and which of
//! the styles of its format scheme hold what F-Office does not draw.

use f_office_paint::stroke::StrokeCap;
use f_office_units::Length;
use f_office_warnings::Warnings;
use f_office_xml::{Document, NodeId};

use crate::color::{DrawColor, PlaceholderModifiers, SchemeColors};
use crate::dash::{LineDash, ReadDash, read_cap, read_dash};
use crate::effect::{OuterShadow, ThemeShadow};
use crate::gradient::{ShapeFillGradient, ThemeGradient};
use crate::line_end::{LineEnds, ReadEnds, read_ends};
use crate::{A, Feature, Warning, effect, emus_of};

/// The colors, fills, line widths, dashes, ends and outer shadows of a theme (`a:theme`) that
/// shapes refer to.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ShapeTheme {
    /// The color scheme.
    pub colors: SchemeColors,
    /// The placeholder-color modifiers of the first three fill styles (`a:fillStyleLst`) when
    /// solid `phClr` fills.
    fill_colors: [Option<PlaceholderModifiers>; 3],
    /// The drawable linear gradient fills of the first three fill styles (`a:fillStyleLst`).
    fill_gradients: [Option<ThemeGradient>; 3],
    /// The placeholder-color modifiers of the first three background fill styles
    /// (`a:bgFillStyleLst`) when solid `phClr` fills.
    bg_fill_colors: [Option<PlaceholderModifiers>; 3],
    /// The drawable linear gradient fills of the first three background fill styles
    /// (`a:bgFillStyleLst`).
    bg_fill_gradients: [Option<ThemeGradient>; 3],
    /// The widths of the first three line styles of the format scheme (`a:lnStyleLst`).
    line_widths: [Option<Length>; 3],
    /// The modifiers of the placeholder color of each of the first three line styles, `None`
    /// for a style whose line is not single or whose fill is not a solid placeholder color
    /// with modifiers that F-Office applies ([`PlaceholderModifiers::read`]).
    line_colors: [Option<PlaceholderModifiers>; 3],
    /// The drawable dashes of the first three line styles (`a:lnStyleLst`).
    line_dashes: [Option<LineDash>; 3],
    /// The explicit end caps (`a:ln/@cap`) of the first three line styles (`a:lnStyleLst`).
    line_caps: [Option<StrokeCap>; 3],
    /// The drawable arrowheads of the first three line styles (`a:lnStyleLst`).
    line_ends: [Option<LineEnds>; 3],
    /// The drawable outer shadows of the first three effect styles (`a:effectStyleLst`).
    effect_shadows: [Option<ThemeShadow>; 3],
    /// Which of the first three styles of each list of the format scheme hold what F-Office
    /// does not draw.
    left_out: LeftOut,
}

/// A style reference of a shape's style, which names a style of a theme's format scheme
/// (`a:fmtScheme`) by its index, counting from 1, with the part of the style that the shape
/// takes.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum StyleReference {
    /// The style of `a:fillRef`: a fill style (`a:fillStyleLst`) for an index from 1 to 999,
    /// and a background fill style (`a:bgFillStyleLst`) from 1001, as 1001 names the first.
    Fill(usize),
    /// The fill and the compound line of the line style of `a:lnRef` (`a:lnStyleLst`).
    Line(usize),
    /// The dash of the line style of `a:lnRef`.
    LineDash(usize),
    /// The ends of the line style of `a:lnRef`.
    LineEnds(usize),
    /// The effect style of `a:effectRef` (`a:effectStyleLst`).
    Effect(usize),
}

/// The index of `a:fillRef` that names the first background fill style; the indices below it
/// name the fill styles.
const FIRST_BACKGROUND_FILL: usize = 1001;

/// Whether each of the first three styles of each list of a theme's format scheme holds what
/// F-Office does not draw where a style reference names it, as [`ShapeTheme::feature`] says.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
struct LeftOut {
    /// The fill styles (`a:fillStyleLst`).
    fills: [bool; 3],
    /// The background fill styles (`a:bgFillStyleLst`).
    background_fills: [bool; 3],
    /// The fills and the compound lines of the line styles (`a:lnStyleLst`).
    lines: [bool; 3],
    /// The dashes of the line styles.
    dashed_lines: [bool; 3],
    /// The ends of the line styles.
    ended_lines: [bool; 3],
    /// The effect styles (`a:effectStyleLst`).
    effects: [bool; 3],
}

impl ShapeTheme {
    /// Reads a theme part's root element. A line style's width or a color's name that does not
    /// read counts as missing, with a warning in `warnings`.
    #[must_use]
    pub fn read(doc: &Document, theme: NodeId, warnings: &mut Warnings<Warning>) -> Self {
        let elements = doc.child(theme, A, "themeElements");
        let colors = elements
            .and_then(|node| doc.child(node, A, "clrScheme"))
            .map_or_default(|scheme| SchemeColors::read(doc, scheme, warnings));
        let scheme = elements.and_then(|node| doc.child(node, A, "fmtScheme"));
        // The styles of the list `list`, each an element `style`, or each element for a list
        // of fills.
        let styles = |list: &str, style: Option<&str>| -> Vec<NodeId> {
            scheme
                .and_then(|node| doc.child(node, A, list))
                .map_or_default(|list| {
                    doc.child_elements(list)
                        .filter(|node| style.is_none_or(|name| doc.is(*node, A, name)))
                        .collect()
                })
        };
        let lines = styles("lnStyleLst", Some("ln"));
        let effect_styles = styles("effectStyleLst", Some("effectStyle"));
        let line_widths = [0, 1, 2].map(|index| {
            lines
                .get(index)
                .and_then(|node| emus_of(doc, *node, "w", warnings))
        });
        let line_colors = [0, 1, 2].map(|index| {
            let line = *lines.get(index)?;
            if !matches!(doc.attribute(line, None, "cmpd"), None | Some("sng")) {
                return None;
            }
            let fill = doc.child(line, A, "solidFill")?;
            PlaceholderModifiers::read(doc, fill, warnings)
        });
        let first_three = |styles: &[NodeId], left_out: fn(&Document, NodeId) -> bool| {
            [0, 1, 2].map(|index| styles.get(index).is_some_and(|node| left_out(doc, *node)))
        };
        let (fill_colors, fill_gradients, fills_left_out) =
            read_fill_styles(doc, &styles("fillStyleLst", None), warnings);
        let (bg_fill_colors, bg_fill_gradients, bg_fills_left_out) =
            read_fill_styles(doc, &styles("bgFillStyleLst", None), warnings);
        let lines_left_out = [0, 1, 2].map(|index| {
            lines.get(index).is_some() && line_colors.get(index).copied().flatten().is_none()
        });
        let parsed_effects = [0, 1, 2].map(|index| {
            effect_styles.get(index).map_or((None, false), |&node| {
                effect::effect_style(doc, node, warnings)
            })
        });
        let [(shadow0, left0), (shadow1, left1), (shadow2, left2)] = parsed_effects;
        let line_dashes = [0, 1, 2].map(|index| {
            let line = *lines.get(index)?;
            match read_dash(doc, line) {
                ReadDash::Dashed(dash) => Some(dash),
                ReadDash::Omitted | ReadDash::Solid | ReadDash::Unsupported => None,
            }
        });
        let line_caps = [0, 1, 2].map(|index| lines.get(index).and_then(|&n| read_cap(doc, n)));
        let line_ends = [0, 1, 2].map(|index| {
            let line = *lines.get(index)?;
            match read_ends(doc, line) {
                ReadEnds::Present(ends) if ends.any() => Some(ends),
                ReadEnds::Omitted | ReadEnds::Present(_) | ReadEnds::Unsupported => None,
            }
        });
        Self {
            colors,
            fill_colors,
            fill_gradients,
            bg_fill_colors,
            bg_fill_gradients,
            line_widths,
            line_colors,
            line_dashes,
            line_caps,
            line_ends,
            effect_shadows: [shadow0, shadow1, shadow2],
            left_out: LeftOut {
                fills: fills_left_out,
                background_fills: bg_fills_left_out,
                lines: lines_left_out,
                dashed_lines: first_three(&lines, |doc, line| {
                    read_dash(doc, line) == ReadDash::Unsupported
                }),
                ended_lines: first_three(&lines, |doc, line| {
                    read_ends(doc, line) == ReadEnds::Unsupported
                }),
                effects: [left0, left1, left2],
            },
        }
    }

    /// Applies the placeholder-color modifiers of the solid fill style named by `a:fillRef`
    /// `index` (1–3 for `a:fillStyleLst`, 1001–1003 for `a:bgFillStyleLst`) to `color`, returning
    /// `color` unchanged when the slot is absent or not a solid `phClr` style.
    pub(crate) fn fill_color(&self, index: usize, color: DrawColor) -> DrawColor {
        let placeholder = if let Some(background) = index.checked_sub(FIRST_BACKGROUND_FILL - 1) {
            background
                .checked_sub(1)
                .and_then(|slot| self.bg_fill_colors.get(slot))
                .copied()
                .flatten()
        } else {
            index
                .checked_sub(1)
                .and_then(|slot| self.fill_colors.get(slot))
                .copied()
                .flatten()
        };
        match placeholder {
            Some(modifiers) => color.in_place_of(modifiers),
            None => color,
        }
    }

    /// Applies the placeholder-color modifiers of the line style named by `a:lnRef` `index`
    /// (counting from 1) to `color`, returning `color` unchanged when the slot is absent or not
    /// a drawable solid `phClr` line style.
    pub(crate) fn line_color(&self, index: usize, color: DrawColor) -> DrawColor {
        let placeholder = index
            .checked_sub(1)
            .and_then(|slot| self.line_colors.get(slot))
            .copied()
            .flatten();
        match placeholder {
            Some(modifiers) => color.in_place_of(modifiers),
            None => color,
        }
    }

    /// The theme fill gradient at `a:fillRef` `index` (1–3 for `a:fillStyleLst`, 1001–1003 for
    /// `a:bgFillStyleLst`), if that slot holds a drawable linear gradient.
    fn fill_gradient_slot(&self, index: usize) -> Option<&ThemeGradient> {
        if let Some(background) = index.checked_sub(FIRST_BACKGROUND_FILL - 1) {
            self.bg_fill_gradients
                .get(background.checked_sub(1)?)?
                .as_ref()
        } else {
            self.fill_gradients.get(index.checked_sub(1)?)?.as_ref()
        }
    }

    /// Whether the fill style named by `a:fillRef` `index` holds a drawable linear gradient.
    pub(crate) fn has_fill_gradient(&self, index: usize) -> bool {
        self.fill_gradient_slot(index).is_some()
    }

    /// Resolves the drawable gradient fill named by `a:fillRef` `index`, substituting `color`
    /// for `phClr` when the style uses the placeholder color.
    pub(crate) fn fill_gradient(
        &self,
        index: usize,
        color: Option<&DrawColor>,
    ) -> Option<ShapeFillGradient> {
        self.fill_gradient_slot(index)?.resolve(color)
    }

    /// The drawable dash of the line style at `index` (counting from 1).
    pub(crate) fn line_dash(&self, index: usize) -> Option<&LineDash> {
        let slot = index.checked_sub(1)?;
        self.line_dashes.get(slot)?.as_ref()
    }

    /// The explicit end cap of the line style at `index` (counting from 1).
    pub(crate) fn line_cap(&self, index: usize) -> Option<StrokeCap> {
        let slot = index.checked_sub(1)?;
        self.line_caps.get(slot).copied().flatten()
    }

    /// The drawable arrowheads of the line style at `index` (counting from 1).
    pub(crate) fn line_ends(&self, index: usize) -> Option<LineEnds> {
        let slot = index.checked_sub(1)?;
        self.line_ends.get(slot).copied().flatten()
    }

    /// Whether the effect style at `index` (counting from 1) holds a drawable outer shadow.
    pub(crate) fn has_effect_shadow(&self, index: usize) -> bool {
        index
            .checked_sub(1)
            .and_then(|slot| self.effect_shadows.get(slot))
            .is_some_and(Option::is_some)
    }

    /// The outer shadow of the effect style that `a:effectRef` with `index` (counting from 1)
    /// names, substituting `color` for `phClr` when the style uses the placeholder color.
    pub(crate) fn effect_shadow(
        &self,
        index: usize,
        color: Option<&DrawColor>,
    ) -> Option<OuterShadow> {
        let slot = index.checked_sub(1)?;
        self.effect_shadows.get(slot)?.as_ref()?.resolve(color)
    }

    /// The width of the line style that a style reference (`a:lnRef`) with this index names,
    /// counting from 1.
    #[must_use]
    pub fn line_width(&self, index: usize) -> Option<Length> {
        let index = index.checked_sub(1)?;
        self.line_widths.get(index).copied().flatten()
    }

    /// The color and the width of a line of the line style that a style reference with this
    /// index names, counting from 1, whose color `color` takes the place of the style's
    /// placeholder color: `color` with the placeholder's modifiers after its own, and the
    /// style's width. `None` when the scheme lacks the style or its width, or when the style's
    /// line is not single or its fill not a solid placeholder color with modifiers that
    /// F-Office applies.
    #[must_use]
    pub fn line_style(&self, index: usize, color: DrawColor) -> Option<(DrawColor, Length)> {
        let slot = index.checked_sub(1)?;
        let placeholder = self.line_colors.get(slot).copied().flatten()?;
        Some((color.in_place_of(placeholder), self.line_width(index)?))
    }

    /// The feature that F-Office does not draw in the part of the style that `reference` names,
    /// where a shape takes it: [`Feature::ThemeStyle`] for a fill style other than a solid
    /// placeholder fill with supported modifiers or a drawable linear gradient, a line style
    /// whose fill is another or whose line is not single, or an effect style with an unsupported
    /// effect or a 3-D look; [`Feature::LineDash`] and [`Feature::LineEnd`] for a line style's
    /// unsupported dash and ends. A style that the scheme lacks holds nothing.
    pub(crate) fn feature(&self, reference: StyleReference) -> Option<Feature> {
        let at = |list: &[bool; 3], index: usize| {
            index
                .checked_sub(1)
                .and_then(|index| list.get(index))
                .copied()
                .unwrap_or(false)
        };
        let LeftOut {
            fills,
            background_fills,
            lines,
            dashed_lines,
            ended_lines,
            effects,
        } = &self.left_out;
        let (left_out, feature) = match reference {
            StyleReference::Fill(index) => match index.checked_sub(FIRST_BACKGROUND_FILL - 1) {
                Some(background) => (at(background_fills, background), Feature::ThemeStyle),
                None => (at(fills, index), Feature::ThemeStyle),
            },
            StyleReference::Line(index) => (at(lines, index), Feature::ThemeStyle),
            StyleReference::LineDash(index) => (at(dashed_lines, index), Feature::LineDash),
            StyleReference::LineEnds(index) => (at(ended_lines, index), Feature::LineEnd),
            StyleReference::Effect(index) => (at(effects, index), Feature::ThemeStyle),
        };
        left_out.then_some(feature)
    }
}

/// Reads the first three fill styles of `list` (`a:fillStyleLst` or `a:bgFillStyleLst`): any
/// solid `phClr` modifiers, any drawable linear gradient per slot, and whether each slot holds
/// an unsupported fill style.
fn read_fill_styles(
    doc: &Document,
    list: &[NodeId],
    warnings: &mut Warnings<Warning>,
) -> (
    [Option<PlaceholderModifiers>; 3],
    [Option<ThemeGradient>; 3],
    [bool; 3],
) {
    let mut parse_one = |index: usize| {
        let Some(&node) = list.get(index) else {
            return (None, None, false);
        };
        if let Some(modifiers) = PlaceholderModifiers::read(doc, node, warnings) {
            return (Some(modifiers), None, false);
        }
        match ThemeGradient::read(doc, node) {
            Some(gradient) => (None, Some(gradient), false),
            None => (None, None, true),
        }
    };
    let [(c0, g0, l0), (c1, g1, l1), (c2, g2, l2)] = [0, 1, 2].map(&mut parse_one);
    ([c0, c1, c2], [g0, g1, g2], [l0, l1, l2])
}

#[cfg(test)]
mod tests {
    use super::{ShapeTheme, StyleReference};
    use crate::{A, Feature};
    use f_office_units::Length;
    use f_office_warnings::Warnings;
    use f_office_xml::{Document, Limits};

    #[test]
    fn reads_the_colors_and_line_widths_and_warns_of_a_width_that_does_not_read() {
        let xml = format!(
            r#"<a:theme xmlns:a="{A}"><a:themeElements><a:clrScheme><a:accent1><a:srgbClr val="4472C4"/></a:accent1></a:clrScheme><a:fmtScheme><a:lnStyleLst><a:ln w="6350"/><a:ln w="1pt"/><a:ln w="19050 "/></a:lnStyleLst></a:fmtScheme></a:themeElements></a:theme>"#
        );
        let doc = Document::parse(xml.as_bytes(), &Limits::default()).unwrap();
        let mut warnings = Warnings::new();
        let theme = ShapeTheme::read(&doc, doc.root().unwrap(), &mut warnings);
        assert_eq!(theme.line_width(1), Length::from_emus(6_350));
        assert_eq!(theme.line_width(2), Length::from_emus(12_700));
        assert_eq!(theme.line_width(3), None);
        let kinds: Vec<_> = warnings.iter().map(|(w, n)| (w.kind(), n)).collect();
        assert_eq!(kinds, [("drawingml-invalid-value", 1)]);
        assert_eq!((theme.line_width(0), theme.line_width(4)), (None, None));
        assert_ne!(theme.colors, ShapeTheme::default().colors);
    }

    #[test]
    fn says_which_styles_of_the_format_scheme_hold_what_it_does_not_draw() {
        let plain = r#"<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>"#;
        let scheme = [
            format!(
                r#"<a:fillStyleLst>{plain}<a:gradFill/><a:solidFill><a:schemeClr val="phClr"><a:hueMod val="50000"/></a:schemeClr></a:solidFill></a:fillStyleLst>"#
            ),
            format!(
                r#"<a:lnStyleLst><a:ln w="6350" cmpd="sng">{plain}<a:prstDash val="dash"/></a:ln><a:ln cmpd="dbl">{plain}<a:tailEnd type="triangle"/></a:ln><a:ln><a:noFill/><a:prstDash val="solid"/><a:headEnd type="none"/></a:ln></a:lnStyleLst>"#
            ),
            "<a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw/></a:effectLst></a:effectStyle></a:effectStyleLst>".to_owned(),
            format!(
                r#"<a:bgFillStyleLst><a:solidFill><a:srgbClr val="FFFFFF"/></a:solidFill>{plain}</a:bgFillStyleLst>"#
            ),
        ]
        .concat();
        let xml = format!(
            r#"<a:theme xmlns:a="{A}"><a:themeElements><a:fmtScheme>{scheme}</a:fmtScheme></a:themeElements></a:theme>"#
        );
        let doc = Document::parse(xml.as_bytes(), &Limits::default()).unwrap();
        let theme = ShapeTheme::read(&doc, doc.root().unwrap(), &mut Warnings::new());
        let style = Some(Feature::ThemeStyle);
        let cases = [
            (StyleReference::Fill(0), None),
            (StyleReference::Fill(1), None),
            (StyleReference::Fill(2), style),
            (StyleReference::Fill(3), style),
            (StyleReference::Fill(4), None),
            (StyleReference::Fill(1000), None),
            (StyleReference::Fill(1001), style),
            (StyleReference::Fill(1002), None),
            // Supported preset dashes are drawn without warning; only unsupported dashes warn.
            (StyleReference::Line(1), None),
            (StyleReference::LineDash(1), None),
            (StyleReference::LineEnds(1), None),
            (StyleReference::Line(2), style),
            (StyleReference::LineDash(2), None),
            (StyleReference::LineEnds(2), None),
            (StyleReference::Line(3), style),
            (StyleReference::LineDash(3), None),
            (StyleReference::LineEnds(3), None),
            (StyleReference::Effect(1), None),
            (StyleReference::Effect(2), style),
            (StyleReference::Effect(3), None),
        ];
        for (reference, feature) in cases {
            assert_eq!(theme.feature(reference), feature, "{reference:?}");
            assert_eq!(ShapeTheme::default().feature(reference), None);
        }
        assert!(theme.line_dash(1).is_some());
        assert!(theme.line_dash(2).is_none());
        assert!(theme.line_ends(2).is_some_and(super::LineEnds::any));
        assert!(theme.line_ends(1).is_none());
    }

    #[test]
    fn gives_a_line_style_with_the_modifiers_of_its_placeholder_after_the_color() {
        use crate::color::{DrawColor, SchemeSlot};
        let fill = |modifiers: &str| {
            format!(
                r#"<a:solidFill><a:schemeClr val="phClr">{modifiers}</a:schemeClr></a:solidFill>"#
            )
        };
        let lines = [
            format!(
                r#"<a:ln w="9525">{}</a:ln>"#,
                fill(r#"<a:shade val="95000"/><a:satMod val="105000"/>"#)
            ),
            format!(r#"<a:ln w="25400">{}</a:ln>"#, fill("")),
            format!(
                r#"<a:ln w="38100">{}</a:ln>"#,
                fill(r#"<a:hueMod val="50000"/>"#)
            ),
        ]
        .concat();
        let xml = format!(
            r#"<a:theme xmlns:a="{A}"><a:themeElements><a:clrScheme><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1></a:clrScheme><a:fmtScheme><a:lnStyleLst>{lines}</a:lnStyleLst></a:fmtScheme></a:themeElements></a:theme>"#
        );
        let doc = Document::parse(xml.as_bytes(), &Limits::default()).unwrap();
        let theme = ShapeTheme::read(&doc, doc.root().unwrap(), &mut Warnings::new());
        let text = || DrawColor::scheme(SchemeSlot::Dark1).tinted(75_000);
        let drawn = |index| {
            theme.line_style(index, text()).map(|(color, width)| {
                let (rgb, _) = color.resolve(&theme.colors).unwrap();
                (format!("{:02X}{:02X}{:02X}", rgb.r, rgb.g, rgb.b), width)
            })
        };
        assert_eq!(
            drawn(1),
            Some(("868686".to_owned(), Length::from_emus(9_525).unwrap()))
        );
        assert_eq!(
            drawn(2),
            Some(("898989".to_owned(), Length::from_emus(25_400).unwrap()))
        );
        // A hue factor is a modifier that F-Office does not apply.
        assert_eq!(drawn(3), None);
        assert_eq!((drawn(0), drawn(4)), (None, None));
    }
}