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_ankr.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 Ankr<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.glyph_data_table_offset_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 Ankr<'_> {
19
    /// `ankr`
20
    const TAG: Tag = Tag::new(b"ankr");
21
}
22
23
impl ReadArgs for Ankr<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Ankr<'a> {
28
6
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
6
        if data.len() < Self::MIN_SIZE {
31
2
            return Err(ReadError::OutOfBounds);
32
4
        }
33
4
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
4
        Ok(Self { data })
37
6
    }
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 AnkrFixedHeader {
45
    pub version: BigEndian<u16>,
46
    pub flags: BigEndian<u16>,
47
    pub lookup_table_offset: BigEndian<Offset32>,
48
    pub glyph_data_table_offset: BigEndian<u32>,
49
}
50
51
#[allow(clippy::absurd_extreme_comparisons)]
52
const _: () = assert!(std::mem::size_of::<AnkrFixedHeader>() <= Ankr::MIN_SIZE);
53
54
/// The [anchor point](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6ankr.html) table.
55
#[derive(Clone)]
56
pub struct Ankr<'a> {
57
    data: TableDataRef<'a, AnkrFixedHeader>,
58
}
59
60
#[allow(clippy::needless_lifetimes)]
61
impl<'a> Ankr<'a> {
62
    pub const MIN_SIZE: usize =
63
        (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
64
    basic_table_impls!(impl_the_methods);
65
66
    /// Version number (set to zero).
67
0
    pub fn version(&self) -> u16 {
68
0
        self.data.header().version.get()
69
0
    }
70
71
    /// Flags (currently unused; set to zero).
72
0
    pub fn flags(&self) -> u16 {
73
0
        self.data.header().flags.get()
74
0
    }
75
76
    /// Offset to the table's lookup table; currently this is always `0x0000000C`.
77
    ///
78
    /// Lookup values are two byte offsets into the glyph data table.
79
0
    pub fn lookup_table_offset(&self) -> Offset32 {
80
0
        self.data.header().lookup_table_offset.get()
81
0
    }
82
83
    /// Attempt to resolve [`lookup_table_offset`][Self::lookup_table_offset].
84
0
    pub fn lookup_table(&self) -> Result<LookupU16<'a>, ReadError> {
85
0
        let data = self.offset_data();
86
0
        self.lookup_table_offset().resolve(data)
87
0
    }
88
89
    /// Offset to the glyph data table.
90
0
    pub fn glyph_data_table_offset(&self) -> u32 {
91
0
        self.data.header().glyph_data_table_offset.get()
92
0
    }
93
94
0
    pub fn version_byte_range(&self) -> Range<usize> {
95
0
        let start = 0;
96
0
        let end = start + u16::RAW_BYTE_LEN;
97
0
        start..end
98
0
    }
99
100
0
    pub fn flags_byte_range(&self) -> Range<usize> {
101
0
        let start = self.version_byte_range().end;
102
0
        let end = start + u16::RAW_BYTE_LEN;
103
0
        start..end
104
0
    }
105
106
0
    pub fn lookup_table_offset_byte_range(&self) -> Range<usize> {
107
0
        let start = self.flags_byte_range().end;
108
0
        let end = start + Offset32::RAW_BYTE_LEN;
109
0
        start..end
110
0
    }
111
112
0
    pub fn glyph_data_table_offset_byte_range(&self) -> Range<usize> {
113
0
        let start = self.lookup_table_offset_byte_range().end;
114
0
        let end = start + u32::RAW_BYTE_LEN;
115
0
        start..end
116
0
    }
117
}
118
119
const _: () = assert!(FontData::default_data_long_enough(Ankr::MIN_SIZE));
120
121
impl Default for Ankr<'_> {
122
0
    fn default() -> Self {
123
        Self {
124
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
125
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
126
        }
127
0
    }
128
}
129
130
impl<'a> MinByteRange<'a> for GlyphDataEntry<'a> {
131
0
    fn min_byte_range(&self) -> Range<usize> {
132
0
        0..self.anchor_points_byte_range().end
133
0
    }
134
0
    fn min_table_bytes(&self) -> &'a [u8] {
135
0
        let range = self.min_byte_range();
136
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
137
0
    }
138
}
139
140
impl ReadArgs for GlyphDataEntry<'_> {
141
    type Args = ();
142
}
143
144
impl<'a> FontRead<'a> for GlyphDataEntry<'a> {
145
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
146
        #[allow(clippy::absurd_extreme_comparisons)]
147
0
        if data.len() < Self::MIN_SIZE {
148
0
            return Err(ReadError::OutOfBounds);
149
0
        }
150
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
151
0
            return Err(ReadError::OutOfBounds);
152
        };
153
0
        Ok(Self { data })
154
0
    }
155
}
156
157
/// The fields at the start of the table, which are read directly.
158
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
159
#[repr(C, packed)]
160
#[doc(hidden)]
161
pub struct GlyphDataEntryFixedHeader {
162
    pub num_points: BigEndian<u32>,
163
}
164
165
#[allow(clippy::absurd_extreme_comparisons)]
166
const _: () = assert!(std::mem::size_of::<GlyphDataEntryFixedHeader>() <= GlyphDataEntry::MIN_SIZE);
167
168
#[derive(Clone)]
169
pub struct GlyphDataEntry<'a> {
170
    data: TableDataRef<'a, GlyphDataEntryFixedHeader>,
171
}
172
173
#[allow(clippy::needless_lifetimes)]
174
impl<'a> GlyphDataEntry<'a> {
175
    pub const MIN_SIZE: usize = u32::RAW_BYTE_LEN;
176
    basic_table_impls!(impl_the_methods);
177
178
    /// Number of anchor points for this glyph.
179
0
    pub fn num_points(&self) -> u32 {
180
0
        self.data.header().num_points.get()
181
0
    }
182
183
    /// Individual anchor points.
184
0
    pub fn anchor_points(&self) -> &'a [AnchorPoint] {
185
0
        let range = self.anchor_points_byte_range();
186
0
        self.offset_data()
187
0
            .read_array(range)
188
0
            .ok()
189
0
            .unwrap_or_default()
190
0
    }
191
192
0
    pub fn num_points_byte_range(&self) -> Range<usize> {
193
0
        let start = 0;
194
0
        let end = start + u32::RAW_BYTE_LEN;
195
0
        start..end
196
0
    }
197
198
0
    pub fn anchor_points_byte_range(&self) -> Range<usize> {
199
0
        let num_points = self.num_points();
200
0
        let start = self.num_points_byte_range().end;
201
0
        let end =
202
0
            start + (transforms::to_usize(num_points)).saturating_mul(AnchorPoint::RAW_BYTE_LEN);
203
0
        start..end
204
0
    }
205
}
206
207
const _: () = assert!(FontData::default_data_long_enough(GlyphDataEntry::MIN_SIZE));
208
209
impl Default for GlyphDataEntry<'_> {
210
0
    fn default() -> Self {
211
        Self {
212
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
213
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
214
        }
215
0
    }
216
}
217
218
/// Individual anchor point.
219
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
220
#[repr(C)]
221
#[repr(packed)]
222
pub struct AnchorPoint {
223
    pub x: BigEndian<i16>,
224
    pub y: BigEndian<i16>,
225
}
226
227
impl AnchorPoint {
228
0
    pub fn x(&self) -> i16 {
229
0
        self.x.get()
230
0
    }
231
232
0
    pub fn y(&self) -> i16 {
233
0
        self.y.get()
234
0
    }
235
}
236
237
impl FixedSize for AnchorPoint {
238
    const RAW_BYTE_LEN: usize = i16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN;
239
}