use super::super::bytecode::HintError;
use crate::ReadError;
#[derive(Clone, PartialEq, Debug)]
pub enum OutlineError {
MissingGlyph,
RecursionLimitExceeded,
TooManyComponents,
TooManyPoints,
InvalidAnchorPoint,
InsufficientMemory,
Hinting(HintError),
Malformed,
}
impl From<ReadError> for OutlineError {
fn from(_: ReadError) -> Self {
Self::Malformed
}
}
impl From<HintError> for OutlineError {
fn from(value: HintError) -> Self {
Self::Hinting(value)
}
}
impl core::fmt::Display for OutlineError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::MissingGlyph => f.write_str("requested glyph was not found in the font"),
Self::RecursionLimitExceeded => {
f.write_str("glyph exceeded the composite recursion limit")
}
Self::TooManyComponents => f.write_str("glyph referenced too many components"),
Self::TooManyPoints => f.write_str("glyph has too many points"),
Self::InvalidAnchorPoint => f.write_str("glyph referenced a nonexistent anchor point"),
Self::InsufficientMemory => f.write_str("outline buffers were too small"),
Self::Hinting(err) => write!(f, "{err}"),
Self::Malformed => f.write_str("font data was malformed"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for OutlineError {}