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 /// [STAT](https://docs.microsoft.com/en-us/typography/opentype/spec/stat) (Style Attributes Table)
9 #[derive(Debug, Clone, Copy)]
10 #[doc(hidden)]
11 pub struct StatMarker {
12     elided_fallback_name_id_byte_start: Option<usize>,
13 }
14 
15 impl StatMarker {
version_byte_range(&self) -> Range<usize>16     fn version_byte_range(&self) -> Range<usize> {
17         let start = 0;
18         start..start + MajorMinor::RAW_BYTE_LEN
19     }
design_axis_size_byte_range(&self) -> Range<usize>20     fn design_axis_size_byte_range(&self) -> Range<usize> {
21         let start = self.version_byte_range().end;
22         start..start + u16::RAW_BYTE_LEN
23     }
design_axis_count_byte_range(&self) -> Range<usize>24     fn design_axis_count_byte_range(&self) -> Range<usize> {
25         let start = self.design_axis_size_byte_range().end;
26         start..start + u16::RAW_BYTE_LEN
27     }
design_axes_offset_byte_range(&self) -> Range<usize>28     fn design_axes_offset_byte_range(&self) -> Range<usize> {
29         let start = self.design_axis_count_byte_range().end;
30         start..start + Offset32::RAW_BYTE_LEN
31     }
axis_value_count_byte_range(&self) -> Range<usize>32     fn axis_value_count_byte_range(&self) -> Range<usize> {
33         let start = self.design_axes_offset_byte_range().end;
34         start..start + u16::RAW_BYTE_LEN
35     }
offset_to_axis_value_offsets_byte_range(&self) -> Range<usize>36     fn offset_to_axis_value_offsets_byte_range(&self) -> Range<usize> {
37         let start = self.axis_value_count_byte_range().end;
38         start..start + Offset32::RAW_BYTE_LEN
39     }
elided_fallback_name_id_byte_range(&self) -> Option<Range<usize>>40     fn elided_fallback_name_id_byte_range(&self) -> Option<Range<usize>> {
41         let start = self.elided_fallback_name_id_byte_start?;
42         Some(start..start + NameId::RAW_BYTE_LEN)
43     }
44 }
45 
46 impl TopLevelTable for Stat<'_> {
47     /// `STAT`
48     const TAG: Tag = Tag::new(b"STAT");
49 }
50 
51 impl<'a> FontRead<'a> for Stat<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>52     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
53         let mut cursor = data.cursor();
54         let version: MajorMinor = cursor.read()?;
55         cursor.advance::<u16>();
56         cursor.advance::<u16>();
57         cursor.advance::<Offset32>();
58         cursor.advance::<u16>();
59         cursor.advance::<Offset32>();
60         let elided_fallback_name_id_byte_start = version
61             .compatible((1, 1))
62             .then(|| cursor.position())
63             .transpose()?;
64         version
65             .compatible((1, 1))
66             .then(|| cursor.advance::<NameId>());
67         cursor.finish(StatMarker {
68             elided_fallback_name_id_byte_start,
69         })
70     }
71 }
72 
73 /// [STAT](https://docs.microsoft.com/en-us/typography/opentype/spec/stat) (Style Attributes Table)
74 pub type Stat<'a> = TableRef<'a, StatMarker>;
75 
76 impl<'a> Stat<'a> {
77     /// Major/minor version number. Set to 1.2 for new fonts.
version(&self) -> MajorMinor78     pub fn version(&self) -> MajorMinor {
79         let range = self.shape.version_byte_range();
80         self.data.read_at(range.start).unwrap()
81     }
82 
83     /// The size in bytes of each axis record.
design_axis_size(&self) -> u1684     pub fn design_axis_size(&self) -> u16 {
85         let range = self.shape.design_axis_size_byte_range();
86         self.data.read_at(range.start).unwrap()
87     }
88 
89     /// The number of axis records. In a font with an 'fvar' table,
90     /// this value must be greater than or equal to the axisCount value
91     /// in the 'fvar' table. In all fonts, must be greater than zero if
92     /// axisValueCount is greater than zero.
design_axis_count(&self) -> u1693     pub fn design_axis_count(&self) -> u16 {
94         let range = self.shape.design_axis_count_byte_range();
95         self.data.read_at(range.start).unwrap()
96     }
97 
98     /// Offset in bytes from the beginning of the STAT table to the
99     /// start of the design axes array. If designAxisCount is zero, set
100     /// to zero; if designAxisCount is greater than zero, must be
101     /// greater than zero.
design_axes_offset(&self) -> Offset32102     pub fn design_axes_offset(&self) -> Offset32 {
103         let range = self.shape.design_axes_offset_byte_range();
104         self.data.read_at(range.start).unwrap()
105     }
106 
107     /// Attempt to resolve [`design_axes_offset`][Self::design_axes_offset].
design_axes(&self) -> Result<&'a [AxisRecord], ReadError>108     pub fn design_axes(&self) -> Result<&'a [AxisRecord], ReadError> {
109         let data = self.data;
110         let args = self.design_axis_count();
111         self.design_axes_offset().resolve_with_args(data, &args)
112     }
113 
114     /// The number of axis value tables.
axis_value_count(&self) -> u16115     pub fn axis_value_count(&self) -> u16 {
116         let range = self.shape.axis_value_count_byte_range();
117         self.data.read_at(range.start).unwrap()
118     }
119 
120     /// Offset in bytes from the beginning of the STAT table to the
121     /// start of the design axes value offsets array. If axisValueCount
122     /// is zero, set to zero; if axisValueCount is greater than zero,
123     /// must be greater than zero.
offset_to_axis_value_offsets(&self) -> Nullable<Offset32>124     pub fn offset_to_axis_value_offsets(&self) -> Nullable<Offset32> {
125         let range = self.shape.offset_to_axis_value_offsets_byte_range();
126         self.data.read_at(range.start).unwrap()
127     }
128 
129     /// Attempt to resolve [`offset_to_axis_value_offsets`][Self::offset_to_axis_value_offsets].
offset_to_axis_values(&self) -> Option<Result<AxisValueArray<'a>, ReadError>>130     pub fn offset_to_axis_values(&self) -> Option<Result<AxisValueArray<'a>, ReadError>> {
131         let data = self.data;
132         let args = self.axis_value_count();
133         self.offset_to_axis_value_offsets()
134             .resolve_with_args(data, &args)
135     }
136 
137     /// Name ID used as fallback when projection of names into a
138     /// particular font model produces a subfamily name containing only
139     /// elidable elements.
elided_fallback_name_id(&self) -> Option<NameId>140     pub fn elided_fallback_name_id(&self) -> Option<NameId> {
141         let range = self.shape.elided_fallback_name_id_byte_range()?;
142         Some(self.data.read_at(range.start).unwrap())
143     }
144 }
145 
146 #[cfg(feature = "traversal")]
147 impl<'a> SomeTable<'a> for Stat<'a> {
type_name(&self) -> &str148     fn type_name(&self) -> &str {
149         "Stat"
150     }
get_field(&self, idx: usize) -> Option<Field<'a>>151     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
152         let version = self.version();
153         match idx {
154             0usize => Some(Field::new("version", self.version())),
155             1usize => Some(Field::new("design_axis_size", self.design_axis_size())),
156             2usize => Some(Field::new("design_axis_count", self.design_axis_count())),
157             3usize => Some(Field::new(
158                 "design_axes_offset",
159                 traversal::FieldType::offset_to_array_of_records(
160                     self.design_axes_offset(),
161                     self.design_axes(),
162                     stringify!(AxisRecord),
163                     self.offset_data(),
164                 ),
165             )),
166             4usize => Some(Field::new("axis_value_count", self.axis_value_count())),
167             5usize => Some(Field::new(
168                 "offset_to_axis_value_offsets",
169                 FieldType::offset(
170                     self.offset_to_axis_value_offsets(),
171                     self.offset_to_axis_values(),
172                 ),
173             )),
174             6usize if version.compatible((1, 1)) => Some(Field::new(
175                 "elided_fallback_name_id",
176                 self.elided_fallback_name_id().unwrap(),
177             )),
178             _ => None,
179         }
180     }
181 }
182 
183 #[cfg(feature = "traversal")]
184 impl<'a> std::fmt::Debug for Stat<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result185     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
186         (self as &dyn SomeTable<'a>).fmt(f)
187     }
188 }
189 
190 /// [Axis Records](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-records)
191 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
192 #[repr(C)]
193 #[repr(packed)]
194 pub struct AxisRecord {
195     /// A tag identifying the axis of design variation.
196     pub axis_tag: BigEndian<Tag>,
197     /// The name ID for entries in the 'name' table that provide a
198     /// display string for this axis.
199     pub axis_name_id: BigEndian<NameId>,
200     /// A value that applications can use to determine primary sorting
201     /// of face names, or for ordering of labels when composing family
202     /// or face names.
203     pub axis_ordering: BigEndian<u16>,
204 }
205 
206 impl AxisRecord {
207     /// A tag identifying the axis of design variation.
axis_tag(&self) -> Tag208     pub fn axis_tag(&self) -> Tag {
209         self.axis_tag.get()
210     }
211 
212     /// The name ID for entries in the 'name' table that provide a
213     /// display string for this axis.
axis_name_id(&self) -> NameId214     pub fn axis_name_id(&self) -> NameId {
215         self.axis_name_id.get()
216     }
217 
218     /// A value that applications can use to determine primary sorting
219     /// of face names, or for ordering of labels when composing family
220     /// or face names.
axis_ordering(&self) -> u16221     pub fn axis_ordering(&self) -> u16 {
222         self.axis_ordering.get()
223     }
224 }
225 
226 impl FixedSize for AxisRecord {
227     const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + NameId::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
228 }
229 
230 impl sealed::Sealed for AxisRecord {}
231 
232 /// SAFETY: see the [`FromBytes`] trait documentation.
233 unsafe impl FromBytes for AxisRecord {
this_trait_should_only_be_implemented_in_generated_code()234     fn this_trait_should_only_be_implemented_in_generated_code() {}
235 }
236 
237 #[cfg(feature = "traversal")]
238 impl<'a> SomeRecord<'a> for AxisRecord {
traverse(self, data: FontData<'a>) -> RecordResolver<'a>239     fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
240         RecordResolver {
241             name: "AxisRecord",
242             get_field: Box::new(move |idx, _data| match idx {
243                 0usize => Some(Field::new("axis_tag", self.axis_tag())),
244                 1usize => Some(Field::new("axis_name_id", self.axis_name_id())),
245                 2usize => Some(Field::new("axis_ordering", self.axis_ordering())),
246                 _ => None,
247             }),
248             data,
249         }
250     }
251 }
252 
253 /// An array of [AxisValue] tables.
254 #[derive(Debug, Clone, Copy)]
255 #[doc(hidden)]
256 pub struct AxisValueArrayMarker {
257     axis_value_offsets_byte_len: usize,
258 }
259 
260 impl AxisValueArrayMarker {
axis_value_offsets_byte_range(&self) -> Range<usize>261     fn axis_value_offsets_byte_range(&self) -> Range<usize> {
262         let start = 0;
263         start..start + self.axis_value_offsets_byte_len
264     }
265 }
266 
267 impl ReadArgs for AxisValueArray<'_> {
268     type Args = u16;
269 }
270 
271 impl<'a> FontReadWithArgs<'a> for AxisValueArray<'a> {
read_with_args(data: FontData<'a>, args: &u16) -> Result<Self, ReadError>272     fn read_with_args(data: FontData<'a>, args: &u16) -> Result<Self, ReadError> {
273         let axis_value_count = *args;
274         let mut cursor = data.cursor();
275         let axis_value_offsets_byte_len = axis_value_count as usize * Offset16::RAW_BYTE_LEN;
276         cursor.advance_by(axis_value_offsets_byte_len);
277         cursor.finish(AxisValueArrayMarker {
278             axis_value_offsets_byte_len,
279         })
280     }
281 }
282 
283 impl<'a> AxisValueArray<'a> {
284     /// A constructor that requires additional arguments.
285     ///
286     /// This type requires some external state in order to be
287     /// parsed.
read(data: FontData<'a>, axis_value_count: u16) -> Result<Self, ReadError>288     pub fn read(data: FontData<'a>, axis_value_count: u16) -> Result<Self, ReadError> {
289         let args = axis_value_count;
290         Self::read_with_args(data, &args)
291     }
292 }
293 
294 /// An array of [AxisValue] tables.
295 pub type AxisValueArray<'a> = TableRef<'a, AxisValueArrayMarker>;
296 
297 impl<'a> AxisValueArray<'a> {
298     /// Array of offsets to axis value tables, in bytes from the start
299     /// of the axis value offsets array.
axis_value_offsets(&self) -> &'a [BigEndian<Offset16>]300     pub fn axis_value_offsets(&self) -> &'a [BigEndian<Offset16>] {
301         let range = self.shape.axis_value_offsets_byte_range();
302         self.data.read_array(range).unwrap()
303     }
304 
305     /// A dynamically resolving wrapper for [`axis_value_offsets`][Self::axis_value_offsets].
axis_values(&self) -> ArrayOfOffsets<'a, AxisValue<'a>, Offset16>306     pub fn axis_values(&self) -> ArrayOfOffsets<'a, AxisValue<'a>, Offset16> {
307         let data = self.data;
308         let offsets = self.axis_value_offsets();
309         ArrayOfOffsets::new(offsets, data, ())
310     }
311 }
312 
313 #[cfg(feature = "traversal")]
314 impl<'a> SomeTable<'a> for AxisValueArray<'a> {
type_name(&self) -> &str315     fn type_name(&self) -> &str {
316         "AxisValueArray"
317     }
get_field(&self, idx: usize) -> Option<Field<'a>>318     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
319         match idx {
320             0usize => Some({
321                 let data = self.data;
322                 Field::new(
323                     "axis_value_offsets",
324                     FieldType::array_of_offsets(
325                         better_type_name::<AxisValue>(),
326                         self.axis_value_offsets(),
327                         move |off| {
328                             let target = off.get().resolve::<AxisValue>(data);
329                             FieldType::offset(off.get(), target)
330                         },
331                     ),
332                 )
333             }),
334             _ => None,
335         }
336     }
337 }
338 
339 #[cfg(feature = "traversal")]
340 impl<'a> std::fmt::Debug for AxisValueArray<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result341     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
342         (self as &dyn SomeTable<'a>).fmt(f)
343     }
344 }
345 
346 /// [Axis Value Tables](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-tables)
347 #[derive(Clone)]
348 pub enum AxisValue<'a> {
349     Format1(AxisValueFormat1<'a>),
350     Format2(AxisValueFormat2<'a>),
351     Format3(AxisValueFormat3<'a>),
352     Format4(AxisValueFormat4<'a>),
353 }
354 
355 impl<'a> AxisValue<'a> {
356     /// Format identifier — set to 1.
format(&self) -> u16357     pub fn format(&self) -> u16 {
358         match self {
359             Self::Format1(item) => item.format(),
360             Self::Format2(item) => item.format(),
361             Self::Format3(item) => item.format(),
362             Self::Format4(item) => item.format(),
363         }
364     }
365 
366     /// Flags — see below for details.
flags(&self) -> AxisValueTableFlags367     pub fn flags(&self) -> AxisValueTableFlags {
368         match self {
369             Self::Format1(item) => item.flags(),
370             Self::Format2(item) => item.flags(),
371             Self::Format3(item) => item.flags(),
372             Self::Format4(item) => item.flags(),
373         }
374     }
375 
376     /// The name ID for entries in the 'name' table that provide a
377     /// display string for this attribute value.
value_name_id(&self) -> NameId378     pub fn value_name_id(&self) -> NameId {
379         match self {
380             Self::Format1(item) => item.value_name_id(),
381             Self::Format2(item) => item.value_name_id(),
382             Self::Format3(item) => item.value_name_id(),
383             Self::Format4(item) => item.value_name_id(),
384         }
385     }
386 }
387 
388 impl<'a> FontRead<'a> for AxisValue<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>389     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
390         let format: u16 = data.read_at(0usize)?;
391         match format {
392             AxisValueFormat1Marker::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
393             AxisValueFormat2Marker::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
394             AxisValueFormat3Marker::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
395             AxisValueFormat4Marker::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
396             other => Err(ReadError::InvalidFormat(other.into())),
397         }
398     }
399 }
400 
401 #[cfg(feature = "traversal")]
402 impl<'a> AxisValue<'a> {
dyn_inner<'b>(&'b self) -> &'b dyn SomeTable<'a>403     fn dyn_inner<'b>(&'b self) -> &'b dyn SomeTable<'a> {
404         match self {
405             Self::Format1(table) => table,
406             Self::Format2(table) => table,
407             Self::Format3(table) => table,
408             Self::Format4(table) => table,
409         }
410     }
411 }
412 
413 #[cfg(feature = "traversal")]
414 impl<'a> std::fmt::Debug for AxisValue<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result415     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
416         self.dyn_inner().fmt(f)
417     }
418 }
419 
420 #[cfg(feature = "traversal")]
421 impl<'a> SomeTable<'a> for AxisValue<'a> {
type_name(&self) -> &str422     fn type_name(&self) -> &str {
423         self.dyn_inner().type_name()
424     }
get_field(&self, idx: usize) -> Option<Field<'a>>425     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
426         self.dyn_inner().get_field(idx)
427     }
428 }
429 
430 impl Format<u16> for AxisValueFormat1Marker {
431     const FORMAT: u16 = 1;
432 }
433 
434 /// [Axis value table format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-1)
435 #[derive(Debug, Clone, Copy)]
436 #[doc(hidden)]
437 pub struct AxisValueFormat1Marker {}
438 
439 impl AxisValueFormat1Marker {
format_byte_range(&self) -> Range<usize>440     fn format_byte_range(&self) -> Range<usize> {
441         let start = 0;
442         start..start + u16::RAW_BYTE_LEN
443     }
axis_index_byte_range(&self) -> Range<usize>444     fn axis_index_byte_range(&self) -> Range<usize> {
445         let start = self.format_byte_range().end;
446         start..start + u16::RAW_BYTE_LEN
447     }
flags_byte_range(&self) -> Range<usize>448     fn flags_byte_range(&self) -> Range<usize> {
449         let start = self.axis_index_byte_range().end;
450         start..start + AxisValueTableFlags::RAW_BYTE_LEN
451     }
value_name_id_byte_range(&self) -> Range<usize>452     fn value_name_id_byte_range(&self) -> Range<usize> {
453         let start = self.flags_byte_range().end;
454         start..start + NameId::RAW_BYTE_LEN
455     }
value_byte_range(&self) -> Range<usize>456     fn value_byte_range(&self) -> Range<usize> {
457         let start = self.value_name_id_byte_range().end;
458         start..start + Fixed::RAW_BYTE_LEN
459     }
460 }
461 
462 impl<'a> FontRead<'a> for AxisValueFormat1<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>463     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
464         let mut cursor = data.cursor();
465         cursor.advance::<u16>();
466         cursor.advance::<u16>();
467         cursor.advance::<AxisValueTableFlags>();
468         cursor.advance::<NameId>();
469         cursor.advance::<Fixed>();
470         cursor.finish(AxisValueFormat1Marker {})
471     }
472 }
473 
474 /// [Axis value table format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-1)
475 pub type AxisValueFormat1<'a> = TableRef<'a, AxisValueFormat1Marker>;
476 
477 impl<'a> AxisValueFormat1<'a> {
478     /// Format identifier — set to 1.
format(&self) -> u16479     pub fn format(&self) -> u16 {
480         let range = self.shape.format_byte_range();
481         self.data.read_at(range.start).unwrap()
482     }
483 
484     /// Zero-base index into the axis record array identifying the axis
485     /// of design variation to which the axis value table applies. Must
486     /// be less than designAxisCount.
axis_index(&self) -> u16487     pub fn axis_index(&self) -> u16 {
488         let range = self.shape.axis_index_byte_range();
489         self.data.read_at(range.start).unwrap()
490     }
491 
492     /// Flags — see below for details.
flags(&self) -> AxisValueTableFlags493     pub fn flags(&self) -> AxisValueTableFlags {
494         let range = self.shape.flags_byte_range();
495         self.data.read_at(range.start).unwrap()
496     }
497 
498     /// The name ID for entries in the 'name' table that provide a
499     /// display string for this attribute value.
value_name_id(&self) -> NameId500     pub fn value_name_id(&self) -> NameId {
501         let range = self.shape.value_name_id_byte_range();
502         self.data.read_at(range.start).unwrap()
503     }
504 
505     /// A numeric value for this attribute value.
value(&self) -> Fixed506     pub fn value(&self) -> Fixed {
507         let range = self.shape.value_byte_range();
508         self.data.read_at(range.start).unwrap()
509     }
510 }
511 
512 #[cfg(feature = "traversal")]
513 impl<'a> SomeTable<'a> for AxisValueFormat1<'a> {
type_name(&self) -> &str514     fn type_name(&self) -> &str {
515         "AxisValueFormat1"
516     }
get_field(&self, idx: usize) -> Option<Field<'a>>517     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
518         match idx {
519             0usize => Some(Field::new("format", self.format())),
520             1usize => Some(Field::new("axis_index", self.axis_index())),
521             2usize => Some(Field::new("flags", self.flags())),
522             3usize => Some(Field::new("value_name_id", self.value_name_id())),
523             4usize => Some(Field::new("value", self.value())),
524             _ => None,
525         }
526     }
527 }
528 
529 #[cfg(feature = "traversal")]
530 impl<'a> std::fmt::Debug for AxisValueFormat1<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result531     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
532         (self as &dyn SomeTable<'a>).fmt(f)
533     }
534 }
535 
536 impl Format<u16> for AxisValueFormat2Marker {
537     const FORMAT: u16 = 2;
538 }
539 
540 /// [Axis value table format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-2)
541 #[derive(Debug, Clone, Copy)]
542 #[doc(hidden)]
543 pub struct AxisValueFormat2Marker {}
544 
545 impl AxisValueFormat2Marker {
format_byte_range(&self) -> Range<usize>546     fn format_byte_range(&self) -> Range<usize> {
547         let start = 0;
548         start..start + u16::RAW_BYTE_LEN
549     }
axis_index_byte_range(&self) -> Range<usize>550     fn axis_index_byte_range(&self) -> Range<usize> {
551         let start = self.format_byte_range().end;
552         start..start + u16::RAW_BYTE_LEN
553     }
flags_byte_range(&self) -> Range<usize>554     fn flags_byte_range(&self) -> Range<usize> {
555         let start = self.axis_index_byte_range().end;
556         start..start + AxisValueTableFlags::RAW_BYTE_LEN
557     }
value_name_id_byte_range(&self) -> Range<usize>558     fn value_name_id_byte_range(&self) -> Range<usize> {
559         let start = self.flags_byte_range().end;
560         start..start + NameId::RAW_BYTE_LEN
561     }
nominal_value_byte_range(&self) -> Range<usize>562     fn nominal_value_byte_range(&self) -> Range<usize> {
563         let start = self.value_name_id_byte_range().end;
564         start..start + Fixed::RAW_BYTE_LEN
565     }
range_min_value_byte_range(&self) -> Range<usize>566     fn range_min_value_byte_range(&self) -> Range<usize> {
567         let start = self.nominal_value_byte_range().end;
568         start..start + Fixed::RAW_BYTE_LEN
569     }
range_max_value_byte_range(&self) -> Range<usize>570     fn range_max_value_byte_range(&self) -> Range<usize> {
571         let start = self.range_min_value_byte_range().end;
572         start..start + Fixed::RAW_BYTE_LEN
573     }
574 }
575 
576 impl<'a> FontRead<'a> for AxisValueFormat2<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>577     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
578         let mut cursor = data.cursor();
579         cursor.advance::<u16>();
580         cursor.advance::<u16>();
581         cursor.advance::<AxisValueTableFlags>();
582         cursor.advance::<NameId>();
583         cursor.advance::<Fixed>();
584         cursor.advance::<Fixed>();
585         cursor.advance::<Fixed>();
586         cursor.finish(AxisValueFormat2Marker {})
587     }
588 }
589 
590 /// [Axis value table format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-2)
591 pub type AxisValueFormat2<'a> = TableRef<'a, AxisValueFormat2Marker>;
592 
593 impl<'a> AxisValueFormat2<'a> {
594     /// Format identifier — set to 2.
format(&self) -> u16595     pub fn format(&self) -> u16 {
596         let range = self.shape.format_byte_range();
597         self.data.read_at(range.start).unwrap()
598     }
599 
600     /// Zero-base index into the axis record array identifying the axis
601     /// of design variation to which the axis value table applies. Must
602     /// be less than designAxisCount.
axis_index(&self) -> u16603     pub fn axis_index(&self) -> u16 {
604         let range = self.shape.axis_index_byte_range();
605         self.data.read_at(range.start).unwrap()
606     }
607 
608     /// Flags — see below for details.
flags(&self) -> AxisValueTableFlags609     pub fn flags(&self) -> AxisValueTableFlags {
610         let range = self.shape.flags_byte_range();
611         self.data.read_at(range.start).unwrap()
612     }
613 
614     /// The name ID for entries in the 'name' table that provide a
615     /// display string for this attribute value.
value_name_id(&self) -> NameId616     pub fn value_name_id(&self) -> NameId {
617         let range = self.shape.value_name_id_byte_range();
618         self.data.read_at(range.start).unwrap()
619     }
620 
621     /// A nominal numeric value for this attribute value.
nominal_value(&self) -> Fixed622     pub fn nominal_value(&self) -> Fixed {
623         let range = self.shape.nominal_value_byte_range();
624         self.data.read_at(range.start).unwrap()
625     }
626 
627     /// The minimum value for a range associated with the specified
628     /// name ID.
range_min_value(&self) -> Fixed629     pub fn range_min_value(&self) -> Fixed {
630         let range = self.shape.range_min_value_byte_range();
631         self.data.read_at(range.start).unwrap()
632     }
633 
634     /// The maximum value for a range associated with the specified
635     /// name ID.
range_max_value(&self) -> Fixed636     pub fn range_max_value(&self) -> Fixed {
637         let range = self.shape.range_max_value_byte_range();
638         self.data.read_at(range.start).unwrap()
639     }
640 }
641 
642 #[cfg(feature = "traversal")]
643 impl<'a> SomeTable<'a> for AxisValueFormat2<'a> {
type_name(&self) -> &str644     fn type_name(&self) -> &str {
645         "AxisValueFormat2"
646     }
get_field(&self, idx: usize) -> Option<Field<'a>>647     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
648         match idx {
649             0usize => Some(Field::new("format", self.format())),
650             1usize => Some(Field::new("axis_index", self.axis_index())),
651             2usize => Some(Field::new("flags", self.flags())),
652             3usize => Some(Field::new("value_name_id", self.value_name_id())),
653             4usize => Some(Field::new("nominal_value", self.nominal_value())),
654             5usize => Some(Field::new("range_min_value", self.range_min_value())),
655             6usize => Some(Field::new("range_max_value", self.range_max_value())),
656             _ => None,
657         }
658     }
659 }
660 
661 #[cfg(feature = "traversal")]
662 impl<'a> std::fmt::Debug for AxisValueFormat2<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result663     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
664         (self as &dyn SomeTable<'a>).fmt(f)
665     }
666 }
667 
668 impl Format<u16> for AxisValueFormat3Marker {
669     const FORMAT: u16 = 3;
670 }
671 
672 /// [Axis value table format 3](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-3)
673 #[derive(Debug, Clone, Copy)]
674 #[doc(hidden)]
675 pub struct AxisValueFormat3Marker {}
676 
677 impl AxisValueFormat3Marker {
format_byte_range(&self) -> Range<usize>678     fn format_byte_range(&self) -> Range<usize> {
679         let start = 0;
680         start..start + u16::RAW_BYTE_LEN
681     }
axis_index_byte_range(&self) -> Range<usize>682     fn axis_index_byte_range(&self) -> Range<usize> {
683         let start = self.format_byte_range().end;
684         start..start + u16::RAW_BYTE_LEN
685     }
flags_byte_range(&self) -> Range<usize>686     fn flags_byte_range(&self) -> Range<usize> {
687         let start = self.axis_index_byte_range().end;
688         start..start + AxisValueTableFlags::RAW_BYTE_LEN
689     }
value_name_id_byte_range(&self) -> Range<usize>690     fn value_name_id_byte_range(&self) -> Range<usize> {
691         let start = self.flags_byte_range().end;
692         start..start + NameId::RAW_BYTE_LEN
693     }
value_byte_range(&self) -> Range<usize>694     fn value_byte_range(&self) -> Range<usize> {
695         let start = self.value_name_id_byte_range().end;
696         start..start + Fixed::RAW_BYTE_LEN
697     }
linked_value_byte_range(&self) -> Range<usize>698     fn linked_value_byte_range(&self) -> Range<usize> {
699         let start = self.value_byte_range().end;
700         start..start + Fixed::RAW_BYTE_LEN
701     }
702 }
703 
704 impl<'a> FontRead<'a> for AxisValueFormat3<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>705     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
706         let mut cursor = data.cursor();
707         cursor.advance::<u16>();
708         cursor.advance::<u16>();
709         cursor.advance::<AxisValueTableFlags>();
710         cursor.advance::<NameId>();
711         cursor.advance::<Fixed>();
712         cursor.advance::<Fixed>();
713         cursor.finish(AxisValueFormat3Marker {})
714     }
715 }
716 
717 /// [Axis value table format 3](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-3)
718 pub type AxisValueFormat3<'a> = TableRef<'a, AxisValueFormat3Marker>;
719 
720 impl<'a> AxisValueFormat3<'a> {
721     /// Format identifier — set to 3.
format(&self) -> u16722     pub fn format(&self) -> u16 {
723         let range = self.shape.format_byte_range();
724         self.data.read_at(range.start).unwrap()
725     }
726 
727     /// Zero-base index into the axis record array identifying the axis
728     /// of design variation to which the axis value table applies. Must
729     /// be less than designAxisCount.
axis_index(&self) -> u16730     pub fn axis_index(&self) -> u16 {
731         let range = self.shape.axis_index_byte_range();
732         self.data.read_at(range.start).unwrap()
733     }
734 
735     /// Flags — see below for details.
flags(&self) -> AxisValueTableFlags736     pub fn flags(&self) -> AxisValueTableFlags {
737         let range = self.shape.flags_byte_range();
738         self.data.read_at(range.start).unwrap()
739     }
740 
741     /// The name ID for entries in the 'name' table that provide a
742     /// display string for this attribute value.
value_name_id(&self) -> NameId743     pub fn value_name_id(&self) -> NameId {
744         let range = self.shape.value_name_id_byte_range();
745         self.data.read_at(range.start).unwrap()
746     }
747 
748     /// A numeric value for this attribute value.
value(&self) -> Fixed749     pub fn value(&self) -> Fixed {
750         let range = self.shape.value_byte_range();
751         self.data.read_at(range.start).unwrap()
752     }
753 
754     /// The numeric value for a style-linked mapping from this value.
linked_value(&self) -> Fixed755     pub fn linked_value(&self) -> Fixed {
756         let range = self.shape.linked_value_byte_range();
757         self.data.read_at(range.start).unwrap()
758     }
759 }
760 
761 #[cfg(feature = "traversal")]
762 impl<'a> SomeTable<'a> for AxisValueFormat3<'a> {
type_name(&self) -> &str763     fn type_name(&self) -> &str {
764         "AxisValueFormat3"
765     }
get_field(&self, idx: usize) -> Option<Field<'a>>766     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
767         match idx {
768             0usize => Some(Field::new("format", self.format())),
769             1usize => Some(Field::new("axis_index", self.axis_index())),
770             2usize => Some(Field::new("flags", self.flags())),
771             3usize => Some(Field::new("value_name_id", self.value_name_id())),
772             4usize => Some(Field::new("value", self.value())),
773             5usize => Some(Field::new("linked_value", self.linked_value())),
774             _ => None,
775         }
776     }
777 }
778 
779 #[cfg(feature = "traversal")]
780 impl<'a> std::fmt::Debug for AxisValueFormat3<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result781     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
782         (self as &dyn SomeTable<'a>).fmt(f)
783     }
784 }
785 
786 impl Format<u16> for AxisValueFormat4Marker {
787     const FORMAT: u16 = 4;
788 }
789 
790 /// [Axis value table format 4](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-4)
791 #[derive(Debug, Clone, Copy)]
792 #[doc(hidden)]
793 pub struct AxisValueFormat4Marker {
794     axis_values_byte_len: usize,
795 }
796 
797 impl AxisValueFormat4Marker {
format_byte_range(&self) -> Range<usize>798     fn format_byte_range(&self) -> Range<usize> {
799         let start = 0;
800         start..start + u16::RAW_BYTE_LEN
801     }
axis_count_byte_range(&self) -> Range<usize>802     fn axis_count_byte_range(&self) -> Range<usize> {
803         let start = self.format_byte_range().end;
804         start..start + u16::RAW_BYTE_LEN
805     }
flags_byte_range(&self) -> Range<usize>806     fn flags_byte_range(&self) -> Range<usize> {
807         let start = self.axis_count_byte_range().end;
808         start..start + AxisValueTableFlags::RAW_BYTE_LEN
809     }
value_name_id_byte_range(&self) -> Range<usize>810     fn value_name_id_byte_range(&self) -> Range<usize> {
811         let start = self.flags_byte_range().end;
812         start..start + NameId::RAW_BYTE_LEN
813     }
axis_values_byte_range(&self) -> Range<usize>814     fn axis_values_byte_range(&self) -> Range<usize> {
815         let start = self.value_name_id_byte_range().end;
816         start..start + self.axis_values_byte_len
817     }
818 }
819 
820 impl<'a> FontRead<'a> for AxisValueFormat4<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>821     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
822         let mut cursor = data.cursor();
823         cursor.advance::<u16>();
824         let axis_count: u16 = cursor.read()?;
825         cursor.advance::<AxisValueTableFlags>();
826         cursor.advance::<NameId>();
827         let axis_values_byte_len = axis_count as usize * AxisValueRecord::RAW_BYTE_LEN;
828         cursor.advance_by(axis_values_byte_len);
829         cursor.finish(AxisValueFormat4Marker {
830             axis_values_byte_len,
831         })
832     }
833 }
834 
835 /// [Axis value table format 4](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-4)
836 pub type AxisValueFormat4<'a> = TableRef<'a, AxisValueFormat4Marker>;
837 
838 impl<'a> AxisValueFormat4<'a> {
839     /// Format identifier — set to 4.
format(&self) -> u16840     pub fn format(&self) -> u16 {
841         let range = self.shape.format_byte_range();
842         self.data.read_at(range.start).unwrap()
843     }
844 
845     /// The total number of axes contributing to this axis-values
846     /// combination.
axis_count(&self) -> u16847     pub fn axis_count(&self) -> u16 {
848         let range = self.shape.axis_count_byte_range();
849         self.data.read_at(range.start).unwrap()
850     }
851 
852     /// Flags — see below for details.
flags(&self) -> AxisValueTableFlags853     pub fn flags(&self) -> AxisValueTableFlags {
854         let range = self.shape.flags_byte_range();
855         self.data.read_at(range.start).unwrap()
856     }
857 
858     /// The name ID for entries in the 'name' table that provide a
859     /// display string for this combination of axis values.
value_name_id(&self) -> NameId860     pub fn value_name_id(&self) -> NameId {
861         let range = self.shape.value_name_id_byte_range();
862         self.data.read_at(range.start).unwrap()
863     }
864 
865     /// Array of AxisValue records that provide the combination of axis
866     /// values, one for each contributing axis.
axis_values(&self) -> &'a [AxisValueRecord]867     pub fn axis_values(&self) -> &'a [AxisValueRecord] {
868         let range = self.shape.axis_values_byte_range();
869         self.data.read_array(range).unwrap()
870     }
871 }
872 
873 #[cfg(feature = "traversal")]
874 impl<'a> SomeTable<'a> for AxisValueFormat4<'a> {
type_name(&self) -> &str875     fn type_name(&self) -> &str {
876         "AxisValueFormat4"
877     }
get_field(&self, idx: usize) -> Option<Field<'a>>878     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
879         match idx {
880             0usize => Some(Field::new("format", self.format())),
881             1usize => Some(Field::new("axis_count", self.axis_count())),
882             2usize => Some(Field::new("flags", self.flags())),
883             3usize => Some(Field::new("value_name_id", self.value_name_id())),
884             4usize => Some(Field::new(
885                 "axis_values",
886                 traversal::FieldType::array_of_records(
887                     stringify!(AxisValueRecord),
888                     self.axis_values(),
889                     self.offset_data(),
890                 ),
891             )),
892             _ => None,
893         }
894     }
895 }
896 
897 #[cfg(feature = "traversal")]
898 impl<'a> std::fmt::Debug for AxisValueFormat4<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result899     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
900         (self as &dyn SomeTable<'a>).fmt(f)
901     }
902 }
903 
904 /// Part of [AxisValueFormat4]
905 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
906 #[repr(C)]
907 #[repr(packed)]
908 pub struct AxisValueRecord {
909     /// Zero-base index into the axis record array identifying the axis
910     /// to which this value applies. Must be less than designAxisCount.
911     pub axis_index: BigEndian<u16>,
912     /// A numeric value for this attribute value.
913     pub value: BigEndian<Fixed>,
914 }
915 
916 impl AxisValueRecord {
917     /// Zero-base index into the axis record array identifying the axis
918     /// to which this value applies. Must be less than designAxisCount.
axis_index(&self) -> u16919     pub fn axis_index(&self) -> u16 {
920         self.axis_index.get()
921     }
922 
923     /// A numeric value for this attribute value.
value(&self) -> Fixed924     pub fn value(&self) -> Fixed {
925         self.value.get()
926     }
927 }
928 
929 impl FixedSize for AxisValueRecord {
930     const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + Fixed::RAW_BYTE_LEN;
931 }
932 
933 impl sealed::Sealed for AxisValueRecord {}
934 
935 /// SAFETY: see the [`FromBytes`] trait documentation.
936 unsafe impl FromBytes for AxisValueRecord {
this_trait_should_only_be_implemented_in_generated_code()937     fn this_trait_should_only_be_implemented_in_generated_code() {}
938 }
939 
940 #[cfg(feature = "traversal")]
941 impl<'a> SomeRecord<'a> for AxisValueRecord {
traverse(self, data: FontData<'a>) -> RecordResolver<'a>942     fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
943         RecordResolver {
944             name: "AxisValueRecord",
945             get_field: Box::new(move |idx, _data| match idx {
946                 0usize => Some(Field::new("axis_index", self.axis_index())),
947                 1usize => Some(Field::new("value", self.value())),
948                 _ => None,
949             }),
950             data,
951         }
952     }
953 }
954 
955 /// [Axis value table flags](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#flags).
956 #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
957 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
958 pub struct AxisValueTableFlags {
959     bits: u16,
960 }
961 
962 impl AxisValueTableFlags {
963     /// If set, this axis value table provides axis value information
964     /// that is applicable to other fonts within the same font family.
965     /// This is used if the other fonts were released earlier and did
966     /// not include information about values for some axis. If newer
967     /// versions of the other fonts include the information themselves
968     /// and are present, then this table is ignored.
969     pub const OLDER_SIBLING_FONT_ATTRIBUTE: Self = Self { bits: 0x0001 };
970 
971     /// If set, it indicates that the axis value represents the
972     /// “normal” value for the axis and may be omitted when
973     /// composing name strings.
974     pub const ELIDABLE_AXIS_VALUE_NAME: Self = Self { bits: 0x0002 };
975 }
976 
977 impl AxisValueTableFlags {
978     ///  Returns an empty set of flags.
979     #[inline]
empty() -> Self980     pub const fn empty() -> Self {
981         Self { bits: 0 }
982     }
983 
984     /// Returns the set containing all flags.
985     #[inline]
all() -> Self986     pub const fn all() -> Self {
987         Self {
988             bits: Self::OLDER_SIBLING_FONT_ATTRIBUTE.bits | Self::ELIDABLE_AXIS_VALUE_NAME.bits,
989         }
990     }
991 
992     /// Returns the raw value of the flags currently stored.
993     #[inline]
bits(&self) -> u16994     pub const fn bits(&self) -> u16 {
995         self.bits
996     }
997 
998     /// Convert from underlying bit representation, unless that
999     /// representation contains bits that do not correspond to a flag.
1000     #[inline]
from_bits(bits: u16) -> Option<Self>1001     pub const fn from_bits(bits: u16) -> Option<Self> {
1002         if (bits & !Self::all().bits()) == 0 {
1003             Some(Self { bits })
1004         } else {
1005             None
1006         }
1007     }
1008 
1009     /// Convert from underlying bit representation, dropping any bits
1010     /// that do not correspond to flags.
1011     #[inline]
from_bits_truncate(bits: u16) -> Self1012     pub const fn from_bits_truncate(bits: u16) -> Self {
1013         Self {
1014             bits: bits & Self::all().bits,
1015         }
1016     }
1017 
1018     /// Returns `true` if no flags are currently stored.
1019     #[inline]
is_empty(&self) -> bool1020     pub const fn is_empty(&self) -> bool {
1021         self.bits() == Self::empty().bits()
1022     }
1023 
1024     /// Returns `true` if there are flags common to both `self` and `other`.
1025     #[inline]
intersects(&self, other: Self) -> bool1026     pub const fn intersects(&self, other: Self) -> bool {
1027         !(Self {
1028             bits: self.bits & other.bits,
1029         })
1030         .is_empty()
1031     }
1032 
1033     /// Returns `true` if all of the flags in `other` are contained within `self`.
1034     #[inline]
contains(&self, other: Self) -> bool1035     pub const fn contains(&self, other: Self) -> bool {
1036         (self.bits & other.bits) == other.bits
1037     }
1038 
1039     /// Inserts the specified flags in-place.
1040     #[inline]
insert(&mut self, other: Self)1041     pub fn insert(&mut self, other: Self) {
1042         self.bits |= other.bits;
1043     }
1044 
1045     /// Removes the specified flags in-place.
1046     #[inline]
remove(&mut self, other: Self)1047     pub fn remove(&mut self, other: Self) {
1048         self.bits &= !other.bits;
1049     }
1050 
1051     /// Toggles the specified flags in-place.
1052     #[inline]
toggle(&mut self, other: Self)1053     pub fn toggle(&mut self, other: Self) {
1054         self.bits ^= other.bits;
1055     }
1056 
1057     /// Returns the intersection between the flags in `self` and
1058     /// `other`.
1059     ///
1060     /// Specifically, the returned set contains only the flags which are
1061     /// present in *both* `self` *and* `other`.
1062     ///
1063     /// This is equivalent to using the `&` operator (e.g.
1064     /// [`ops::BitAnd`]), as in `flags & other`.
1065     ///
1066     /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
1067     #[inline]
1068     #[must_use]
intersection(self, other: Self) -> Self1069     pub const fn intersection(self, other: Self) -> Self {
1070         Self {
1071             bits: self.bits & other.bits,
1072         }
1073     }
1074 
1075     /// Returns the union of between the flags in `self` and `other`.
1076     ///
1077     /// Specifically, the returned set contains all flags which are
1078     /// present in *either* `self` *or* `other`, including any which are
1079     /// present in both.
1080     ///
1081     /// This is equivalent to using the `|` operator (e.g.
1082     /// [`ops::BitOr`]), as in `flags | other`.
1083     ///
1084     /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
1085     #[inline]
1086     #[must_use]
union(self, other: Self) -> Self1087     pub const fn union(self, other: Self) -> Self {
1088         Self {
1089             bits: self.bits | other.bits,
1090         }
1091     }
1092 
1093     /// Returns the difference between the flags in `self` and `other`.
1094     ///
1095     /// Specifically, the returned set contains all flags present in
1096     /// `self`, except for the ones present in `other`.
1097     ///
1098     /// It is also conceptually equivalent to the "bit-clear" operation:
1099     /// `flags & !other` (and this syntax is also supported).
1100     ///
1101     /// This is equivalent to using the `-` operator (e.g.
1102     /// [`ops::Sub`]), as in `flags - other`.
1103     ///
1104     /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
1105     #[inline]
1106     #[must_use]
difference(self, other: Self) -> Self1107     pub const fn difference(self, other: Self) -> Self {
1108         Self {
1109             bits: self.bits & !other.bits,
1110         }
1111     }
1112 }
1113 
1114 impl std::ops::BitOr for AxisValueTableFlags {
1115     type Output = Self;
1116 
1117     /// Returns the union of the two sets of flags.
1118     #[inline]
bitor(self, other: AxisValueTableFlags) -> Self1119     fn bitor(self, other: AxisValueTableFlags) -> Self {
1120         Self {
1121             bits: self.bits | other.bits,
1122         }
1123     }
1124 }
1125 
1126 impl std::ops::BitOrAssign for AxisValueTableFlags {
1127     /// Adds the set of flags.
1128     #[inline]
bitor_assign(&mut self, other: Self)1129     fn bitor_assign(&mut self, other: Self) {
1130         self.bits |= other.bits;
1131     }
1132 }
1133 
1134 impl std::ops::BitXor for AxisValueTableFlags {
1135     type Output = Self;
1136 
1137     /// Returns the left flags, but with all the right flags toggled.
1138     #[inline]
bitxor(self, other: Self) -> Self1139     fn bitxor(self, other: Self) -> Self {
1140         Self {
1141             bits: self.bits ^ other.bits,
1142         }
1143     }
1144 }
1145 
1146 impl std::ops::BitXorAssign for AxisValueTableFlags {
1147     /// Toggles the set of flags.
1148     #[inline]
bitxor_assign(&mut self, other: Self)1149     fn bitxor_assign(&mut self, other: Self) {
1150         self.bits ^= other.bits;
1151     }
1152 }
1153 
1154 impl std::ops::BitAnd for AxisValueTableFlags {
1155     type Output = Self;
1156 
1157     /// Returns the intersection between the two sets of flags.
1158     #[inline]
bitand(self, other: Self) -> Self1159     fn bitand(self, other: Self) -> Self {
1160         Self {
1161             bits: self.bits & other.bits,
1162         }
1163     }
1164 }
1165 
1166 impl std::ops::BitAndAssign for AxisValueTableFlags {
1167     /// Disables all flags disabled in the set.
1168     #[inline]
bitand_assign(&mut self, other: Self)1169     fn bitand_assign(&mut self, other: Self) {
1170         self.bits &= other.bits;
1171     }
1172 }
1173 
1174 impl std::ops::Sub for AxisValueTableFlags {
1175     type Output = Self;
1176 
1177     /// Returns the set difference of the two sets of flags.
1178     #[inline]
sub(self, other: Self) -> Self1179     fn sub(self, other: Self) -> Self {
1180         Self {
1181             bits: self.bits & !other.bits,
1182         }
1183     }
1184 }
1185 
1186 impl std::ops::SubAssign for AxisValueTableFlags {
1187     /// Disables all flags enabled in the set.
1188     #[inline]
sub_assign(&mut self, other: Self)1189     fn sub_assign(&mut self, other: Self) {
1190         self.bits &= !other.bits;
1191     }
1192 }
1193 
1194 impl std::ops::Not for AxisValueTableFlags {
1195     type Output = Self;
1196 
1197     /// Returns the complement of this set of flags.
1198     #[inline]
not(self) -> Self1199     fn not(self) -> Self {
1200         Self { bits: !self.bits } & Self::all()
1201     }
1202 }
1203 
1204 impl std::fmt::Debug for AxisValueTableFlags {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result1205     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1206         let members: &[(&str, Self)] = &[
1207             (
1208                 "OLDER_SIBLING_FONT_ATTRIBUTE",
1209                 Self::OLDER_SIBLING_FONT_ATTRIBUTE,
1210             ),
1211             ("ELIDABLE_AXIS_VALUE_NAME", Self::ELIDABLE_AXIS_VALUE_NAME),
1212         ];
1213         let mut first = true;
1214         for (name, value) in members {
1215             if self.contains(*value) {
1216                 if !first {
1217                     f.write_str(" | ")?;
1218                 }
1219                 first = false;
1220                 f.write_str(name)?;
1221             }
1222         }
1223         if first {
1224             f.write_str("(empty)")?;
1225         }
1226         Ok(())
1227     }
1228 }
1229 
1230 impl std::fmt::Binary for AxisValueTableFlags {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result1231     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1232         std::fmt::Binary::fmt(&self.bits, f)
1233     }
1234 }
1235 
1236 impl std::fmt::Octal for AxisValueTableFlags {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result1237     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1238         std::fmt::Octal::fmt(&self.bits, f)
1239     }
1240 }
1241 
1242 impl std::fmt::LowerHex for AxisValueTableFlags {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result1243     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1244         std::fmt::LowerHex::fmt(&self.bits, f)
1245     }
1246 }
1247 
1248 impl std::fmt::UpperHex for AxisValueTableFlags {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result1249     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1250         std::fmt::UpperHex::fmt(&self.bits, f)
1251     }
1252 }
1253 
1254 impl font_types::Scalar for AxisValueTableFlags {
1255     type Raw = <u16 as font_types::Scalar>::Raw;
to_raw(self) -> Self::Raw1256     fn to_raw(self) -> Self::Raw {
1257         self.bits().to_raw()
1258     }
from_raw(raw: Self::Raw) -> Self1259     fn from_raw(raw: Self::Raw) -> Self {
1260         let t = <u16>::from_raw(raw);
1261         Self::from_bits_truncate(t)
1262     }
1263 }
1264 
1265 #[cfg(feature = "traversal")]
1266 impl<'a> From<AxisValueTableFlags> for FieldType<'a> {
from(src: AxisValueTableFlags) -> FieldType<'a>1267     fn from(src: AxisValueTableFlags) -> FieldType<'a> {
1268         src.bits().into()
1269     }
1270 }
1271