#[allow(unused_imports)]
use crate::codegen_prelude::*;
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct GaspMarker {
gasp_ranges_byte_len: usize,
}
impl GaspMarker {
fn version_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u16::RAW_BYTE_LEN
}
fn num_ranges_byte_range(&self) -> Range<usize> {
let start = self.version_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
fn gasp_ranges_byte_range(&self) -> Range<usize> {
let start = self.num_ranges_byte_range().end;
start..start + self.gasp_ranges_byte_len
}
}
impl TopLevelTable for Gasp<'_> {
const TAG: Tag = Tag::new(b"gasp");
}
impl<'a> FontRead<'a> for Gasp<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u16>();
let num_ranges: u16 = cursor.read()?;
let gasp_ranges_byte_len = (num_ranges as usize)
.checked_mul(GaspRange::RAW_BYTE_LEN)
.ok_or(ReadError::OutOfBounds)?;
cursor.advance_by(gasp_ranges_byte_len);
cursor.finish(GaspMarker {
gasp_ranges_byte_len,
})
}
}
pub type Gasp<'a> = TableRef<'a, GaspMarker>;
impl<'a> Gasp<'a> {
pub fn version(&self) -> u16 {
let range = self.shape.version_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn num_ranges(&self) -> u16 {
let range = self.shape.num_ranges_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn gasp_ranges(&self) -> &'a [GaspRange] {
let range = self.shape.gasp_ranges_byte_range();
self.data.read_array(range).unwrap()
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for Gasp<'a> {
fn type_name(&self) -> &str {
"Gasp"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
match idx {
0usize => Some(Field::new("version", self.version())),
1usize => Some(Field::new("num_ranges", self.num_ranges())),
2usize => Some(Field::new(
"gasp_ranges",
traversal::FieldType::array_of_records(
stringify!(GaspRange),
self.gasp_ranges(),
self.offset_data(),
),
)),
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> std::fmt::Debug for Gasp<'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 GaspRange {
pub range_max_ppem: BigEndian<u16>,
pub range_gasp_behavior: BigEndian<GaspRangeBehavior>,
}
impl GaspRange {
pub fn range_max_ppem(&self) -> u16 {
self.range_max_ppem.get()
}
pub fn range_gasp_behavior(&self) -> GaspRangeBehavior {
self.range_gasp_behavior.get()
}
}
impl FixedSize for GaspRange {
const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + GaspRangeBehavior::RAW_BYTE_LEN;
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeRecord<'a> for GaspRange {
fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
RecordResolver {
name: "GaspRange",
get_field: Box::new(move |idx, _data| match idx {
0usize => Some(Field::new("range_max_ppem", self.range_max_ppem())),
1usize => Some(Field::new(
"range_gasp_behavior",
self.range_gasp_behavior(),
)),
_ => None,
}),
data,
}
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct GaspRangeBehavior {
bits: u16,
}
impl GaspRangeBehavior {
pub const GASP_GRIDFIT: Self = Self { bits: 0x0001 };
pub const GASP_DOGRAY: Self = Self { bits: 0x0002 };
pub const GASP_SYMMETRIC_GRIDFIT: Self = Self { bits: 0x0004 };
pub const GASP_SYMMETRIC_SMOOTHING: Self = Self { bits: 0x0008 };
}
impl GaspRangeBehavior {
#[inline]
pub const fn empty() -> Self {
Self { bits: 0 }
}
#[inline]
pub const fn all() -> Self {
Self {
bits: Self::GASP_GRIDFIT.bits
| Self::GASP_DOGRAY.bits
| Self::GASP_SYMMETRIC_GRIDFIT.bits
| Self::GASP_SYMMETRIC_SMOOTHING.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 GaspRangeBehavior {
type Output = Self;
#[inline]
fn bitor(self, other: GaspRangeBehavior) -> Self {
Self {
bits: self.bits | other.bits,
}
}
}
impl std::ops::BitOrAssign for GaspRangeBehavior {
#[inline]
fn bitor_assign(&mut self, other: Self) {
self.bits |= other.bits;
}
}
impl std::ops::BitXor for GaspRangeBehavior {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
Self {
bits: self.bits ^ other.bits,
}
}
}
impl std::ops::BitXorAssign for GaspRangeBehavior {
#[inline]
fn bitxor_assign(&mut self, other: Self) {
self.bits ^= other.bits;
}
}
impl std::ops::BitAnd for GaspRangeBehavior {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self {
Self {
bits: self.bits & other.bits,
}
}
}
impl std::ops::BitAndAssign for GaspRangeBehavior {
#[inline]
fn bitand_assign(&mut self, other: Self) {
self.bits &= other.bits;
}
}
impl std::ops::Sub for GaspRangeBehavior {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self {
Self {
bits: self.bits & !other.bits,
}
}
}
impl std::ops::SubAssign for GaspRangeBehavior {
#[inline]
fn sub_assign(&mut self, other: Self) {
self.bits &= !other.bits;
}
}
impl std::ops::Not for GaspRangeBehavior {
type Output = Self;
#[inline]
fn not(self) -> Self {
Self { bits: !self.bits } & Self::all()
}
}
impl std::fmt::Debug for GaspRangeBehavior {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let members: &[(&str, Self)] = &[
("GASP_GRIDFIT", Self::GASP_GRIDFIT),
("GASP_DOGRAY", Self::GASP_DOGRAY),
("GASP_SYMMETRIC_GRIDFIT", Self::GASP_SYMMETRIC_GRIDFIT),
("GASP_SYMMETRIC_SMOOTHING", Self::GASP_SYMMETRIC_SMOOTHING),
];
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 GaspRangeBehavior {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Binary::fmt(&self.bits, f)
}
}
impl std::fmt::Octal for GaspRangeBehavior {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Octal::fmt(&self.bits, f)
}
}
impl std::fmt::LowerHex for GaspRangeBehavior {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::LowerHex::fmt(&self.bits, f)
}
}
impl std::fmt::UpperHex for GaspRangeBehavior {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::UpperHex::fmt(&self.bits, f)
}
}
impl font_types::Scalar for GaspRangeBehavior {
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)
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> From<GaspRangeBehavior> for FieldType<'a> {
fn from(src: GaspRangeBehavior) -> FieldType<'a> {
src.bits().into()
}
}