#[allow(unused_imports)]
use crate::codegen_prelude::*;
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct FeatMarker {
names_byte_len: usize,
}
impl FeatMarker {
fn version_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + MajorMinor::RAW_BYTE_LEN
}
fn feature_name_count_byte_range(&self) -> Range<usize> {
let start = self.version_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
fn _reserved1_byte_range(&self) -> Range<usize> {
let start = self.feature_name_count_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
fn _reserved2_byte_range(&self) -> Range<usize> {
let start = self._reserved1_byte_range().end;
start..start + u32::RAW_BYTE_LEN
}
fn names_byte_range(&self) -> Range<usize> {
let start = self._reserved2_byte_range().end;
start..start + self.names_byte_len
}
}
impl TopLevelTable for Feat<'_> {
const TAG: Tag = Tag::new(b"feat");
}
impl<'a> FontRead<'a> for Feat<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<MajorMinor>();
let feature_name_count: u16 = cursor.read()?;
cursor.advance::<u16>();
cursor.advance::<u32>();
let names_byte_len = (feature_name_count as usize)
.checked_mul(FeatureName::RAW_BYTE_LEN)
.ok_or(ReadError::OutOfBounds)?;
cursor.advance_by(names_byte_len);
cursor.finish(FeatMarker { names_byte_len })
}
}
pub type Feat<'a> = TableRef<'a, FeatMarker>;
impl<'a> Feat<'a> {
pub fn version(&self) -> MajorMinor {
let range = self.shape.version_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn feature_name_count(&self) -> u16 {
let range = self.shape.feature_name_count_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn names(&self) -> &'a [FeatureName] {
let range = self.shape.names_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for Feat<'a> {
fn type_name(&self) -> &str {
"Feat"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("version", self.version())),
1usize => Some(Field::new("feature_name_count", self.feature_name_count())),
2usize => Some(Field::new(
"names",
traversal::FieldType::array_of_records(
stringify!(FeatureName),
self.names(),
self.offset_data(),
),
)),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> std::fmt::Debug for Feat<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
#[repr(C)]
#[repr(packed)]
pub struct FeatureName {
pub feature: BigEndian<u16>,
pub n_settings: BigEndian<u16>,
pub setting_table_offset: BigEndian<Offset32>,
pub feature_flags: BigEndian<u16>,
pub name_index: BigEndian<NameId>,
}
impl FeatureName {
pub fn feature(&self) -> u16 {
self.feature.get()
}
pub fn n_settings(&self) -> u16 {
self.n_settings.get()
}
pub fn setting_table_offset(&self) -> Offset32 {
self.setting_table_offset.get()
}
pub fn setting_table<'a>(&self, data: FontData<'a>) -> Result<SettingNameArray<'a>, ReadError> {
let args = self.n_settings();
self.setting_table_offset().resolve_with_args(data, &args)
}
pub fn feature_flags(&self) -> u16 {
self.feature_flags.get()
}
pub fn name_index(&self) -> NameId {
self.name_index.get()
}
}
impl FixedSize for FeatureName {
const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN
+ Offset32::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN
+ NameId::RAW_BYTE_LEN;
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeRecord<'a> for FeatureName {
fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
RecordResolver {
name: "FeatureName",
get_field: Box::new(move |idx, _data| match idx {
0usize => Some(Field::new("feature", self.feature())),
1usize => Some(Field::new("n_settings", self.n_settings())),
2usize => Some(Field::new(
"setting_table_offset",
FieldType::offset(self.setting_table_offset(), self.setting_table(_data)),
)),
3usize => Some(Field::new("feature_flags", self.feature_flags())),
4usize => Some(Field::new("name_index", self.name_index())),
_ => None,
}),
data,
}
}
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct SettingNameArrayMarker {
settings_byte_len: usize,
}
impl SettingNameArrayMarker {
fn settings_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + self.settings_byte_len
}
}
impl ReadArgs for SettingNameArray<'_> {
type Args = u16;
}
impl<'a> FontReadWithArgs<'a> for SettingNameArray<'a> {
fn read_with_args(data: FontData<'a>, args: &u16) -> Result<Self, ReadError> {
let n_settings = *args;
let mut cursor = data.cursor();
let settings_byte_len = (n_settings as usize)
.checked_mul(SettingName::RAW_BYTE_LEN)
.ok_or(ReadError::OutOfBounds)?;
cursor.advance_by(settings_byte_len);
cursor.finish(SettingNameArrayMarker { settings_byte_len })
}
}
impl<'a> SettingNameArray<'a> {
pub fn read(data: FontData<'a>, n_settings: u16) -> Result<Self, ReadError> {
let args = n_settings;
Self::read_with_args(data, &args)
}
}
pub type SettingNameArray<'a> = TableRef<'a, SettingNameArrayMarker>;
impl<'a> SettingNameArray<'a> {
pub fn settings(&self) -> &'a [SettingName] {
let range = self.shape.settings_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for SettingNameArray<'a> {
fn type_name(&self) -> &str {
"SettingNameArray"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new(
"settings",
traversal::FieldType::array_of_records(
stringify!(SettingName),
self.settings(),
self.offset_data(),
),
)),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> std::fmt::Debug for SettingNameArray<'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 SettingName {
pub setting: BigEndian<u16>,
pub name_index: BigEndian<NameId>,
}
impl SettingName {
pub fn setting(&self) -> u16 {
self.setting.get()
}
pub fn name_index(&self) -> NameId {
self.name_index.get()
}
}
impl FixedSize for SettingName {
const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + NameId::RAW_BYTE_LEN;
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeRecord<'a> for SettingName {
fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
RecordResolver {
name: "SettingName",
get_field: Box::new(move |idx, _data| match idx {
0usize => Some(Field::new("setting", self.setting())),
1usize => Some(Field::new("name_index", self.name_index())),
_ => None,
}),
data,
}
}
}