use core::fmt;
use read_fonts::types::GlyphId;
pub use read_fonts::{tables::postscript::Error as CffError, ReadError};
pub use super::glyf::HintError;
pub use super::path::ToPathError;
#[derive(Clone, Debug)]
pub enum DrawError {
NoSources,
GlyphNotFound(GlyphId),
InsufficientMemory,
RecursionLimitExceeded(GlyphId),
HintingFailed(HintError),
InvalidAnchorPoint(GlyphId, u16),
PostScript(CffError),
ToPath(ToPathError),
Read(ReadError),
HarfBuzzHintingUnsupported,
}
impl From<HintError> for DrawError {
fn from(value: HintError) -> Self {
Self::HintingFailed(value)
}
}
impl From<ToPathError> for DrawError {
fn from(e: ToPathError) -> Self {
Self::ToPath(e)
}
}
impl From<ReadError> for DrawError {
fn from(e: ReadError) -> Self {
Self::Read(e)
}
}
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}",
super::GLYF_COMPOSITE_RECURSION_LIMIT,
),
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::ToPath(e) => write!(f, "{e}"),
Self::Read(e) => write!(f, "{e}"),
Self::HarfBuzzHintingUnsupported => write!(
f,
"HarfBuzz style paths with hinting is not (yet?) supported"
),
}
}
}