/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.46.0/generated/generated_feat.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 Feat<'a> { |
9 | 0 | fn min_byte_range(&self) -> Range<usize> { |
10 | 0 | 0..self.names_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 Feat<'_> { |
19 | | /// `feat` |
20 | | const TAG: Tag = Tag::new(b"feat"); |
21 | | } |
22 | | |
23 | | impl ReadArgs for Feat<'_> { |
24 | | type Args = (); |
25 | | } |
26 | | |
27 | | impl<'a> FontRead<'a> for Feat<'a> { |
28 | 5 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
29 | | #[allow(clippy::absurd_extreme_comparisons)] |
30 | 5 | if data.len() < Self::MIN_SIZE { |
31 | 3 | return Err(ReadError::OutOfBounds); |
32 | 2 | } |
33 | 2 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
34 | 0 | return Err(ReadError::OutOfBounds); |
35 | | }; |
36 | 2 | Ok(Self { data }) |
37 | 5 | } |
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 FeatFixedHeader { |
45 | | pub version: BigEndian<MajorMinor>, |
46 | | pub feature_name_count: BigEndian<u16>, |
47 | | pub _reserved1: BigEndian<u16>, |
48 | | pub _reserved2: BigEndian<u32>, |
49 | | } |
50 | | |
51 | | #[allow(clippy::absurd_extreme_comparisons)] |
52 | | const _: () = assert!(std::mem::size_of::<FeatFixedHeader>() <= Feat::MIN_SIZE); |
53 | | |
54 | | /// The [feature name](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6feat.html) table. |
55 | | #[derive(Clone)] |
56 | | pub struct Feat<'a> { |
57 | | data: TableDataRef<'a, FeatFixedHeader>, |
58 | | } |
59 | | |
60 | | #[allow(clippy::needless_lifetimes)] |
61 | | impl<'a> Feat<'a> { |
62 | | pub const MIN_SIZE: usize = |
63 | | (MajorMinor::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN); |
64 | | basic_table_impls!(impl_the_methods); |
65 | | |
66 | | /// Version number of the feature name table (0x00010000 for the current |
67 | | /// version). |
68 | 0 | pub fn version(&self) -> MajorMinor { |
69 | 0 | self.data.header().version.get() |
70 | 0 | } |
71 | | |
72 | | /// The number of entries in the feature name array. |
73 | 0 | pub fn feature_name_count(&self) -> u16 { |
74 | 0 | self.data.header().feature_name_count.get() |
75 | 0 | } |
76 | | |
77 | | /// The feature name array, sorted by feature type. |
78 | 0 | pub fn names(&self) -> &'a [FeatureName] { |
79 | 0 | let range = self.names_byte_range(); |
80 | 0 | self.offset_data() |
81 | 0 | .read_array(range) |
82 | 0 | .ok() |
83 | 0 | .unwrap_or_default() |
84 | 0 | } |
85 | | |
86 | 0 | pub fn version_byte_range(&self) -> Range<usize> { |
87 | 0 | let start = 0; |
88 | 0 | let end = start + MajorMinor::RAW_BYTE_LEN; |
89 | 0 | start..end |
90 | 0 | } |
91 | | |
92 | 0 | pub fn feature_name_count_byte_range(&self) -> Range<usize> { |
93 | 0 | let start = self.version_byte_range().end; |
94 | 0 | let end = start + u16::RAW_BYTE_LEN; |
95 | 0 | start..end |
96 | 0 | } |
97 | | |
98 | 0 | pub fn _reserved1_byte_range(&self) -> Range<usize> { |
99 | 0 | let start = self.feature_name_count_byte_range().end; |
100 | 0 | let end = start + u16::RAW_BYTE_LEN; |
101 | 0 | start..end |
102 | 0 | } |
103 | | |
104 | 0 | pub fn _reserved2_byte_range(&self) -> Range<usize> { |
105 | 0 | let start = self._reserved1_byte_range().end; |
106 | 0 | let end = start + u32::RAW_BYTE_LEN; |
107 | 0 | start..end |
108 | 0 | } |
109 | | |
110 | 0 | pub fn names_byte_range(&self) -> Range<usize> { |
111 | 0 | let feature_name_count = self.feature_name_count(); |
112 | 0 | let start = self._reserved2_byte_range().end; |
113 | 0 | let end = start |
114 | 0 | + (transforms::to_usize(feature_name_count)).saturating_mul(FeatureName::RAW_BYTE_LEN); |
115 | 0 | start..end |
116 | 0 | } |
117 | | } |
118 | | |
119 | | const _: () = assert!(FontData::default_data_long_enough(Feat::MIN_SIZE)); |
120 | | |
121 | | impl Default for Feat<'_> { |
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 | | /// Type, flags and names for a feature. |
131 | | #[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)] |
132 | | #[repr(C)] |
133 | | #[repr(packed)] |
134 | | pub struct FeatureName { |
135 | | /// Feature type. |
136 | | pub feature: BigEndian<u16>, |
137 | | /// The number of records in the setting name array. |
138 | | pub n_settings: BigEndian<u16>, |
139 | | /// Offset in bytes from the beginning of this table to this feature's |
140 | | /// setting name array. The actual type of record this offset refers |
141 | | /// to will depend on the exclusivity value, as described below. |
142 | | pub setting_table_offset: BigEndian<Offset32>, |
143 | | /// Flags associated with the feature type. |
144 | | pub feature_flags: BigEndian<u16>, |
145 | | /// The name table index for the feature's name. |
146 | | pub name_index: BigEndian<NameId>, |
147 | | } |
148 | | |
149 | | impl FeatureName { |
150 | | /// Feature type. |
151 | 0 | pub fn feature(&self) -> u16 { |
152 | 0 | self.feature.get() |
153 | 0 | } |
154 | | |
155 | | /// The number of records in the setting name array. |
156 | 0 | pub fn n_settings(&self) -> u16 { |
157 | 0 | self.n_settings.get() |
158 | 0 | } |
159 | | |
160 | | /// Offset in bytes from the beginning of this table to this feature's |
161 | | /// setting name array. The actual type of record this offset refers |
162 | | /// to will depend on the exclusivity value, as described below. |
163 | 0 | pub fn setting_table_offset(&self) -> Offset32 { |
164 | 0 | self.setting_table_offset.get() |
165 | 0 | } |
166 | | |
167 | | /// Offset in bytes from the beginning of this table to this feature's |
168 | | /// setting name array. The actual type of record this offset refers |
169 | | /// to will depend on the exclusivity value, as described below. |
170 | | /// |
171 | | /// The `data` argument should be retrieved from the parent table |
172 | | /// By calling its `offset_data` method. |
173 | 0 | pub fn setting_table<'a>(&self, data: FontData<'a>) -> Result<SettingNameArray<'a>, ReadError> { |
174 | 0 | let args = self.n_settings(); |
175 | 0 | self.setting_table_offset().resolve_with_args(data, args) |
176 | 0 | } |
177 | | |
178 | | /// Flags associated with the feature type. |
179 | 0 | pub fn feature_flags(&self) -> u16 { |
180 | 0 | self.feature_flags.get() |
181 | 0 | } |
182 | | |
183 | | /// The name table index for the feature's name. |
184 | 0 | pub fn name_index(&self) -> NameId { |
185 | 0 | self.name_index.get() |
186 | 0 | } |
187 | | } |
188 | | |
189 | | impl FixedSize for FeatureName { |
190 | | const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN |
191 | | + u16::RAW_BYTE_LEN |
192 | | + Offset32::RAW_BYTE_LEN |
193 | | + u16::RAW_BYTE_LEN |
194 | | + NameId::RAW_BYTE_LEN; |
195 | | } |
196 | | |
197 | | impl<'a> MinByteRange<'a> for SettingNameArray<'a> { |
198 | 0 | fn min_byte_range(&self) -> Range<usize> { |
199 | 0 | 0..self.settings_byte_range().end |
200 | 0 | } |
201 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
202 | 0 | let range = self.min_byte_range(); |
203 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
204 | 0 | } |
205 | | } |
206 | | |
207 | | impl ReadArgs for SettingNameArray<'_> { |
208 | | type Args = u16; |
209 | | } |
210 | | |
211 | | impl<'a> FontRead<'a> for SettingNameArray<'a> { |
212 | 0 | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
213 | 0 | let n_settings = args; |
214 | | |
215 | | #[allow(clippy::absurd_extreme_comparisons)] |
216 | 0 | if data.len() < Self::MIN_SIZE { |
217 | 0 | return Err(ReadError::OutOfBounds); |
218 | 0 | } |
219 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
220 | 0 | return Err(ReadError::OutOfBounds); |
221 | | }; |
222 | 0 | Ok(Self { data, n_settings }) |
223 | 0 | } |
224 | | } |
225 | | |
226 | | impl<'a> SettingNameArray<'a> { |
227 | | /// A constructor that requires additional arguments. |
228 | | /// |
229 | | /// This type requires some external state in order to be |
230 | | /// parsed. |
231 | 0 | pub fn read(data: FontData<'a>, n_settings: u16) -> Result<Self, ReadError> { |
232 | 0 | let args = n_settings; |
233 | 0 | Self::read_with_args(data, args) |
234 | 0 | } |
235 | | } |
236 | | |
237 | | /// The fields at the start of the table, which are read directly. |
238 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
239 | | #[repr(C, packed)] |
240 | | #[doc(hidden)] |
241 | | pub struct SettingNameArrayFixedHeader {} |
242 | | |
243 | | #[allow(clippy::absurd_extreme_comparisons)] |
244 | | const _: () = |
245 | | assert!(std::mem::size_of::<SettingNameArrayFixedHeader>() <= SettingNameArray::MIN_SIZE); |
246 | | |
247 | | #[derive(Clone)] |
248 | | pub struct SettingNameArray<'a> { |
249 | | data: TableDataRef<'a, SettingNameArrayFixedHeader>, |
250 | | n_settings: u16, |
251 | | } |
252 | | |
253 | | #[allow(clippy::needless_lifetimes)] |
254 | | impl<'a> SettingNameArray<'a> { |
255 | | pub const MIN_SIZE: usize = 0; |
256 | | basic_table_impls!(impl_the_methods); |
257 | | |
258 | | /// List of setting names for a feature. |
259 | 0 | pub fn settings(&self) -> &'a [SettingName] { |
260 | 0 | let range = self.settings_byte_range(); |
261 | 0 | self.offset_data() |
262 | 0 | .read_array(range) |
263 | 0 | .ok() |
264 | 0 | .unwrap_or_default() |
265 | 0 | } |
266 | | |
267 | 0 | pub(crate) fn n_settings(&self) -> u16 { |
268 | 0 | self.n_settings |
269 | 0 | } |
270 | | |
271 | 0 | pub fn settings_byte_range(&self) -> Range<usize> { |
272 | 0 | let n_settings = self.n_settings(); |
273 | 0 | let start = 0; |
274 | 0 | let end = |
275 | 0 | start + (transforms::to_usize(n_settings)).saturating_mul(SettingName::RAW_BYTE_LEN); |
276 | 0 | start..end |
277 | 0 | } |
278 | | } |
279 | | |
280 | | #[allow(clippy::absurd_extreme_comparisons)] |
281 | | const _: () = assert!(FontData::default_data_long_enough( |
282 | | SettingNameArray::MIN_SIZE |
283 | | )); |
284 | | |
285 | | impl Default for SettingNameArray<'_> { |
286 | 0 | fn default() -> Self { |
287 | | Self { |
288 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
289 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
290 | 0 | n_settings: Default::default(), |
291 | | } |
292 | 0 | } |
293 | | } |
294 | | |
295 | | /// Associates a setting with a name identifier. |
296 | | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)] |
297 | | #[repr(C)] |
298 | | #[repr(packed)] |
299 | | pub struct SettingName { |
300 | | /// The setting. |
301 | | pub setting: BigEndian<u16>, |
302 | | /// The name table index for the setting's name. |
303 | | pub name_index: BigEndian<NameId>, |
304 | | } |
305 | | |
306 | | impl SettingName { |
307 | | /// The setting. |
308 | 0 | pub fn setting(&self) -> u16 { |
309 | 0 | self.setting.get() |
310 | 0 | } |
311 | | |
312 | | /// The name table index for the setting's name. |
313 | 0 | pub fn name_index(&self) -> NameId { |
314 | 0 | self.name_index.get() |
315 | 0 | } |
316 | | } |
317 | | |
318 | | impl FixedSize for SettingName { |
319 | | const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + NameId::RAW_BYTE_LEN; |
320 | | } |