use std::fmt;
use crate::error::InternalRenderingError;
#[derive(Clone)]
pub enum FilterError {
InvalidInput,
InvalidParameter(String),
BadInputSurfaceStatus(cairo::Error),
CairoError(cairo::Error),
Rendering(InternalRenderingError),
LightingInputTooSmall,
}
#[derive(Debug)]
pub enum FilterResolveError {
ReferenceToNonFilterElement,
InvalidLightSourceCount,
ChildNodeInError,
}
impl fmt::Display for FilterError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
FilterError::InvalidInput => write!(f, "invalid value of the `in` attribute"),
FilterError::InvalidParameter(ref s) => write!(f, "invalid parameter value: {s}"),
FilterError::BadInputSurfaceStatus(ref status) => {
write!(f, "invalid status of the input surface: {status}")
}
FilterError::CairoError(ref status) => write!(f, "Cairo error: {status}"),
FilterError::Rendering(ref e) => write!(f, "Rendering error: {e}"),
FilterError::LightingInputTooSmall => write!(
f,
"lighting filter input surface is too small (less than 2×2 pixels)"
),
}
}
}
impl fmt::Display for FilterResolveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
FilterResolveError::ReferenceToNonFilterElement => {
write!(f, "reference to a non-filter element")
}
FilterResolveError::InvalidLightSourceCount => write!(f, "invalid light source count"),
FilterResolveError::ChildNodeInError => write!(f, "child node was in error"),
}
}
}
impl From<cairo::Error> for FilterError {
#[inline]
fn from(x: cairo::Error) -> Self {
FilterError::CairoError(x)
}
}
impl From<InternalRenderingError> for FilterError {
#[inline]
fn from(e: InternalRenderingError) -> Self {
FilterError::Rendering(e)
}
}