use core::fmt;
use read_fonts::types::GlyphId;
pub use read_fonts::ps::error::Error as CffError;
pub use super::glyf::HintError;
#[derive(Clone, Debug)]
pub enum DrawError {
NoSources,
GlyphNotFound(GlyphId),
InsufficientMemory,
RecursionLimitExceeded(GlyphId),
TooManyPoints(GlyphId),
HintingFailed(HintError),
InvalidAnchorPoint(GlyphId, u16),
PostScript(CffError),
Malformed,
HarfBuzzHintingUnsupported,
}
impl From<HintError> for DrawError {
fn from(value: HintError) -> Self {
Self::HintingFailed(value)
}
}
impl From<CffError> for DrawError {
fn from(value: CffError) -> Self {
Self::PostScript(value)
}
}
impl fmt::Display for DrawError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::NoSources => write!(f, "No glyph sources are available for the given font"),
Self::GlyphNotFound(gid) => write!(f, "Glyph {gid} was not found in the given font"),
Self::InsufficientMemory => write!(f, "exceeded memory limits"),
Self::RecursionLimitExceeded(gid) => write!(
f,
"Recursion limit ({}) exceeded when loading composite component {gid}",
read_fonts::limits::MAX_RECURSION_DEPTH,
),
Self::TooManyPoints(gid) => write!(f, "Glyph {gid} contains more than 64k points"),
Self::HintingFailed(e) => write!(f, "{e}"),
Self::InvalidAnchorPoint(gid, index) => write!(
f,
"Invalid anchor point index ({index}) for composite glyph {gid}",
),
Self::PostScript(e) => write!(f, "{e}"),
Self::Malformed => write!(f, "font data was absent or malformed"),
Self::HarfBuzzHintingUnsupported => write!(
f,
"HarfBuzz style paths with hinting is not (yet?) supported"
),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for DrawError {}