#[allow(unused_imports)]
use crate::codegen_prelude::*;
impl<'a> MinByteRange<'a> for Math<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.math_variants_offset_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 Math<'_> {
const TAG: Tag = Tag::new(b"MATH");
}
impl ReadArgs for Math<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for Math<'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);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data })
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct MathFixedHeader {
pub version: BigEndian<MajorMinor>,
pub math_constants_offset: BigEndian<Offset16>,
pub math_glyph_info_offset: BigEndian<Offset16>,
pub math_variants_offset: BigEndian<Offset16>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(std::mem::size_of::<MathFixedHeader>() <= Math::MIN_SIZE);
#[derive(Clone)]
pub struct Math<'a> {
data: TableDataRef<'a, MathFixedHeader>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> Math<'a> {
pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn version(&self) -> MajorMinor {
self.data.header().version.get()
}
pub fn math_constants_offset(&self) -> Offset16 {
self.data.header().math_constants_offset.get()
}
pub fn math_constants(&self) -> Result<MathConstants<'a>, ReadError> {
let data = self.offset_data();
self.math_constants_offset().resolve(data)
}
pub fn math_glyph_info_offset(&self) -> Offset16 {
self.data.header().math_glyph_info_offset.get()
}
pub fn math_glyph_info(&self) -> Result<MathGlyphInfo<'a>, ReadError> {
let data = self.offset_data();
self.math_glyph_info_offset().resolve(data)
}
pub fn math_variants_offset(&self) -> Offset16 {
self.data.header().math_variants_offset.get()
}
pub fn math_variants(&self) -> Result<MathVariants<'a>, ReadError> {
let data = self.offset_data();
self.math_variants_offset().resolve(data)
}
pub fn version_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + MajorMinor::RAW_BYTE_LEN;
start..end
}
pub fn math_constants_offset_byte_range(&self) -> Range<usize> {
let start = self.version_byte_range().end;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn math_glyph_info_offset_byte_range(&self) -> Range<usize> {
let start = self.math_constants_offset_byte_range().end;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn math_variants_offset_byte_range(&self) -> Range<usize> {
let start = self.math_glyph_info_offset_byte_range().end;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(Math::MIN_SIZE));
impl Default for Math<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
}
}
}
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
#[repr(C)]
#[repr(packed)]
pub struct MathValueRecord {
pub value: BigEndian<FWord>,
pub device_offset: BigEndian<Nullable<Offset16>>,
}
impl MathValueRecord {
pub fn value(&self) -> FWord {
self.value.get()
}
pub fn device_offset(&self) -> Nullable<Offset16> {
self.device_offset.get()
}
pub fn device<'a>(
&self,
data: FontData<'a>,
) -> Option<Result<DeviceOrVariationIndex<'a>, ReadError>> {
self.device_offset().resolve(data)
}
}
impl FixedSize for MathValueRecord {
const RAW_BYTE_LEN: usize = FWord::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN;
}
impl<'a> MinByteRange<'a> for MathConstants<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.radical_degree_bottom_raise_percent_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 ReadArgs for MathConstants<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for MathConstants<'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);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data })
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct MathConstantsFixedHeader {
pub script_percent_scale_down: BigEndian<i16>,
pub script_script_percent_scale_down: BigEndian<i16>,
pub delimited_sub_formula_min_height: BigEndian<UfWord>,
pub display_operator_min_height: BigEndian<UfWord>,
pub math_leading: MathValueRecord,
pub axis_height: MathValueRecord,
pub accent_base_height: MathValueRecord,
pub flattened_accent_base_height: MathValueRecord,
pub subscript_shift_down: MathValueRecord,
pub subscript_top_max: MathValueRecord,
pub subscript_baseline_drop_min: MathValueRecord,
pub superscript_shift_up: MathValueRecord,
pub superscript_shift_up_cramped: MathValueRecord,
pub superscript_bottom_min: MathValueRecord,
pub superscript_baseline_drop_max: MathValueRecord,
pub sub_superscript_gap_min: MathValueRecord,
pub superscript_bottom_max_with_subscript: MathValueRecord,
pub space_after_script: MathValueRecord,
pub upper_limit_gap_min: MathValueRecord,
pub upper_limit_baseline_rise_min: MathValueRecord,
pub lower_limit_gap_min: MathValueRecord,
pub lower_limit_baseline_drop_min: MathValueRecord,
pub stack_top_shift_up: MathValueRecord,
pub stack_top_display_style_shift_up: MathValueRecord,
pub stack_bottom_shift_down: MathValueRecord,
pub stack_bottom_display_style_shift_down: MathValueRecord,
pub stack_gap_min: MathValueRecord,
pub stack_display_style_gap_min: MathValueRecord,
pub stretch_stack_top_shift_up: MathValueRecord,
pub stretch_stack_bottom_shift_down: MathValueRecord,
pub stretch_stack_gap_above_min: MathValueRecord,
pub stretch_stack_gap_below_min: MathValueRecord,
pub fraction_numerator_shift_up: MathValueRecord,
pub fraction_numerator_display_style_shift_up: MathValueRecord,
pub fraction_denominator_shift_down: MathValueRecord,
pub fraction_denominator_display_style_shift_down: MathValueRecord,
pub fraction_numerator_gap_min: MathValueRecord,
pub fraction_num_display_style_gap_min: MathValueRecord,
pub fraction_rule_thickness: MathValueRecord,
pub fraction_denominator_gap_min: MathValueRecord,
pub fraction_denom_display_style_gap_min: MathValueRecord,
pub skewed_fraction_horizontal_gap: MathValueRecord,
pub skewed_fraction_vertical_gap: MathValueRecord,
pub overbar_vertical_gap: MathValueRecord,
pub overbar_rule_thickness: MathValueRecord,
pub overbar_extra_ascender: MathValueRecord,
pub underbar_vertical_gap: MathValueRecord,
pub underbar_rule_thickness: MathValueRecord,
pub underbar_extra_descender: MathValueRecord,
pub radical_vertical_gap: MathValueRecord,
pub radical_display_style_vertical_gap: MathValueRecord,
pub radical_rule_thickness: MathValueRecord,
pub radical_extra_ascender: MathValueRecord,
pub radical_kern_before_degree: MathValueRecord,
pub radical_kern_after_degree: MathValueRecord,
pub radical_degree_bottom_raise_percent: BigEndian<i16>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(std::mem::size_of::<MathConstantsFixedHeader>() <= MathConstants::MIN_SIZE);
#[derive(Clone)]
pub struct MathConstants<'a> {
data: TableDataRef<'a, MathConstantsFixedHeader>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> MathConstants<'a> {
pub const MIN_SIZE: usize = (i16::RAW_BYTE_LEN
+ i16::RAW_BYTE_LEN
+ UfWord::RAW_BYTE_LEN
+ UfWord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ MathValueRecord::RAW_BYTE_LEN
+ i16::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn script_percent_scale_down(&self) -> i16 {
self.data.header().script_percent_scale_down.get()
}
pub fn script_script_percent_scale_down(&self) -> i16 {
self.data.header().script_script_percent_scale_down.get()
}
pub fn delimited_sub_formula_min_height(&self) -> UfWord {
self.data.header().delimited_sub_formula_min_height.get()
}
pub fn display_operator_min_height(&self) -> UfWord {
self.data.header().display_operator_min_height.get()
}
pub fn math_leading(&self) -> &'a MathValueRecord {
&self.data.header().math_leading
}
pub fn axis_height(&self) -> &'a MathValueRecord {
&self.data.header().axis_height
}
pub fn accent_base_height(&self) -> &'a MathValueRecord {
&self.data.header().accent_base_height
}
pub fn flattened_accent_base_height(&self) -> &'a MathValueRecord {
&self.data.header().flattened_accent_base_height
}
pub fn subscript_shift_down(&self) -> &'a MathValueRecord {
&self.data.header().subscript_shift_down
}
pub fn subscript_top_max(&self) -> &'a MathValueRecord {
&self.data.header().subscript_top_max
}
pub fn subscript_baseline_drop_min(&self) -> &'a MathValueRecord {
&self.data.header().subscript_baseline_drop_min
}
pub fn superscript_shift_up(&self) -> &'a MathValueRecord {
&self.data.header().superscript_shift_up
}
pub fn superscript_shift_up_cramped(&self) -> &'a MathValueRecord {
&self.data.header().superscript_shift_up_cramped
}
pub fn superscript_bottom_min(&self) -> &'a MathValueRecord {
&self.data.header().superscript_bottom_min
}
pub fn superscript_baseline_drop_max(&self) -> &'a MathValueRecord {
&self.data.header().superscript_baseline_drop_max
}
pub fn sub_superscript_gap_min(&self) -> &'a MathValueRecord {
&self.data.header().sub_superscript_gap_min
}
pub fn superscript_bottom_max_with_subscript(&self) -> &'a MathValueRecord {
&self.data.header().superscript_bottom_max_with_subscript
}
pub fn space_after_script(&self) -> &'a MathValueRecord {
&self.data.header().space_after_script
}
pub fn upper_limit_gap_min(&self) -> &'a MathValueRecord {
&self.data.header().upper_limit_gap_min
}
pub fn upper_limit_baseline_rise_min(&self) -> &'a MathValueRecord {
&self.data.header().upper_limit_baseline_rise_min
}
pub fn lower_limit_gap_min(&self) -> &'a MathValueRecord {
&self.data.header().lower_limit_gap_min
}
pub fn lower_limit_baseline_drop_min(&self) -> &'a MathValueRecord {
&self.data.header().lower_limit_baseline_drop_min
}
pub fn stack_top_shift_up(&self) -> &'a MathValueRecord {
&self.data.header().stack_top_shift_up
}
pub fn stack_top_display_style_shift_up(&self) -> &'a MathValueRecord {
&self.data.header().stack_top_display_style_shift_up
}
pub fn stack_bottom_shift_down(&self) -> &'a MathValueRecord {
&self.data.header().stack_bottom_shift_down
}
pub fn stack_bottom_display_style_shift_down(&self) -> &'a MathValueRecord {
&self.data.header().stack_bottom_display_style_shift_down
}
pub fn stack_gap_min(&self) -> &'a MathValueRecord {
&self.data.header().stack_gap_min
}
pub fn stack_display_style_gap_min(&self) -> &'a MathValueRecord {
&self.data.header().stack_display_style_gap_min
}
pub fn stretch_stack_top_shift_up(&self) -> &'a MathValueRecord {
&self.data.header().stretch_stack_top_shift_up
}
pub fn stretch_stack_bottom_shift_down(&self) -> &'a MathValueRecord {
&self.data.header().stretch_stack_bottom_shift_down
}
pub fn stretch_stack_gap_above_min(&self) -> &'a MathValueRecord {
&self.data.header().stretch_stack_gap_above_min
}
pub fn stretch_stack_gap_below_min(&self) -> &'a MathValueRecord {
&self.data.header().stretch_stack_gap_below_min
}
pub fn fraction_numerator_shift_up(&self) -> &'a MathValueRecord {
&self.data.header().fraction_numerator_shift_up
}
pub fn fraction_numerator_display_style_shift_up(&self) -> &'a MathValueRecord {
&self.data.header().fraction_numerator_display_style_shift_up
}
pub fn fraction_denominator_shift_down(&self) -> &'a MathValueRecord {
&self.data.header().fraction_denominator_shift_down
}
pub fn fraction_denominator_display_style_shift_down(&self) -> &'a MathValueRecord {
&self
.data
.header()
.fraction_denominator_display_style_shift_down
}
pub fn fraction_numerator_gap_min(&self) -> &'a MathValueRecord {
&self.data.header().fraction_numerator_gap_min
}
pub fn fraction_num_display_style_gap_min(&self) -> &'a MathValueRecord {
&self.data.header().fraction_num_display_style_gap_min
}
pub fn fraction_rule_thickness(&self) -> &'a MathValueRecord {
&self.data.header().fraction_rule_thickness
}
pub fn fraction_denominator_gap_min(&self) -> &'a MathValueRecord {
&self.data.header().fraction_denominator_gap_min
}
pub fn fraction_denom_display_style_gap_min(&self) -> &'a MathValueRecord {
&self.data.header().fraction_denom_display_style_gap_min
}
pub fn skewed_fraction_horizontal_gap(&self) -> &'a MathValueRecord {
&self.data.header().skewed_fraction_horizontal_gap
}
pub fn skewed_fraction_vertical_gap(&self) -> &'a MathValueRecord {
&self.data.header().skewed_fraction_vertical_gap
}
pub fn overbar_vertical_gap(&self) -> &'a MathValueRecord {
&self.data.header().overbar_vertical_gap
}
pub fn overbar_rule_thickness(&self) -> &'a MathValueRecord {
&self.data.header().overbar_rule_thickness
}
pub fn overbar_extra_ascender(&self) -> &'a MathValueRecord {
&self.data.header().overbar_extra_ascender
}
pub fn underbar_vertical_gap(&self) -> &'a MathValueRecord {
&self.data.header().underbar_vertical_gap
}
pub fn underbar_rule_thickness(&self) -> &'a MathValueRecord {
&self.data.header().underbar_rule_thickness
}
pub fn underbar_extra_descender(&self) -> &'a MathValueRecord {
&self.data.header().underbar_extra_descender
}
pub fn radical_vertical_gap(&self) -> &'a MathValueRecord {
&self.data.header().radical_vertical_gap
}
pub fn radical_display_style_vertical_gap(&self) -> &'a MathValueRecord {
&self.data.header().radical_display_style_vertical_gap
}
pub fn radical_rule_thickness(&self) -> &'a MathValueRecord {
&self.data.header().radical_rule_thickness
}
pub fn radical_extra_ascender(&self) -> &'a MathValueRecord {
&self.data.header().radical_extra_ascender
}
pub fn radical_kern_before_degree(&self) -> &'a MathValueRecord {
&self.data.header().radical_kern_before_degree
}
pub fn radical_kern_after_degree(&self) -> &'a MathValueRecord {
&self.data.header().radical_kern_after_degree
}
pub fn radical_degree_bottom_raise_percent(&self) -> i16 {
self.data.header().radical_degree_bottom_raise_percent.get()
}
pub fn script_percent_scale_down_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + i16::RAW_BYTE_LEN;
start..end
}
pub fn script_script_percent_scale_down_byte_range(&self) -> Range<usize> {
let start = self.script_percent_scale_down_byte_range().end;
let end = start + i16::RAW_BYTE_LEN;
start..end
}
pub fn delimited_sub_formula_min_height_byte_range(&self) -> Range<usize> {
let start = self.script_script_percent_scale_down_byte_range().end;
let end = start + UfWord::RAW_BYTE_LEN;
start..end
}
pub fn display_operator_min_height_byte_range(&self) -> Range<usize> {
let start = self.delimited_sub_formula_min_height_byte_range().end;
let end = start + UfWord::RAW_BYTE_LEN;
start..end
}
pub fn math_leading_byte_range(&self) -> Range<usize> {
let start = self.display_operator_min_height_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn axis_height_byte_range(&self) -> Range<usize> {
let start = self.math_leading_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn accent_base_height_byte_range(&self) -> Range<usize> {
let start = self.axis_height_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn flattened_accent_base_height_byte_range(&self) -> Range<usize> {
let start = self.accent_base_height_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn subscript_shift_down_byte_range(&self) -> Range<usize> {
let start = self.flattened_accent_base_height_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn subscript_top_max_byte_range(&self) -> Range<usize> {
let start = self.subscript_shift_down_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn subscript_baseline_drop_min_byte_range(&self) -> Range<usize> {
let start = self.subscript_top_max_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn superscript_shift_up_byte_range(&self) -> Range<usize> {
let start = self.subscript_baseline_drop_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn superscript_shift_up_cramped_byte_range(&self) -> Range<usize> {
let start = self.superscript_shift_up_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn superscript_bottom_min_byte_range(&self) -> Range<usize> {
let start = self.superscript_shift_up_cramped_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn superscript_baseline_drop_max_byte_range(&self) -> Range<usize> {
let start = self.superscript_bottom_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn sub_superscript_gap_min_byte_range(&self) -> Range<usize> {
let start = self.superscript_baseline_drop_max_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn superscript_bottom_max_with_subscript_byte_range(&self) -> Range<usize> {
let start = self.sub_superscript_gap_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn space_after_script_byte_range(&self) -> Range<usize> {
let start = self.superscript_bottom_max_with_subscript_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn upper_limit_gap_min_byte_range(&self) -> Range<usize> {
let start = self.space_after_script_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn upper_limit_baseline_rise_min_byte_range(&self) -> Range<usize> {
let start = self.upper_limit_gap_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn lower_limit_gap_min_byte_range(&self) -> Range<usize> {
let start = self.upper_limit_baseline_rise_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn lower_limit_baseline_drop_min_byte_range(&self) -> Range<usize> {
let start = self.lower_limit_gap_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn stack_top_shift_up_byte_range(&self) -> Range<usize> {
let start = self.lower_limit_baseline_drop_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn stack_top_display_style_shift_up_byte_range(&self) -> Range<usize> {
let start = self.stack_top_shift_up_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn stack_bottom_shift_down_byte_range(&self) -> Range<usize> {
let start = self.stack_top_display_style_shift_up_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn stack_bottom_display_style_shift_down_byte_range(&self) -> Range<usize> {
let start = self.stack_bottom_shift_down_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn stack_gap_min_byte_range(&self) -> Range<usize> {
let start = self.stack_bottom_display_style_shift_down_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn stack_display_style_gap_min_byte_range(&self) -> Range<usize> {
let start = self.stack_gap_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn stretch_stack_top_shift_up_byte_range(&self) -> Range<usize> {
let start = self.stack_display_style_gap_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn stretch_stack_bottom_shift_down_byte_range(&self) -> Range<usize> {
let start = self.stretch_stack_top_shift_up_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn stretch_stack_gap_above_min_byte_range(&self) -> Range<usize> {
let start = self.stretch_stack_bottom_shift_down_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn stretch_stack_gap_below_min_byte_range(&self) -> Range<usize> {
let start = self.stretch_stack_gap_above_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn fraction_numerator_shift_up_byte_range(&self) -> Range<usize> {
let start = self.stretch_stack_gap_below_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn fraction_numerator_display_style_shift_up_byte_range(&self) -> Range<usize> {
let start = self.fraction_numerator_shift_up_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn fraction_denominator_shift_down_byte_range(&self) -> Range<usize> {
let start = self
.fraction_numerator_display_style_shift_up_byte_range()
.end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn fraction_denominator_display_style_shift_down_byte_range(&self) -> Range<usize> {
let start = self.fraction_denominator_shift_down_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn fraction_numerator_gap_min_byte_range(&self) -> Range<usize> {
let start = self
.fraction_denominator_display_style_shift_down_byte_range()
.end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn fraction_num_display_style_gap_min_byte_range(&self) -> Range<usize> {
let start = self.fraction_numerator_gap_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn fraction_rule_thickness_byte_range(&self) -> Range<usize> {
let start = self.fraction_num_display_style_gap_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn fraction_denominator_gap_min_byte_range(&self) -> Range<usize> {
let start = self.fraction_rule_thickness_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn fraction_denom_display_style_gap_min_byte_range(&self) -> Range<usize> {
let start = self.fraction_denominator_gap_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn skewed_fraction_horizontal_gap_byte_range(&self) -> Range<usize> {
let start = self.fraction_denom_display_style_gap_min_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn skewed_fraction_vertical_gap_byte_range(&self) -> Range<usize> {
let start = self.skewed_fraction_horizontal_gap_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn overbar_vertical_gap_byte_range(&self) -> Range<usize> {
let start = self.skewed_fraction_vertical_gap_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn overbar_rule_thickness_byte_range(&self) -> Range<usize> {
let start = self.overbar_vertical_gap_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn overbar_extra_ascender_byte_range(&self) -> Range<usize> {
let start = self.overbar_rule_thickness_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn underbar_vertical_gap_byte_range(&self) -> Range<usize> {
let start = self.overbar_extra_ascender_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn underbar_rule_thickness_byte_range(&self) -> Range<usize> {
let start = self.underbar_vertical_gap_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn underbar_extra_descender_byte_range(&self) -> Range<usize> {
let start = self.underbar_rule_thickness_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn radical_vertical_gap_byte_range(&self) -> Range<usize> {
let start = self.underbar_extra_descender_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn radical_display_style_vertical_gap_byte_range(&self) -> Range<usize> {
let start = self.radical_vertical_gap_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn radical_rule_thickness_byte_range(&self) -> Range<usize> {
let start = self.radical_display_style_vertical_gap_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn radical_extra_ascender_byte_range(&self) -> Range<usize> {
let start = self.radical_rule_thickness_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn radical_kern_before_degree_byte_range(&self) -> Range<usize> {
let start = self.radical_extra_ascender_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn radical_kern_after_degree_byte_range(&self) -> Range<usize> {
let start = self.radical_kern_before_degree_byte_range().end;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn radical_degree_bottom_raise_percent_byte_range(&self) -> Range<usize> {
let start = self.radical_kern_after_degree_byte_range().end;
let end = start + i16::RAW_BYTE_LEN;
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(MathConstants::MIN_SIZE));
impl Default for MathConstants<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
}
}
}
impl<'a> MinByteRange<'a> for MathGlyphInfo<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.math_kern_info_offset_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 ReadArgs for MathGlyphInfo<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for MathGlyphInfo<'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);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data })
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct MathGlyphInfoFixedHeader {
pub math_italics_correction_info_offset: BigEndian<Nullable<Offset16>>,
pub math_top_accent_attachment_offset: BigEndian<Nullable<Offset16>>,
pub extended_shape_coverage_offset: BigEndian<Nullable<Offset16>>,
pub math_kern_info_offset: BigEndian<Nullable<Offset16>>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(std::mem::size_of::<MathGlyphInfoFixedHeader>() <= MathGlyphInfo::MIN_SIZE);
#[derive(Clone)]
pub struct MathGlyphInfo<'a> {
data: TableDataRef<'a, MathGlyphInfoFixedHeader>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> MathGlyphInfo<'a> {
pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn math_italics_correction_info_offset(&self) -> Nullable<Offset16> {
self.data.header().math_italics_correction_info_offset.get()
}
pub fn math_italics_correction_info(
&self,
) -> Option<Result<MathItalicsCorrectionInfo<'a>, ReadError>> {
let data = self.offset_data();
self.math_italics_correction_info_offset().resolve(data)
}
pub fn math_top_accent_attachment_offset(&self) -> Nullable<Offset16> {
self.data.header().math_top_accent_attachment_offset.get()
}
pub fn math_top_accent_attachment(
&self,
) -> Option<Result<MathTopAccentAttachment<'a>, ReadError>> {
let data = self.offset_data();
self.math_top_accent_attachment_offset().resolve(data)
}
pub fn extended_shape_coverage_offset(&self) -> Nullable<Offset16> {
self.data.header().extended_shape_coverage_offset.get()
}
pub fn extended_shape_coverage(&self) -> Option<Result<CoverageTable<'a>, ReadError>> {
let data = self.offset_data();
self.extended_shape_coverage_offset().resolve(data)
}
pub fn math_kern_info_offset(&self) -> Nullable<Offset16> {
self.data.header().math_kern_info_offset.get()
}
pub fn math_kern_info(&self) -> Option<Result<MathKernInfo<'a>, ReadError>> {
let data = self.offset_data();
self.math_kern_info_offset().resolve(data)
}
pub fn math_italics_correction_info_offset_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn math_top_accent_attachment_offset_byte_range(&self) -> Range<usize> {
let start = self.math_italics_correction_info_offset_byte_range().end;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn extended_shape_coverage_offset_byte_range(&self) -> Range<usize> {
let start = self.math_top_accent_attachment_offset_byte_range().end;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn math_kern_info_offset_byte_range(&self) -> Range<usize> {
let start = self.extended_shape_coverage_offset_byte_range().end;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(MathGlyphInfo::MIN_SIZE));
impl Default for MathGlyphInfo<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
}
}
}
impl<'a> MinByteRange<'a> for MathItalicsCorrectionInfo<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.italics_correction_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 ReadArgs for MathItalicsCorrectionInfo<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for MathItalicsCorrectionInfo<'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);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data })
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct MathItalicsCorrectionInfoFixedHeader {
pub coverage_offset: BigEndian<Offset16>,
pub italics_correction_count: BigEndian<u16>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(
std::mem::size_of::<MathItalicsCorrectionInfoFixedHeader>()
<= MathItalicsCorrectionInfo::MIN_SIZE
);
#[derive(Clone)]
pub struct MathItalicsCorrectionInfo<'a> {
data: TableDataRef<'a, MathItalicsCorrectionInfoFixedHeader>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> MathItalicsCorrectionInfo<'a> {
pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn coverage_offset(&self) -> Offset16 {
self.data.header().coverage_offset.get()
}
pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
let data = self.offset_data();
self.coverage_offset().resolve(data)
}
pub fn italics_correction_count(&self) -> u16 {
self.data.header().italics_correction_count.get()
}
pub fn italics_correction(&self) -> &'a [MathValueRecord] {
let range = self.italics_correction_byte_range();
self.offset_data()
.read_array(range)
.ok()
.unwrap_or_default()
}
pub fn coverage_offset_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn italics_correction_count_byte_range(&self) -> Range<usize> {
let start = self.coverage_offset_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn italics_correction_byte_range(&self) -> Range<usize> {
let italics_correction_count = self.italics_correction_count();
let start = self.italics_correction_count_byte_range().end;
let end = start
+ (transforms::to_usize(italics_correction_count))
.saturating_mul(MathValueRecord::RAW_BYTE_LEN);
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(
MathItalicsCorrectionInfo::MIN_SIZE
));
impl Default for MathItalicsCorrectionInfo<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
}
}
}
impl<'a> MinByteRange<'a> for MathTopAccentAttachment<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.top_accent_attachment_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 ReadArgs for MathTopAccentAttachment<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for MathTopAccentAttachment<'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);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data })
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct MathTopAccentAttachmentFixedHeader {
pub top_accent_coverage_offset: BigEndian<Offset16>,
pub top_accent_attachment_count: BigEndian<u16>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(
std::mem::size_of::<MathTopAccentAttachmentFixedHeader>() <= MathTopAccentAttachment::MIN_SIZE
);
#[derive(Clone)]
pub struct MathTopAccentAttachment<'a> {
data: TableDataRef<'a, MathTopAccentAttachmentFixedHeader>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> MathTopAccentAttachment<'a> {
pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn top_accent_coverage_offset(&self) -> Offset16 {
self.data.header().top_accent_coverage_offset.get()
}
pub fn top_accent_coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
let data = self.offset_data();
self.top_accent_coverage_offset().resolve(data)
}
pub fn top_accent_attachment_count(&self) -> u16 {
self.data.header().top_accent_attachment_count.get()
}
pub fn top_accent_attachment(&self) -> &'a [MathValueRecord] {
let range = self.top_accent_attachment_byte_range();
self.offset_data()
.read_array(range)
.ok()
.unwrap_or_default()
}
pub fn top_accent_coverage_offset_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn top_accent_attachment_count_byte_range(&self) -> Range<usize> {
let start = self.top_accent_coverage_offset_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn top_accent_attachment_byte_range(&self) -> Range<usize> {
let top_accent_attachment_count = self.top_accent_attachment_count();
let start = self.top_accent_attachment_count_byte_range().end;
let end = start
+ (transforms::to_usize(top_accent_attachment_count))
.saturating_mul(MathValueRecord::RAW_BYTE_LEN);
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(
MathTopAccentAttachment::MIN_SIZE
));
impl Default for MathTopAccentAttachment<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
}
}
}
impl<'a> MinByteRange<'a> for MathKernInfo<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.math_kern_info_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 ReadArgs for MathKernInfo<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for MathKernInfo<'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);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data })
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct MathKernInfoFixedHeader {
pub math_kern_coverage_offset: BigEndian<Offset16>,
pub math_kern_count: BigEndian<u16>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(std::mem::size_of::<MathKernInfoFixedHeader>() <= MathKernInfo::MIN_SIZE);
#[derive(Clone)]
pub struct MathKernInfo<'a> {
data: TableDataRef<'a, MathKernInfoFixedHeader>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> MathKernInfo<'a> {
pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn math_kern_coverage_offset(&self) -> Offset16 {
self.data.header().math_kern_coverage_offset.get()
}
pub fn math_kern_coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
let data = self.offset_data();
self.math_kern_coverage_offset().resolve(data)
}
pub fn math_kern_count(&self) -> u16 {
self.data.header().math_kern_count.get()
}
pub fn math_kern_info_records(&self) -> &'a [MathKernInfoRecord] {
let range = self.math_kern_info_records_byte_range();
self.offset_data()
.read_array(range)
.ok()
.unwrap_or_default()
}
pub fn math_kern_coverage_offset_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn math_kern_count_byte_range(&self) -> Range<usize> {
let start = self.math_kern_coverage_offset_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn math_kern_info_records_byte_range(&self) -> Range<usize> {
let math_kern_count = self.math_kern_count();
let start = self.math_kern_count_byte_range().end;
let end = start
+ (transforms::to_usize(math_kern_count))
.saturating_mul(MathKernInfoRecord::RAW_BYTE_LEN);
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(MathKernInfo::MIN_SIZE));
impl Default for MathKernInfo<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
}
}
}
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
#[repr(C)]
#[repr(packed)]
pub struct MathKernInfoRecord {
pub top_right_math_kern_offset: BigEndian<Nullable<Offset16>>,
pub top_left_math_kern_offset: BigEndian<Nullable<Offset16>>,
pub bottom_right_math_kern_offset: BigEndian<Nullable<Offset16>>,
pub bottom_left_math_kern_offset: BigEndian<Nullable<Offset16>>,
}
impl MathKernInfoRecord {
pub fn top_right_math_kern_offset(&self) -> Nullable<Offset16> {
self.top_right_math_kern_offset.get()
}
pub fn top_right_math_kern<'a>(
&self,
data: FontData<'a>,
) -> Option<Result<MathKern<'a>, ReadError>> {
self.top_right_math_kern_offset().resolve(data)
}
pub fn top_left_math_kern_offset(&self) -> Nullable<Offset16> {
self.top_left_math_kern_offset.get()
}
pub fn top_left_math_kern<'a>(
&self,
data: FontData<'a>,
) -> Option<Result<MathKern<'a>, ReadError>> {
self.top_left_math_kern_offset().resolve(data)
}
pub fn bottom_right_math_kern_offset(&self) -> Nullable<Offset16> {
self.bottom_right_math_kern_offset.get()
}
pub fn bottom_right_math_kern<'a>(
&self,
data: FontData<'a>,
) -> Option<Result<MathKern<'a>, ReadError>> {
self.bottom_right_math_kern_offset().resolve(data)
}
pub fn bottom_left_math_kern_offset(&self) -> Nullable<Offset16> {
self.bottom_left_math_kern_offset.get()
}
pub fn bottom_left_math_kern<'a>(
&self,
data: FontData<'a>,
) -> Option<Result<MathKern<'a>, ReadError>> {
self.bottom_left_math_kern_offset().resolve(data)
}
}
impl FixedSize for MathKernInfoRecord {
const RAW_BYTE_LEN: usize = Offset16::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN;
}
impl<'a> MinByteRange<'a> for MathKern<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.kern_values_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 ReadArgs for MathKern<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for MathKern<'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);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data })
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct MathKernFixedHeader {
pub height_count: BigEndian<u16>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(std::mem::size_of::<MathKernFixedHeader>() <= MathKern::MIN_SIZE);
#[derive(Clone)]
pub struct MathKern<'a> {
data: TableDataRef<'a, MathKernFixedHeader>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> MathKern<'a> {
pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
basic_table_impls!(impl_the_methods);
pub fn height_count(&self) -> u16 {
self.data.header().height_count.get()
}
pub fn correction_height(&self) -> &'a [MathValueRecord] {
let range = self.correction_height_byte_range();
self.offset_data()
.read_array(range)
.ok()
.unwrap_or_default()
}
pub fn kern_values(&self) -> &'a [MathValueRecord] {
let range = self.kern_values_byte_range();
self.offset_data()
.read_array(range)
.ok()
.unwrap_or_default()
}
pub fn height_count_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn correction_height_byte_range(&self) -> Range<usize> {
let height_count = self.height_count();
let start = self.height_count_byte_range().end;
let end = start
+ (transforms::to_usize(height_count)).saturating_mul(MathValueRecord::RAW_BYTE_LEN);
start..end
}
pub fn kern_values_byte_range(&self) -> Range<usize> {
let height_count = self.height_count();
let start = self.correction_height_byte_range().end;
let end = start
+ (transforms::add(height_count, 1_usize))
.saturating_mul(MathValueRecord::RAW_BYTE_LEN);
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(MathKern::MIN_SIZE));
impl Default for MathKern<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
}
}
}
impl<'a> MinByteRange<'a> for MathVariants<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.horiz_glyph_construction_offsets_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 ReadArgs for MathVariants<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for MathVariants<'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);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data })
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct MathVariantsFixedHeader {
pub min_connector_overlap: BigEndian<UfWord>,
pub vert_glyph_coverage_offset: BigEndian<Nullable<Offset16>>,
pub horiz_glyph_coverage_offset: BigEndian<Nullable<Offset16>>,
pub vert_glyph_count: BigEndian<u16>,
pub horiz_glyph_count: BigEndian<u16>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(std::mem::size_of::<MathVariantsFixedHeader>() <= MathVariants::MIN_SIZE);
#[derive(Clone)]
pub struct MathVariants<'a> {
data: TableDataRef<'a, MathVariantsFixedHeader>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> MathVariants<'a> {
pub const MIN_SIZE: usize = (UfWord::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN
+ Offset16::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN
+ u16::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn min_connector_overlap(&self) -> UfWord {
self.data.header().min_connector_overlap.get()
}
pub fn vert_glyph_coverage_offset(&self) -> Nullable<Offset16> {
self.data.header().vert_glyph_coverage_offset.get()
}
pub fn vert_glyph_coverage(&self) -> Option<Result<CoverageTable<'a>, ReadError>> {
let data = self.offset_data();
self.vert_glyph_coverage_offset().resolve(data)
}
pub fn horiz_glyph_coverage_offset(&self) -> Nullable<Offset16> {
self.data.header().horiz_glyph_coverage_offset.get()
}
pub fn horiz_glyph_coverage(&self) -> Option<Result<CoverageTable<'a>, ReadError>> {
let data = self.offset_data();
self.horiz_glyph_coverage_offset().resolve(data)
}
pub fn vert_glyph_count(&self) -> u16 {
self.data.header().vert_glyph_count.get()
}
pub fn horiz_glyph_count(&self) -> u16 {
self.data.header().horiz_glyph_count.get()
}
pub fn vert_glyph_construction_offsets(&self) -> &'a [BigEndian<Offset16>] {
let range = self.vert_glyph_construction_offsets_byte_range();
self.offset_data()
.read_array(range)
.ok()
.unwrap_or_default()
}
pub fn vert_glyph_constructions(
&self,
) -> ArrayOfOffsets<'a, MathGlyphConstruction<'a>, Offset16> {
let data = self.offset_data();
let offsets = self.vert_glyph_construction_offsets();
ArrayOfOffsets::new(offsets, data, ())
}
pub fn horiz_glyph_construction_offsets(&self) -> &'a [BigEndian<Offset16>] {
let range = self.horiz_glyph_construction_offsets_byte_range();
self.offset_data()
.read_array(range)
.ok()
.unwrap_or_default()
}
pub fn horiz_glyph_constructions(
&self,
) -> ArrayOfOffsets<'a, MathGlyphConstruction<'a>, Offset16> {
let data = self.offset_data();
let offsets = self.horiz_glyph_construction_offsets();
ArrayOfOffsets::new(offsets, data, ())
}
pub fn min_connector_overlap_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + UfWord::RAW_BYTE_LEN;
start..end
}
pub fn vert_glyph_coverage_offset_byte_range(&self) -> Range<usize> {
let start = self.min_connector_overlap_byte_range().end;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn horiz_glyph_coverage_offset_byte_range(&self) -> Range<usize> {
let start = self.vert_glyph_coverage_offset_byte_range().end;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn vert_glyph_count_byte_range(&self) -> Range<usize> {
let start = self.horiz_glyph_coverage_offset_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn horiz_glyph_count_byte_range(&self) -> Range<usize> {
let start = self.vert_glyph_count_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn vert_glyph_construction_offsets_byte_range(&self) -> Range<usize> {
let vert_glyph_count = self.vert_glyph_count();
let start = self.horiz_glyph_count_byte_range().end;
let end =
start + (transforms::to_usize(vert_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN);
start..end
}
pub fn horiz_glyph_construction_offsets_byte_range(&self) -> Range<usize> {
let horiz_glyph_count = self.horiz_glyph_count();
let start = self.vert_glyph_construction_offsets_byte_range().end;
let end = start
+ (transforms::to_usize(horiz_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN);
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(MathVariants::MIN_SIZE));
impl Default for MathVariants<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
}
}
}
impl<'a> MinByteRange<'a> for MathGlyphConstruction<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.math_glyph_variant_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 ReadArgs for MathGlyphConstruction<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for MathGlyphConstruction<'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);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data })
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct MathGlyphConstructionFixedHeader {
pub glyph_assembly_offset: BigEndian<Nullable<Offset16>>,
pub variant_count: BigEndian<u16>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(
std::mem::size_of::<MathGlyphConstructionFixedHeader>() <= MathGlyphConstruction::MIN_SIZE
);
#[derive(Clone)]
pub struct MathGlyphConstruction<'a> {
data: TableDataRef<'a, MathGlyphConstructionFixedHeader>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> MathGlyphConstruction<'a> {
pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn glyph_assembly_offset(&self) -> Nullable<Offset16> {
self.data.header().glyph_assembly_offset.get()
}
pub fn glyph_assembly(&self) -> Option<Result<GlyphAssembly<'a>, ReadError>> {
let data = self.offset_data();
self.glyph_assembly_offset().resolve(data)
}
pub fn variant_count(&self) -> u16 {
self.data.header().variant_count.get()
}
pub fn math_glyph_variant_records(&self) -> &'a [MathGlyphVariantRecord] {
let range = self.math_glyph_variant_records_byte_range();
self.offset_data()
.read_array(range)
.ok()
.unwrap_or_default()
}
pub fn glyph_assembly_offset_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + Offset16::RAW_BYTE_LEN;
start..end
}
pub fn variant_count_byte_range(&self) -> Range<usize> {
let start = self.glyph_assembly_offset_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn math_glyph_variant_records_byte_range(&self) -> Range<usize> {
let variant_count = self.variant_count();
let start = self.variant_count_byte_range().end;
let end = start
+ (transforms::to_usize(variant_count))
.saturating_mul(MathGlyphVariantRecord::RAW_BYTE_LEN);
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(
MathGlyphConstruction::MIN_SIZE
));
impl Default for MathGlyphConstruction<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
#[repr(C)]
#[repr(packed)]
pub struct MathGlyphVariantRecord {
pub variant_glyph: BigEndian<GlyphId16>,
pub advance_measurement: BigEndian<UfWord>,
}
impl MathGlyphVariantRecord {
pub fn variant_glyph(&self) -> GlyphId16 {
self.variant_glyph.get()
}
pub fn advance_measurement(&self) -> UfWord {
self.advance_measurement.get()
}
}
impl FixedSize for MathGlyphVariantRecord {
const RAW_BYTE_LEN: usize = GlyphId16::RAW_BYTE_LEN + UfWord::RAW_BYTE_LEN;
}
impl<'a> MinByteRange<'a> for GlyphAssembly<'a> {
fn min_byte_range(&self) -> Range<usize> {
0..self.part_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 ReadArgs for GlyphAssembly<'_> {
type Args = ();
}
impl<'a> FontRead<'a> for GlyphAssembly<'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);
}
let Some(data) = TableDataRef::new(data.as_bytes()) else {
return Err(ReadError::OutOfBounds);
};
Ok(Self { data })
}
}
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
#[repr(C, packed)]
#[doc(hidden)]
pub struct GlyphAssemblyFixedHeader {
pub italics_correction: MathValueRecord,
pub part_count: BigEndian<u16>,
}
#[allow(clippy::absurd_extreme_comparisons)]
const _: () = assert!(std::mem::size_of::<GlyphAssemblyFixedHeader>() <= GlyphAssembly::MIN_SIZE);
#[derive(Clone)]
pub struct GlyphAssembly<'a> {
data: TableDataRef<'a, GlyphAssemblyFixedHeader>,
}
#[allow(clippy::needless_lifetimes)]
impl<'a> GlyphAssembly<'a> {
pub const MIN_SIZE: usize = (MathValueRecord::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
basic_table_impls!(impl_the_methods);
pub fn italics_correction(&self) -> &'a MathValueRecord {
&self.data.header().italics_correction
}
pub fn part_count(&self) -> u16 {
self.data.header().part_count.get()
}
pub fn part_records(&self) -> &'a [GlyphPartRecord] {
let range = self.part_records_byte_range();
self.offset_data()
.read_array(range)
.ok()
.unwrap_or_default()
}
pub fn italics_correction_byte_range(&self) -> Range<usize> {
let start = 0;
let end = start + MathValueRecord::RAW_BYTE_LEN;
start..end
}
pub fn part_count_byte_range(&self) -> Range<usize> {
let start = self.italics_correction_byte_range().end;
let end = start + u16::RAW_BYTE_LEN;
start..end
}
pub fn part_records_byte_range(&self) -> Range<usize> {
let part_count = self.part_count();
let start = self.part_count_byte_range().end;
let end = start
+ (transforms::to_usize(part_count)).saturating_mul(GlyphPartRecord::RAW_BYTE_LEN);
start..end
}
}
const _: () = assert!(FontData::default_data_long_enough(GlyphAssembly::MIN_SIZE));
impl Default for GlyphAssembly<'_> {
fn default() -> Self {
Self {
data: TableDataRef::new(FontData::default_table_data().as_bytes())
.unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
#[repr(C)]
#[repr(packed)]
pub struct GlyphPartRecord {
pub glyph_id: BigEndian<GlyphId16>,
pub start_connector_length: BigEndian<UfWord>,
pub end_connector_length: BigEndian<UfWord>,
pub full_advance: BigEndian<UfWord>,
pub part_flags: BigEndian<PartFlags>,
}
impl GlyphPartRecord {
pub fn glyph_id(&self) -> GlyphId16 {
self.glyph_id.get()
}
pub fn start_connector_length(&self) -> UfWord {
self.start_connector_length.get()
}
pub fn end_connector_length(&self) -> UfWord {
self.end_connector_length.get()
}
pub fn full_advance(&self) -> UfWord {
self.full_advance.get()
}
pub fn part_flags(&self) -> PartFlags {
self.part_flags.get()
}
}
impl FixedSize for GlyphPartRecord {
const RAW_BYTE_LEN: usize = GlyphId16::RAW_BYTE_LEN
+ UfWord::RAW_BYTE_LEN
+ UfWord::RAW_BYTE_LEN
+ UfWord::RAW_BYTE_LEN
+ PartFlags::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 PartFlags {
bits: u16,
}
impl PartFlags {
pub const EXTENDER_FLAG: Self = Self { bits: 0x0001 };
}
impl PartFlags {
#[inline]
pub const fn empty() -> Self {
Self { bits: 0 }
}
#[inline]
pub const fn all() -> Self {
Self {
bits: Self::EXTENDER_FLAG.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 PartFlags {
type Output = Self;
#[inline]
fn bitor(self, other: PartFlags) -> Self {
Self {
bits: self.bits | other.bits,
}
}
}
impl std::ops::BitOrAssign for PartFlags {
#[inline]
fn bitor_assign(&mut self, other: Self) {
self.bits |= other.bits;
}
}
impl std::ops::BitXor for PartFlags {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
Self {
bits: self.bits ^ other.bits,
}
}
}
impl std::ops::BitXorAssign for PartFlags {
#[inline]
fn bitxor_assign(&mut self, other: Self) {
self.bits ^= other.bits;
}
}
impl std::ops::BitAnd for PartFlags {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self {
Self {
bits: self.bits & other.bits,
}
}
}
impl std::ops::BitAndAssign for PartFlags {
#[inline]
fn bitand_assign(&mut self, other: Self) {
self.bits &= other.bits;
}
}
impl std::ops::Sub for PartFlags {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self {
Self {
bits: self.bits & !other.bits,
}
}
}
impl std::ops::SubAssign for PartFlags {
#[inline]
fn sub_assign(&mut self, other: Self) {
self.bits &= !other.bits;
}
}
impl std::ops::Not for PartFlags {
type Output = Self;
#[inline]
fn not(self) -> Self {
Self { bits: !self.bits } & Self::all()
}
}
impl std::fmt::Debug for PartFlags {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let members: &[(&str, Self)] = &[("EXTENDER_FLAG", Self::EXTENDER_FLAG)];
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 PartFlags {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Binary::fmt(&self.bits, f)
}
}
impl std::fmt::Octal for PartFlags {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Octal::fmt(&self.bits, f)
}
}
impl std::fmt::LowerHex for PartFlags {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::LowerHex::fmt(&self.bits, f)
}
}
impl std::fmt::UpperHex for PartFlags {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::UpperHex::fmt(&self.bits, f)
}
}
impl font_types::Scalar for PartFlags {
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)
}
}