Skip to main content

read_fonts/generated/
generated_cblc.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 Cblc<'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.data.as_bytes().get(range).unwrap_or_default()
15    }
16}
17
18impl TopLevelTable for Cblc<'_> {
19    /// `CBLC`
20    const TAG: Tag = Tag::new(b"CBLC");
21}
22
23impl ReadArgs for Cblc<'_> {
24    type Args = ();
25}
26
27impl<'a> FontRead<'a> for Cblc<'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 [Color Bitmap Location](https://learn.microsoft.com/en-us/typography/opentype/spec/cblc) table
38#[derive(Clone)]
39pub struct Cblc<'a> {
40    data: FontData<'a>,
41}
42
43#[allow(clippy::needless_lifetimes)]
44impl<'a> Cblc<'a> {
45    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
46    basic_table_impls!(impl_the_methods);
47
48    /// Major version of the CBLC table, = 3.
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 CBLC 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    /// Number of BitmapSize records.
61    pub fn num_sizes(&self) -> u32 {
62        let range = self.num_sizes_byte_range();
63        self.data.read_at(range.start).ok().unwrap()
64    }
65
66    /// BitmapSize records array.
67    pub fn bitmap_sizes(&self) -> &'a [BitmapSize] {
68        let range = self.bitmap_sizes_byte_range();
69        self.data.read_array(range).ok().unwrap_or_default()
70    }
71
72    pub fn major_version_byte_range(&self) -> Range<usize> {
73        let start = 0;
74        let end = start + u16::RAW_BYTE_LEN;
75        start..end
76    }
77
78    pub fn minor_version_byte_range(&self) -> Range<usize> {
79        let start = self.major_version_byte_range().end;
80        let end = start + u16::RAW_BYTE_LEN;
81        start..end
82    }
83
84    pub fn num_sizes_byte_range(&self) -> Range<usize> {
85        let start = self.minor_version_byte_range().end;
86        let end = start + u32::RAW_BYTE_LEN;
87        start..end
88    }
89
90    pub fn bitmap_sizes_byte_range(&self) -> Range<usize> {
91        let num_sizes = self.num_sizes();
92        let start = self.num_sizes_byte_range().end;
93        let end =
94            start + (transforms::to_usize(num_sizes)).saturating_mul(BitmapSize::RAW_BYTE_LEN);
95        start..end
96    }
97}
98
99const _: () = assert!(FontData::default_data_long_enough(Cblc::MIN_SIZE));
100
101impl Default for Cblc<'_> {
102    fn default() -> Self {
103        Self {
104            data: FontData::default_table_data(),
105        }
106    }
107}
108
109#[cfg(feature = "experimental_traverse")]
110impl<'a> SomeTable<'a> for Cblc<'a> {
111    fn type_name(&self) -> &str {
112        "Cblc"
113    }
114    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
115        match idx {
116            0usize => Some(Field::new("major_version", self.major_version())),
117            1usize => Some(Field::new("minor_version", self.minor_version())),
118            2usize => Some(Field::new("num_sizes", self.num_sizes())),
119            3usize => Some(Field::new(
120                "bitmap_sizes",
121                traversal::FieldType::array_of_records(
122                    stringify!(BitmapSize),
123                    self.bitmap_sizes(),
124                    self.offset_data(),
125                ),
126            )),
127            _ => None,
128        }
129    }
130}
131
132#[cfg(feature = "experimental_traverse")]
133#[allow(clippy::needless_lifetimes)]
134impl<'a> std::fmt::Debug for Cblc<'a> {
135    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
136        (self as &dyn SomeTable<'a>).fmt(f)
137    }
138}