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.offset_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 ReadArgs for Cbdt<'_> {
24    type Args = ();
25}
26
27impl<'a> FontRead<'a> for Cbdt<'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 CbdtFixedHeader {
45    pub major_version: BigEndian<u16>,
46    pub minor_version: BigEndian<u16>,
47}
48
49#[allow(clippy::absurd_extreme_comparisons)]
50const _: () = assert!(std::mem::size_of::<CbdtFixedHeader>() <= Cbdt::MIN_SIZE);
51
52/// The [Color Bitmap Data](https://learn.microsoft.com/en-us/typography/opentype/spec/cbdt) table
53#[derive(Clone)]
54pub struct Cbdt<'a> {
55    data: TableDataRef<'a, CbdtFixedHeader>,
56}
57
58#[allow(clippy::needless_lifetimes)]
59impl<'a> Cbdt<'a> {
60    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
61    basic_table_impls!(impl_the_methods);
62
63    /// Major version of the CBDT table, = 3.
64    pub fn major_version(&self) -> u16 {
65        self.data.header().major_version.get()
66    }
67
68    /// Minor version of CBDT table, = 0.
69    pub fn minor_version(&self) -> u16 {
70        self.data.header().minor_version.get()
71    }
72
73    pub fn major_version_byte_range(&self) -> Range<usize> {
74        let start = 0;
75        let end = start + u16::RAW_BYTE_LEN;
76        start..end
77    }
78
79    pub fn minor_version_byte_range(&self) -> Range<usize> {
80        let start = self.major_version_byte_range().end;
81        let end = start + u16::RAW_BYTE_LEN;
82        start..end
83    }
84}
85
86const _: () = assert!(FontData::default_data_long_enough(Cbdt::MIN_SIZE));
87
88impl Default for Cbdt<'_> {
89    fn default() -> Self {
90        Self {
91            data: TableDataRef::new(FontData::default_table_data().as_bytes())
92                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
93        }
94    }
95}