#![allow(clippy::cast_sign_loss)]
use crate::error::ParseResult;
use crate::reader::{BinaryReader, Parse};
mod simple;
pub use simple::SimpleGlyf;
mod compound;
pub use compound::CompoundGlyf;
mod svg;
#[derive(Debug, Clone)]
pub enum GlyfOutline {
Simple(SimpleGlyf),
Compound(CompoundGlyf),
}
impl Default for GlyfOutline {
fn default() -> Self {
GlyfOutline::Simple(SimpleGlyf {
contours: vec![],
num_contours: 0,
x: (0, 0),
y: (0, 0),
})
}
}
impl GlyfOutline {
#[must_use]
pub fn is_simple(&self) -> bool {
matches!(self, GlyfOutline::Simple(_))
}
#[must_use]
pub fn is_compound(&self) -> bool {
matches!(self, GlyfOutline::Compound(_))
}
}
impl Parse for GlyfOutline {
fn parse(reader: &mut BinaryReader) -> ParseResult<Self> {
let num_contours = reader.read_i16()?;
let xmin = reader.read_i16()?;
let ymin = reader.read_i16()?;
let xmax = reader.read_i16()?;
let ymax = reader.read_i16()?;
if num_contours >= 0 {
let mut glyph = SimpleGlyf {
contours: Vec::with_capacity(num_contours as usize),
num_contours,
x: (xmin, xmax),
y: (ymin, ymax),
};
glyph.parse_with(reader)?;
Ok(GlyfOutline::Simple(glyph))
} else {
let glyph = CompoundGlyf::parse(reader)?;
Ok(GlyfOutline::Compound(glyph))
}
}
}