Skip to main content

read_fonts/generated/
generated_eblc.rs

1// THIS FILE IS AUTOGENERATED.
2// Any changes to this file will be overwritten.
3// For more information about how codegen works, see font-codegen/README.md
4
5#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Eblc<'a> {
9    fn min_byte_range(&self) -> Range<usize> {
10        0..self.bitmap_sizes_byte_range().end
11    }
12    fn min_table_bytes(&self) -> &'a [u8] {
13        let range = self.min_byte_range();
14        self.offset_data().as_bytes().get(range).unwrap_or_default()
15    }
16}
17
18impl TopLevelTable for Eblc<'_> {
19    /// `EBLC`
20    const TAG: Tag = Tag::new(b"EBLC");
21}
22
23impl ReadArgs for Eblc<'_> {
24    type Args = ();
25}
26
27impl<'a> FontRead<'a> for Eblc<'a> {
28    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29        #[allow(clippy::absurd_extreme_comparisons)]
30        if data.len() < Self::MIN_SIZE {
31            return Err(ReadError::OutOfBounds);
32        }
33        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34            return Err(ReadError::OutOfBounds);
35        };
36        Ok(Self { data })
37    }
38}
39
40/// The fields at the start of the table, which are read directly.
41#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42#[repr(C, packed)]
43#[doc(hidden)]
44pub struct EblcFixedHeader {
45    pub major_version: BigEndian<u16>,
46    pub minor_version: BigEndian<u16>,
47    pub num_sizes: BigEndian<u32>,
48}
49
50#[allow(clippy::absurd_extreme_comparisons)]
51const _: () = assert!(std::mem::size_of::<EblcFixedHeader>() <= Eblc::MIN_SIZE);
52
53/// The [Embedded Bitmap Location](https://learn.microsoft.com/en-us/typography/opentype/spec/eblc) table
54#[derive(Clone)]
55pub struct Eblc<'a> {
56    data: TableDataRef<'a, EblcFixedHeader>,
57}
58
59#[allow(clippy::needless_lifetimes)]
60impl<'a> Eblc<'a> {
61    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
62    basic_table_impls!(impl_the_methods);
63
64    /// Major version of the EBLC table, = 2.
65    pub fn major_version(&self) -> u16 {
66        self.data.header().major_version.get()
67    }
68
69    /// Minor version of EBLC table, = 0.
70    pub fn minor_version(&self) -> u16 {
71        self.data.header().minor_version.get()
72    }
73
74    /// Number of BitmapSize records.
75    pub fn num_sizes(&self) -> u32 {
76        self.data.header().num_sizes.get()
77    }
78
79    /// BitmapSize records array.
80    pub fn bitmap_sizes(&self) -> &'a [BitmapSize] {
81        let range = self.bitmap_sizes_byte_range();
82        self.offset_data()
83            .read_array(range)
84            .ok()
85            .unwrap_or_default()
86    }
87
88    pub fn major_version_byte_range(&self) -> Range<usize> {
89        let start = 0;
90        let end = start + u16::RAW_BYTE_LEN;
91        start..end
92    }
93
94    pub fn minor_version_byte_range(&self) -> Range<usize> {
95        let start = self.major_version_byte_range().end;
96        let end = start + u16::RAW_BYTE_LEN;
97        start..end
98    }
99
100    pub fn num_sizes_byte_range(&self) -> Range<usize> {
101        let start = self.minor_version_byte_range().end;
102        let end = start + u32::RAW_BYTE_LEN;
103        start..end
104    }
105
106    pub fn bitmap_sizes_byte_range(&self) -> Range<usize> {
107        let num_sizes = self.num_sizes();
108        let start = self.num_sizes_byte_range().end;
109        let end =
110            start + (transforms::to_usize(num_sizes)).saturating_mul(BitmapSize::RAW_BYTE_LEN);
111        start..end
112    }
113}
114
115const _: () = assert!(FontData::default_data_long_enough(Eblc::MIN_SIZE));
116
117impl Default for Eblc<'_> {
118    fn default() -> Self {
119        Self {
120            data: TableDataRef::new(FontData::default_table_data().as_bytes())
121                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
122        }
123    }
124}