#[allow(unused_imports)]
use crate::codegen_prelude::*;
impl<'a> MinByteRange<'a> for Stat<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.offset_to_axis_value_offsets_byte_range().end
}
fn min_table_bytes(&self) -> &'a [u8] {
let range = self.min_byte_range();
self.data.as_bytes().get(range).unwrap_or_default()
}
}
impl TopLevelTable for Stat<'_> {
const TAG: Tag = Tag::new(b"STAT");
}
impl ReadArgs for Stat<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for Stat<'a> {
fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
#[allow(clippy::absurd_extreme_comparisons)]
if data.len() < Self::MIN_SIZE {
return Err(ReadError::OutOfBounds);
}
Ok(Self { data })
}
}
#[derive(Clone)]
pub struct Stat<'a> {
data: FontData<'a>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> Stat<'a> {
pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN
+ Offset32::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN
+ Offset32::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn version(&self) -> MajorMinor {
let range = self.version_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn design_axis_size(&self) -> u16 {
let range = self.design_axis_size_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn design_axis_count(&self) -> u16 {
let range = self.design_axis_count_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn design_axes_offset(&self) -> Offset32 {
let range = self.design_axes_offset_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn design_axes(&self) -> Result<&'a [AxisRecord], ReadError> {
let data = self.data;
let args = self.design_axis_count();
self.design_axes_offset().resolve_with_args(data, args)
}
pub fn axis_value_count(&self) -> u16 {
let range = self.axis_value_count_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn offset_to_axis_value_offsets(&self) -> Nullable<Offset32> {
let range = self.offset_to_axis_value_offsets_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn offset_to_axis_values(&self) -> Option<Result<AxisValueArray<'a>, ReadError>> {
let data = self.data;
let args = self.axis_value_count();
self.offset_to_axis_value_offsets()
.resolve_with_args(data, args)
}
pub fn elided_fallback_name_id(&self) -> Option<NameId> {
let range = self.elided_fallback_name_id_byte_range();
(!range.is_empty())
.then(|| self.data.read_at(range.start).ok())
.flatten()
}
pub fn version_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + MajorMinor::RAW_BYTE_LEN;
start..end
}
pub fn design_axis_size_byte_range(&self) -> Range<usize> {
let start = self.version_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn design_axis_count_byte_range(&self) -> Range<usize> {
let start = self.design_axis_size_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn design_axes_offset_byte_range(&self) -> Range<usize> {
let start = self.design_axis_count_byte_range().end;
let end = start + Offset32::RAW_BYTE_LEN;
start..end
}
pub fn axis_value_count_byte_range(&self) -> Range<usize> {
let start = self.design_axes_offset_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn offset_to_axis_value_offsets_byte_range(&self) -> Range<usize> {
let start = self.axis_value_count_byte_range().end;
let end = start + Offset32::RAW_BYTE_LEN;
start..end
}
pub fn elided_fallback_name_id_byte_range(&self) -> Range<usize> {
let start = self.offset_to_axis_value_offsets_byte_range().end;
let end = if self.version().compatible((1u16, 1u16)) {
start + NameId::RAW_BYTE_LEN
} else {
start
};
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(Stat::MIN_SIZE));
impl Default for Stat<'_> {
fn default() -> Self {
Self {
data: FontData::default_table_data(),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
#[repr(C)]
#[repr(packed)]
pub struct AxisRecord {
pub axis_tag: BigEndian<Tag>,
pub axis_name_id: BigEndian<NameId>,
pub axis_ordering: BigEndian<u16>,
}
impl AxisRecord {
pub fn axis_tag(&self) -> Tag {
self.axis_tag.get()
}
pub fn axis_name_id(&self) -> NameId {
self.axis_name_id.get()
}
pub fn axis_ordering(&self) -> u16 {
self.axis_ordering.get()
}
}
impl FixedSize for AxisRecord {
const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + NameId::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
}
impl<'a> MinByteRange<'a> for AxisValueArray<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.axis_value_offsets_byte_range().end
}
fn min_table_bytes(&self) -> &'a [u8] {
let range = self.min_byte_range();
self.data.as_bytes().get(range).unwrap_or_default()
}
}
impl ReadArgs for AxisValueArray<'_> {
type Args = u16;
}
impl<'a> FontRead<'a> for AxisValueArray<'a> {
fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> {
let axis_value_count = args;
#[allow(clippy::absurd_extreme_comparisons)]
if data.len() < Self::MIN_SIZE {
return Err(ReadError::OutOfBounds);
}
Ok(Self {
data,
axis_value_count,
})
}
}
impl<'a> AxisValueArray<'a> {
pub fn read(data: FontData<'a>, axis_value_count: u16) -> Result<Self, ReadError> {
let args = axis_value_count;
Self::read_with_args(data, args)
}
}
#[derive(Clone)]
pub struct AxisValueArray<'a> {
data: FontData<'a>,
axis_value_count: u16,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> AxisValueArray<'a> {
pub const MIN_SIZE: usize = 0;
basic_table_impls!(impl_the_methods);
pub fn axis_value_offsets(&self) -> &'a [BigEndian<Offset16>] {
let range = self.axis_value_offsets_byte_range();
self.data.read_array(range).ok().unwrap_or_default()
}
pub fn axis_values(&self) -> ArrayOfOffsets<'a, AxisValue<'a>, Offset16> {
let data = self.data;
let offsets = self.axis_value_offsets();
ArrayOfOffsets::new(offsets, data, ())
}
pub(crate) fn axis_value_count(&self) -> u16 {
self.axis_value_count
}
pub fn axis_value_offsets_byte_range(&self) -> Range<usize> {
let axis_value_count = self.axis_value_count();
let start = 0;
let end =
start + (transforms::to_usize(axis_value_count)).saturating_mul(Offset16::RAW_BYTE_LEN);
start..end
}
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(FontData::default_data_long_enough(AxisValueArray::MIN_SIZE));
impl Default for AxisValueArray<'_> {
fn default() -> Self {
Self {
data: FontData::default_table_data(),
axis_value_count: Default::default(),
}
}
}
#[derive(Clone)]
pub enum AxisValue<'a> {
Format1(AxisValueFormat1<'a>),
Format2(AxisValueFormat2<'a>),
Format3(AxisValueFormat3<'a>),
Format4(AxisValueFormat4<'a>),
}
impl Default for AxisValue<'_> {
fn default() -> Self {
Self::Format1(Default::default())
}
}
impl<'a> AxisValue<'a> {
pub fn offset_data(&self) -> FontData<'a> {
match self {
Self::Format1(item) => item.offset_data(),
Self::Format2(item) => item.offset_data(),
Self::Format3(item) => item.offset_data(),
Self::Format4(item) => item.offset_data(),
}
}
pub fn format(&self) -> u16 {
match self {
Self::Format1(item) => item.format(),
Self::Format2(item) => item.format(),
Self::Format3(item) => item.format(),
Self::Format4(item) => item.format(),
}
}
pub fn flags(&self) -> AxisValueTableFlags {
match self {
Self::Format1(item) => item.flags(),
Self::Format2(item) => item.flags(),
Self::Format3(item) => item.flags(),
Self::Format4(item) => item.flags(),
}
}
pub fn value_name_id(&self) -> NameId {
match self {
Self::Format1(item) => item.value_name_id(),
Self::Format2(item) => item.value_name_id(),
Self::Format3(item) => item.value_name_id(),
Self::Format4(item) => item.value_name_id(),
}
}
}
impl ReadArgs for AxisValue<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for AxisValue<'a> {
fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
let format: u16 = data.read_at(0usize)?;
match format {
AxisValueFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
AxisValueFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
AxisValueFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
AxisValueFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
other => Err(ReadError::InvalidFormat(other.into())),
}
}
}
impl<'a> MinByteRange<'a> for AxisValue<'a> {
fn min_byte_range(&self) -> Range<usize> {
match self {
Self::Format1(item) => item.min_byte_range(),
Self::Format2(item) => item.min_byte_range(),
Self::Format3(item) => item.min_byte_range(),
Self::Format4(item) => item.min_byte_range(),
}
}
fn min_table_bytes(&self) -> &'a [u8] {
match self {
Self::Format1(item) => item.min_table_bytes(),
Self::Format2(item) => item.min_table_bytes(),
Self::Format3(item) => item.min_table_bytes(),
Self::Format4(item) => item.min_table_bytes(),
}
}
}
impl Format<u16> for AxisValueFormat1<'_> {
const FORMAT: u16 = 1;
}
impl<'a> MinByteRange<'a> for AxisValueFormat1<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.value_byte_range().end
}
fn min_table_bytes(&self) -> &'a [u8] {
let range = self.min_byte_range();
self.data.as_bytes().get(range).unwrap_or_default()
}
}
impl ReadArgs for AxisValueFormat1<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for AxisValueFormat1<'a> {
fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
#[allow(clippy::absurd_extreme_comparisons)]
if data.len() < Self::MIN_SIZE {
return Err(ReadError::OutOfBounds);
}
Ok(Self { data })
}
}
#[derive(Clone)]
pub struct AxisValueFormat1<'a> {
data: FontData<'a>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> AxisValueFormat1<'a> {
pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN
+ AxisValueTableFlags::RAW_BYTE_LEN
+ NameId::RAW_BYTE_LEN
+ Fixed::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn format(&self) -> u16 {
let range = self.format_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn axis_index(&self) -> u16 {
let range = self.axis_index_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn flags(&self) -> AxisValueTableFlags {
let range = self.flags_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn value_name_id(&self) -> NameId {
let range = self.value_name_id_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn value(&self) -> Fixed {
let range = self.value_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn format_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn axis_index_byte_range(&self) -> Range<usize> {
let start = self.format_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn flags_byte_range(&self) -> Range<usize> {
let start = self.axis_index_byte_range().end;
let end = start + AxisValueTableFlags::RAW_BYTE_LEN;
start..end
}
pub fn value_name_id_byte_range(&self) -> Range<usize> {
let start = self.flags_byte_range().end;
let end = start + NameId::RAW_BYTE_LEN;
start..end
}
pub fn value_byte_range(&self) -> Range<usize> {
let start = self.value_name_id_byte_range().end;
let end = start + Fixed::RAW_BYTE_LEN;
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(
AxisValueFormat1::MIN_SIZE
));
impl Default for AxisValueFormat1<'_> {
fn default() -> Self {
Self {
data: FontData::default_format_1_u16_table_data(),
}
}
}
impl Format<u16> for AxisValueFormat2<'_> {
const FORMAT: u16 = 2;
}
impl<'a> MinByteRange<'a> for AxisValueFormat2<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.range_max_value_byte_range().end
}
fn min_table_bytes(&self) -> &'a [u8] {
let range = self.min_byte_range();
self.data.as_bytes().get(range).unwrap_or_default()
}
}
impl ReadArgs for AxisValueFormat2<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for AxisValueFormat2<'a> {
fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
#[allow(clippy::absurd_extreme_comparisons)]
if data.len() < Self::MIN_SIZE {
return Err(ReadError::OutOfBounds);
}
Ok(Self { data })
}
}
#[derive(Clone)]
pub struct AxisValueFormat2<'a> {
data: FontData<'a>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> AxisValueFormat2<'a> {
pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN
+ AxisValueTableFlags::RAW_BYTE_LEN
+ NameId::RAW_BYTE_LEN
+ Fixed::RAW_BYTE_LEN
+ Fixed::RAW_BYTE_LEN
+ Fixed::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn format(&self) -> u16 {
let range = self.format_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn axis_index(&self) -> u16 {
let range = self.axis_index_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn flags(&self) -> AxisValueTableFlags {
let range = self.flags_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn value_name_id(&self) -> NameId {
let range = self.value_name_id_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn nominal_value(&self) -> Fixed {
let range = self.nominal_value_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn range_min_value(&self) -> Fixed {
let range = self.range_min_value_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn range_max_value(&self) -> Fixed {
let range = self.range_max_value_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn format_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn axis_index_byte_range(&self) -> Range<usize> {
let start = self.format_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn flags_byte_range(&self) -> Range<usize> {
let start = self.axis_index_byte_range().end;
let end = start + AxisValueTableFlags::RAW_BYTE_LEN;
start..end
}
pub fn value_name_id_byte_range(&self) -> Range<usize> {
let start = self.flags_byte_range().end;
let end = start + NameId::RAW_BYTE_LEN;
start..end
}
pub fn nominal_value_byte_range(&self) -> Range<usize> {
let start = self.value_name_id_byte_range().end;
let end = start + Fixed::RAW_BYTE_LEN;
start..end
}
pub fn range_min_value_byte_range(&self) -> Range<usize> {
let start = self.nominal_value_byte_range().end;
let end = start + Fixed::RAW_BYTE_LEN;
start..end
}
pub fn range_max_value_byte_range(&self) -> Range<usize> {
let start = self.range_min_value_byte_range().end;
let end = start + Fixed::RAW_BYTE_LEN;
start..end
}
}
impl Format<u16> for AxisValueFormat3<'_> {
const FORMAT: u16 = 3;
}
impl<'a> MinByteRange<'a> for AxisValueFormat3<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.linked_value_byte_range().end
}
fn min_table_bytes(&self) -> &'a [u8] {
let range = self.min_byte_range();
self.data.as_bytes().get(range).unwrap_or_default()
}
}
impl ReadArgs for AxisValueFormat3<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for AxisValueFormat3<'a> {
fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
#[allow(clippy::absurd_extreme_comparisons)]
if data.len() < Self::MIN_SIZE {
return Err(ReadError::OutOfBounds);
}
Ok(Self { data })
}
}
#[derive(Clone)]
pub struct AxisValueFormat3<'a> {
data: FontData<'a>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> AxisValueFormat3<'a> {
pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN
+ AxisValueTableFlags::RAW_BYTE_LEN
+ NameId::RAW_BYTE_LEN
+ Fixed::RAW_BYTE_LEN
+ Fixed::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn format(&self) -> u16 {
let range = self.format_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn axis_index(&self) -> u16 {
let range = self.axis_index_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn flags(&self) -> AxisValueTableFlags {
let range = self.flags_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn value_name_id(&self) -> NameId {
let range = self.value_name_id_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn value(&self) -> Fixed {
let range = self.value_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn linked_value(&self) -> Fixed {
let range = self.linked_value_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn format_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn axis_index_byte_range(&self) -> Range<usize> {
let start = self.format_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn flags_byte_range(&self) -> Range<usize> {
let start = self.axis_index_byte_range().end;
let end = start + AxisValueTableFlags::RAW_BYTE_LEN;
start..end
}
pub fn value_name_id_byte_range(&self) -> Range<usize> {
let start = self.flags_byte_range().end;
let end = start + NameId::RAW_BYTE_LEN;
start..end
}
pub fn value_byte_range(&self) -> Range<usize> {
let start = self.value_name_id_byte_range().end;
let end = start + Fixed::RAW_BYTE_LEN;
start..end
}
pub fn linked_value_byte_range(&self) -> Range<usize> {
let start = self.value_byte_range().end;
let end = start + Fixed::RAW_BYTE_LEN;
start..end
}
}
impl Format<u16> for AxisValueFormat4<'_> {
const FORMAT: u16 = 4;
}
impl<'a> MinByteRange<'a> for AxisValueFormat4<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.axis_values_byte_range().end
}
fn min_table_bytes(&self) -> &'a [u8] {
let range = self.min_byte_range();
self.data.as_bytes().get(range).unwrap_or_default()
}
}
impl ReadArgs for AxisValueFormat4<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for AxisValueFormat4<'a> {
fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
#[allow(clippy::absurd_extreme_comparisons)]
if data.len() < Self::MIN_SIZE {
return Err(ReadError::OutOfBounds);
}
Ok(Self { data })
}
}
#[derive(Clone)]
pub struct AxisValueFormat4<'a> {
data: FontData<'a>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> AxisValueFormat4<'a> {
pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN
+ AxisValueTableFlags::RAW_BYTE_LEN
+ NameId::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn format(&self) -> u16 {
let range = self.format_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn axis_count(&self) -> u16 {
let range = self.axis_count_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn flags(&self) -> AxisValueTableFlags {
let range = self.flags_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn value_name_id(&self) -> NameId {
let range = self.value_name_id_byte_range();
self.data.read_at(range.start).ok().unwrap()
}
pub fn axis_values(&self) -> &'a [AxisValueRecord] {
let range = self.axis_values_byte_range();
self.data.read_array(range).ok().unwrap_or_default()
}
pub fn format_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn axis_count_byte_range(&self) -> Range<usize> {
let start = self.format_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn flags_byte_range(&self) -> Range<usize> {
let start = self.axis_count_byte_range().end;
let end = start + AxisValueTableFlags::RAW_BYTE_LEN;
start..end
}
pub fn value_name_id_byte_range(&self) -> Range<usize> {
let start = self.flags_byte_range().end;
let end = start + NameId::RAW_BYTE_LEN;
start..end
}
pub fn axis_values_byte_range(&self) -> Range<usize> {
let axis_count = self.axis_count();
let start = self.value_name_id_byte_range().end;
let end = start
+ (transforms::to_usize(axis_count)).saturating_mul(AxisValueRecord::RAW_BYTE_LEN);
start..end
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
#[repr(C)]
#[repr(packed)]
pub struct AxisValueRecord {
pub axis_index: BigEndian<u16>,
pub value: BigEndian<Fixed>,
}
impl AxisValueRecord {
pub fn axis_index(&self) -> u16 {
self.axis_index.get()
}
pub fn value(&self) -> Fixed {
self.value.get()
}
}
impl FixedSize for AxisValueRecord {
const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + Fixed::RAW_BYTE_LEN;
}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct AxisValueTableFlags {
bits: u16,
}
impl AxisValueTableFlags {
pub const OLDER_SIBLING_FONT_ATTRIBUTE: Self = Self { bits: 0x0001 };
pub const ELIDABLE_AXIS_VALUE_NAME: Self = Self { bits: 0x0002 };
}
impl AxisValueTableFlags {
#[inline]
pub const fn empty() -> Self {
Self { bits: 0 }
}
#[inline]
pub const fn all() -> Self {
Self {
bits: Self::OLDER_SIBLING_FONT_ATTRIBUTE.bits | Self::ELIDABLE_AXIS_VALUE_NAME.bits,
}
}
#[inline]
pub const fn bits(&self) -> u16 {
self.bits
}
#[inline]
pub const fn from_bits(bits: u16) -> Option<Self> {
if (bits & !Self::all().bits()) == 0 {
Some(Self { bits })
} else {
None
}
}
#[inline]
pub const fn from_bits_truncate(bits: u16) -> Self {
Self {
bits: bits & Self::all().bits,
}
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.bits() == Self::empty().bits()
}
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
!(Self {
bits: self.bits & other.bits,
})
.is_empty()
}
#[inline]
pub const fn contains(&self, other: Self) -> bool {
(self.bits & other.bits) == other.bits
}
#[inline]
pub fn insert(&mut self, other: Self) {
self.bits |= other.bits;
}
#[inline]
pub fn remove(&mut self, other: Self) {
self.bits &= !other.bits;
}
#[inline]
pub fn toggle(&mut self, other: Self) {
self.bits ^= other.bits;
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self {
bits: self.bits & other.bits,
}
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self {
bits: self.bits | other.bits,
}
}
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self {
bits: self.bits & !other.bits,
}
}
}
impl std::ops::BitOr for AxisValueTableFlags {
type Output = Self;
#[inline]
fn bitor(self, other: AxisValueTableFlags) -> Self {
Self {
bits: self.bits | other.bits,
}
}
}
impl std::ops::BitOrAssign for AxisValueTableFlags {
#[inline]
fn bitor_assign(&mut self, other: Self) {
self.bits |= other.bits;
}
}
impl std::ops::BitXor for AxisValueTableFlags {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
Self {
bits: self.bits ^ other.bits,
}
}
}
impl std::ops::BitXorAssign for AxisValueTableFlags {
#[inline]
fn bitxor_assign(&mut self, other: Self) {
self.bits ^= other.bits;
}
}
impl std::ops::BitAnd for AxisValueTableFlags {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self {
Self {
bits: self.bits & other.bits,
}
}
}
impl std::ops::BitAndAssign for AxisValueTableFlags {
#[inline]
fn bitand_assign(&mut self, other: Self) {
self.bits &= other.bits;
}
}
impl std::ops::Sub for AxisValueTableFlags {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self {
Self {
bits: self.bits & !other.bits,
}
}
}
impl std::ops::SubAssign for AxisValueTableFlags {
#[inline]
fn sub_assign(&mut self, other: Self) {
self.bits &= !other.bits;
}
}
impl std::ops::Not for AxisValueTableFlags {
type Output = Self;
#[inline]
fn not(self) -> Self {
Self { bits: !self.bits } & Self::all()
}
}
impl std::fmt::Debug for AxisValueTableFlags {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let members: &[(&str, Self)] = &[
(
"OLDER_SIBLING_FONT_ATTRIBUTE",
Self::OLDER_SIBLING_FONT_ATTRIBUTE,
),
("ELIDABLE_AXIS_VALUE_NAME", Self::ELIDABLE_AXIS_VALUE_NAME),
];
let mut first = true;
for (name, value) in members {
if self.contains(*value) {
if !first {
f.write_str(" | ")?;
}
first = false;
f.write_str(name)?;
}
}
if first {
f.write_str("(empty)")?;
}
Ok(())
}
}
impl std::fmt::Binary for AxisValueTableFlags {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Binary::fmt(&self.bits, f)
}
}
impl std::fmt::Octal for AxisValueTableFlags {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Octal::fmt(&self.bits, f)
}
}
impl std::fmt::LowerHex for AxisValueTableFlags {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::LowerHex::fmt(&self.bits, f)
}
}
impl std::fmt::UpperHex for AxisValueTableFlags {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::UpperHex::fmt(&self.bits, f)
}
}
impl font_types::Scalar for AxisValueTableFlags {
type Raw = <u16 as font_types::Scalar>::Raw;
fn to_raw(self) -> Self::Raw {
self.bits().to_raw()
}
fn from_raw(raw: Self::Raw) -> Self {
let t = <u16>::from_raw(raw);
Self::from_bits_truncate(t)
}
}