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
//! What can go wrong badly enough to abandon a render.
//!
//! Almost nothing does. Rendering a damaged page is the normal case, and
//! every recovery — an undrawable matrix, a shading whose function will not
//! evaluate, a pattern whose steps are degenerate — is a skipped object and a
//! [`Diagnostic`](pdfrum_common::Diagnostic), not an error. `Err` is reserved
//! for "there is no output at all".
/// A render that could not produce a pixmap.
#[derive(Debug, thiserror::Error, PartialEq, Eq, Clone)]
#[non_exhaustive]
pub enum Error {
/// The requested target exceeds what a backend can allocate.
///
/// `vello_cpu` sizes every scene, pixmap and mask with `u16`, so 65535 is
/// the hard ceiling in either axis; the bound is enforced in the engine so
/// both backends agree rather than one of them failing later.
#[error("render target {width}x{height} exceeds the {limit}px backend limit")]
TargetTooLarge {
/// The requested width in pixels.
width: u32,
/// The requested height in pixels.
height: u32,
/// The largest dimension a backend accepts.
limit: u32,
},
/// The requested target has a zero axis, so there is nothing to render
/// into.
#[error("render target {width}x{height} is empty")]
TargetEmpty {
/// The requested width in pixels.
width: u32,
/// The requested height in pixels.
height: u32,
},
/// [`RenderSession::deadline`](crate::RenderSession::deadline) passed:
/// before the target was allocated, or during the walk, which stops at
/// the next object and reports here rather than handing back a page with
/// the rest missing.
#[error(transparent)]
Limit(pdfrum_common::LimitExceeded),
/// A PNG could not be encoded — only with the `png` feature. The
/// encoder's own message, since its error type is neither comparable nor
/// cloneable and this one is both.
#[cfg(feature = "png")]
#[error("PNG encoding failed: {0}")]
Png(String),
/// A file could not be written — only with the `png` feature; the I/O
/// error's message.
#[cfg(feature = "png")]
#[error("writing the file failed: {0}")]
Io(String),
}
#[cfg(feature = "png")]
impl From<png::EncodingError> for Error {
fn from(error: png::EncodingError) -> Self {
Error::Png(error.to_string())
}
}
#[cfg(feature = "png")]
impl From<std::io::Error> for Error {
fn from(error: std::io::Error) -> Self {
Error::Io(error.to_string())
}
}