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        start..start + u16::RAW_BYTE_LEN
59    }
60
61    pub fn minor_version_byte_range(&self) -> Range<usize> {
62        let start = self.major_version_byte_range().end;
63        start..start + u16::RAW_BYTE_LEN
64    }
65}
66
67const _: () = assert!(FontData::default_data_long_enough(Cbdt::MIN_SIZE));
68
69impl Default for Cbdt<'_> {
70    fn default() -> Self {
71        Self {
72            data: FontData::default_table_data(),
73        }
74    }
75}
76
77#[cfg(feature = "experimental_traverse")]
78impl<'a> SomeTable<'a> for Cbdt<'a> {
79    fn type_name(&self) -> &str {
80        "Cbdt"
81    }
82    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
83        match idx {
84            0usize => Some(Field::new("major_version", self.major_version())),
85            1usize => Some(Field::new("minor_version", self.minor_version())),
86            _ => None,
87        }
88    }
89}
90
91#[cfg(feature = "experimental_traverse")]
92#[allow(clippy::needless_lifetimes)]
93impl<'a> std::fmt::Debug for Cbdt<'a> {
94    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95        (self as &dyn SomeTable<'a>).fmt(f)
96    }
97}