use super::parse_prelude::*;
pub const VMTX: Tag = Tag::new(b"vmtx");
#[derive(Copy, Clone, Debug)]
pub struct VMetric {
pub advance_height: u16,
pub tsb: i16,
}
impl ReadData for VMetric {
unsafe fn read_data_unchecked(buf: &[u8], offset: usize) -> Self {
Self {
advance_height: u16::read_data_unchecked(buf, offset),
tsb: i16::read_data_unchecked(buf, offset + 2),
}
}
}
#[derive(Copy, Clone)]
pub struct Vmtx<'a> {
data: Buffer<'a>,
num_glyphs: u16,
num_vmetrics: u16,
}
impl<'a> Vmtx<'a> {
pub fn new(data: &'a [u8], num_glyphs: u16, num_vmetrics: u16) -> Self {
Self {
data: Buffer::new(data),
num_glyphs,
num_vmetrics,
}
}
pub fn num_glyphs(&self) -> u16 {
self.num_glyphs
}
pub fn hmetrics(&self) -> Slice<'a, VMetric> {
self.data
.read_slice(0, self.num_vmetrics as usize)
.unwrap_or_default()
}
pub fn tsbs(&self) -> Slice<'a, FWord> {
let offset = self.num_vmetrics as usize * 4;
let len = (self.num_glyphs as usize).saturating_sub(self.num_vmetrics as usize);
self.data.read_slice(offset, len).unwrap_or_default()
}
}