Coverage Report

Created: 2026-04-01 07:11

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