#[allow(unused_imports)]
use crate::codegen_prelude::*;
#[derive(Clone)]
pub enum Lookup<'a> {
Format0(Lookup0<'a>),
Format2(Lookup2<'a>),
Format4(Lookup4<'a>),
Format6(Lookup6<'a>),
Format8(Lookup8<'a>),
Format10(Lookup10<'a>),
}
impl<'a> Lookup<'a> {
pub fn offset_data(&self) -> FontData<'a> {
match self {
Self::Format0(item) => item.offset_data(),
Self::Format2(item) => item.offset_data(),
Self::Format4(item) => item.offset_data(),
Self::Format6(item) => item.offset_data(),
Self::Format8(item) => item.offset_data(),
Self::Format10(item) => item.offset_data(),
}
}
pub fn format(&self) -> u16 {
match self {
Self::Format0(item) => item.format(),
Self::Format2(item) => item.format(),
Self::Format4(item) => item.format(),
Self::Format6(item) => item.format(),
Self::Format8(item) => item.format(),
Self::Format10(item) => item.format(),
}
}
}
impl<'a> FontRead<'a> for Lookup<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let format: u16 = data.read_at(0usize)?;
match format {
Lookup0Marker::FORMAT => Ok(Self::Format0(FontRead::read(data)?)),
Lookup2Marker::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
Lookup4Marker::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
Lookup6Marker::FORMAT => Ok(Self::Format6(FontRead::read(data)?)),
Lookup8Marker::FORMAT => Ok(Self::Format8(FontRead::read(data)?)),
Lookup10Marker::FORMAT => Ok(Self::Format10(FontRead::read(data)?)),
other => Err(ReadError::InvalidFormat(other.into())),
}
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> Lookup<'a> {
fn dyn_inner<'b>(&'b self) -> &'b dyn SomeTable<'a> {
match self {
Self::Format0(table) => table,
Self::Format2(table) => table,
Self::Format4(table) => table,
Self::Format6(table) => table,
Self::Format8(table) => table,
Self::Format10(table) => table,
}
}
}
#[cfg(feature = "experimental_traverse")]
impl std::fmt::Debug for Lookup<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for Lookup<'a> {
fn type_name(&self) -> &str {
self.dyn_inner().type_name()
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.dyn_inner().get_field(idx)
}
}
impl Format<u16> for Lookup0Marker {
const FORMAT: u16 = 0;
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct Lookup0Marker {
values_data_byte_len: usize,
}
impl Lookup0Marker {
pub fn format_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u16::RAW_BYTE_LEN
}
pub fn values_data_byte_range(&self) -> Range<usize> {
let start = self.format_byte_range().end;
start..start + self.values_data_byte_len
}
}
impl<'a> FontRead<'a> for Lookup0<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u16>();
let values_data_byte_len = cursor.remaining_bytes() / u8::RAW_BYTE_LEN * u8::RAW_BYTE_LEN;
cursor.advance_by(values_data_byte_len);
cursor.finish(Lookup0Marker {
values_data_byte_len,
})
}
}
pub type Lookup0<'a> = TableRef<'a, Lookup0Marker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> Lookup0<'a> {
pub fn format(&self) -> u16 {
let range = self.shape.format_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn values_data(&self) -> &'a [u8] {
let range = self.shape.values_data_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for Lookup0<'a> {
fn type_name(&self) -> &str {
"Lookup0"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("format", self.format())),
1usize => Some(Field::new("values_data", self.values_data())),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for Lookup0<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
impl Format<u16> for Lookup2Marker {
const FORMAT: u16 = 2;
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct Lookup2Marker {
segments_data_byte_len: usize,
}
impl Lookup2Marker {
pub fn format_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u16::RAW_BYTE_LEN
}
pub fn unit_size_byte_range(&self) -> Range<usize> {
let start = self.format_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn n_units_byte_range(&self) -> Range<usize> {
let start = self.unit_size_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn search_range_byte_range(&self) -> Range<usize> {
let start = self.n_units_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn entry_selector_byte_range(&self) -> Range<usize> {
let start = self.search_range_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn range_shift_byte_range(&self) -> Range<usize> {
let start = self.entry_selector_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn segments_data_byte_range(&self) -> Range<usize> {
let start = self.range_shift_byte_range().end;
start..start + self.segments_data_byte_len
}
}
impl<'a> FontRead<'a> for Lookup2<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u16>();
let unit_size: u16 = cursor.read()?;
let n_units: u16 = cursor.read()?;
cursor.advance::<u16>();
cursor.advance::<u16>();
cursor.advance::<u16>();
let segments_data_byte_len = (transforms::add_multiply(unit_size, 0_usize, n_units))
.checked_mul(u8::RAW_BYTE_LEN)
.ok_or(ReadError::OutOfBounds)?;
cursor.advance_by(segments_data_byte_len);
cursor.finish(Lookup2Marker {
segments_data_byte_len,
})
}
}
pub type Lookup2<'a> = TableRef<'a, Lookup2Marker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> Lookup2<'a> {
pub fn format(&self) -> u16 {
let range = self.shape.format_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn unit_size(&self) -> u16 {
let range = self.shape.unit_size_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn n_units(&self) -> u16 {
let range = self.shape.n_units_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn search_range(&self) -> u16 {
let range = self.shape.search_range_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn entry_selector(&self) -> u16 {
let range = self.shape.entry_selector_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn range_shift(&self) -> u16 {
let range = self.shape.range_shift_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn segments_data(&self) -> &'a [u8] {
let range = self.shape.segments_data_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for Lookup2<'a> {
fn type_name(&self) -> &str {
"Lookup2"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("format", self.format())),
1usize => Some(Field::new("unit_size", self.unit_size())),
2usize => Some(Field::new("n_units", self.n_units())),
3usize => Some(Field::new("search_range", self.search_range())),
4usize => Some(Field::new("entry_selector", self.entry_selector())),
5usize => Some(Field::new("range_shift", self.range_shift())),
6usize => Some(Field::new("segments_data", self.segments_data())),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for Lookup2<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
impl Format<u16> for Lookup4Marker {
const FORMAT: u16 = 4;
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct Lookup4Marker {
segments_byte_len: usize,
}
impl Lookup4Marker {
pub fn format_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u16::RAW_BYTE_LEN
}
pub fn unit_size_byte_range(&self) -> Range<usize> {
let start = self.format_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn n_units_byte_range(&self) -> Range<usize> {
let start = self.unit_size_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn search_range_byte_range(&self) -> Range<usize> {
let start = self.n_units_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn entry_selector_byte_range(&self) -> Range<usize> {
let start = self.search_range_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn range_shift_byte_range(&self) -> Range<usize> {
let start = self.entry_selector_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn segments_byte_range(&self) -> Range<usize> {
let start = self.range_shift_byte_range().end;
start..start + self.segments_byte_len
}
}
impl<'a> FontRead<'a> for Lookup4<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u16>();
cursor.advance::<u16>();
let n_units: u16 = cursor.read()?;
cursor.advance::<u16>();
cursor.advance::<u16>();
cursor.advance::<u16>();
let segments_byte_len = (n_units as usize)
.checked_mul(LookupSegment4::RAW_BYTE_LEN)
.ok_or(ReadError::OutOfBounds)?;
cursor.advance_by(segments_byte_len);
cursor.finish(Lookup4Marker { segments_byte_len })
}
}
pub type Lookup4<'a> = TableRef<'a, Lookup4Marker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> Lookup4<'a> {
pub fn format(&self) -> u16 {
let range = self.shape.format_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn unit_size(&self) -> u16 {
let range = self.shape.unit_size_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn n_units(&self) -> u16 {
let range = self.shape.n_units_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn search_range(&self) -> u16 {
let range = self.shape.search_range_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn entry_selector(&self) -> u16 {
let range = self.shape.entry_selector_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn range_shift(&self) -> u16 {
let range = self.shape.range_shift_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn segments(&self) -> &'a [LookupSegment4] {
let range = self.shape.segments_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for Lookup4<'a> {
fn type_name(&self) -> &str {
"Lookup4"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("format", self.format())),
1usize => Some(Field::new("unit_size", self.unit_size())),
2usize => Some(Field::new("n_units", self.n_units())),
3usize => Some(Field::new("search_range", self.search_range())),
4usize => Some(Field::new("entry_selector", self.entry_selector())),
5usize => Some(Field::new("range_shift", self.range_shift())),
6usize => Some(Field::new(
"segments",
traversal::FieldType::array_of_records(
stringify!(LookupSegment4),
self.segments(),
self.offset_data(),
),
)),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for Lookup4<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
#[repr(C)]
#[repr(packed)]
pub struct LookupSegment4 {
pub last_glyph: BigEndian<u16>,
pub first_glyph: BigEndian<u16>,
pub value_offset: BigEndian<u16>,
}
impl LookupSegment4 {
pub fn last_glyph(&self) -> u16 {
self.last_glyph.get()
}
pub fn first_glyph(&self) -> u16 {
self.first_glyph.get()
}
pub fn value_offset(&self) -> u16 {
self.value_offset.get()
}
}
impl FixedSize for LookupSegment4 {
const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeRecord<'a> for LookupSegment4 {
fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
RecordResolver {
name: "LookupSegment4",
get_field: Box::new(move |idx, _data| match idx {
0usize => Some(Field::new("last_glyph", self.last_glyph())),
1usize => Some(Field::new("first_glyph", self.first_glyph())),
2usize => Some(Field::new("value_offset", self.value_offset())),
_ => None,
}),
data,
}
}
}
impl Format<u16> for Lookup6Marker {
const FORMAT: u16 = 6;
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct Lookup6Marker {
entries_data_byte_len: usize,
}
impl Lookup6Marker {
pub fn format_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u16::RAW_BYTE_LEN
}
pub fn unit_size_byte_range(&self) -> Range<usize> {
let start = self.format_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn n_units_byte_range(&self) -> Range<usize> {
let start = self.unit_size_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn search_range_byte_range(&self) -> Range<usize> {
let start = self.n_units_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn entry_selector_byte_range(&self) -> Range<usize> {
let start = self.search_range_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn range_shift_byte_range(&self) -> Range<usize> {
let start = self.entry_selector_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn entries_data_byte_range(&self) -> Range<usize> {
let start = self.range_shift_byte_range().end;
start..start + self.entries_data_byte_len
}
}
impl<'a> FontRead<'a> for Lookup6<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u16>();
let unit_size: u16 = cursor.read()?;
let n_units: u16 = cursor.read()?;
cursor.advance::<u16>();
cursor.advance::<u16>();
cursor.advance::<u16>();
let entries_data_byte_len = (transforms::add_multiply(unit_size, 0_usize, n_units))
.checked_mul(u8::RAW_BYTE_LEN)
.ok_or(ReadError::OutOfBounds)?;
cursor.advance_by(entries_data_byte_len);
cursor.finish(Lookup6Marker {
entries_data_byte_len,
})
}
}
pub type Lookup6<'a> = TableRef<'a, Lookup6Marker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> Lookup6<'a> {
pub fn format(&self) -> u16 {
let range = self.shape.format_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn unit_size(&self) -> u16 {
let range = self.shape.unit_size_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn n_units(&self) -> u16 {
let range = self.shape.n_units_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn search_range(&self) -> u16 {
let range = self.shape.search_range_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn entry_selector(&self) -> u16 {
let range = self.shape.entry_selector_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn range_shift(&self) -> u16 {
let range = self.shape.range_shift_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn entries_data(&self) -> &'a [u8] {
let range = self.shape.entries_data_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for Lookup6<'a> {
fn type_name(&self) -> &str {
"Lookup6"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("format", self.format())),
1usize => Some(Field::new("unit_size", self.unit_size())),
2usize => Some(Field::new("n_units", self.n_units())),
3usize => Some(Field::new("search_range", self.search_range())),
4usize => Some(Field::new("entry_selector", self.entry_selector())),
5usize => Some(Field::new("range_shift", self.range_shift())),
6usize => Some(Field::new("entries_data", self.entries_data())),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for Lookup6<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
impl Format<u16> for Lookup8Marker {
const FORMAT: u16 = 8;
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct Lookup8Marker {
value_array_byte_len: usize,
}
impl Lookup8Marker {
pub fn format_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u16::RAW_BYTE_LEN
}
pub fn first_glyph_byte_range(&self) -> Range<usize> {
let start = self.format_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn glyph_count_byte_range(&self) -> Range<usize> {
let start = self.first_glyph_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn value_array_byte_range(&self) -> Range<usize> {
let start = self.glyph_count_byte_range().end;
start..start + self.value_array_byte_len
}
}
impl<'a> FontRead<'a> for Lookup8<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u16>();
cursor.advance::<u16>();
cursor.advance::<u16>();
let value_array_byte_len = cursor.remaining_bytes() / u16::RAW_BYTE_LEN * u16::RAW_BYTE_LEN;
cursor.advance_by(value_array_byte_len);
cursor.finish(Lookup8Marker {
value_array_byte_len,
})
}
}
pub type Lookup8<'a> = TableRef<'a, Lookup8Marker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> Lookup8<'a> {
pub fn format(&self) -> u16 {
let range = self.shape.format_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn first_glyph(&self) -> u16 {
let range = self.shape.first_glyph_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn glyph_count(&self) -> u16 {
let range = self.shape.glyph_count_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn value_array(&self) -> &'a [BigEndian<u16>] {
let range = self.shape.value_array_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for Lookup8<'a> {
fn type_name(&self) -> &str {
"Lookup8"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("format", self.format())),
1usize => Some(Field::new("first_glyph", self.first_glyph())),
2usize => Some(Field::new("glyph_count", self.glyph_count())),
3usize => Some(Field::new("value_array", self.value_array())),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for Lookup8<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
impl Format<u16> for Lookup10Marker {
const FORMAT: u16 = 10;
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct Lookup10Marker {
values_data_byte_len: usize,
}
impl Lookup10Marker {
pub fn format_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u16::RAW_BYTE_LEN
}
pub fn unit_size_byte_range(&self) -> Range<usize> {
let start = self.format_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn first_glyph_byte_range(&self) -> Range<usize> {
let start = self.unit_size_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn glyph_count_byte_range(&self) -> Range<usize> {
let start = self.first_glyph_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn values_data_byte_range(&self) -> Range<usize> {
let start = self.glyph_count_byte_range().end;
start..start + self.values_data_byte_len
}
}
impl<'a> FontRead<'a> for Lookup10<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u16>();
cursor.advance::<u16>();
cursor.advance::<u16>();
cursor.advance::<u16>();
let values_data_byte_len = cursor.remaining_bytes() / u8::RAW_BYTE_LEN * u8::RAW_BYTE_LEN;
cursor.advance_by(values_data_byte_len);
cursor.finish(Lookup10Marker {
values_data_byte_len,
})
}
}
pub type Lookup10<'a> = TableRef<'a, Lookup10Marker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> Lookup10<'a> {
pub fn format(&self) -> u16 {
let range = self.shape.format_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn unit_size(&self) -> u16 {
let range = self.shape.unit_size_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn first_glyph(&self) -> u16 {
let range = self.shape.first_glyph_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn glyph_count(&self) -> u16 {
let range = self.shape.glyph_count_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn values_data(&self) -> &'a [u8] {
let range = self.shape.values_data_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for Lookup10<'a> {
fn type_name(&self) -> &str {
"Lookup10"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("format", self.format())),
1usize => Some(Field::new("unit_size", self.unit_size())),
2usize => Some(Field::new("first_glyph", self.first_glyph())),
3usize => Some(Field::new("glyph_count", self.glyph_count())),
4usize => Some(Field::new("values_data", self.values_data())),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for Lookup10<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct StateHeaderMarker {}
impl StateHeaderMarker {
pub fn state_size_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u16::RAW_BYTE_LEN
}
pub fn class_table_offset_byte_range(&self) -> Range<usize> {
let start = self.state_size_byte_range().end;
start..start + Offset16::RAW_BYTE_LEN
}
pub fn state_array_offset_byte_range(&self) -> Range<usize> {
let start = self.class_table_offset_byte_range().end;
start..start + Offset16::RAW_BYTE_LEN
}
pub fn entry_table_offset_byte_range(&self) -> Range<usize> {
let start = self.state_array_offset_byte_range().end;
start..start + Offset16::RAW_BYTE_LEN
}
}
impl<'a> FontRead<'a> for StateHeader<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u16>();
cursor.advance::<Offset16>();
cursor.advance::<Offset16>();
cursor.advance::<Offset16>();
cursor.finish(StateHeaderMarker {})
}
}
pub type StateHeader<'a> = TableRef<'a, StateHeaderMarker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> StateHeader<'a> {
pub fn state_size(&self) -> u16 {
let range = self.shape.state_size_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn class_table_offset(&self) -> Offset16 {
let range = self.shape.class_table_offset_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn class_table(&self) -> Result<ClassSubtable<'a>, ReadError> {
let data = self.data;
self.class_table_offset().resolve(data)
}
pub fn state_array_offset(&self) -> Offset16 {
let range = self.shape.state_array_offset_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn state_array(&self) -> Result<RawBytes<'a>, ReadError> {
let data = self.data;
self.state_array_offset().resolve(data)
}
pub fn entry_table_offset(&self) -> Offset16 {
let range = self.shape.entry_table_offset_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn entry_table(&self) -> Result<RawBytes<'a>, ReadError> {
let data = self.data;
self.entry_table_offset().resolve(data)
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for StateHeader<'a> {
fn type_name(&self) -> &str {
"StateHeader"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("state_size", self.state_size())),
1usize => Some(Field::new(
"class_table_offset",
FieldType::offset(self.class_table_offset(), self.class_table()),
)),
2usize => Some(Field::new(
"state_array_offset",
FieldType::offset(self.state_array_offset(), self.state_array()),
)),
3usize => Some(Field::new(
"entry_table_offset",
FieldType::offset(self.entry_table_offset(), self.entry_table()),
)),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for StateHeader<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct ClassSubtableMarker {
class_array_byte_len: usize,
}
impl ClassSubtableMarker {
pub fn first_glyph_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u16::RAW_BYTE_LEN
}
pub fn n_glyphs_byte_range(&self) -> Range<usize> {
let start = self.first_glyph_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
pub fn class_array_byte_range(&self) -> Range<usize> {
let start = self.n_glyphs_byte_range().end;
start..start + self.class_array_byte_len
}
}
impl<'a> FontRead<'a> for ClassSubtable<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u16>();
let n_glyphs: u16 = cursor.read()?;
let class_array_byte_len = (n_glyphs as usize)
.checked_mul(u8::RAW_BYTE_LEN)
.ok_or(ReadError::OutOfBounds)?;
cursor.advance_by(class_array_byte_len);
cursor.finish(ClassSubtableMarker {
class_array_byte_len,
})
}
}
pub type ClassSubtable<'a> = TableRef<'a, ClassSubtableMarker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> ClassSubtable<'a> {
pub fn first_glyph(&self) -> u16 {
let range = self.shape.first_glyph_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn n_glyphs(&self) -> u16 {
let range = self.shape.n_glyphs_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn class_array(&self) -> &'a [u8] {
let range = self.shape.class_array_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for ClassSubtable<'a> {
fn type_name(&self) -> &str {
"ClassSubtable"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("first_glyph", self.first_glyph())),
1usize => Some(Field::new("n_glyphs", self.n_glyphs())),
2usize => Some(Field::new("class_array", self.class_array())),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for ClassSubtable<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct RawBytesMarker {
data_byte_len: usize,
}
impl RawBytesMarker {
pub fn data_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + self.data_byte_len
}
}
impl<'a> FontRead<'a> for RawBytes<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
let data_byte_len = cursor.remaining_bytes() / u8::RAW_BYTE_LEN * u8::RAW_BYTE_LEN;
cursor.advance_by(data_byte_len);
cursor.finish(RawBytesMarker { data_byte_len })
}
}
pub type RawBytes<'a> = TableRef<'a, RawBytesMarker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> RawBytes<'a> {
pub fn data(&self) -> &'a [u8] {
let range = self.shape.data_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for RawBytes<'a> {
fn type_name(&self) -> &str {
"RawBytes"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("data", self.data())),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for RawBytes<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct StxHeaderMarker {}
impl StxHeaderMarker {
pub fn n_classes_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u32::RAW_BYTE_LEN
}
pub fn class_table_offset_byte_range(&self) -> Range<usize> {
let start = self.n_classes_byte_range().end;
start..start + Offset32::RAW_BYTE_LEN
}
pub fn state_array_offset_byte_range(&self) -> Range<usize> {
let start = self.class_table_offset_byte_range().end;
start..start + Offset32::RAW_BYTE_LEN
}
pub fn entry_table_offset_byte_range(&self) -> Range<usize> {
let start = self.state_array_offset_byte_range().end;
start..start + Offset32::RAW_BYTE_LEN
}
}
impl<'a> FontRead<'a> for StxHeader<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u32>();
cursor.advance::<Offset32>();
cursor.advance::<Offset32>();
cursor.advance::<Offset32>();
cursor.finish(StxHeaderMarker {})
}
}
pub type StxHeader<'a> = TableRef<'a, StxHeaderMarker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> StxHeader<'a> {
pub fn n_classes(&self) -> u32 {
let range = self.shape.n_classes_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn class_table_offset(&self) -> Offset32 {
let range = self.shape.class_table_offset_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn class_table(&self) -> Result<LookupU16<'a>, ReadError> {
let data = self.data;
self.class_table_offset().resolve(data)
}
pub fn state_array_offset(&self) -> Offset32 {
let range = self.shape.state_array_offset_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn state_array(&self) -> Result<RawWords<'a>, ReadError> {
let data = self.data;
self.state_array_offset().resolve(data)
}
pub fn entry_table_offset(&self) -> Offset32 {
let range = self.shape.entry_table_offset_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn entry_table(&self) -> Result<RawBytes<'a>, ReadError> {
let data = self.data;
self.entry_table_offset().resolve(data)
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for StxHeader<'a> {
fn type_name(&self) -> &str {
"StxHeader"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("n_classes", self.n_classes())),
1usize => Some(Field::new(
"class_table_offset",
FieldType::offset(self.class_table_offset(), self.class_table()),
)),
2usize => Some(Field::new(
"state_array_offset",
FieldType::offset(self.state_array_offset(), self.state_array()),
)),
3usize => Some(Field::new(
"entry_table_offset",
FieldType::offset(self.entry_table_offset(), self.entry_table()),
)),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for StxHeader<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct RawWordsMarker {
data_byte_len: usize,
}
impl RawWordsMarker {
pub fn data_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + self.data_byte_len
}
}
impl<'a> FontRead<'a> for RawWords<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
let data_byte_len = cursor.remaining_bytes() / u16::RAW_BYTE_LEN * u16::RAW_BYTE_LEN;
cursor.advance_by(data_byte_len);
cursor.finish(RawWordsMarker { data_byte_len })
}
}
pub type RawWords<'a> = TableRef<'a, RawWordsMarker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> RawWords<'a> {
pub fn data(&self) -> &'a [BigEndian<u16>] {
let range = self.shape.data_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for RawWords<'a> {
fn type_name(&self) -> &str {
"RawWords"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("data", self.data())),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for RawWords<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}