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_meta.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 Meta<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.data_maps_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 Meta<'_> {
19
    /// `meta`
20
    const TAG: Tag = Tag::new(b"meta");
21
}
22
23
impl ReadArgs for Meta<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Meta<'a> {
28
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
0
        if data.len() < Self::MIN_SIZE {
31
0
            return Err(ReadError::OutOfBounds);
32
0
        }
33
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
0
        Ok(Self { data })
37
0
    }
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 MetaFixedHeader {
45
    pub version: BigEndian<u32>,
46
    pub flags: BigEndian<u32>,
47
    pub reserved: BigEndian<u32>,
48
    pub data_maps_count: BigEndian<u32>,
49
}
50
51
#[allow(clippy::absurd_extreme_comparisons)]
52
const _: () = assert!(std::mem::size_of::<MetaFixedHeader>() <= Meta::MIN_SIZE);
53
54
/// [`meta`](https://docs.microsoft.com/en-us/typography/opentype/spec/meta)
55
#[derive(Clone)]
56
pub struct Meta<'a> {
57
    data: TableDataRef<'a, MetaFixedHeader>,
58
}
59
60
#[allow(clippy::needless_lifetimes)]
61
impl<'a> Meta<'a> {
62
    pub const MIN_SIZE: usize =
63
        (u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
64
    basic_table_impls!(impl_the_methods);
65
66
    /// Version number of the metadata table — set to 1.
67
0
    pub fn version(&self) -> u32 {
68
0
        self.data.header().version.get()
69
0
    }
70
71
    /// Flags — currently unused; set to 0.
72
0
    pub fn flags(&self) -> u32 {
73
0
        self.data.header().flags.get()
74
0
    }
75
76
    /// The number of data maps in the table.
77
0
    pub fn data_maps_count(&self) -> u32 {
78
0
        self.data.header().data_maps_count.get()
79
0
    }
80
81
    /// Array of data map records.
82
0
    pub fn data_maps(&self) -> &'a [DataMapRecord] {
83
0
        let range = self.data_maps_byte_range();
84
0
        self.offset_data()
85
0
            .read_array(range)
86
0
            .ok()
87
0
            .unwrap_or_default()
88
0
    }
89
90
0
    pub fn version_byte_range(&self) -> Range<usize> {
91
0
        let start = 0;
92
0
        let end = start + u32::RAW_BYTE_LEN;
93
0
        start..end
94
0
    }
95
96
0
    pub fn flags_byte_range(&self) -> Range<usize> {
97
0
        let start = self.version_byte_range().end;
98
0
        let end = start + u32::RAW_BYTE_LEN;
99
0
        start..end
100
0
    }
101
102
0
    pub fn reserved_byte_range(&self) -> Range<usize> {
103
0
        let start = self.flags_byte_range().end;
104
0
        let end = start + u32::RAW_BYTE_LEN;
105
0
        start..end
106
0
    }
107
108
0
    pub fn data_maps_count_byte_range(&self) -> Range<usize> {
109
0
        let start = self.reserved_byte_range().end;
110
0
        let end = start + u32::RAW_BYTE_LEN;
111
0
        start..end
112
0
    }
113
114
0
    pub fn data_maps_byte_range(&self) -> Range<usize> {
115
0
        let data_maps_count = self.data_maps_count();
116
0
        let start = self.data_maps_count_byte_range().end;
117
0
        let end = start
118
0
            + (transforms::to_usize(data_maps_count)).saturating_mul(DataMapRecord::RAW_BYTE_LEN);
119
0
        start..end
120
0
    }
121
}
122
123
const _: () = assert!(FontData::default_data_long_enough(Meta::MIN_SIZE));
124
125
impl Default for Meta<'_> {
126
0
    fn default() -> Self {
127
        Self {
128
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
129
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
130
        }
131
0
    }
132
}
133
134
///  <https://learn.microsoft.com/en-us/typography/opentype/spec/meta#table-formats>
135
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
136
#[repr(C)]
137
#[repr(packed)]
138
pub struct DataMapRecord {
139
    /// A tag indicating the type of metadata.
140
    pub tag: BigEndian<Tag>,
141
    /// Offset in bytes from the beginning of the metadata table to the data for this tag.
142
    pub data_offset: BigEndian<Offset32>,
143
    /// Length of the data, in bytes. The data is not required to be padded to any byte boundary.
144
    pub data_length: BigEndian<u32>,
145
}
146
147
impl DataMapRecord {
148
    /// A tag indicating the type of metadata.
149
0
    pub fn tag(&self) -> Tag {
150
0
        self.tag.get()
151
0
    }
152
153
    /// Offset in bytes from the beginning of the metadata table to the data for this tag.
154
0
    pub fn data_offset(&self) -> Offset32 {
155
0
        self.data_offset.get()
156
0
    }
157
158
    /// Offset in bytes from the beginning of the metadata table to the data for this tag.
159
    ///
160
    /// The `data` argument should be retrieved from the parent table
161
    /// By calling its `offset_data` method.
162
0
    pub fn data<'a>(&self, data: FontData<'a>) -> Result<Metadata<'a>, ReadError> {
163
0
        let args = (self.tag(), self.data_length());
164
0
        self.data_offset().resolve_with_args(data, args)
165
0
    }
166
167
    /// Length of the data, in bytes. The data is not required to be padded to any byte boundary.
168
0
    pub fn data_length(&self) -> u32 {
169
0
        self.data_length.get()
170
0
    }
171
}
172
173
impl FixedSize for DataMapRecord {
174
    const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN;
175
}