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
8/// The [Color Bitmap Data](https://learn.microsoft.com/en-us/typography/opentype/spec/cbdt) table
9#[derive(Debug, Clone, Copy)]
10#[doc(hidden)]
11pub struct CbdtMarker {}
12
13impl CbdtMarker {
14    pub fn major_version_byte_range(&self) -> Range<usize> {
15        let start = 0;
16        start..start + u16::RAW_BYTE_LEN
17    }
18
19    pub fn minor_version_byte_range(&self) -> Range<usize> {
20        let start = self.major_version_byte_range().end;
21        start..start + u16::RAW_BYTE_LEN
22    }
23}
24
25impl MinByteRange for CbdtMarker {
26    fn min_byte_range(&self) -> Range<usize> {
27        0..self.minor_version_byte_range().end
28    }
29}
30
31impl TopLevelTable for Cbdt<'_> {
32    /// `CBDT`
33    const TAG: Tag = Tag::new(b"CBDT");
34}
35
36impl<'a> FontRead<'a> for Cbdt<'a> {
37    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
38        let mut cursor = data.cursor();
39        cursor.advance::<u16>();
40        cursor.advance::<u16>();
41        cursor.finish(CbdtMarker {})
42    }
43}
44
45/// The [Color Bitmap Data](https://learn.microsoft.com/en-us/typography/opentype/spec/cbdt) table
46pub type Cbdt<'a> = TableRef<'a, CbdtMarker>;
47
48#[allow(clippy::needless_lifetimes)]
49impl<'a> Cbdt<'a> {
50    /// Major version of the CBDT table, = 3.
51    pub fn major_version(&self) -> u16 {
52        let range = self.shape.major_version_byte_range();
53        self.data.read_at(range.start).unwrap()
54    }
55
56    /// Minor version of CBDT table, = 0.
57    pub fn minor_version(&self) -> u16 {
58        let range = self.shape.minor_version_byte_range();
59        self.data.read_at(range.start).unwrap()
60    }
61}
62
63#[cfg(feature = "experimental_traverse")]
64impl<'a> SomeTable<'a> for Cbdt<'a> {
65    fn type_name(&self) -> &str {
66        "Cbdt"
67    }
68    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
69        match idx {
70            0usize => Some(Field::new("major_version", self.major_version())),
71            1usize => Some(Field::new("minor_version", self.minor_version())),
72            _ => None,
73        }
74    }
75}
76
77#[cfg(feature = "experimental_traverse")]
78#[allow(clippy::needless_lifetimes)]
79impl<'a> std::fmt::Debug for Cbdt<'a> {
80    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81        (self as &dyn SomeTable<'a>).fmt(f)
82    }
83}