use truetype::GlyphID;
use crate::Result;
#[derive(Clone, Debug)]
pub enum Class {
Format1(Class1),
Format2(Class2),
}
table! {
pub Class1 { format (u16 ), start_glyph_id (GlyphID), glyph_count (u16 ),
indices (Vec<u16>) |this, tape| { tape.take_given(this.glyph_count as usize)
},
}
}
table! {
pub Class2 { format (u16), record_count (u16),
records (Vec<Record>) |this, tape| { tape.take_given(this.record_count as usize)
},
}
}
table! {
#[derive(Copy)]
pub Record { start_glyph_id (GlyphID), end_glyph_id (GlyphID), index (u16 ), }
}
impl Default for Class {
#[inline]
fn default() -> Self {
Class::Format1(Class1::default())
}
}
impl crate::value::Read for Class {
fn read<T: crate::tape::Read>(tape: &mut T) -> Result<Self> {
Ok(match tape.peek::<u16>()? {
1 => Class::Format1(tape.take()?),
2 => Class::Format2(tape.take()?),
value => raise!("found an unknown format of the glyph class ({value})"),
})
}
}