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