Skip to main content

read_fonts/generated/
generated_ebdt.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 Ebdt<'a> {
9    fn min_byte_range(&self) -> Range<usize> {
10        0..self.minor_version_byte_range().end
11    }
12    fn min_table_bytes(&self) -> &'a [u8] {
13        let range = self.min_byte_range();
14        self.data.as_bytes().get(range).unwrap_or_default()
15    }
16}
17
18impl TopLevelTable for Ebdt<'_> {
19    /// `EBDT`
20    const TAG: Tag = Tag::new(b"EBDT");
21}
22
23impl ReadArgs for Ebdt<'_> {
24    type Args = ();
25}
26
27impl<'a> FontRead<'a> for Ebdt<'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        Ok(Self { data })
34    }
35}
36
37/// The [Embedded Bitmap Data](https://learn.microsoft.com/en-us/typography/opentype/spec/ebdt) table
38#[derive(Clone)]
39pub struct Ebdt<'a> {
40    data: FontData<'a>,
41}
42
43#[allow(clippy::needless_lifetimes)]
44impl<'a> Ebdt<'a> {
45    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
46    basic_table_impls!(impl_the_methods);
47
48    /// Major version of the EBDT table, = 2.
49    pub fn major_version(&self) -> u16 {
50        let range = self.major_version_byte_range();
51        self.data.read_at(range.start).ok().unwrap()
52    }
53
54    /// Minor version of EBDT table, = 0.
55    pub fn minor_version(&self) -> u16 {
56        let range = self.minor_version_byte_range();
57        self.data.read_at(range.start).ok().unwrap()
58    }
59
60    pub fn major_version_byte_range(&self) -> Range<usize> {
61        let start = 0;
62        let end = start + u16::RAW_BYTE_LEN;
63        start..end
64    }
65
66    pub fn minor_version_byte_range(&self) -> Range<usize> {
67        let start = self.major_version_byte_range().end;
68        let end = start + u16::RAW_BYTE_LEN;
69        start..end
70    }
71}
72
73const _: () = assert!(FontData::default_data_long_enough(Ebdt::MIN_SIZE));
74
75impl Default for Ebdt<'_> {
76    fn default() -> Self {
77        Self {
78            data: FontData::default_table_data(),
79        }
80    }
81}
82
83#[cfg(feature = "experimental_traverse")]
84impl<'a> SomeTable<'a> for Ebdt<'a> {
85    fn type_name(&self) -> &str {
86        "Ebdt"
87    }
88    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
89        match idx {
90            0usize => Some(Field::new("major_version", self.major_version())),
91            1usize => Some(Field::new("minor_version", self.minor_version())),
92            _ => None,
93        }
94    }
95}
96
97#[cfg(feature = "experimental_traverse")]
98#[allow(clippy::needless_lifetimes)]
99impl<'a> std::fmt::Debug for Ebdt<'a> {
100    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
101        (self as &dyn SomeTable<'a>).fmt(f)
102    }
103}