pdfrum_font/error.rs
1//! The one error type this crate returns.
2//!
3//! Almost nothing here can fail: a simple font always constructs, even with no
4//! glyphs at all, and a damaged font program degrades into substitution rather
5//! than erroring. `Err` is reserved for the four CID-font cases PDFium itself
6//! treats as "this resource does not exist", and for a font program no backend
7//! can read at all.
8
9use thiserror::Error;
10
11/// What went wrong while loading a font.
12#[derive(Debug, Clone, PartialEq, Eq, Error)]
13#[non_exhaustive]
14pub enum Error {
15 /// A Type0 font's `/DescendantFonts` was missing, was not an array, or did
16 /// not hold exactly one element. PDFium fails the load here and the
17 /// content-stream interpreter then skips text using the font.
18 #[error("a Type0 font's /DescendantFonts must hold exactly one dictionary")]
19 BadDescendantFonts,
20 /// A Type0 font's `/Encoding` was absent, or was neither a name nor a
21 /// stream.
22 #[error("a Type0 font's /Encoding must be a predefined name or a CMap stream")]
23 BadCidEncoding,
24 /// A font program was present but no backend could read it. The font falls
25 /// back to substitution; this is returned only by the direct
26 /// program-loading entry point.
27 #[error("the embedded font program is in no format this build can read")]
28 UnreadableFontProgram,
29}