1use std::fmt;
2
3use crate::error::{InternalRenderingError, InvalidTransform};
4
5#[derive(Clone)]
7pub enum FilterError {
8 InvalidInput,
10 InvalidParameter(String),
12 BadInputSurfaceStatus(cairo::Error),
14 CairoError(cairo::Error),
19 Rendering(InternalRenderingError),
21 LightingInputTooSmall,
23}
24
25#[derive(Debug)]
27pub enum FilterResolveError {
28 ReferenceToNonFilterElement,
30 InvalidLightSourceCount,
32 ChildNodeInError,
34}
35
36impl fmt::Display for FilterError {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 match *self {
39 FilterError::InvalidInput => write!(f, "invalid value of the `in` attribute"),
40 FilterError::InvalidParameter(ref s) => write!(f, "invalid parameter value: {s}"),
41 FilterError::BadInputSurfaceStatus(ref status) => {
42 write!(f, "invalid status of the input surface: {status}")
43 }
44 FilterError::CairoError(ref status) => write!(f, "Cairo error: {status}"),
45 FilterError::Rendering(ref e) => write!(f, "Rendering error: {e}"),
46 FilterError::LightingInputTooSmall => write!(
47 f,
48 "lighting filter input surface is too small (less than 2×2 pixels)"
49 ),
50 }
51 }
52}
53
54impl fmt::Display for FilterResolveError {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 match *self {
57 FilterResolveError::ReferenceToNonFilterElement => {
58 write!(f, "reference to a non-filter element")
59 }
60 FilterResolveError::InvalidLightSourceCount => write!(f, "invalid light source count"),
61 FilterResolveError::ChildNodeInError => write!(f, "child node was in error"),
62 }
63 }
64}
65
66impl From<cairo::Error> for FilterError {
67 #[inline]
68 fn from(x: cairo::Error) -> Self {
69 FilterError::CairoError(x)
70 }
71}
72
73impl From<InternalRenderingError> for FilterError {
74 #[inline]
75 fn from(e: InternalRenderingError) -> Self {
76 FilterError::Rendering(e)
77 }
78}
79
80impl From<Box<InternalRenderingError>> for FilterError {
81 #[inline]
82 fn from(e: Box<InternalRenderingError>) -> Self {
83 FilterError::Rendering(*e)
84 }
85}
86
87impl From<InvalidTransform> for FilterError {
88 fn from(_: InvalidTransform) -> Self {
89 FilterError::Rendering(InternalRenderingError::InvalidTransform)
90 }
91}