/src/fontations/read-fonts/generated/generated_varc.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 | | /// [VARC](https://github.com/harfbuzz/boring-expansion-spec/blob/main/VARC.md) (Variable Composites / Components Table) |
9 | | /// |
10 | | /// [FontTools VARC](https://github.com/fonttools/fonttools/blob/5e6b12d12fa08abafbeb7570f47707fbedf69a45/Lib/fontTools/ttLib/tables/otData.py#L3459-L3476) |
11 | | #[derive(Debug, Clone, Copy)] |
12 | | #[doc(hidden)] |
13 | | pub struct VarcMarker {} |
14 | | |
15 | | impl VarcMarker { |
16 | 0 | pub fn version_byte_range(&self) -> Range<usize> { |
17 | 0 | let start = 0; |
18 | 0 | start..start + MajorMinor::RAW_BYTE_LEN |
19 | 0 | } |
20 | | |
21 | 0 | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
22 | 0 | let start = self.version_byte_range().end; |
23 | 0 | start..start + Offset32::RAW_BYTE_LEN |
24 | 0 | } |
25 | | |
26 | 0 | pub fn multi_var_store_offset_byte_range(&self) -> Range<usize> { |
27 | 0 | let start = self.coverage_offset_byte_range().end; |
28 | 0 | start..start + Offset32::RAW_BYTE_LEN |
29 | 0 | } |
30 | | |
31 | 0 | pub fn condition_list_offset_byte_range(&self) -> Range<usize> { |
32 | 0 | let start = self.multi_var_store_offset_byte_range().end; |
33 | 0 | start..start + Offset32::RAW_BYTE_LEN |
34 | 0 | } |
35 | | |
36 | 0 | pub fn axis_indices_list_offset_byte_range(&self) -> Range<usize> { |
37 | 0 | let start = self.condition_list_offset_byte_range().end; |
38 | 0 | start..start + Offset32::RAW_BYTE_LEN |
39 | 0 | } |
40 | | |
41 | 0 | pub fn var_composite_glyphs_offset_byte_range(&self) -> Range<usize> { |
42 | 0 | let start = self.axis_indices_list_offset_byte_range().end; |
43 | 0 | start..start + Offset32::RAW_BYTE_LEN |
44 | 0 | } |
45 | | } |
46 | | |
47 | | impl MinByteRange for VarcMarker { |
48 | 0 | fn min_byte_range(&self) -> Range<usize> { |
49 | 0 | 0..self.var_composite_glyphs_offset_byte_range().end |
50 | 0 | } |
51 | | } |
52 | | |
53 | | impl TopLevelTable for Varc<'_> { |
54 | | /// `VARC` |
55 | | const TAG: Tag = Tag::new(b"VARC"); |
56 | | } |
57 | | |
58 | | impl<'a> FontRead<'a> for Varc<'a> { |
59 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
60 | 0 | let mut cursor = data.cursor(); |
61 | 0 | cursor.advance::<MajorMinor>(); |
62 | 0 | cursor.advance::<Offset32>(); |
63 | 0 | cursor.advance::<Offset32>(); |
64 | 0 | cursor.advance::<Offset32>(); |
65 | 0 | cursor.advance::<Offset32>(); |
66 | 0 | cursor.advance::<Offset32>(); |
67 | 0 | cursor.finish(VarcMarker {}) |
68 | 0 | } |
69 | | } |
70 | | |
71 | | /// [VARC](https://github.com/harfbuzz/boring-expansion-spec/blob/main/VARC.md) (Variable Composites / Components Table) |
72 | | /// |
73 | | /// [FontTools VARC](https://github.com/fonttools/fonttools/blob/5e6b12d12fa08abafbeb7570f47707fbedf69a45/Lib/fontTools/ttLib/tables/otData.py#L3459-L3476) |
74 | | pub type Varc<'a> = TableRef<'a, VarcMarker>; |
75 | | |
76 | | #[allow(clippy::needless_lifetimes)] |
77 | | impl<'a> Varc<'a> { |
78 | | /// Major/minor version number. Set to 1.0. |
79 | 0 | pub fn version(&self) -> MajorMinor { |
80 | 0 | let range = self.shape.version_byte_range(); |
81 | 0 | self.data.read_at(range.start).unwrap() |
82 | 0 | } |
83 | | |
84 | 0 | pub fn coverage_offset(&self) -> Offset32 { |
85 | 0 | let range = self.shape.coverage_offset_byte_range(); |
86 | 0 | self.data.read_at(range.start).unwrap() |
87 | 0 | } |
88 | | |
89 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
90 | 0 | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
91 | 0 | let data = self.data; |
92 | 0 | self.coverage_offset().resolve(data) |
93 | 0 | } |
94 | | |
95 | 0 | pub fn multi_var_store_offset(&self) -> Nullable<Offset32> { |
96 | 0 | let range = self.shape.multi_var_store_offset_byte_range(); |
97 | 0 | self.data.read_at(range.start).unwrap() |
98 | 0 | } |
99 | | |
100 | | /// Attempt to resolve [`multi_var_store_offset`][Self::multi_var_store_offset]. |
101 | 0 | pub fn multi_var_store(&self) -> Option<Result<MultiItemVariationStore<'a>, ReadError>> { |
102 | 0 | let data = self.data; |
103 | 0 | self.multi_var_store_offset().resolve(data) |
104 | 0 | } |
105 | | |
106 | 0 | pub fn condition_list_offset(&self) -> Nullable<Offset32> { |
107 | 0 | let range = self.shape.condition_list_offset_byte_range(); |
108 | 0 | self.data.read_at(range.start).unwrap() |
109 | 0 | } |
110 | | |
111 | | /// Attempt to resolve [`condition_list_offset`][Self::condition_list_offset]. |
112 | 0 | pub fn condition_list(&self) -> Option<Result<ConditionList<'a>, ReadError>> { |
113 | 0 | let data = self.data; |
114 | 0 | self.condition_list_offset().resolve(data) |
115 | 0 | } |
116 | | |
117 | 0 | pub fn axis_indices_list_offset(&self) -> Nullable<Offset32> { |
118 | 0 | let range = self.shape.axis_indices_list_offset_byte_range(); |
119 | 0 | self.data.read_at(range.start).unwrap() |
120 | 0 | } |
121 | | |
122 | | /// Attempt to resolve [`axis_indices_list_offset`][Self::axis_indices_list_offset]. |
123 | 0 | pub fn axis_indices_list(&self) -> Option<Result<Index2<'a>, ReadError>> { |
124 | 0 | let data = self.data; |
125 | 0 | self.axis_indices_list_offset().resolve(data) |
126 | 0 | } |
127 | | |
128 | 0 | pub fn var_composite_glyphs_offset(&self) -> Offset32 { |
129 | 0 | let range = self.shape.var_composite_glyphs_offset_byte_range(); |
130 | 0 | self.data.read_at(range.start).unwrap() |
131 | 0 | } |
132 | | |
133 | | /// Attempt to resolve [`var_composite_glyphs_offset`][Self::var_composite_glyphs_offset]. |
134 | 0 | pub fn var_composite_glyphs(&self) -> Result<Index2<'a>, ReadError> { |
135 | 0 | let data = self.data; |
136 | 0 | self.var_composite_glyphs_offset().resolve(data) |
137 | 0 | } |
138 | | } |
139 | | |
140 | | #[cfg(feature = "experimental_traverse")] |
141 | | impl<'a> SomeTable<'a> for Varc<'a> { |
142 | | fn type_name(&self) -> &str { |
143 | | "Varc" |
144 | | } |
145 | | fn get_field(&self, idx: usize) -> Option<Field<'a>> { |
146 | | match idx { |
147 | | 0usize => Some(Field::new("version", self.version())), |
148 | | 1usize => Some(Field::new( |
149 | | "coverage_offset", |
150 | | FieldType::offset(self.coverage_offset(), self.coverage()), |
151 | | )), |
152 | | 2usize => Some(Field::new( |
153 | | "multi_var_store_offset", |
154 | | FieldType::offset(self.multi_var_store_offset(), self.multi_var_store()), |
155 | | )), |
156 | | 3usize => Some(Field::new( |
157 | | "condition_list_offset", |
158 | | FieldType::offset(self.condition_list_offset(), self.condition_list()), |
159 | | )), |
160 | | 4usize => Some(Field::new( |
161 | | "axis_indices_list_offset", |
162 | | FieldType::offset(self.axis_indices_list_offset(), self.axis_indices_list()), |
163 | | )), |
164 | | 5usize => Some(Field::new( |
165 | | "var_composite_glyphs_offset", |
166 | | FieldType::offset( |
167 | | self.var_composite_glyphs_offset(), |
168 | | self.var_composite_glyphs(), |
169 | | ), |
170 | | )), |
171 | | _ => None, |
172 | | } |
173 | | } |
174 | | } |
175 | | |
176 | | #[cfg(feature = "experimental_traverse")] |
177 | | #[allow(clippy::needless_lifetimes)] |
178 | | impl<'a> std::fmt::Debug for Varc<'a> { |
179 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
180 | | (self as &dyn SomeTable<'a>).fmt(f) |
181 | | } |
182 | | } |
183 | | |
184 | | impl Format<u16> for MultiItemVariationStoreMarker { |
185 | | const FORMAT: u16 = 1; |
186 | | } |
187 | | |
188 | | /// * <https://github.com/fonttools/fonttools/blob/5e6b12d12fa08abafbeb7570f47707fbedf69a45/Lib/fontTools/ttLib/tables/otData.py#L3451-L3457> |
189 | | /// * <https://github.com/harfbuzz/harfbuzz/blob/7be12b33e3f07067c159d8f516eb31df58c75876/src/hb-ot-layout-common.hh#L3517-L3520C3> |
190 | | #[derive(Debug, Clone, Copy)] |
191 | | #[doc(hidden)] |
192 | | pub struct MultiItemVariationStoreMarker { |
193 | | variation_data_offsets_byte_len: usize, |
194 | | } |
195 | | |
196 | | impl MultiItemVariationStoreMarker { |
197 | 0 | pub fn format_byte_range(&self) -> Range<usize> { |
198 | 0 | let start = 0; |
199 | 0 | start..start + u16::RAW_BYTE_LEN |
200 | 0 | } |
201 | | |
202 | 0 | pub fn region_list_offset_byte_range(&self) -> Range<usize> { |
203 | 0 | let start = self.format_byte_range().end; |
204 | 0 | start..start + Offset32::RAW_BYTE_LEN |
205 | 0 | } |
206 | | |
207 | 0 | pub fn variation_data_count_byte_range(&self) -> Range<usize> { |
208 | 0 | let start = self.region_list_offset_byte_range().end; |
209 | 0 | start..start + u16::RAW_BYTE_LEN |
210 | 0 | } |
211 | | |
212 | 0 | pub fn variation_data_offsets_byte_range(&self) -> Range<usize> { |
213 | 0 | let start = self.variation_data_count_byte_range().end; |
214 | 0 | start..start + self.variation_data_offsets_byte_len |
215 | 0 | } |
216 | | } |
217 | | |
218 | | impl MinByteRange for MultiItemVariationStoreMarker { |
219 | 0 | fn min_byte_range(&self) -> Range<usize> { |
220 | 0 | 0..self.variation_data_offsets_byte_range().end |
221 | 0 | } |
222 | | } |
223 | | |
224 | | impl<'a> FontRead<'a> for MultiItemVariationStore<'a> { |
225 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
226 | 0 | let mut cursor = data.cursor(); |
227 | 0 | cursor.advance::<u16>(); |
228 | 0 | cursor.advance::<Offset32>(); |
229 | 0 | let variation_data_count: u16 = cursor.read()?; |
230 | 0 | let variation_data_offsets_byte_len = (variation_data_count as usize) |
231 | 0 | .checked_mul(Offset32::RAW_BYTE_LEN) |
232 | 0 | .ok_or(ReadError::OutOfBounds)?; |
233 | 0 | cursor.advance_by(variation_data_offsets_byte_len); |
234 | 0 | cursor.finish(MultiItemVariationStoreMarker { |
235 | 0 | variation_data_offsets_byte_len, |
236 | 0 | }) |
237 | 0 | } |
238 | | } |
239 | | |
240 | | /// * <https://github.com/fonttools/fonttools/blob/5e6b12d12fa08abafbeb7570f47707fbedf69a45/Lib/fontTools/ttLib/tables/otData.py#L3451-L3457> |
241 | | /// * <https://github.com/harfbuzz/harfbuzz/blob/7be12b33e3f07067c159d8f516eb31df58c75876/src/hb-ot-layout-common.hh#L3517-L3520C3> |
242 | | pub type MultiItemVariationStore<'a> = TableRef<'a, MultiItemVariationStoreMarker>; |
243 | | |
244 | | #[allow(clippy::needless_lifetimes)] |
245 | | impl<'a> MultiItemVariationStore<'a> { |
246 | 0 | pub fn format(&self) -> u16 { |
247 | 0 | let range = self.shape.format_byte_range(); |
248 | 0 | self.data.read_at(range.start).unwrap() |
249 | 0 | } |
250 | | |
251 | 0 | pub fn region_list_offset(&self) -> Offset32 { |
252 | 0 | let range = self.shape.region_list_offset_byte_range(); |
253 | 0 | self.data.read_at(range.start).unwrap() |
254 | 0 | } |
255 | | |
256 | | /// Attempt to resolve [`region_list_offset`][Self::region_list_offset]. |
257 | 0 | pub fn region_list(&self) -> Result<SparseVariationRegionList<'a>, ReadError> { |
258 | 0 | let data = self.data; |
259 | 0 | self.region_list_offset().resolve(data) |
260 | 0 | } |
261 | | |
262 | 0 | pub fn variation_data_count(&self) -> u16 { |
263 | 0 | let range = self.shape.variation_data_count_byte_range(); |
264 | 0 | self.data.read_at(range.start).unwrap() |
265 | 0 | } |
266 | | |
267 | 0 | pub fn variation_data_offsets(&self) -> &'a [BigEndian<Offset32>] { |
268 | 0 | let range = self.shape.variation_data_offsets_byte_range(); |
269 | 0 | self.data.read_array(range).unwrap() |
270 | 0 | } |
271 | | |
272 | | /// A dynamically resolving wrapper for [`variation_data_offsets`][Self::variation_data_offsets]. |
273 | 0 | pub fn variation_data(&self) -> ArrayOfOffsets<'a, MultiItemVariationData<'a>, Offset32> { |
274 | 0 | let data = self.data; |
275 | 0 | let offsets = self.variation_data_offsets(); |
276 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
277 | 0 | } |
278 | | } |
279 | | |
280 | | #[cfg(feature = "experimental_traverse")] |
281 | | impl<'a> SomeTable<'a> for MultiItemVariationStore<'a> { |
282 | | fn type_name(&self) -> &str { |
283 | | "MultiItemVariationStore" |
284 | | } |
285 | | fn get_field(&self, idx: usize) -> Option<Field<'a>> { |
286 | | match idx { |
287 | | 0usize => Some(Field::new("format", self.format())), |
288 | | 1usize => Some(Field::new( |
289 | | "region_list_offset", |
290 | | FieldType::offset(self.region_list_offset(), self.region_list()), |
291 | | )), |
292 | | 2usize => Some(Field::new( |
293 | | "variation_data_count", |
294 | | self.variation_data_count(), |
295 | | )), |
296 | | 3usize => Some({ |
297 | | let data = self.data; |
298 | | Field::new( |
299 | | "variation_data_offsets", |
300 | | FieldType::array_of_offsets( |
301 | | better_type_name::<MultiItemVariationData>(), |
302 | | self.variation_data_offsets(), |
303 | | move |off| { |
304 | | let target = off.get().resolve::<MultiItemVariationData>(data); |
305 | | FieldType::offset(off.get(), target) |
306 | | }, |
307 | | ), |
308 | | ) |
309 | | }), |
310 | | _ => None, |
311 | | } |
312 | | } |
313 | | } |
314 | | |
315 | | #[cfg(feature = "experimental_traverse")] |
316 | | #[allow(clippy::needless_lifetimes)] |
317 | | impl<'a> std::fmt::Debug for MultiItemVariationStore<'a> { |
318 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
319 | | (self as &dyn SomeTable<'a>).fmt(f) |
320 | | } |
321 | | } |
322 | | |
323 | | #[derive(Debug, Clone, Copy)] |
324 | | #[doc(hidden)] |
325 | | pub struct SparseVariationRegionListMarker { |
326 | | region_offsets_byte_len: usize, |
327 | | } |
328 | | |
329 | | impl SparseVariationRegionListMarker { |
330 | 0 | pub fn region_count_byte_range(&self) -> Range<usize> { |
331 | 0 | let start = 0; |
332 | 0 | start..start + u16::RAW_BYTE_LEN |
333 | 0 | } |
334 | | |
335 | 0 | pub fn region_offsets_byte_range(&self) -> Range<usize> { |
336 | 0 | let start = self.region_count_byte_range().end; |
337 | 0 | start..start + self.region_offsets_byte_len |
338 | 0 | } |
339 | | } |
340 | | |
341 | | impl MinByteRange for SparseVariationRegionListMarker { |
342 | 0 | fn min_byte_range(&self) -> Range<usize> { |
343 | 0 | 0..self.region_offsets_byte_range().end |
344 | 0 | } |
345 | | } |
346 | | |
347 | | impl<'a> FontRead<'a> for SparseVariationRegionList<'a> { |
348 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
349 | 0 | let mut cursor = data.cursor(); |
350 | 0 | let region_count: u16 = cursor.read()?; |
351 | 0 | let region_offsets_byte_len = (region_count as usize) |
352 | 0 | .checked_mul(Offset32::RAW_BYTE_LEN) |
353 | 0 | .ok_or(ReadError::OutOfBounds)?; |
354 | 0 | cursor.advance_by(region_offsets_byte_len); |
355 | 0 | cursor.finish(SparseVariationRegionListMarker { |
356 | 0 | region_offsets_byte_len, |
357 | 0 | }) |
358 | 0 | } |
359 | | } |
360 | | |
361 | | pub type SparseVariationRegionList<'a> = TableRef<'a, SparseVariationRegionListMarker>; |
362 | | |
363 | | #[allow(clippy::needless_lifetimes)] |
364 | | impl<'a> SparseVariationRegionList<'a> { |
365 | 0 | pub fn region_count(&self) -> u16 { |
366 | 0 | let range = self.shape.region_count_byte_range(); |
367 | 0 | self.data.read_at(range.start).unwrap() |
368 | 0 | } |
369 | | |
370 | 0 | pub fn region_offsets(&self) -> &'a [BigEndian<Offset32>] { |
371 | 0 | let range = self.shape.region_offsets_byte_range(); |
372 | 0 | self.data.read_array(range).unwrap() |
373 | 0 | } |
374 | | |
375 | | /// A dynamically resolving wrapper for [`region_offsets`][Self::region_offsets]. |
376 | 0 | pub fn regions(&self) -> ArrayOfOffsets<'a, SparseVariationRegion<'a>, Offset32> { |
377 | 0 | let data = self.data; |
378 | 0 | let offsets = self.region_offsets(); |
379 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
380 | 0 | } |
381 | | } |
382 | | |
383 | | #[cfg(feature = "experimental_traverse")] |
384 | | impl<'a> SomeTable<'a> for SparseVariationRegionList<'a> { |
385 | | fn type_name(&self) -> &str { |
386 | | "SparseVariationRegionList" |
387 | | } |
388 | | fn get_field(&self, idx: usize) -> Option<Field<'a>> { |
389 | | match idx { |
390 | | 0usize => Some(Field::new("region_count", self.region_count())), |
391 | | 1usize => Some({ |
392 | | let data = self.data; |
393 | | Field::new( |
394 | | "region_offsets", |
395 | | FieldType::array_of_offsets( |
396 | | better_type_name::<SparseVariationRegion>(), |
397 | | self.region_offsets(), |
398 | | move |off| { |
399 | | let target = off.get().resolve::<SparseVariationRegion>(data); |
400 | | FieldType::offset(off.get(), target) |
401 | | }, |
402 | | ), |
403 | | ) |
404 | | }), |
405 | | _ => None, |
406 | | } |
407 | | } |
408 | | } |
409 | | |
410 | | #[cfg(feature = "experimental_traverse")] |
411 | | #[allow(clippy::needless_lifetimes)] |
412 | | impl<'a> std::fmt::Debug for SparseVariationRegionList<'a> { |
413 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
414 | | (self as &dyn SomeTable<'a>).fmt(f) |
415 | | } |
416 | | } |
417 | | |
418 | | #[derive(Debug, Clone, Copy)] |
419 | | #[doc(hidden)] |
420 | | pub struct SparseVariationRegionMarker { |
421 | | region_axis_offsets_byte_len: usize, |
422 | | } |
423 | | |
424 | | impl SparseVariationRegionMarker { |
425 | 0 | pub fn region_axis_count_byte_range(&self) -> Range<usize> { |
426 | 0 | let start = 0; |
427 | 0 | start..start + u16::RAW_BYTE_LEN |
428 | 0 | } |
429 | | |
430 | 0 | pub fn region_axis_offsets_byte_range(&self) -> Range<usize> { |
431 | 0 | let start = self.region_axis_count_byte_range().end; |
432 | 0 | start..start + self.region_axis_offsets_byte_len |
433 | 0 | } |
434 | | } |
435 | | |
436 | | impl MinByteRange for SparseVariationRegionMarker { |
437 | 0 | fn min_byte_range(&self) -> Range<usize> { |
438 | 0 | 0..self.region_axis_offsets_byte_range().end |
439 | 0 | } |
440 | | } |
441 | | |
442 | | impl<'a> FontRead<'a> for SparseVariationRegion<'a> { |
443 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
444 | 0 | let mut cursor = data.cursor(); |
445 | 0 | let region_axis_count: u16 = cursor.read()?; |
446 | 0 | let region_axis_offsets_byte_len = (region_axis_count as usize) |
447 | 0 | .checked_mul(SparseRegionAxisCoordinates::RAW_BYTE_LEN) |
448 | 0 | .ok_or(ReadError::OutOfBounds)?; |
449 | 0 | cursor.advance_by(region_axis_offsets_byte_len); |
450 | 0 | cursor.finish(SparseVariationRegionMarker { |
451 | 0 | region_axis_offsets_byte_len, |
452 | 0 | }) |
453 | 0 | } |
454 | | } |
455 | | |
456 | | pub type SparseVariationRegion<'a> = TableRef<'a, SparseVariationRegionMarker>; |
457 | | |
458 | | #[allow(clippy::needless_lifetimes)] |
459 | | impl<'a> SparseVariationRegion<'a> { |
460 | 0 | pub fn region_axis_count(&self) -> u16 { |
461 | 0 | let range = self.shape.region_axis_count_byte_range(); |
462 | 0 | self.data.read_at(range.start).unwrap() |
463 | 0 | } |
464 | | |
465 | 0 | pub fn region_axis_offsets(&self) -> &'a [SparseRegionAxisCoordinates] { |
466 | 0 | let range = self.shape.region_axis_offsets_byte_range(); |
467 | 0 | self.data.read_array(range).unwrap() |
468 | 0 | } |
469 | | } |
470 | | |
471 | | #[cfg(feature = "experimental_traverse")] |
472 | | impl<'a> SomeTable<'a> for SparseVariationRegion<'a> { |
473 | | fn type_name(&self) -> &str { |
474 | | "SparseVariationRegion" |
475 | | } |
476 | | fn get_field(&self, idx: usize) -> Option<Field<'a>> { |
477 | | match idx { |
478 | | 0usize => Some(Field::new("region_axis_count", self.region_axis_count())), |
479 | | 1usize => Some(Field::new( |
480 | | "region_axis_offsets", |
481 | | traversal::FieldType::array_of_records( |
482 | | stringify!(SparseRegionAxisCoordinates), |
483 | | self.region_axis_offsets(), |
484 | | self.offset_data(), |
485 | | ), |
486 | | )), |
487 | | _ => None, |
488 | | } |
489 | | } |
490 | | } |
491 | | |
492 | | #[cfg(feature = "experimental_traverse")] |
493 | | #[allow(clippy::needless_lifetimes)] |
494 | | impl<'a> std::fmt::Debug for SparseVariationRegion<'a> { |
495 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
496 | | (self as &dyn SomeTable<'a>).fmt(f) |
497 | | } |
498 | | } |
499 | | |
500 | | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)] |
501 | | #[repr(C)] |
502 | | #[repr(packed)] |
503 | | pub struct SparseRegionAxisCoordinates { |
504 | | pub axis_index: BigEndian<u16>, |
505 | | pub start: BigEndian<F2Dot14>, |
506 | | pub peak: BigEndian<F2Dot14>, |
507 | | pub end: BigEndian<F2Dot14>, |
508 | | } |
509 | | |
510 | | impl SparseRegionAxisCoordinates { |
511 | 0 | pub fn axis_index(&self) -> u16 { |
512 | 0 | self.axis_index.get() |
513 | 0 | } |
514 | | |
515 | 0 | pub fn start(&self) -> F2Dot14 { |
516 | 0 | self.start.get() |
517 | 0 | } |
518 | | |
519 | 0 | pub fn peak(&self) -> F2Dot14 { |
520 | 0 | self.peak.get() |
521 | 0 | } |
522 | | |
523 | 0 | pub fn end(&self) -> F2Dot14 { |
524 | 0 | self.end.get() |
525 | 0 | } |
526 | | } |
527 | | |
528 | | impl FixedSize for SparseRegionAxisCoordinates { |
529 | | const RAW_BYTE_LEN: usize = |
530 | | u16::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN; |
531 | | } |
532 | | |
533 | | #[cfg(feature = "experimental_traverse")] |
534 | | impl<'a> SomeRecord<'a> for SparseRegionAxisCoordinates { |
535 | | fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> { |
536 | | RecordResolver { |
537 | | name: "SparseRegionAxisCoordinates", |
538 | | get_field: Box::new(move |idx, _data| match idx { |
539 | | 0usize => Some(Field::new("axis_index", self.axis_index())), |
540 | | 1usize => Some(Field::new("start", self.start())), |
541 | | 2usize => Some(Field::new("peak", self.peak())), |
542 | | 3usize => Some(Field::new("end", self.end())), |
543 | | _ => None, |
544 | | }), |
545 | | data, |
546 | | } |
547 | | } |
548 | | } |
549 | | |
550 | | impl Format<u8> for MultiItemVariationDataMarker { |
551 | | const FORMAT: u8 = 1; |
552 | | } |
553 | | |
554 | | #[derive(Debug, Clone, Copy)] |
555 | | #[doc(hidden)] |
556 | | pub struct MultiItemVariationDataMarker { |
557 | | region_indices_byte_len: usize, |
558 | | raw_delta_sets_byte_len: usize, |
559 | | } |
560 | | |
561 | | impl MultiItemVariationDataMarker { |
562 | 0 | pub fn format_byte_range(&self) -> Range<usize> { |
563 | 0 | let start = 0; |
564 | 0 | start..start + u8::RAW_BYTE_LEN |
565 | 0 | } |
566 | | |
567 | 0 | pub fn region_index_count_byte_range(&self) -> Range<usize> { |
568 | 0 | let start = self.format_byte_range().end; |
569 | 0 | start..start + u16::RAW_BYTE_LEN |
570 | 0 | } |
571 | | |
572 | 0 | pub fn region_indices_byte_range(&self) -> Range<usize> { |
573 | 0 | let start = self.region_index_count_byte_range().end; |
574 | 0 | start..start + self.region_indices_byte_len |
575 | 0 | } |
576 | | |
577 | 0 | pub fn raw_delta_sets_byte_range(&self) -> Range<usize> { |
578 | 0 | let start = self.region_indices_byte_range().end; |
579 | 0 | start..start + self.raw_delta_sets_byte_len |
580 | 0 | } |
581 | | } |
582 | | |
583 | | impl MinByteRange for MultiItemVariationDataMarker { |
584 | 0 | fn min_byte_range(&self) -> Range<usize> { |
585 | 0 | 0..self.raw_delta_sets_byte_range().end |
586 | 0 | } |
587 | | } |
588 | | |
589 | | impl<'a> FontRead<'a> for MultiItemVariationData<'a> { |
590 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
591 | 0 | let mut cursor = data.cursor(); |
592 | 0 | cursor.advance::<u8>(); |
593 | 0 | let region_index_count: u16 = cursor.read()?; |
594 | 0 | let region_indices_byte_len = (region_index_count as usize) |
595 | 0 | .checked_mul(u16::RAW_BYTE_LEN) |
596 | 0 | .ok_or(ReadError::OutOfBounds)?; |
597 | 0 | cursor.advance_by(region_indices_byte_len); |
598 | 0 | let raw_delta_sets_byte_len = |
599 | 0 | cursor.remaining_bytes() / u8::RAW_BYTE_LEN * u8::RAW_BYTE_LEN; |
600 | 0 | cursor.advance_by(raw_delta_sets_byte_len); |
601 | 0 | cursor.finish(MultiItemVariationDataMarker { |
602 | 0 | region_indices_byte_len, |
603 | 0 | raw_delta_sets_byte_len, |
604 | 0 | }) |
605 | 0 | } |
606 | | } |
607 | | |
608 | | pub type MultiItemVariationData<'a> = TableRef<'a, MultiItemVariationDataMarker>; |
609 | | |
610 | | #[allow(clippy::needless_lifetimes)] |
611 | | impl<'a> MultiItemVariationData<'a> { |
612 | 0 | pub fn format(&self) -> u8 { |
613 | 0 | let range = self.shape.format_byte_range(); |
614 | 0 | self.data.read_at(range.start).unwrap() |
615 | 0 | } |
616 | | |
617 | 0 | pub fn region_index_count(&self) -> u16 { |
618 | 0 | let range = self.shape.region_index_count_byte_range(); |
619 | 0 | self.data.read_at(range.start).unwrap() |
620 | 0 | } |
621 | | |
622 | 0 | pub fn region_indices(&self) -> &'a [BigEndian<u16>] { |
623 | 0 | let range = self.shape.region_indices_byte_range(); |
624 | 0 | self.data.read_array(range).unwrap() |
625 | 0 | } |
626 | | |
627 | 0 | pub fn raw_delta_sets(&self) -> &'a [u8] { |
628 | 0 | let range = self.shape.raw_delta_sets_byte_range(); |
629 | 0 | self.data.read_array(range).unwrap() |
630 | 0 | } |
631 | | } |
632 | | |
633 | | #[cfg(feature = "experimental_traverse")] |
634 | | impl<'a> SomeTable<'a> for MultiItemVariationData<'a> { |
635 | | fn type_name(&self) -> &str { |
636 | | "MultiItemVariationData" |
637 | | } |
638 | | fn get_field(&self, idx: usize) -> Option<Field<'a>> { |
639 | | match idx { |
640 | | 0usize => Some(Field::new("format", self.format())), |
641 | | 1usize => Some(Field::new("region_index_count", self.region_index_count())), |
642 | | 2usize => Some(Field::new("region_indices", self.region_indices())), |
643 | | 3usize => Some(Field::new("raw_delta_sets", self.raw_delta_sets())), |
644 | | _ => None, |
645 | | } |
646 | | } |
647 | | } |
648 | | |
649 | | #[cfg(feature = "experimental_traverse")] |
650 | | #[allow(clippy::needless_lifetimes)] |
651 | | impl<'a> std::fmt::Debug for MultiItemVariationData<'a> { |
652 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
653 | | (self as &dyn SomeTable<'a>).fmt(f) |
654 | | } |
655 | | } |
656 | | |
657 | | #[derive(Debug, Clone, Copy)] |
658 | | #[doc(hidden)] |
659 | | pub struct ConditionListMarker { |
660 | | condition_offsets_byte_len: usize, |
661 | | } |
662 | | |
663 | | impl ConditionListMarker { |
664 | 0 | pub fn condition_count_byte_range(&self) -> Range<usize> { |
665 | 0 | let start = 0; |
666 | 0 | start..start + u32::RAW_BYTE_LEN |
667 | 0 | } |
668 | | |
669 | 0 | pub fn condition_offsets_byte_range(&self) -> Range<usize> { |
670 | 0 | let start = self.condition_count_byte_range().end; |
671 | 0 | start..start + self.condition_offsets_byte_len |
672 | 0 | } |
673 | | } |
674 | | |
675 | | impl MinByteRange for ConditionListMarker { |
676 | 0 | fn min_byte_range(&self) -> Range<usize> { |
677 | 0 | 0..self.condition_offsets_byte_range().end |
678 | 0 | } |
679 | | } |
680 | | |
681 | | impl<'a> FontRead<'a> for ConditionList<'a> { |
682 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
683 | 0 | let mut cursor = data.cursor(); |
684 | 0 | let condition_count: u32 = cursor.read()?; |
685 | 0 | let condition_offsets_byte_len = (condition_count as usize) |
686 | 0 | .checked_mul(Offset32::RAW_BYTE_LEN) |
687 | 0 | .ok_or(ReadError::OutOfBounds)?; |
688 | 0 | cursor.advance_by(condition_offsets_byte_len); |
689 | 0 | cursor.finish(ConditionListMarker { |
690 | 0 | condition_offsets_byte_len, |
691 | 0 | }) |
692 | 0 | } |
693 | | } |
694 | | |
695 | | pub type ConditionList<'a> = TableRef<'a, ConditionListMarker>; |
696 | | |
697 | | #[allow(clippy::needless_lifetimes)] |
698 | | impl<'a> ConditionList<'a> { |
699 | 0 | pub fn condition_count(&self) -> u32 { |
700 | 0 | let range = self.shape.condition_count_byte_range(); |
701 | 0 | self.data.read_at(range.start).unwrap() |
702 | 0 | } |
703 | | |
704 | 0 | pub fn condition_offsets(&self) -> &'a [BigEndian<Offset32>] { |
705 | 0 | let range = self.shape.condition_offsets_byte_range(); |
706 | 0 | self.data.read_array(range).unwrap() |
707 | 0 | } |
708 | | |
709 | | /// A dynamically resolving wrapper for [`condition_offsets`][Self::condition_offsets]. |
710 | 0 | pub fn conditions(&self) -> ArrayOfOffsets<'a, Condition<'a>, Offset32> { |
711 | 0 | let data = self.data; |
712 | 0 | let offsets = self.condition_offsets(); |
713 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
714 | 0 | } |
715 | | } |
716 | | |
717 | | #[cfg(feature = "experimental_traverse")] |
718 | | impl<'a> SomeTable<'a> for ConditionList<'a> { |
719 | | fn type_name(&self) -> &str { |
720 | | "ConditionList" |
721 | | } |
722 | | fn get_field(&self, idx: usize) -> Option<Field<'a>> { |
723 | | match idx { |
724 | | 0usize => Some(Field::new("condition_count", self.condition_count())), |
725 | | 1usize => Some({ |
726 | | let data = self.data; |
727 | | Field::new( |
728 | | "condition_offsets", |
729 | | FieldType::array_of_offsets( |
730 | | better_type_name::<Condition>(), |
731 | | self.condition_offsets(), |
732 | | move |off| { |
733 | | let target = off.get().resolve::<Condition>(data); |
734 | | FieldType::offset(off.get(), target) |
735 | | }, |
736 | | ), |
737 | | ) |
738 | | }), |
739 | | _ => None, |
740 | | } |
741 | | } |
742 | | } |
743 | | |
744 | | #[cfg(feature = "experimental_traverse")] |
745 | | #[allow(clippy::needless_lifetimes)] |
746 | | impl<'a> std::fmt::Debug for ConditionList<'a> { |
747 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
748 | | (self as &dyn SomeTable<'a>).fmt(f) |
749 | | } |
750 | | } |
751 | | |
752 | | /// Flags used in the [VarcComponent] byte stream |
753 | | /// |
754 | | /// <https://github.com/harfbuzz/boring-expansion-spec/blob/main/VARC.md#variable-component-flags> |
755 | | #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)] |
756 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
757 | | #[repr(transparent)] |
758 | | pub struct VarcFlags { |
759 | | bits: u32, |
760 | | } |
761 | | |
762 | | impl VarcFlags { |
763 | | pub const RESET_UNSPECIFIED_AXES: Self = Self { |
764 | | bits: 0b0000_0000_0000_0001, |
765 | | }; |
766 | | |
767 | | pub const HAVE_AXES: Self = Self { |
768 | | bits: 0b0000_0000_0000_0010, |
769 | | }; |
770 | | |
771 | | pub const AXIS_VALUES_HAVE_VARIATION: Self = Self { |
772 | | bits: 0b0000_0000_0000_0100, |
773 | | }; |
774 | | |
775 | | pub const TRANSFORM_HAS_VARIATION: Self = Self { |
776 | | bits: 0b0000_0000_0000_1000, |
777 | | }; |
778 | | |
779 | | pub const HAVE_TRANSLATE_X: Self = Self { |
780 | | bits: 0b0000_0000_0001_0000, |
781 | | }; |
782 | | |
783 | | pub const HAVE_TRANSLATE_Y: Self = Self { |
784 | | bits: 0b0000_0000_0010_0000, |
785 | | }; |
786 | | |
787 | | pub const HAVE_ROTATION: Self = Self { |
788 | | bits: 0b0000_0000_0100_0000, |
789 | | }; |
790 | | |
791 | | pub const HAVE_CONDITION: Self = Self { |
792 | | bits: 0b0000_0000_1000_0000, |
793 | | }; |
794 | | |
795 | | pub const HAVE_SCALE_X: Self = Self { |
796 | | bits: 0b0000_0001_0000_0000, |
797 | | }; |
798 | | |
799 | | pub const HAVE_SCALE_Y: Self = Self { |
800 | | bits: 0b0000_0010_0000_0000, |
801 | | }; |
802 | | |
803 | | pub const HAVE_TCENTER_X: Self = Self { |
804 | | bits: 0b0000_0100_0000_0000, |
805 | | }; |
806 | | |
807 | | pub const HAVE_TCENTER_Y: Self = Self { |
808 | | bits: 0b0000_1000_0000_0000, |
809 | | }; |
810 | | |
811 | | pub const GID_IS_24BIT: Self = Self { |
812 | | bits: 0b0001_0000_0000_0000, |
813 | | }; |
814 | | |
815 | | pub const HAVE_SKEW_X: Self = Self { |
816 | | bits: 0b0010_0000_0000_0000, |
817 | | }; |
818 | | |
819 | | pub const HAVE_SKEW_Y: Self = Self { |
820 | | bits: 0b0100_0000_0000_0000, |
821 | | }; |
822 | | |
823 | | pub const RESERVED_MASK: Self = Self { bits: 0xFFFF8000 }; |
824 | | } |
825 | | |
826 | | impl VarcFlags { |
827 | | /// Returns an empty set of flags. |
828 | | #[inline] |
829 | 0 | pub const fn empty() -> Self { |
830 | 0 | Self { bits: 0 } |
831 | 0 | } |
832 | | |
833 | | /// Returns the set containing all flags. |
834 | | #[inline] |
835 | 0 | pub const fn all() -> Self { |
836 | 0 | Self { |
837 | 0 | bits: Self::RESET_UNSPECIFIED_AXES.bits |
838 | 0 | | Self::HAVE_AXES.bits |
839 | 0 | | Self::AXIS_VALUES_HAVE_VARIATION.bits |
840 | 0 | | Self::TRANSFORM_HAS_VARIATION.bits |
841 | 0 | | Self::HAVE_TRANSLATE_X.bits |
842 | 0 | | Self::HAVE_TRANSLATE_Y.bits |
843 | 0 | | Self::HAVE_ROTATION.bits |
844 | 0 | | Self::HAVE_CONDITION.bits |
845 | 0 | | Self::HAVE_SCALE_X.bits |
846 | 0 | | Self::HAVE_SCALE_Y.bits |
847 | 0 | | Self::HAVE_TCENTER_X.bits |
848 | 0 | | Self::HAVE_TCENTER_Y.bits |
849 | 0 | | Self::GID_IS_24BIT.bits |
850 | 0 | | Self::HAVE_SKEW_X.bits |
851 | 0 | | Self::HAVE_SKEW_Y.bits |
852 | 0 | | Self::RESERVED_MASK.bits, |
853 | 0 | } |
854 | 0 | } |
855 | | |
856 | | /// Returns the raw value of the flags currently stored. |
857 | | #[inline] |
858 | 0 | pub const fn bits(&self) -> u32 { |
859 | 0 | self.bits |
860 | 0 | } |
861 | | |
862 | | /// Convert from underlying bit representation, unless that |
863 | | /// representation contains bits that do not correspond to a flag. |
864 | | #[inline] |
865 | 0 | pub const fn from_bits(bits: u32) -> Option<Self> { |
866 | 0 | if (bits & !Self::all().bits()) == 0 { |
867 | 0 | Some(Self { bits }) |
868 | | } else { |
869 | 0 | None |
870 | | } |
871 | 0 | } |
872 | | |
873 | | /// Convert from underlying bit representation, dropping any bits |
874 | | /// that do not correspond to flags. |
875 | | #[inline] |
876 | 0 | pub const fn from_bits_truncate(bits: u32) -> Self { |
877 | 0 | Self { |
878 | 0 | bits: bits & Self::all().bits, |
879 | 0 | } |
880 | 0 | } |
881 | | |
882 | | /// Returns `true` if no flags are currently stored. |
883 | | #[inline] |
884 | 0 | pub const fn is_empty(&self) -> bool { |
885 | 0 | self.bits() == Self::empty().bits() |
886 | 0 | } |
887 | | |
888 | | /// Returns `true` if there are flags common to both `self` and `other`. |
889 | | #[inline] |
890 | 0 | pub const fn intersects(&self, other: Self) -> bool { |
891 | 0 | !(Self { |
892 | 0 | bits: self.bits & other.bits, |
893 | 0 | }) |
894 | 0 | .is_empty() |
895 | 0 | } |
896 | | |
897 | | /// Returns `true` if all of the flags in `other` are contained within `self`. |
898 | | #[inline] |
899 | 0 | pub const fn contains(&self, other: Self) -> bool { |
900 | 0 | (self.bits & other.bits) == other.bits |
901 | 0 | } |
902 | | |
903 | | /// Inserts the specified flags in-place. |
904 | | #[inline] |
905 | 0 | pub fn insert(&mut self, other: Self) { |
906 | 0 | self.bits |= other.bits; |
907 | 0 | } |
908 | | |
909 | | /// Removes the specified flags in-place. |
910 | | #[inline] |
911 | 0 | pub fn remove(&mut self, other: Self) { |
912 | 0 | self.bits &= !other.bits; |
913 | 0 | } |
914 | | |
915 | | /// Toggles the specified flags in-place. |
916 | | #[inline] |
917 | 0 | pub fn toggle(&mut self, other: Self) { |
918 | 0 | self.bits ^= other.bits; |
919 | 0 | } |
920 | | |
921 | | /// Returns the intersection between the flags in `self` and |
922 | | /// `other`. |
923 | | /// |
924 | | /// Specifically, the returned set contains only the flags which are |
925 | | /// present in *both* `self` *and* `other`. |
926 | | /// |
927 | | /// This is equivalent to using the `&` operator (e.g. |
928 | | /// [`ops::BitAnd`]), as in `flags & other`. |
929 | | /// |
930 | | /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html |
931 | | #[inline] |
932 | | #[must_use] |
933 | 0 | pub const fn intersection(self, other: Self) -> Self { |
934 | 0 | Self { |
935 | 0 | bits: self.bits & other.bits, |
936 | 0 | } |
937 | 0 | } |
938 | | |
939 | | /// Returns the union of between the flags in `self` and `other`. |
940 | | /// |
941 | | /// Specifically, the returned set contains all flags which are |
942 | | /// present in *either* `self` *or* `other`, including any which are |
943 | | /// present in both. |
944 | | /// |
945 | | /// This is equivalent to using the `|` operator (e.g. |
946 | | /// [`ops::BitOr`]), as in `flags | other`. |
947 | | /// |
948 | | /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html |
949 | | #[inline] |
950 | | #[must_use] |
951 | 0 | pub const fn union(self, other: Self) -> Self { |
952 | 0 | Self { |
953 | 0 | bits: self.bits | other.bits, |
954 | 0 | } |
955 | 0 | } |
956 | | |
957 | | /// Returns the difference between the flags in `self` and `other`. |
958 | | /// |
959 | | /// Specifically, the returned set contains all flags present in |
960 | | /// `self`, except for the ones present in `other`. |
961 | | /// |
962 | | /// It is also conceptually equivalent to the "bit-clear" operation: |
963 | | /// `flags & !other` (and this syntax is also supported). |
964 | | /// |
965 | | /// This is equivalent to using the `-` operator (e.g. |
966 | | /// [`ops::Sub`]), as in `flags - other`. |
967 | | /// |
968 | | /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html |
969 | | #[inline] |
970 | | #[must_use] |
971 | 0 | pub const fn difference(self, other: Self) -> Self { |
972 | 0 | Self { |
973 | 0 | bits: self.bits & !other.bits, |
974 | 0 | } |
975 | 0 | } |
976 | | } |
977 | | |
978 | | impl std::ops::BitOr for VarcFlags { |
979 | | type Output = Self; |
980 | | |
981 | | /// Returns the union of the two sets of flags. |
982 | | #[inline] |
983 | 0 | fn bitor(self, other: VarcFlags) -> Self { |
984 | 0 | Self { |
985 | 0 | bits: self.bits | other.bits, |
986 | 0 | } |
987 | 0 | } |
988 | | } |
989 | | |
990 | | impl std::ops::BitOrAssign for VarcFlags { |
991 | | /// Adds the set of flags. |
992 | | #[inline] |
993 | 0 | fn bitor_assign(&mut self, other: Self) { |
994 | 0 | self.bits |= other.bits; |
995 | 0 | } |
996 | | } |
997 | | |
998 | | impl std::ops::BitXor for VarcFlags { |
999 | | type Output = Self; |
1000 | | |
1001 | | /// Returns the left flags, but with all the right flags toggled. |
1002 | | #[inline] |
1003 | 0 | fn bitxor(self, other: Self) -> Self { |
1004 | 0 | Self { |
1005 | 0 | bits: self.bits ^ other.bits, |
1006 | 0 | } |
1007 | 0 | } |
1008 | | } |
1009 | | |
1010 | | impl std::ops::BitXorAssign for VarcFlags { |
1011 | | /// Toggles the set of flags. |
1012 | | #[inline] |
1013 | 0 | fn bitxor_assign(&mut self, other: Self) { |
1014 | 0 | self.bits ^= other.bits; |
1015 | 0 | } |
1016 | | } |
1017 | | |
1018 | | impl std::ops::BitAnd for VarcFlags { |
1019 | | type Output = Self; |
1020 | | |
1021 | | /// Returns the intersection between the two sets of flags. |
1022 | | #[inline] |
1023 | 0 | fn bitand(self, other: Self) -> Self { |
1024 | 0 | Self { |
1025 | 0 | bits: self.bits & other.bits, |
1026 | 0 | } |
1027 | 0 | } |
1028 | | } |
1029 | | |
1030 | | impl std::ops::BitAndAssign for VarcFlags { |
1031 | | /// Disables all flags disabled in the set. |
1032 | | #[inline] |
1033 | 0 | fn bitand_assign(&mut self, other: Self) { |
1034 | 0 | self.bits &= other.bits; |
1035 | 0 | } |
1036 | | } |
1037 | | |
1038 | | impl std::ops::Sub for VarcFlags { |
1039 | | type Output = Self; |
1040 | | |
1041 | | /// Returns the set difference of the two sets of flags. |
1042 | | #[inline] |
1043 | 0 | fn sub(self, other: Self) -> Self { |
1044 | 0 | Self { |
1045 | 0 | bits: self.bits & !other.bits, |
1046 | 0 | } |
1047 | 0 | } |
1048 | | } |
1049 | | |
1050 | | impl std::ops::SubAssign for VarcFlags { |
1051 | | /// Disables all flags enabled in the set. |
1052 | | #[inline] |
1053 | 0 | fn sub_assign(&mut self, other: Self) { |
1054 | 0 | self.bits &= !other.bits; |
1055 | 0 | } |
1056 | | } |
1057 | | |
1058 | | impl std::ops::Not for VarcFlags { |
1059 | | type Output = Self; |
1060 | | |
1061 | | /// Returns the complement of this set of flags. |
1062 | | #[inline] |
1063 | 0 | fn not(self) -> Self { |
1064 | 0 | Self { bits: !self.bits } & Self::all() |
1065 | 0 | } |
1066 | | } |
1067 | | |
1068 | | impl std::fmt::Debug for VarcFlags { |
1069 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
1070 | 0 | let members: &[(&str, Self)] = &[ |
1071 | 0 | ("RESET_UNSPECIFIED_AXES", Self::RESET_UNSPECIFIED_AXES), |
1072 | 0 | ("HAVE_AXES", Self::HAVE_AXES), |
1073 | 0 | ( |
1074 | 0 | "AXIS_VALUES_HAVE_VARIATION", |
1075 | 0 | Self::AXIS_VALUES_HAVE_VARIATION, |
1076 | 0 | ), |
1077 | 0 | ("TRANSFORM_HAS_VARIATION", Self::TRANSFORM_HAS_VARIATION), |
1078 | 0 | ("HAVE_TRANSLATE_X", Self::HAVE_TRANSLATE_X), |
1079 | 0 | ("HAVE_TRANSLATE_Y", Self::HAVE_TRANSLATE_Y), |
1080 | 0 | ("HAVE_ROTATION", Self::HAVE_ROTATION), |
1081 | 0 | ("HAVE_CONDITION", Self::HAVE_CONDITION), |
1082 | 0 | ("HAVE_SCALE_X", Self::HAVE_SCALE_X), |
1083 | 0 | ("HAVE_SCALE_Y", Self::HAVE_SCALE_Y), |
1084 | 0 | ("HAVE_TCENTER_X", Self::HAVE_TCENTER_X), |
1085 | 0 | ("HAVE_TCENTER_Y", Self::HAVE_TCENTER_Y), |
1086 | 0 | ("GID_IS_24BIT", Self::GID_IS_24BIT), |
1087 | 0 | ("HAVE_SKEW_X", Self::HAVE_SKEW_X), |
1088 | 0 | ("HAVE_SKEW_Y", Self::HAVE_SKEW_Y), |
1089 | 0 | ("RESERVED_MASK", Self::RESERVED_MASK), |
1090 | 0 | ]; |
1091 | 0 | let mut first = true; |
1092 | 0 | for (name, value) in members { |
1093 | 0 | if self.contains(*value) { |
1094 | 0 | if !first { |
1095 | 0 | f.write_str(" | ")?; |
1096 | 0 | } |
1097 | 0 | first = false; |
1098 | 0 | f.write_str(name)?; |
1099 | 0 | } |
1100 | | } |
1101 | 0 | if first { |
1102 | 0 | f.write_str("(empty)")?; |
1103 | 0 | } |
1104 | 0 | Ok(()) |
1105 | 0 | } |
1106 | | } |
1107 | | |
1108 | | impl std::fmt::Binary for VarcFlags { |
1109 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
1110 | 0 | std::fmt::Binary::fmt(&self.bits, f) |
1111 | 0 | } |
1112 | | } |
1113 | | |
1114 | | impl std::fmt::Octal for VarcFlags { |
1115 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
1116 | 0 | std::fmt::Octal::fmt(&self.bits, f) |
1117 | 0 | } |
1118 | | } |
1119 | | |
1120 | | impl std::fmt::LowerHex for VarcFlags { |
1121 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
1122 | 0 | std::fmt::LowerHex::fmt(&self.bits, f) |
1123 | 0 | } |
1124 | | } |
1125 | | |
1126 | | impl std::fmt::UpperHex for VarcFlags { |
1127 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
1128 | 0 | std::fmt::UpperHex::fmt(&self.bits, f) |
1129 | 0 | } |
1130 | | } |
1131 | | |
1132 | | impl font_types::Scalar for VarcFlags { |
1133 | | type Raw = <u32 as font_types::Scalar>::Raw; |
1134 | 0 | fn to_raw(self) -> Self::Raw { |
1135 | 0 | self.bits().to_raw() |
1136 | 0 | } |
1137 | 0 | fn from_raw(raw: Self::Raw) -> Self { |
1138 | 0 | let t = <u32>::from_raw(raw); |
1139 | 0 | Self::from_bits_truncate(t) |
1140 | 0 | } |
1141 | | } |
1142 | | |
1143 | | #[cfg(feature = "experimental_traverse")] |
1144 | | impl<'a> From<VarcFlags> for FieldType<'a> { |
1145 | | fn from(src: VarcFlags) -> FieldType<'a> { |
1146 | | src.bits().into() |
1147 | | } |
1148 | | } |