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 /// The ['gvar' header](https://learn.microsoft.com/en-us/typography/opentype/spec/gvar#gvar-header)
9 #[derive(Debug, Clone, Copy)]
10 #[doc(hidden)]
11 pub struct GvarMarker {
12     glyph_variation_data_offsets_byte_len: usize,
13 }
14 
15 impl GvarMarker {
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     }
axis_count_byte_range(&self) -> Range<usize>20     fn axis_count_byte_range(&self) -> Range<usize> {
21         let start = self.version_byte_range().end;
22         start..start + u16::RAW_BYTE_LEN
23     }
shared_tuple_count_byte_range(&self) -> Range<usize>24     fn shared_tuple_count_byte_range(&self) -> Range<usize> {
25         let start = self.axis_count_byte_range().end;
26         start..start + u16::RAW_BYTE_LEN
27     }
shared_tuples_offset_byte_range(&self) -> Range<usize>28     fn shared_tuples_offset_byte_range(&self) -> Range<usize> {
29         let start = self.shared_tuple_count_byte_range().end;
30         start..start + Offset32::RAW_BYTE_LEN
31     }
glyph_count_byte_range(&self) -> Range<usize>32     fn glyph_count_byte_range(&self) -> Range<usize> {
33         let start = self.shared_tuples_offset_byte_range().end;
34         start..start + u16::RAW_BYTE_LEN
35     }
flags_byte_range(&self) -> Range<usize>36     fn flags_byte_range(&self) -> Range<usize> {
37         let start = self.glyph_count_byte_range().end;
38         start..start + GvarFlags::RAW_BYTE_LEN
39     }
glyph_variation_data_array_offset_byte_range(&self) -> Range<usize>40     fn glyph_variation_data_array_offset_byte_range(&self) -> Range<usize> {
41         let start = self.flags_byte_range().end;
42         start..start + u32::RAW_BYTE_LEN
43     }
glyph_variation_data_offsets_byte_range(&self) -> Range<usize>44     fn glyph_variation_data_offsets_byte_range(&self) -> Range<usize> {
45         let start = self.glyph_variation_data_array_offset_byte_range().end;
46         start..start + self.glyph_variation_data_offsets_byte_len
47     }
48 }
49 
50 impl TopLevelTable for Gvar<'_> {
51     /// `gvar`
52     const TAG: Tag = Tag::new(b"gvar");
53 }
54 
55 impl<'a> FontRead<'a> for Gvar<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>56     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
57         let mut cursor = data.cursor();
58         cursor.advance::<MajorMinor>();
59         cursor.advance::<u16>();
60         cursor.advance::<u16>();
61         cursor.advance::<Offset32>();
62         let glyph_count: u16 = cursor.read()?;
63         let flags: GvarFlags = cursor.read()?;
64         cursor.advance::<u32>();
65         let glyph_variation_data_offsets_byte_len =
66             transforms::add(glyph_count, 1_usize) * <U16Or32 as ComputeSize>::compute_size(&flags);
67         cursor.advance_by(glyph_variation_data_offsets_byte_len);
68         cursor.finish(GvarMarker {
69             glyph_variation_data_offsets_byte_len,
70         })
71     }
72 }
73 
74 /// The ['gvar' header](https://learn.microsoft.com/en-us/typography/opentype/spec/gvar#gvar-header)
75 pub type Gvar<'a> = TableRef<'a, GvarMarker>;
76 
77 impl<'a> Gvar<'a> {
78     /// Major/minor version number of the glyph variations table — set to (1,0).
version(&self) -> MajorMinor79     pub fn version(&self) -> MajorMinor {
80         let range = self.shape.version_byte_range();
81         self.data.read_at(range.start).unwrap()
82     }
83 
84     /// The number of variation axes for this font. This must be the
85     /// same number as axisCount in the 'fvar' table.
axis_count(&self) -> u1686     pub fn axis_count(&self) -> u16 {
87         let range = self.shape.axis_count_byte_range();
88         self.data.read_at(range.start).unwrap()
89     }
90 
91     /// The number of shared tuple records. Shared tuple records can be
92     /// referenced within glyph variation data tables for multiple
93     /// glyphs, as opposed to other tuple records stored directly
94     /// within a glyph variation data table.
shared_tuple_count(&self) -> u1695     pub fn shared_tuple_count(&self) -> u16 {
96         let range = self.shape.shared_tuple_count_byte_range();
97         self.data.read_at(range.start).unwrap()
98     }
99 
100     /// Offset from the start of this table to the shared tuple records.
shared_tuples_offset(&self) -> Offset32101     pub fn shared_tuples_offset(&self) -> Offset32 {
102         let range = self.shape.shared_tuples_offset_byte_range();
103         self.data.read_at(range.start).unwrap()
104     }
105 
106     /// Attempt to resolve [`shared_tuples_offset`][Self::shared_tuples_offset].
shared_tuples(&self) -> Result<SharedTuples<'a>, ReadError>107     pub fn shared_tuples(&self) -> Result<SharedTuples<'a>, ReadError> {
108         let data = self.data;
109         let args = (self.shared_tuple_count(), self.axis_count());
110         self.shared_tuples_offset().resolve_with_args(data, &args)
111     }
112 
113     /// The number of glyphs in this font. This must match the number
114     /// of glyphs stored elsewhere in the font.
glyph_count(&self) -> u16115     pub fn glyph_count(&self) -> u16 {
116         let range = self.shape.glyph_count_byte_range();
117         self.data.read_at(range.start).unwrap()
118     }
119 
120     /// Bit-field that gives the format of the offset array that
121     /// follows. If bit 0 is clear, the offsets are uint16; if bit 0 is
122     /// set, the offsets are uint32.
flags(&self) -> GvarFlags123     pub fn flags(&self) -> GvarFlags {
124         let range = self.shape.flags_byte_range();
125         self.data.read_at(range.start).unwrap()
126     }
127 
128     /// Offset from the start of this table to the array of
129     /// GlyphVariationData tables.
glyph_variation_data_array_offset(&self) -> u32130     pub fn glyph_variation_data_array_offset(&self) -> u32 {
131         let range = self.shape.glyph_variation_data_array_offset_byte_range();
132         self.data.read_at(range.start).unwrap()
133     }
134 
135     /// Offsets from the start of the GlyphVariationData array to each
136     /// GlyphVariationData table.
glyph_variation_data_offsets(&self) -> ComputedArray<'a, U16Or32>137     pub fn glyph_variation_data_offsets(&self) -> ComputedArray<'a, U16Or32> {
138         let range = self.shape.glyph_variation_data_offsets_byte_range();
139         self.data.read_with_args(range, &self.flags()).unwrap()
140     }
141 }
142 
143 #[cfg(feature = "traversal")]
144 impl<'a> SomeTable<'a> for Gvar<'a> {
type_name(&self) -> &str145     fn type_name(&self) -> &str {
146         "Gvar"
147     }
get_field(&self, idx: usize) -> Option<Field<'a>>148     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
149         match idx {
150             0usize => Some(Field::new("version", self.version())),
151             1usize => Some(Field::new("axis_count", self.axis_count())),
152             2usize => Some(Field::new("shared_tuple_count", self.shared_tuple_count())),
153             3usize => Some(Field::new(
154                 "shared_tuples_offset",
155                 FieldType::offset(self.shared_tuples_offset(), self.shared_tuples()),
156             )),
157             4usize => Some(Field::new("glyph_count", self.glyph_count())),
158             5usize => Some(Field::new("flags", self.flags())),
159             6usize => Some(Field::new(
160                 "glyph_variation_data_array_offset",
161                 self.glyph_variation_data_array_offset(),
162             )),
163             7usize => Some(Field::new(
164                 "glyph_variation_data_offsets",
165                 traversal::FieldType::Unknown,
166             )),
167             _ => None,
168         }
169     }
170 }
171 
172 #[cfg(feature = "traversal")]
173 impl<'a> std::fmt::Debug for Gvar<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result174     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
175         (self as &dyn SomeTable<'a>).fmt(f)
176     }
177 }
178 
179 #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
180 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
181 pub struct GvarFlags {
182     bits: u16,
183 }
184 
185 impl GvarFlags {
186     /// If set, offsets to GlyphVariationData are 32 bits
187     pub const LONG_OFFSETS: Self = Self { bits: 1 };
188 }
189 
190 impl GvarFlags {
191     ///  Returns an empty set of flags.
192     #[inline]
empty() -> Self193     pub const fn empty() -> Self {
194         Self { bits: 0 }
195     }
196 
197     /// Returns the set containing all flags.
198     #[inline]
all() -> Self199     pub const fn all() -> Self {
200         Self {
201             bits: Self::LONG_OFFSETS.bits,
202         }
203     }
204 
205     /// Returns the raw value of the flags currently stored.
206     #[inline]
bits(&self) -> u16207     pub const fn bits(&self) -> u16 {
208         self.bits
209     }
210 
211     /// Convert from underlying bit representation, unless that
212     /// representation contains bits that do not correspond to a flag.
213     #[inline]
from_bits(bits: u16) -> Option<Self>214     pub const fn from_bits(bits: u16) -> Option<Self> {
215         if (bits & !Self::all().bits()) == 0 {
216             Some(Self { bits })
217         } else {
218             None
219         }
220     }
221 
222     /// Convert from underlying bit representation, dropping any bits
223     /// that do not correspond to flags.
224     #[inline]
from_bits_truncate(bits: u16) -> Self225     pub const fn from_bits_truncate(bits: u16) -> Self {
226         Self {
227             bits: bits & Self::all().bits,
228         }
229     }
230 
231     /// Returns `true` if no flags are currently stored.
232     #[inline]
is_empty(&self) -> bool233     pub const fn is_empty(&self) -> bool {
234         self.bits() == Self::empty().bits()
235     }
236 
237     /// Returns `true` if there are flags common to both `self` and `other`.
238     #[inline]
intersects(&self, other: Self) -> bool239     pub const fn intersects(&self, other: Self) -> bool {
240         !(Self {
241             bits: self.bits & other.bits,
242         })
243         .is_empty()
244     }
245 
246     /// Returns `true` if all of the flags in `other` are contained within `self`.
247     #[inline]
contains(&self, other: Self) -> bool248     pub const fn contains(&self, other: Self) -> bool {
249         (self.bits & other.bits) == other.bits
250     }
251 
252     /// Inserts the specified flags in-place.
253     #[inline]
insert(&mut self, other: Self)254     pub fn insert(&mut self, other: Self) {
255         self.bits |= other.bits;
256     }
257 
258     /// Removes the specified flags in-place.
259     #[inline]
remove(&mut self, other: Self)260     pub fn remove(&mut self, other: Self) {
261         self.bits &= !other.bits;
262     }
263 
264     /// Toggles the specified flags in-place.
265     #[inline]
toggle(&mut self, other: Self)266     pub fn toggle(&mut self, other: Self) {
267         self.bits ^= other.bits;
268     }
269 
270     /// Returns the intersection between the flags in `self` and
271     /// `other`.
272     ///
273     /// Specifically, the returned set contains only the flags which are
274     /// present in *both* `self` *and* `other`.
275     ///
276     /// This is equivalent to using the `&` operator (e.g.
277     /// [`ops::BitAnd`]), as in `flags & other`.
278     ///
279     /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
280     #[inline]
281     #[must_use]
intersection(self, other: Self) -> Self282     pub const fn intersection(self, other: Self) -> Self {
283         Self {
284             bits: self.bits & other.bits,
285         }
286     }
287 
288     /// Returns the union of between the flags in `self` and `other`.
289     ///
290     /// Specifically, the returned set contains all flags which are
291     /// present in *either* `self` *or* `other`, including any which are
292     /// present in both.
293     ///
294     /// This is equivalent to using the `|` operator (e.g.
295     /// [`ops::BitOr`]), as in `flags | other`.
296     ///
297     /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
298     #[inline]
299     #[must_use]
union(self, other: Self) -> Self300     pub const fn union(self, other: Self) -> Self {
301         Self {
302             bits: self.bits | other.bits,
303         }
304     }
305 
306     /// Returns the difference between the flags in `self` and `other`.
307     ///
308     /// Specifically, the returned set contains all flags present in
309     /// `self`, except for the ones present in `other`.
310     ///
311     /// It is also conceptually equivalent to the "bit-clear" operation:
312     /// `flags & !other` (and this syntax is also supported).
313     ///
314     /// This is equivalent to using the `-` operator (e.g.
315     /// [`ops::Sub`]), as in `flags - other`.
316     ///
317     /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
318     #[inline]
319     #[must_use]
difference(self, other: Self) -> Self320     pub const fn difference(self, other: Self) -> Self {
321         Self {
322             bits: self.bits & !other.bits,
323         }
324     }
325 }
326 
327 impl std::ops::BitOr for GvarFlags {
328     type Output = Self;
329 
330     /// Returns the union of the two sets of flags.
331     #[inline]
bitor(self, other: GvarFlags) -> Self332     fn bitor(self, other: GvarFlags) -> Self {
333         Self {
334             bits: self.bits | other.bits,
335         }
336     }
337 }
338 
339 impl std::ops::BitOrAssign for GvarFlags {
340     /// Adds the set of flags.
341     #[inline]
bitor_assign(&mut self, other: Self)342     fn bitor_assign(&mut self, other: Self) {
343         self.bits |= other.bits;
344     }
345 }
346 
347 impl std::ops::BitXor for GvarFlags {
348     type Output = Self;
349 
350     /// Returns the left flags, but with all the right flags toggled.
351     #[inline]
bitxor(self, other: Self) -> Self352     fn bitxor(self, other: Self) -> Self {
353         Self {
354             bits: self.bits ^ other.bits,
355         }
356     }
357 }
358 
359 impl std::ops::BitXorAssign for GvarFlags {
360     /// Toggles the set of flags.
361     #[inline]
bitxor_assign(&mut self, other: Self)362     fn bitxor_assign(&mut self, other: Self) {
363         self.bits ^= other.bits;
364     }
365 }
366 
367 impl std::ops::BitAnd for GvarFlags {
368     type Output = Self;
369 
370     /// Returns the intersection between the two sets of flags.
371     #[inline]
bitand(self, other: Self) -> Self372     fn bitand(self, other: Self) -> Self {
373         Self {
374             bits: self.bits & other.bits,
375         }
376     }
377 }
378 
379 impl std::ops::BitAndAssign for GvarFlags {
380     /// Disables all flags disabled in the set.
381     #[inline]
bitand_assign(&mut self, other: Self)382     fn bitand_assign(&mut self, other: Self) {
383         self.bits &= other.bits;
384     }
385 }
386 
387 impl std::ops::Sub for GvarFlags {
388     type Output = Self;
389 
390     /// Returns the set difference of the two sets of flags.
391     #[inline]
sub(self, other: Self) -> Self392     fn sub(self, other: Self) -> Self {
393         Self {
394             bits: self.bits & !other.bits,
395         }
396     }
397 }
398 
399 impl std::ops::SubAssign for GvarFlags {
400     /// Disables all flags enabled in the set.
401     #[inline]
sub_assign(&mut self, other: Self)402     fn sub_assign(&mut self, other: Self) {
403         self.bits &= !other.bits;
404     }
405 }
406 
407 impl std::ops::Not for GvarFlags {
408     type Output = Self;
409 
410     /// Returns the complement of this set of flags.
411     #[inline]
not(self) -> Self412     fn not(self) -> Self {
413         Self { bits: !self.bits } & Self::all()
414     }
415 }
416 
417 impl std::fmt::Debug for GvarFlags {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result418     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
419         let members: &[(&str, Self)] = &[("LONG_OFFSETS", Self::LONG_OFFSETS)];
420         let mut first = true;
421         for (name, value) in members {
422             if self.contains(*value) {
423                 if !first {
424                     f.write_str(" | ")?;
425                 }
426                 first = false;
427                 f.write_str(name)?;
428             }
429         }
430         if first {
431             f.write_str("(empty)")?;
432         }
433         Ok(())
434     }
435 }
436 
437 impl std::fmt::Binary for GvarFlags {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result438     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
439         std::fmt::Binary::fmt(&self.bits, f)
440     }
441 }
442 
443 impl std::fmt::Octal for GvarFlags {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result444     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
445         std::fmt::Octal::fmt(&self.bits, f)
446     }
447 }
448 
449 impl std::fmt::LowerHex for GvarFlags {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result450     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
451         std::fmt::LowerHex::fmt(&self.bits, f)
452     }
453 }
454 
455 impl std::fmt::UpperHex for GvarFlags {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result456     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
457         std::fmt::UpperHex::fmt(&self.bits, f)
458     }
459 }
460 
461 impl font_types::Scalar for GvarFlags {
462     type Raw = <u16 as font_types::Scalar>::Raw;
to_raw(self) -> Self::Raw463     fn to_raw(self) -> Self::Raw {
464         self.bits().to_raw()
465     }
from_raw(raw: Self::Raw) -> Self466     fn from_raw(raw: Self::Raw) -> Self {
467         let t = <u16>::from_raw(raw);
468         Self::from_bits_truncate(t)
469     }
470 }
471 
472 #[cfg(feature = "traversal")]
473 impl<'a> From<GvarFlags> for FieldType<'a> {
from(src: GvarFlags) -> FieldType<'a>474     fn from(src: GvarFlags) -> FieldType<'a> {
475         src.bits().into()
476     }
477 }
478 
479 /// Array of tuple records shared across all glyph variation data tables.
480 #[derive(Debug, Clone, Copy)]
481 #[doc(hidden)]
482 pub struct SharedTuplesMarker {
483     axis_count: u16,
484     tuples_byte_len: usize,
485 }
486 
487 impl SharedTuplesMarker {
tuples_byte_range(&self) -> Range<usize>488     fn tuples_byte_range(&self) -> Range<usize> {
489         let start = 0;
490         start..start + self.tuples_byte_len
491     }
492 }
493 
494 impl ReadArgs for SharedTuples<'_> {
495     type Args = (u16, u16);
496 }
497 
498 impl<'a> FontReadWithArgs<'a> for SharedTuples<'a> {
read_with_args(data: FontData<'a>, args: &(u16, u16)) -> Result<Self, ReadError>499     fn read_with_args(data: FontData<'a>, args: &(u16, u16)) -> Result<Self, ReadError> {
500         let (shared_tuple_count, axis_count) = *args;
501         let mut cursor = data.cursor();
502         let tuples_byte_len =
503             shared_tuple_count as usize * <Tuple as ComputeSize>::compute_size(&axis_count);
504         cursor.advance_by(tuples_byte_len);
505         cursor.finish(SharedTuplesMarker {
506             axis_count,
507             tuples_byte_len,
508         })
509     }
510 }
511 
512 impl<'a> SharedTuples<'a> {
513     /// A constructor that requires additional arguments.
514     ///
515     /// This type requires some external state in order to be
516     /// parsed.
read( data: FontData<'a>, shared_tuple_count: u16, axis_count: u16, ) -> Result<Self, ReadError>517     pub fn read(
518         data: FontData<'a>,
519         shared_tuple_count: u16,
520         axis_count: u16,
521     ) -> Result<Self, ReadError> {
522         let args = (shared_tuple_count, axis_count);
523         Self::read_with_args(data, &args)
524     }
525 }
526 
527 /// Array of tuple records shared across all glyph variation data tables.
528 pub type SharedTuples<'a> = TableRef<'a, SharedTuplesMarker>;
529 
530 impl<'a> SharedTuples<'a> {
tuples(&self) -> ComputedArray<'a, Tuple<'a>>531     pub fn tuples(&self) -> ComputedArray<'a, Tuple<'a>> {
532         let range = self.shape.tuples_byte_range();
533         self.data.read_with_args(range, &self.axis_count()).unwrap()
534     }
535 
axis_count(&self) -> u16536     pub(crate) fn axis_count(&self) -> u16 {
537         self.shape.axis_count
538     }
539 }
540 
541 #[cfg(feature = "traversal")]
542 impl<'a> SomeTable<'a> for SharedTuples<'a> {
type_name(&self) -> &str543     fn type_name(&self) -> &str {
544         "SharedTuples"
545     }
get_field(&self, idx: usize) -> Option<Field<'a>>546     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
547         match idx {
548             0usize => Some(Field::new(
549                 "tuples",
550                 traversal::FieldType::computed_array("Tuple", self.tuples(), self.offset_data()),
551             )),
552             _ => None,
553         }
554     }
555 }
556 
557 #[cfg(feature = "traversal")]
558 impl<'a> std::fmt::Debug for SharedTuples<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result559     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
560         (self as &dyn SomeTable<'a>).fmt(f)
561     }
562 }
563 
564 /// The [GlyphVariationData](https://learn.microsoft.com/en-us/typography/opentype/spec/gvar#the-glyphvariationdata-table-array) table
565 #[derive(Debug, Clone, Copy)]
566 #[doc(hidden)]
567 pub struct GlyphVariationDataHeaderMarker {
568     tuple_variation_headers_byte_len: usize,
569 }
570 
571 impl GlyphVariationDataHeaderMarker {
tuple_variation_count_byte_range(&self) -> Range<usize>572     fn tuple_variation_count_byte_range(&self) -> Range<usize> {
573         let start = 0;
574         start..start + TupleVariationCount::RAW_BYTE_LEN
575     }
serialized_data_offset_byte_range(&self) -> Range<usize>576     fn serialized_data_offset_byte_range(&self) -> Range<usize> {
577         let start = self.tuple_variation_count_byte_range().end;
578         start..start + Offset16::RAW_BYTE_LEN
579     }
tuple_variation_headers_byte_range(&self) -> Range<usize>580     fn tuple_variation_headers_byte_range(&self) -> Range<usize> {
581         let start = self.serialized_data_offset_byte_range().end;
582         start..start + self.tuple_variation_headers_byte_len
583     }
584 }
585 
586 impl<'a> FontRead<'a> for GlyphVariationDataHeader<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>587     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
588         let mut cursor = data.cursor();
589         cursor.advance::<TupleVariationCount>();
590         cursor.advance::<Offset16>();
591         let tuple_variation_headers_byte_len = cursor.remaining_bytes();
592         cursor.advance_by(tuple_variation_headers_byte_len);
593         cursor.finish(GlyphVariationDataHeaderMarker {
594             tuple_variation_headers_byte_len,
595         })
596     }
597 }
598 
599 /// The [GlyphVariationData](https://learn.microsoft.com/en-us/typography/opentype/spec/gvar#the-glyphvariationdata-table-array) table
600 pub type GlyphVariationDataHeader<'a> = TableRef<'a, GlyphVariationDataHeaderMarker>;
601 
602 impl<'a> GlyphVariationDataHeader<'a> {
603     /// A packed field. The high 4 bits are flags, and the low 12 bits
604     /// are the number of tuple variation tables for this glyph. The
605     /// number of tuple variation tables can be any number between 1
606     /// and 4095.
tuple_variation_count(&self) -> TupleVariationCount607     pub fn tuple_variation_count(&self) -> TupleVariationCount {
608         let range = self.shape.tuple_variation_count_byte_range();
609         self.data.read_at(range.start).unwrap()
610     }
611 
612     /// Offset from the start of the GlyphVariationData table to the
613     /// serialized data
serialized_data_offset(&self) -> Offset16614     pub fn serialized_data_offset(&self) -> Offset16 {
615         let range = self.shape.serialized_data_offset_byte_range();
616         self.data.read_at(range.start).unwrap()
617     }
618 
619     /// Attempt to resolve [`serialized_data_offset`][Self::serialized_data_offset].
serialized_data(&self) -> Result<FontData<'a>, ReadError>620     pub fn serialized_data(&self) -> Result<FontData<'a>, ReadError> {
621         let data = self.data;
622         self.serialized_data_offset().resolve(data)
623     }
624 
625     /// Array of tuple variation headers.
tuple_variation_headers(&self) -> VarLenArray<'a, TupleVariationHeader>626     pub fn tuple_variation_headers(&self) -> VarLenArray<'a, TupleVariationHeader> {
627         let range = self.shape.tuple_variation_headers_byte_range();
628         VarLenArray::read(self.data.split_off(range.start).unwrap()).unwrap()
629     }
630 }
631 
632 #[cfg(feature = "traversal")]
633 impl<'a> SomeTable<'a> for GlyphVariationDataHeader<'a> {
type_name(&self) -> &str634     fn type_name(&self) -> &str {
635         "GlyphVariationDataHeader"
636     }
get_field(&self, idx: usize) -> Option<Field<'a>>637     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
638         match idx {
639             0usize => Some(Field::new(
640                 "tuple_variation_count",
641                 traversal::FieldType::Unknown,
642             )),
643             1usize => Some(Field::new(
644                 "serialized_data_offset",
645                 traversal::FieldType::Unknown,
646             )),
647             2usize => Some(Field::new(
648                 "tuple_variation_headers",
649                 traversal::FieldType::Unknown,
650             )),
651             _ => None,
652         }
653     }
654 }
655 
656 #[cfg(feature = "traversal")]
657 impl<'a> std::fmt::Debug for GlyphVariationDataHeader<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result658     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
659         (self as &dyn SomeTable<'a>).fmt(f)
660     }
661 }
662