Coverage Report

Created: 2026-08-11 07:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fontations/read-fonts/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.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
        Ok(Self { data })
34
0
    }
35
}
36
37
/// [`meta`](https://docs.microsoft.com/en-us/typography/opentype/spec/meta)
38
#[derive(Clone)]
39
pub struct Meta<'a> {
40
    data: FontData<'a>,
41
}
42
43
#[allow(clippy::needless_lifetimes)]
44
impl<'a> Meta<'a> {
45
    pub const MIN_SIZE: usize =
46
        (u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
47
    basic_table_impls!(impl_the_methods);
48
49
    /// Version number of the metadata table — set to 1.
50
0
    pub fn version(&self) -> u32 {
51
0
        let range = self.version_byte_range();
52
0
        self.data.read_at(range.start).ok().unwrap()
53
0
    }
54
55
    /// Flags — currently unused; set to 0.
56
0
    pub fn flags(&self) -> u32 {
57
0
        let range = self.flags_byte_range();
58
0
        self.data.read_at(range.start).ok().unwrap()
59
0
    }
60
61
    /// The number of data maps in the table.
62
0
    pub fn data_maps_count(&self) -> u32 {
63
0
        let range = self.data_maps_count_byte_range();
64
0
        self.data.read_at(range.start).ok().unwrap()
65
0
    }
66
67
    /// Array of data map records.
68
0
    pub fn data_maps(&self) -> &'a [DataMapRecord] {
69
0
        let range = self.data_maps_byte_range();
70
0
        self.data.read_array(range).ok().unwrap_or_default()
71
0
    }
72
73
0
    pub fn version_byte_range(&self) -> Range<usize> {
74
0
        let start = 0;
75
0
        let end = start + u32::RAW_BYTE_LEN;
76
0
        start..end
77
0
    }
78
79
0
    pub fn flags_byte_range(&self) -> Range<usize> {
80
0
        let start = self.version_byte_range().end;
81
0
        let end = start + u32::RAW_BYTE_LEN;
82
0
        start..end
83
0
    }
84
85
0
    pub fn reserved_byte_range(&self) -> Range<usize> {
86
0
        let start = self.flags_byte_range().end;
87
0
        let end = start + u32::RAW_BYTE_LEN;
88
0
        start..end
89
0
    }
90
91
0
    pub fn data_maps_count_byte_range(&self) -> Range<usize> {
92
0
        let start = self.reserved_byte_range().end;
93
0
        let end = start + u32::RAW_BYTE_LEN;
94
0
        start..end
95
0
    }
96
97
0
    pub fn data_maps_byte_range(&self) -> Range<usize> {
98
0
        let data_maps_count = self.data_maps_count();
99
0
        let start = self.data_maps_count_byte_range().end;
100
0
        let end = start
101
0
            + (transforms::to_usize(data_maps_count)).saturating_mul(DataMapRecord::RAW_BYTE_LEN);
102
0
        start..end
103
0
    }
104
}
105
106
const _: () = assert!(FontData::default_data_long_enough(Meta::MIN_SIZE));
107
108
impl Default for Meta<'_> {
109
0
    fn default() -> Self {
110
0
        Self {
111
0
            data: FontData::default_table_data(),
112
0
        }
113
0
    }
114
}
115
116
#[cfg(feature = "experimental_traverse")]
117
impl<'a> SomeTable<'a> for Meta<'a> {
118
    fn type_name(&self) -> &str {
119
        "Meta"
120
    }
121
    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
122
        match idx {
123
            0usize => Some(Field::new("version", self.version())),
124
            1usize => Some(Field::new("flags", self.flags())),
125
            2usize => Some(Field::new("data_maps_count", self.data_maps_count())),
126
            3usize => Some(Field::new(
127
                "data_maps",
128
                traversal::FieldType::array_of_records(
129
                    stringify!(DataMapRecord),
130
                    self.data_maps(),
131
                    self.offset_data(),
132
                ),
133
            )),
134
            _ => None,
135
        }
136
    }
137
}
138
139
#[cfg(feature = "experimental_traverse")]
140
#[allow(clippy::needless_lifetimes)]
141
impl<'a> std::fmt::Debug for Meta<'a> {
142
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
143
        (self as &dyn SomeTable<'a>).fmt(f)
144
    }
145
}
146
147
///  <https://learn.microsoft.com/en-us/typography/opentype/spec/meta#table-formats>
148
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
149
#[repr(C)]
150
#[repr(packed)]
151
pub struct DataMapRecord {
152
    /// A tag indicating the type of metadata.
153
    pub tag: BigEndian<Tag>,
154
    /// Offset in bytes from the beginning of the metadata table to the data for this tag.
155
    pub data_offset: BigEndian<Offset32>,
156
    /// Length of the data, in bytes. The data is not required to be padded to any byte boundary.
157
    pub data_length: BigEndian<u32>,
158
}
159
160
impl DataMapRecord {
161
    /// A tag indicating the type of metadata.
162
0
    pub fn tag(&self) -> Tag {
163
0
        self.tag.get()
164
0
    }
165
166
    /// Offset in bytes from the beginning of the metadata table to the data for this tag.
167
0
    pub fn data_offset(&self) -> Offset32 {
168
0
        self.data_offset.get()
169
0
    }
170
171
    /// Offset in bytes from the beginning of the metadata table to the data for this tag.
172
    ///
173
    /// The `data` argument should be retrieved from the parent table
174
    /// By calling its `offset_data` method.
175
0
    pub fn data<'a>(&self, data: FontData<'a>) -> Result<Metadata<'a>, ReadError> {
176
0
        let args = (self.tag(), self.data_length());
177
0
        self.data_offset().resolve_with_args(data, args)
178
0
    }
179
180
    /// Length of the data, in bytes. The data is not required to be padded to any byte boundary.
181
0
    pub fn data_length(&self) -> u32 {
182
0
        self.data_length.get()
183
0
    }
184
}
185
186
impl FixedSize for DataMapRecord {
187
    const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN;
188
}
189
190
#[cfg(feature = "experimental_traverse")]
191
impl<'a> SomeRecord<'a> for DataMapRecord {
192
    fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
193
        RecordResolver {
194
            name: "DataMapRecord",
195
            get_field: Box::new(move |idx, _data| match idx {
196
                0usize => Some(Field::new("tag", self.tag())),
197
                1usize => Some(Field::new("data_offset", traversal::FieldType::Unknown)),
198
                2usize => Some(Field::new("data_length", self.data_length())),
199
                _ => None,
200
            }),
201
            data,
202
        }
203
    }
204
}