f-office 0.2.4

Renders Office Open XML documents the way Microsoft Office does.
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
//! Public API of F-Office.
//!
//! F-Office renders Office Open XML documents the way Microsoft Office does, starting with
//! Word's DOCX format. This crate opens a file and lays it out into a display list, which
//! `f-office-raster` draws as pixels, or writes it as a PDF file. The other `f-office-*` crates
//! are internal and have no stability promise before 1.0.

use std::fmt;

pub mod edit;
mod export;
mod fidelity;
mod incremental;
mod pictures;
#[cfg(any(test, feature = "development"))]
pub mod suite;

pub use fidelity::{
    FidelityLevel, FidelityReport, FontMatchKind, FontStatus, MissingGlyphGroup, Omission,
    OmissionKind,
};
pub use incremental::{LayoutContinuation, LayoutProgress, PreparedDocument};

#[cfg(any(test, feature = "development"))]
use f_office_docx::PlacedLine;
use f_office_docx::TextMap;
use f_office_fonts::FontDb;
use f_office_opc::Package;

/// The configuration: the setup of Word's machine and the user's choice of fonts, and the types
/// of its keys.
pub use f_office_docx::configuration;
/// Why a target's ID names no target, or the configuration or the target's profile does not
/// read: the error of `Target::from_str` and of [`Error::Configuration`].
pub use f_office_docx::configuration::Error as ConfigurationError;
pub use f_office_docx::{
    ART_PICTURES_BYTE_LIMIT, ART_PICTURES_CLIP_DEPTH_LIMIT, ART_PICTURES_COMMAND_LIMIT,
    ART_PICTURES_REACH_LIMIT, ART_PICTURES_SHAPE_LIMIT, ART_PICTURES_SIZE_LIMIT, Address,
    AddressError, AddressStep, ArtPictures, ArtPicturesError, ArtPicturesFault, CellPlace,
    Configuration, DateTime, EndHyphen, LineTextEnd, LineTurn, LinkTarget, NumberSeparators,
    NumberSeparatorsError, StoryBookmark, StoryLink, StoryParagraph, Target, TextBlock,
    TextBlockKind, TextCluster, TextLine, TextStory,
};
pub use f_office_fonts::FontDb as FontDatabase;
pub use f_office_opc::{Limits, RandomAccessRead, XmlLimits};
pub use f_office_paint::{DisplayList, ImageFault, ImageFormat, Page};
pub use f_office_units::Length;
pub use f_office_warnings::Name;

/// The warnings of the DOCX layout, which [`Warning::Docx`] holds, and the types of their
/// fields.
pub mod docx {
    pub use f_office_docx::{
        ChartReason, Drawing, DrawingMlFeature, DrawingMlWarning, Feature, GroupTransform, Limit,
        MatchedFont, MetafileRecordType, MetafileWarning, NoteKind, ReadAs, Reason,
        SubstituteLayout, UnicodeBlock, ValuePlace, Warning,
    };
    pub use f_office_fonts::ShapeFailure;
}

/// The warnings of the PDF writer, which [`Warning::Pdf`] holds.
pub mod pdf {
    pub use f_office_pdf::Warning;
}

// A finished display list, and the document that holds
// it, stay `Send + Sync`.
const _: () = {
    const fn shared<T: Send + Sync>() {}
    shared::<DisplayList>();
    shared::<Document>();
};

/// Timing spans of the rendering stages: `open` (the package),
/// `docx` (reading the parts and the layout), `layout` (the layout passes inside `docx`) and
/// `pdf` (writing the PDF file), recorded on a thread that called [`timing::arm`].
#[cfg(feature = "timing")]
pub mod timing {
    pub use f_office_docx::timing::{arm, take};
}

/// Why a document could not be rendered.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
    /// The package could not be read.
    Package(f_office_opc::Error),
    /// The DOCX content could not be laid out.
    Docx(f_office_docx::Error),
    /// The pages could not be written as PDF.
    Pdf(f_office_pdf::Error),
    /// The configuration or the target's profile does not read.
    Configuration(ConfigurationError),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(match self {
            Self::Package(_) => "the package could not be read",
            Self::Docx(_) => "the DOCX content could not be laid out",
            Self::Pdf(_) => "the pages could not be written as PDF",
            Self::Configuration(_) => "the configuration or the target's profile does not read",
        })
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        Some(match self {
            Self::Package(error) => error,
            Self::Docx(error) => error,
            Self::Pdf(error) => error,
            Self::Configuration(error) => error,
        })
    }
}

/// What a rendering left out of the file, or drew in another way than the file asks, while it
/// went on with the rest. A warning holds no content of the document, only the names that the
/// file uses to point at a part or a font, cut and with printable characters only ([`Name`]).
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Warning {
    /// A warning of the DOCX layout.
    Docx(docx::Warning),
    /// A warning of the PDF writer.
    Pdf(pdf::Warning),
    /// A picture whose file the target's PDF writer writes again, such as each JPEG file at
    /// its quality, and that keeps its own file because its data does not decode.
    PictureNotWrittenAgain {
        /// The picture's format.
        format: ImageFormat,
    },
    /// An edit changed a package that holds a digital signature, which no longer matches the
    /// changed parts ([`edit::apply`]).
    SignatureBroken,
    /// A deleted block held the reference of a footnote or an endnote, whose note stays in its
    /// part ([`edit::apply`]).
    NoteKept,
}

impl Warning {
    /// The warning's kind, a short name that stays the same across versions and holds no name
    /// of the file, such as `font-substituted`, for a caller that counts warnings or writes them
    /// where the names of the file may not go.
    #[must_use]
    pub fn kind(&self) -> &'static str {
        match self {
            Self::Docx(warning) => warning.kind(),
            Self::Pdf(warning) => warning.kind(),
            Self::PictureNotWrittenAgain { .. } => "picture-not-written-again",
            Self::SignatureBroken => "signature-broken",
            Self::NoteKept => "note-kept",
        }
    }
}

impl fmt::Display for Warning {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Docx(warning) => warning.fmt(f),
            Self::Pdf(warning) => warning.fmt(f),
            Self::PictureNotWrittenAgain { format } => write!(
                f,
                "a picture in {format} format keeps its own file, which the target's PDF writer \
                 writes again: its data does not decode"
            ),
            Self::SignatureBroken => f.write_str(
                "the package holds a digital signature, which the edits break: sign the new file again",
            ),
            Self::NoteKept => f.write_str(
                "a deleted block held the reference of a footnote or an endnote, and the note stays in its part: delete it with a raw edit if it must go",
            ),
        }
    }
}

/// The warnings of a call, each distinct warning once with the number of times it came.
pub type Warnings = f_office_warnings::Warnings<Warning>;

/// The value of a call with its warnings.
pub type Warned<T> = f_office_warnings::Warned<T, Warning>;

/// The error chain of `error`: its own text, then the text of each cause that
/// [`source`](std::error::Error::source) gives, joined by `: `. Each error of F-Office writes only
/// its own text and gives its cause through `source`, so a place that shows an error to a person
/// writes this, so that the cause stays visible.
#[must_use]
pub fn error_chain(error: &dyn std::error::Error) -> String {
    let mut text = error.to_string();
    let mut cause = error.source();
    while let Some(next) = cause {
        text.push_str(": ");
        text.push_str(&next.to_string());
        cause = next.source();
    }
    text
}

/// Choices for opening a document that the document itself does not make. Start from
/// [`Options::default`] and set the fields that differ, so that a new field breaks no caller.
/// The default lays out for the default target with its defaults.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Options {
    /// The local date and time that `DATE` and `TIME` fields show, as Word shows the time of
    /// printing. Without it, they show the results stored in the file, so that the same file
    /// always gives the same pages.
    pub now: Option<DateTime>,
    /// The configuration of the pages: the target and the setup of Word's machine, such as the
    /// resolution of the printer that Word lays out for ([`Configuration::of`]).
    pub configuration: Configuration,
    /// The development override of the target profile's values, such as quirk variants,
    /// after the configuration.
    #[cfg(any(test, feature = "development"))]
    pub overrides: f_office_docx::profile::Overrides,
    /// The limits that protect the readers against a hostile file: those of the ZIP file and
    /// those of each XML part. A limit of the ZIP file that the file breaks stops the document
    /// ([`Error::Package`]), with an error that names the limit. An XML part that breaks a limit
    /// does not read, and the part policy decides: the main document part and the package's
    /// relationships stop the document ([`Error::Docx`]), and another part is skipped with a
    /// warning.
    pub limits: Limits,
}

impl Default for Options {
    fn default() -> Self {
        Self {
            now: None,
            configuration: Configuration::of(Target::default()),
            #[cfg(any(test, feature = "development"))]
            overrides: f_office_docx::profile::Overrides::default(),
            limits: Limits::default(),
        }
    }
}

impl Options {
    /// Options for the base target, used by internal layout unit tests written against the base
    /// profile.
    #[cfg(test)]
    pub(crate) fn base() -> Self {
        Self {
            configuration: Configuration::of(Target::base()),
            ..Self::default()
        }
    }

    /// The options of the layout: the same choices without the limits, which the package
    /// carries to every reader of its parts.
    fn layout(&self) -> f_office_docx::Options {
        let mut layout = f_office_docx::Options::default();
        layout.now = self.now;
        layout.configuration = self.configuration.clone();
        #[cfg(any(test, feature = "development"))]
        {
            layout.overrides = self.overrides.clone();
        }
        layout
    }
}

/// A DOCX file opened and laid out once for a target: its display list, which an output draws or
/// writes, the places of its lines, and the text blocks of its body. It holds no state of the
/// parse or the layout: what the layout left out or drew in another way comes out of
/// [`Document::open`] beside it.
#[derive(Clone, Debug)]
pub struct Document {
    list: DisplayList,
    #[cfg(any(test, feature = "development"))]
    lines: Vec<PlacedLine>,
    #[cfg(any(test, feature = "development"))]
    tables: Vec<f_office_docx::TableColumns>,
    text_blocks: Vec<TextBlock>,
    text_map: TextMap,
    fidelity: FidelityReport,
}

impl Document {
    /// Opens a DOCX file and lays it out into pages for the target of `options`, with the
    /// warnings of what it left out or drew in another way. The layout runs once, here.
    ///
    /// # Errors
    ///
    /// Returns an error when the file is not a readable DOCX package or its content cannot be
    /// laid out, or when the configuration or the target's profile does not read.
    pub fn open(docx: &[u8], fonts: &FontDb, options: &Options) -> Result<Warned<Self>, Error> {
        Self::open_with_art(docx, fonts, &ArtPictures::new(), options)
    }

    /// Opens a DOCX file as [`Document::open`] does, with the pictures of the art page borders
    /// `art`, which the caller adds beside the fonts ([`ArtPictures::add`]). A page border's side
    /// of an art style whose picture `art` lacks is not drawn, with a warning.
    ///
    /// # Errors
    ///
    /// As [`Document::open`].
    pub fn open_with_art(
        docx: &[u8],
        fonts: &FontDb,
        art: &ArtPictures,
        options: &Options,
    ) -> Result<Warned<Self>, Error> {
        Self::open_with((docx, fonts, art), &options.limits, &options.layout())
    }

    /// Opens a DOCX file from disk and lays it out into pages for the target of `options`,
    /// reading only the ZIP central directory and the parts needed for layout without loading
    /// the entire file into memory.
    ///
    /// # Errors
    ///
    /// Returns an error when the file cannot be opened as a DOCX package, its content cannot be
    /// laid out, or the configuration or target profile does not read.
    #[cfg(not(target_arch = "wasm32"))]
    pub fn open_file(
        path: &std::path::Path,
        fonts: &FontDb,
        options: &Options,
    ) -> Result<Warned<Self>, Error> {
        Self::open_file_with_art(path, fonts, &ArtPictures::new(), options)
    }

    /// Opens a DOCX file from disk as [`Document::open_file`] does, with art page-border
    /// pictures `art`.
    ///
    /// # Errors
    ///
    /// As [`Document::open_file`].
    #[cfg(not(target_arch = "wasm32"))]
    pub fn open_file_with_art(
        path: &std::path::Path,
        fonts: &FontDb,
        art: &ArtPictures,
        options: &Options,
    ) -> Result<Warned<Self>, Error> {
        let package =
            f_office_docx::timing::span("open", || Package::open_file(path, &options.limits))
                .map_err(Error::Package)?;
        Self::open_package((&package, fonts, art), &options.layout())
    }

    /// Opens a DOCX package from a caller-provided random-access byte source (such as a browser
    /// `File.slice()` or OPFS sync handle) without copying the whole archive into memory.
    ///
    /// # Errors
    ///
    /// As [`Document::open`].
    pub fn open_source(
        source: std::sync::Arc<dyn RandomAccessRead>,
        fonts: &FontDb,
        options: &Options,
    ) -> Result<Warned<Self>, Error> {
        Self::open_source_with_art(source, fonts, &ArtPictures::new(), options)
    }

    /// Opens a DOCX package from a random-access byte source as [`Document::open_source`] does,
    /// with art page-border pictures `art`.
    ///
    /// # Errors
    ///
    /// As [`Document::open`].
    pub fn open_source_with_art(
        source: std::sync::Arc<dyn RandomAccessRead>,
        fonts: &FontDb,
        art: &ArtPictures,
        options: &Options,
    ) -> Result<Warned<Self>, Error> {
        let package =
            f_office_docx::timing::span("open", || Package::open_source(source, &options.limits))
                .map_err(Error::Package)?;
        Self::open_package((&package, fonts, art), &options.layout())
    }

    /// Opens a DOCX file within `limits` with its fonts and art pictures, and lays it out with
    /// the layout's own options, as [`Document::open_with_art`] does.
    fn open_with(
        (docx, fonts, art): (&[u8], &FontDb, &ArtPictures),
        limits: &Limits,
        layout: &f_office_docx::Options,
    ) -> Result<Warned<Self>, Error> {
        let package = f_office_docx::timing::span("open", || Package::open(docx, limits))
            .map_err(Error::Package)?;
        Self::open_package((&package, fonts, art), layout)
    }

    /// Lays out an already-indexed OPC `package` with `fonts`, `art`, and `layout`.
    fn open_package(
        (package, fonts, art): (&Package, &FontDb, &ArtPictures),
        layout: &f_office_docx::Options,
    ) -> Result<Warned<Self>, Error> {
        let laid_out = f_office_docx::timing::span("docx", || {
            f_office_docx::layout_lines(package, (fonts, art), layout)
        })
        .map_err(|error| match error {
            f_office_docx::Error::Configuration(error) => Error::Configuration(error),
            error => Error::Docx(error),
        })?;
        let (doc, warnings) = incremental::finish_laid_out(laid_out);
        Ok(Warned::new(doc, warnings))
    }

    /// The display list of the pages, the only border between the layout and an output.
    #[must_use]
    pub fn display_list(&self) -> &DisplayList {
        &self.list
    }

    /// Typed rendering fidelity summary derived from layout font records and warnings.
    #[must_use]
    pub fn fidelity(&self) -> &FidelityReport {
        &self.fidelity
    }

    /// The pages in order: the pages of the display list ([`Document::display_list`]).
    #[must_use]
    pub fn pages(&self) -> &[Page] {
        self.list.pages()
    }

    /// The number of pages.
    #[must_use]
    pub fn page_count(&self) -> usize {
        self.pages().len()
    }

    /// The page at `index`, counted from 0, or none past the last page.
    #[must_use]
    pub fn page(&self, index: usize) -> Option<&Page> {
        self.pages().get(index)
    }

    /// The width and the height of the page at `index`, counted from 0, without drawing it, or
    /// none past the last page.
    #[must_use]
    pub fn page_size(&self, index: usize) -> Option<(Length, Length)> {
        self.page(index).map(|page| (page.width(), page.height()))
    }

    /// The paragraphs and tables of the body in the order of the document, each with its
    /// address, which counts from 1, its kind with its style and text, and the indices of the
    /// pages that its lines lie on, which count from 0 as [`Document::page`] does. The pages are
    /// those of this document's layout, so of the configuration that it was opened with
    /// ([`Options::configuration`]): the same file can give other pages for another target.
    /// The paragraphs of a table's cells follow the table. Headers, footers, notes and text
    /// boxes are not text blocks.
    #[must_use]
    pub fn text_blocks(&self) -> &[TextBlock] {
        &self.text_blocks
    }

    /// The text map of the page at `index`, counted from 0 (**Text map**): its lines in reading
    /// order, the header first, then the body, the endnotes, the frames, the text boxes, the
    /// footnotes and the footer.
    /// Each line names its story and its paragraph in [`Document::story_text`], with its range
    /// of the paragraph's text, its line box and its clusters in visual order with their edges
    /// on the page. It is empty past the last page.
    #[must_use]
    pub fn text_map(&self, index: usize) -> Vec<TextLine> {
        self.text_map.page(index)
    }

    /// The text maps of the pages at `indices`, each as [`Document::text_map`] gives it, from
    /// one read of each story on them: a viewer that needs many pages, such as for a search,
    /// reads the body once and not once for each page.
    #[must_use]
    pub fn text_maps(&self, indices: &[usize]) -> Vec<Vec<TextLine>> {
        self.text_map.pages(indices)
    }

    /// The text of `story` by paragraph (**Story text**): the texts of the paragraph's laid out
    /// lines joined, so that a field gives its shown result, a list label is given as drawn,
    /// hidden text is left out, and an automatic hyphen at a wrap is not in it.
    #[must_use]
    pub fn story_text(&self, story: TextStory) -> Vec<StoryParagraph> {
        self.text_map.story(story)
    }

    /// Writes the pages as a PDF file, with the fonts subset and embedded, and with the warnings
    /// of the PDF writer.
    ///
    /// Each page becomes one PDF page of the same size, with every glyph at its laid out position
    /// and with its text, so that a viewer can search and copy it. The same document and fonts
    /// always give the same bytes.
    ///
    /// # Errors
    ///
    /// Returns an error when the pages cannot be written as PDF.
    pub fn write_pdf(&self, fonts: &FontDb) -> Result<Warned<Vec<u8>>, Error> {
        let pdf = f_office_docx::timing::span("pdf", || f_office_pdf::write_pdf(&self.list, fonts))
            .map_err(Error::Pdf)?;
        Ok(Warned::new(pdf.value, pdf.warnings.map(Warning::Pdf)))
    }

    /// Streams the pages directly as a PDF 1.7 document into `writer` without buffering the
    /// complete PDF bytes in memory.
    ///
    /// # Errors
    ///
    /// Returns an error when the pages cannot be written as PDF or when writing to `writer` fails.
    pub fn write_pdf_to<W: std::io::Write>(
        &self,
        fonts: &FontDb,
        writer: &mut W,
    ) -> Result<Warned<()>, Error> {
        let pdf = f_office_docx::timing::span("pdf", || {
            f_office_pdf::write_pdf_to(&self.list, fonts, writer)
        })
        .map_err(Error::Pdf)?;
        Ok(Warned::new((), pdf.warnings.map(Warning::Pdf)))
    }
}

#[cfg(test)]
mod tests {
    use super::{Document, Error, FontDb, Options, error_chain};

    #[test]
    fn says_the_warnings_of_the_output_with_their_kinds() {
        use super::{ImageFault, ImageFormat, Warning, pdf};
        let skipped = Warning::Pdf(pdf::Warning::ImageSkipped {
            format: ImageFormat::Wmf,
            fault: ImageFault::Format,
        });
        assert_eq!(skipped.kind(), "pdf-image-skipped");
        assert_eq!(
            skipped.to_string(),
            "an image in WMF format is left out of the PDF: the output draws no image of this \
             format"
        );
        let kept = Warning::PictureNotWrittenAgain {
            format: ImageFormat::Jpeg,
        };
        assert_eq!(kept.kind(), "picture-not-written-again");
        assert_eq!(
            kept.to_string(),
            "a picture in JPEG format keeps its own file, which the target's PDF writer writes \
             again: its data does not decode"
        );
    }

    #[test]
    fn rejects_a_file_that_is_not_a_package_for_every_target() {
        let error = Document::open(b"not a zip", &FontDb::new(), &Options::default()).unwrap_err();
        assert!(matches!(error, Error::Package(_)));
        assert_ne!(error.to_string(), "");
        // The same error, with the same text and cause, for every target.
        for target in super::Target::all() {
            let options = Options {
                configuration: super::Configuration::of(target),
                ..Options::default()
            };
            let with = Document::open(b"not a zip", &FontDb::new(), &options).unwrap_err();
            assert!(matches!(with, Error::Package(_)));
            assert_eq!(error_chain(&with), error_chain(&error));
        }
    }

    #[test]
    fn gives_the_pdf_error_as_its_cause() {
        let error = Error::Pdf(f_office_pdf::Error::NoPages);
        assert_eq!(error.to_string(), "the pages could not be written as PDF");
        let cause = std::error::Error::source(&error).map(ToString::to_string);
        assert_eq!(cause.as_deref(), Some("the display list has no page"));
    }

    #[test]
    fn writes_the_error_chain_down_to_the_first_cause() {
        let error = Document::open(b"not a zip", &FontDb::new(), &Options::default()).unwrap_err();
        let chain = error_chain(&error);
        assert!(
            chain.starts_with("the package could not be read: unreadable ZIP package: "),
            "{chain}"
        );
        let docx = Error::Docx(f_office_docx::Error::Package(
            f_office_opc::Error::NoMainDocument,
        ));
        assert_eq!(
            error_chain(&docx),
            "the DOCX content could not be laid out: the package could not be read: package has \
             no main document"
        );
        let leaf = f_office_pdf::Error::NoPages;
        assert_eq!(error_chain(&leaf), "the display list has no page");
    }
}

#[cfg(test)]
mod comment_tests;
#[cfg(test)]
mod layout_tests;
#[cfg(test)]
mod pdf_tests;
#[cfg(test)]
mod picture_tests;
#[cfg(test)]
mod test_fonts;
#[cfg(test)]
mod text_block_tests;