#[allow(unused_imports)]
use crate::codegen_prelude::*;
impl<'a> MinByteRange<'a> for Hdmx<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.records_byte_range().end
}
fn min_table_bytes(&self) -> &'a [u8] {
let range = self.min_byte_range();
self.offset_data().as_bytes().get(range).unwrap_or_default()
}
}
impl TopLevelTable for Hdmx<'_> {
const TAG: Tag = Tag::new(b"hdmx");
}
impl ReadArgs for Hdmx<'_> {
type Args = u32;
}
impl<'a> FontRead<'a> for Hdmx<'a> {
fn read_with_args(data: FontData<'a>, args: u32) -> Result<Self, ReadError> {
let num_glyphs = args;
#[allow(clippy::absurd_extreme_comparisons)]
if data.len() < Self::MIN_SIZE {
return Err(ReadError::OutOfBounds);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data, num_glyphs })
}
}
impl<'a> Hdmx<'a> {
pub fn read(data: FontData<'a>, num_glyphs: u32) -> Result<Self, ReadError> {
let args = num_glyphs;
Self::read_with_args(data, args)
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct HdmxFixedHeader {
pub version: BigEndian<u16>,
pub num_records: BigEndian<u16>,
pub size_device_record: BigEndian<u32>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(std::mem::size_of::<HdmxFixedHeader>() <= Hdmx::MIN_SIZE);
#[derive(Clone)]
pub struct Hdmx<'a> {
data: TableDataRef<'a, HdmxFixedHeader>,
num_glyphs: u32,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> Hdmx<'a> {
pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn version(&self) -> u16 {
self.data.header().version.get()
}
pub fn num_records(&self) -> u16 {
self.data.header().num_records.get()
}
pub fn size_device_record(&self) -> u32 {
self.data.header().size_device_record.get()
}
pub fn records(&self) -> ComputedArray<'a, DeviceRecord<'a>> {
let range = self.records_byte_range();
ComputedArray::new(
self.offset_data(),
range,
(self.num_glyphs(), self.size_device_record()),
)
.unwrap_or_default()
}
pub(crate) fn num_glyphs(&self) -> u32 {
self.num_glyphs
}
pub fn version_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn num_records_byte_range(&self) -> Range<usize> {
let start = self.version_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn size_device_record_byte_range(&self) -> Range<usize> {
let start = self.num_records_byte_range().end;
let end = start + u32::RAW_BYTE_LEN;
start..end
}
pub fn records_byte_range(&self) -> Range<usize> {
let num_records = self.num_records();
let start = self.size_device_record_byte_range().end;
let end = start
+ (transforms::to_usize(num_records)).saturating_mul(
<DeviceRecord as ComputeSize>::compute_size((
self.num_glyphs(),
self.size_device_record(),
))
.unwrap_or(0),
);
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(Hdmx::MIN_SIZE));
impl Default for Hdmx<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
num_glyphs: Default::default(),
}
}
}