use std::mem::size_of;
use read_fonts::{
tables::glyf::{to_path, Glyph, PointFlags, ToPathError},
types::{F26Dot6, Fixed, GlyphId, Pen, Point},
};
use super::ScalerMemory;
#[derive(Default)]
pub struct ScalerGlyph<'a> {
pub glyph_id: GlyphId,
pub glyph: Option<Glyph<'a>>,
pub points: usize,
pub contours: usize,
pub max_simple_points: usize,
pub max_other_points: usize,
pub max_component_delta_stack: usize,
pub has_hinting: bool,
pub has_variations: bool,
pub has_overlaps: bool,
}
impl<'a> ScalerGlyph<'a> {
pub fn required_buffer_size(&self) -> usize {
let mut size = 0;
size += self.points * size_of::<Point<F26Dot6>>();
size +=
self.max_other_points * size_of::<Point<i32>>() * if self.has_hinting { 2 } else { 1 };
size += self.contours * size_of::<u16>();
size += self.points * size_of::<PointFlags>();
if self.has_variations {
size += self.max_simple_points * size_of::<Point<Fixed>>();
size += self.max_simple_points * size_of::<Point<Fixed>>();
size += self.max_component_delta_stack * size_of::<Point<Fixed>>();
}
if size != 0 {
size += std::mem::align_of::<i32>();
}
size
}
pub fn memory_from_buffer(&self, buf: &'a mut [u8]) -> Option<ScalerMemory<'a>> {
ScalerMemory::new(self, buf)
}
}
#[derive(Debug)]
pub struct ScalerOutline<'a> {
pub points: &'a mut [Point<F26Dot6>],
pub flags: &'a mut [PointFlags],
pub contours: &'a mut [u16],
}
impl<'a> ScalerOutline<'a> {
pub fn to_path(&self, pen: &mut impl Pen) -> Result<(), ToPathError> {
to_path(self.points, self.flags, self.contours, pen)
}
}