Skip to main content

read_fonts/generated/
generated_cbdt.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 Cbdt<'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 Cbdt<'_> {
19    /// `CBDT`
20    const TAG: Tag = Tag::new(b"CBDT");
21}
22
23impl<'a> FontRead<'a> for Cbdt<'a> {
24    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
25        #[allow(clippy::absurd_extreme_comparisons)]
26        if data.len() < Self::MIN_SIZE {
27            return Err(ReadError::OutOfBounds);
28        }
29        Ok(Self { data })
30    }
31}
32
33/// The [Color Bitmap Data](https://learn.microsoft.com/en-us/typography/opentype/spec/cbdt) table
34#[derive(Clone)]
35pub struct Cbdt<'a> {
36    data: FontData<'a>,
37}
38
39#[allow(clippy::needless_lifetimes)]
40impl<'a> Cbdt<'a> {
41    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
42    basic_table_impls!(impl_the_methods);
43
44    /// Major version of the CBDT table, = 3.
45    pub fn major_version(&self) -> u16 {
46        let range = self.major_version_byte_range();
47        self.data.read_at(range.start).ok().unwrap()
48    }
49
50    /// Minor version of CBDT table, = 0.
51    pub fn minor_version(&self) -> u16 {
52        let range = self.minor_version_byte_range();
53        self.data.read_at(range.start).ok().unwrap()
54    }
55
56    pub fn major_version_byte_range(&self) -> Range<usize> {
57        let start = 0;
58        let end = start + u16::RAW_BYTE_LEN;
59        start..end
60    }
61
62    pub fn minor_version_byte_range(&self) -> Range<usize> {
63        let start = self.major_version_byte_range().end;
64        let end = start + u16::RAW_BYTE_LEN;
65        start..end
66    }
67}
68
69const _: () = assert!(FontData::default_data_long_enough(Cbdt::MIN_SIZE));
70
71impl Default for Cbdt<'_> {
72    fn default() -> Self {
73        Self {
74            data: FontData::default_table_data(),
75        }
76    }
77}
78
79#[cfg(feature = "experimental_traverse")]
80impl<'a> SomeTable<'a> for Cbdt<'a> {
81    fn type_name(&self) -> &str {
82        "Cbdt"
83    }
84    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
85        match idx {
86            0usize => Some(Field::new("major_version", self.major_version())),
87            1usize => Some(Field::new("minor_version", self.minor_version())),
88            _ => None,
89        }
90    }
91}
92
93#[cfg(feature = "experimental_traverse")]
94#[allow(clippy::needless_lifetimes)]
95impl<'a> std::fmt::Debug for Cbdt<'a> {
96    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97        (self as &dyn SomeTable<'a>).fmt(f)
98    }
99}