Coverage Report

Created: 2026-10-24 07:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.46.0/generated/generated_cblc.rs
Line
Count
Source
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)]
6
use crate::codegen_prelude::*;
7
8
impl<'a> MinByteRange<'a> for Cblc<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.bitmap_sizes_byte_range().end
11
0
    }
12
0
    fn min_table_bytes(&self) -> &'a [u8] {
13
0
        let range = self.min_byte_range();
14
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
15
0
    }
16
}
17
18
impl TopLevelTable for Cblc<'_> {
19
    /// `CBLC`
20
    const TAG: Tag = Tag::new(b"CBLC");
21
}
22
23
impl ReadArgs for Cblc<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Cblc<'a> {
28
3
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
3
        if data.len() < Self::MIN_SIZE {
31
2
            return Err(ReadError::OutOfBounds);
32
1
        }
33
1
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
1
        Ok(Self { data })
37
3
    }
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)]
44
pub struct CblcFixedHeader {
45
    pub major_version: BigEndian<u16>,
46
    pub minor_version: BigEndian<u16>,
47
    pub num_sizes: BigEndian<u32>,
48
}
49
50
#[allow(clippy::absurd_extreme_comparisons)]
51
const _: () = assert!(std::mem::size_of::<CblcFixedHeader>() <= Cblc::MIN_SIZE);
52
53
/// The [Color Bitmap Location](https://learn.microsoft.com/en-us/typography/opentype/spec/cblc) table
54
#[derive(Clone)]
55
pub struct Cblc<'a> {
56
    data: TableDataRef<'a, CblcFixedHeader>,
57
}
58
59
#[allow(clippy::needless_lifetimes)]
60
impl<'a> Cblc<'a> {
61
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
62
    basic_table_impls!(impl_the_methods);
63
64
    /// Major version of the CBLC table, = 3.
65
0
    pub fn major_version(&self) -> u16 {
66
0
        self.data.header().major_version.get()
67
0
    }
68
69
    /// Minor version of CBLC table, = 0.
70
0
    pub fn minor_version(&self) -> u16 {
71
0
        self.data.header().minor_version.get()
72
0
    }
73
74
    /// Number of BitmapSize records.
75
0
    pub fn num_sizes(&self) -> u32 {
76
0
        self.data.header().num_sizes.get()
77
0
    }
78
79
    /// BitmapSize records array.
80
0
    pub fn bitmap_sizes(&self) -> &'a [BitmapSize] {
81
0
        let range = self.bitmap_sizes_byte_range();
82
0
        self.offset_data()
83
0
            .read_array(range)
84
0
            .ok()
85
0
            .unwrap_or_default()
86
0
    }
87
88
0
    pub fn major_version_byte_range(&self) -> Range<usize> {
89
0
        let start = 0;
90
0
        let end = start + u16::RAW_BYTE_LEN;
91
0
        start..end
92
0
    }
93
94
0
    pub fn minor_version_byte_range(&self) -> Range<usize> {
95
0
        let start = self.major_version_byte_range().end;
96
0
        let end = start + u16::RAW_BYTE_LEN;
97
0
        start..end
98
0
    }
99
100
0
    pub fn num_sizes_byte_range(&self) -> Range<usize> {
101
0
        let start = self.minor_version_byte_range().end;
102
0
        let end = start + u32::RAW_BYTE_LEN;
103
0
        start..end
104
0
    }
105
106
0
    pub fn bitmap_sizes_byte_range(&self) -> Range<usize> {
107
0
        let num_sizes = self.num_sizes();
108
0
        let start = self.num_sizes_byte_range().end;
109
0
        let end =
110
0
            start + (transforms::to_usize(num_sizes)).saturating_mul(BitmapSize::RAW_BYTE_LEN);
111
0
        start..end
112
0
    }
113
}
114
115
const _: () = assert!(FontData::default_data_long_enough(Cblc::MIN_SIZE));
116
117
impl Default for Cblc<'_> {
118
0
    fn default() -> Self {
119
        Self {
120
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
121
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
122
        }
123
0
    }
124
}