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 /// [TupleVariationHeader](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#tuplevariationheader)
9 #[derive(Debug, Clone, Copy)]
10 #[doc(hidden)]
11 pub struct TupleVariationHeaderMarker {
12     peak_tuple_byte_len: usize,
13     intermediate_start_tuple_byte_len: usize,
14     intermediate_end_tuple_byte_len: usize,
15 }
16 
17 impl TupleVariationHeaderMarker {
variation_data_size_byte_range(&self) -> Range<usize>18     fn variation_data_size_byte_range(&self) -> Range<usize> {
19         let start = 0;
20         start..start + u16::RAW_BYTE_LEN
21     }
tuple_index_byte_range(&self) -> Range<usize>22     fn tuple_index_byte_range(&self) -> Range<usize> {
23         let start = self.variation_data_size_byte_range().end;
24         start..start + TupleIndex::RAW_BYTE_LEN
25     }
peak_tuple_byte_range(&self) -> Range<usize>26     fn peak_tuple_byte_range(&self) -> Range<usize> {
27         let start = self.tuple_index_byte_range().end;
28         start..start + self.peak_tuple_byte_len
29     }
intermediate_start_tuple_byte_range(&self) -> Range<usize>30     fn intermediate_start_tuple_byte_range(&self) -> Range<usize> {
31         let start = self.peak_tuple_byte_range().end;
32         start..start + self.intermediate_start_tuple_byte_len
33     }
intermediate_end_tuple_byte_range(&self) -> Range<usize>34     fn intermediate_end_tuple_byte_range(&self) -> Range<usize> {
35         let start = self.intermediate_start_tuple_byte_range().end;
36         start..start + self.intermediate_end_tuple_byte_len
37     }
38 }
39 
40 impl ReadArgs for TupleVariationHeader<'_> {
41     type Args = u16;
42 }
43 
44 impl<'a> FontReadWithArgs<'a> for TupleVariationHeader<'a> {
read_with_args(data: FontData<'a>, args: &u16) -> Result<Self, ReadError>45     fn read_with_args(data: FontData<'a>, args: &u16) -> Result<Self, ReadError> {
46         let axis_count = *args;
47         let mut cursor = data.cursor();
48         cursor.advance::<u16>();
49         let tuple_index: TupleIndex = cursor.read()?;
50         let peak_tuple_byte_len =
51             TupleIndex::tuple_len(tuple_index, axis_count, 0_usize) * F2Dot14::RAW_BYTE_LEN;
52         cursor.advance_by(peak_tuple_byte_len);
53         let intermediate_start_tuple_byte_len =
54             TupleIndex::tuple_len(tuple_index, axis_count, 1_usize) * F2Dot14::RAW_BYTE_LEN;
55         cursor.advance_by(intermediate_start_tuple_byte_len);
56         let intermediate_end_tuple_byte_len =
57             TupleIndex::tuple_len(tuple_index, axis_count, 1_usize) * F2Dot14::RAW_BYTE_LEN;
58         cursor.advance_by(intermediate_end_tuple_byte_len);
59         cursor.finish(TupleVariationHeaderMarker {
60             peak_tuple_byte_len,
61             intermediate_start_tuple_byte_len,
62             intermediate_end_tuple_byte_len,
63         })
64     }
65 }
66 
67 impl<'a> TupleVariationHeader<'a> {
68     /// A constructor that requires additional arguments.
69     ///
70     /// This type requires some external state in order to be
71     /// parsed.
read(data: FontData<'a>, axis_count: u16) -> Result<Self, ReadError>72     pub fn read(data: FontData<'a>, axis_count: u16) -> Result<Self, ReadError> {
73         let args = axis_count;
74         Self::read_with_args(data, &args)
75     }
76 }
77 
78 /// [TupleVariationHeader](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#tuplevariationheader)
79 pub type TupleVariationHeader<'a> = TableRef<'a, TupleVariationHeaderMarker>;
80 
81 impl<'a> TupleVariationHeader<'a> {
82     /// The size in bytes of the serialized data for this tuple
83     /// variation table.
variation_data_size(&self) -> u1684     pub fn variation_data_size(&self) -> u16 {
85         let range = self.shape.variation_data_size_byte_range();
86         self.data.read_at(range.start).unwrap()
87     }
88 
89     /// A packed field. The high 4 bits are flags (see below). The low
90     /// 12 bits are an index into a shared tuple records array.
tuple_index(&self) -> TupleIndex91     pub fn tuple_index(&self) -> TupleIndex {
92         let range = self.shape.tuple_index_byte_range();
93         self.data.read_at(range.start).unwrap()
94     }
95 }
96 
97 #[cfg(feature = "traversal")]
98 impl<'a> SomeTable<'a> for TupleVariationHeader<'a> {
type_name(&self) -> &str99     fn type_name(&self) -> &str {
100         "TupleVariationHeader"
101     }
get_field(&self, idx: usize) -> Option<Field<'a>>102     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
103         match idx {
104             0usize => Some(Field::new(
105                 "variation_data_size",
106                 self.variation_data_size(),
107             )),
108             1usize => Some(Field::new("tuple_index", self.traverse_tuple_index())),
109             _ => None,
110         }
111     }
112 }
113 
114 #[cfg(feature = "traversal")]
115 impl<'a> std::fmt::Debug for TupleVariationHeader<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result116     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
117         (self as &dyn SomeTable<'a>).fmt(f)
118     }
119 }
120 
121 /// A [Tuple Record](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#tuple-records)
122 ///
123 /// The tuple variation store formats reference regions within the font’s
124 /// variation space using tuple records. A tuple record identifies a position
125 /// in terms of normalized coordinates, which use F2DOT14 values.
126 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
127 pub struct Tuple<'a> {
128     /// Coordinate array specifying a position within the font’s variation space.
129     ///
130     /// The number of elements must match the axisCount specified in the
131     /// 'fvar' table.
132     pub values: &'a [BigEndian<F2Dot14>],
133 }
134 
135 impl<'a> Tuple<'a> {
136     /// Coordinate array specifying a position within the font’s variation space.
137     ///
138     /// The number of elements must match the axisCount specified in the
139     /// 'fvar' table.
values(&self) -> &'a [BigEndian<F2Dot14>]140     pub fn values(&self) -> &'a [BigEndian<F2Dot14>] {
141         self.values
142     }
143 }
144 
145 impl ReadArgs for Tuple<'_> {
146     type Args = u16;
147 }
148 
149 impl ComputeSize for Tuple<'_> {
compute_size(args: &u16) -> usize150     fn compute_size(args: &u16) -> usize {
151         let axis_count = *args;
152         axis_count as usize * F2Dot14::RAW_BYTE_LEN
153     }
154 }
155 
156 impl<'a> FontReadWithArgs<'a> for Tuple<'a> {
read_with_args(data: FontData<'a>, args: &u16) -> Result<Self, ReadError>157     fn read_with_args(data: FontData<'a>, args: &u16) -> Result<Self, ReadError> {
158         let mut cursor = data.cursor();
159         let axis_count = *args;
160         Ok(Self {
161             values: cursor.read_array(axis_count as usize)?,
162         })
163     }
164 }
165 
166 impl<'a> Tuple<'a> {
167     /// A constructor that requires additional arguments.
168     ///
169     /// This type requires some external state in order to be
170     /// parsed.
read(data: FontData<'a>, axis_count: u16) -> Result<Self, ReadError>171     pub fn read(data: FontData<'a>, axis_count: u16) -> Result<Self, ReadError> {
172         let args = axis_count;
173         Self::read_with_args(data, &args)
174     }
175 }
176 
177 #[cfg(feature = "traversal")]
178 impl<'a> SomeRecord<'a> for Tuple<'a> {
traverse(self, data: FontData<'a>) -> RecordResolver<'a>179     fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
180         RecordResolver {
181             name: "Tuple",
182             get_field: Box::new(move |idx, _data| match idx {
183                 0usize => Some(Field::new("values", self.values())),
184                 _ => None,
185             }),
186             data,
187         }
188     }
189 }
190 
191 impl Format<u8> for DeltaSetIndexMapFormat0Marker {
192     const FORMAT: u8 = 0;
193 }
194 
195 /// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table format 0
196 #[derive(Debug, Clone, Copy)]
197 #[doc(hidden)]
198 pub struct DeltaSetIndexMapFormat0Marker {
199     map_data_byte_len: usize,
200 }
201 
202 impl DeltaSetIndexMapFormat0Marker {
format_byte_range(&self) -> Range<usize>203     fn format_byte_range(&self) -> Range<usize> {
204         let start = 0;
205         start..start + u8::RAW_BYTE_LEN
206     }
entry_format_byte_range(&self) -> Range<usize>207     fn entry_format_byte_range(&self) -> Range<usize> {
208         let start = self.format_byte_range().end;
209         start..start + EntryFormat::RAW_BYTE_LEN
210     }
map_count_byte_range(&self) -> Range<usize>211     fn map_count_byte_range(&self) -> Range<usize> {
212         let start = self.entry_format_byte_range().end;
213         start..start + u16::RAW_BYTE_LEN
214     }
map_data_byte_range(&self) -> Range<usize>215     fn map_data_byte_range(&self) -> Range<usize> {
216         let start = self.map_count_byte_range().end;
217         start..start + self.map_data_byte_len
218     }
219 }
220 
221 impl<'a> FontRead<'a> for DeltaSetIndexMapFormat0<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>222     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
223         let mut cursor = data.cursor();
224         cursor.advance::<u8>();
225         let entry_format: EntryFormat = cursor.read()?;
226         let map_count: u16 = cursor.read()?;
227         let map_data_byte_len = EntryFormat::map_size(entry_format, map_count) * u8::RAW_BYTE_LEN;
228         cursor.advance_by(map_data_byte_len);
229         cursor.finish(DeltaSetIndexMapFormat0Marker { map_data_byte_len })
230     }
231 }
232 
233 /// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table format 0
234 pub type DeltaSetIndexMapFormat0<'a> = TableRef<'a, DeltaSetIndexMapFormat0Marker>;
235 
236 impl<'a> DeltaSetIndexMapFormat0<'a> {
237     /// DeltaSetIndexMap format: set to 0.
format(&self) -> u8238     pub fn format(&self) -> u8 {
239         let range = self.shape.format_byte_range();
240         self.data.read_at(range.start).unwrap()
241     }
242 
243     /// A packed field that describes the compressed representation of
244     /// delta-set indices. See details below.
entry_format(&self) -> EntryFormat245     pub fn entry_format(&self) -> EntryFormat {
246         let range = self.shape.entry_format_byte_range();
247         self.data.read_at(range.start).unwrap()
248     }
249 
250     /// The number of mapping entries.
map_count(&self) -> u16251     pub fn map_count(&self) -> u16 {
252         let range = self.shape.map_count_byte_range();
253         self.data.read_at(range.start).unwrap()
254     }
255 
256     /// The delta-set index mapping data. See details below.
map_data(&self) -> &'a [u8]257     pub fn map_data(&self) -> &'a [u8] {
258         let range = self.shape.map_data_byte_range();
259         self.data.read_array(range).unwrap()
260     }
261 }
262 
263 #[cfg(feature = "traversal")]
264 impl<'a> SomeTable<'a> for DeltaSetIndexMapFormat0<'a> {
type_name(&self) -> &str265     fn type_name(&self) -> &str {
266         "DeltaSetIndexMapFormat0"
267     }
get_field(&self, idx: usize) -> Option<Field<'a>>268     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
269         match idx {
270             0usize => Some(Field::new("format", self.format())),
271             1usize => Some(Field::new("entry_format", self.entry_format())),
272             2usize => Some(Field::new("map_count", self.map_count())),
273             3usize => Some(Field::new("map_data", self.map_data())),
274             _ => None,
275         }
276     }
277 }
278 
279 #[cfg(feature = "traversal")]
280 impl<'a> std::fmt::Debug for DeltaSetIndexMapFormat0<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result281     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
282         (self as &dyn SomeTable<'a>).fmt(f)
283     }
284 }
285 
286 impl Format<u8> for DeltaSetIndexMapFormat1Marker {
287     const FORMAT: u8 = 1;
288 }
289 
290 /// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table format 1
291 #[derive(Debug, Clone, Copy)]
292 #[doc(hidden)]
293 pub struct DeltaSetIndexMapFormat1Marker {
294     map_data_byte_len: usize,
295 }
296 
297 impl DeltaSetIndexMapFormat1Marker {
format_byte_range(&self) -> Range<usize>298     fn format_byte_range(&self) -> Range<usize> {
299         let start = 0;
300         start..start + u8::RAW_BYTE_LEN
301     }
entry_format_byte_range(&self) -> Range<usize>302     fn entry_format_byte_range(&self) -> Range<usize> {
303         let start = self.format_byte_range().end;
304         start..start + EntryFormat::RAW_BYTE_LEN
305     }
map_count_byte_range(&self) -> Range<usize>306     fn map_count_byte_range(&self) -> Range<usize> {
307         let start = self.entry_format_byte_range().end;
308         start..start + u32::RAW_BYTE_LEN
309     }
map_data_byte_range(&self) -> Range<usize>310     fn map_data_byte_range(&self) -> Range<usize> {
311         let start = self.map_count_byte_range().end;
312         start..start + self.map_data_byte_len
313     }
314 }
315 
316 impl<'a> FontRead<'a> for DeltaSetIndexMapFormat1<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>317     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
318         let mut cursor = data.cursor();
319         cursor.advance::<u8>();
320         let entry_format: EntryFormat = cursor.read()?;
321         let map_count: u32 = cursor.read()?;
322         let map_data_byte_len = EntryFormat::map_size(entry_format, map_count) * u8::RAW_BYTE_LEN;
323         cursor.advance_by(map_data_byte_len);
324         cursor.finish(DeltaSetIndexMapFormat1Marker { map_data_byte_len })
325     }
326 }
327 
328 /// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table format 1
329 pub type DeltaSetIndexMapFormat1<'a> = TableRef<'a, DeltaSetIndexMapFormat1Marker>;
330 
331 impl<'a> DeltaSetIndexMapFormat1<'a> {
332     /// DeltaSetIndexMap format: set to 1.
format(&self) -> u8333     pub fn format(&self) -> u8 {
334         let range = self.shape.format_byte_range();
335         self.data.read_at(range.start).unwrap()
336     }
337 
338     /// A packed field that describes the compressed representation of
339     /// delta-set indices. See details below.
entry_format(&self) -> EntryFormat340     pub fn entry_format(&self) -> EntryFormat {
341         let range = self.shape.entry_format_byte_range();
342         self.data.read_at(range.start).unwrap()
343     }
344 
345     /// The number of mapping entries.
map_count(&self) -> u32346     pub fn map_count(&self) -> u32 {
347         let range = self.shape.map_count_byte_range();
348         self.data.read_at(range.start).unwrap()
349     }
350 
351     /// The delta-set index mapping data. See details below.
map_data(&self) -> &'a [u8]352     pub fn map_data(&self) -> &'a [u8] {
353         let range = self.shape.map_data_byte_range();
354         self.data.read_array(range).unwrap()
355     }
356 }
357 
358 #[cfg(feature = "traversal")]
359 impl<'a> SomeTable<'a> for DeltaSetIndexMapFormat1<'a> {
type_name(&self) -> &str360     fn type_name(&self) -> &str {
361         "DeltaSetIndexMapFormat1"
362     }
get_field(&self, idx: usize) -> Option<Field<'a>>363     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
364         match idx {
365             0usize => Some(Field::new("format", self.format())),
366             1usize => Some(Field::new("entry_format", self.entry_format())),
367             2usize => Some(Field::new("map_count", self.map_count())),
368             3usize => Some(Field::new("map_data", self.map_data())),
369             _ => None,
370         }
371     }
372 }
373 
374 #[cfg(feature = "traversal")]
375 impl<'a> std::fmt::Debug for DeltaSetIndexMapFormat1<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result376     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
377         (self as &dyn SomeTable<'a>).fmt(f)
378     }
379 }
380 
381 /// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table
382 #[derive(Clone)]
383 pub enum DeltaSetIndexMap<'a> {
384     Format0(DeltaSetIndexMapFormat0<'a>),
385     Format1(DeltaSetIndexMapFormat1<'a>),
386 }
387 
388 impl<'a> DeltaSetIndexMap<'a> {
389     /// DeltaSetIndexMap format: set to 0.
format(&self) -> u8390     pub fn format(&self) -> u8 {
391         match self {
392             Self::Format0(item) => item.format(),
393             Self::Format1(item) => item.format(),
394         }
395     }
396 
397     /// A packed field that describes the compressed representation of
398     /// delta-set indices. See details below.
entry_format(&self) -> EntryFormat399     pub fn entry_format(&self) -> EntryFormat {
400         match self {
401             Self::Format0(item) => item.entry_format(),
402             Self::Format1(item) => item.entry_format(),
403         }
404     }
405 
406     /// The delta-set index mapping data. See details below.
map_data(&self) -> &'a [u8]407     pub fn map_data(&self) -> &'a [u8] {
408         match self {
409             Self::Format0(item) => item.map_data(),
410             Self::Format1(item) => item.map_data(),
411         }
412     }
413 }
414 
415 impl<'a> FontRead<'a> for DeltaSetIndexMap<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>416     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
417         let format: u8 = data.read_at(0usize)?;
418         match format {
419             DeltaSetIndexMapFormat0Marker::FORMAT => Ok(Self::Format0(FontRead::read(data)?)),
420             DeltaSetIndexMapFormat1Marker::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
421             other => Err(ReadError::InvalidFormat(other.into())),
422         }
423     }
424 }
425 
426 #[cfg(feature = "traversal")]
427 impl<'a> DeltaSetIndexMap<'a> {
dyn_inner<'b>(&'b self) -> &'b dyn SomeTable<'a>428     fn dyn_inner<'b>(&'b self) -> &'b dyn SomeTable<'a> {
429         match self {
430             Self::Format0(table) => table,
431             Self::Format1(table) => table,
432         }
433     }
434 }
435 
436 #[cfg(feature = "traversal")]
437 impl<'a> std::fmt::Debug for DeltaSetIndexMap<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result438     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
439         self.dyn_inner().fmt(f)
440     }
441 }
442 
443 #[cfg(feature = "traversal")]
444 impl<'a> SomeTable<'a> for DeltaSetIndexMap<'a> {
type_name(&self) -> &str445     fn type_name(&self) -> &str {
446         self.dyn_inner().type_name()
447     }
get_field(&self, idx: usize) -> Option<Field<'a>>448     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
449         self.dyn_inner().get_field(idx)
450     }
451 }
452 
453 /// Entry format for a [DeltaSetIndexMap].
454 #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
455 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
456 pub struct EntryFormat {
457     bits: u8,
458 }
459 
460 impl EntryFormat {
461     /// Mask for the low 4 bits, which give the count of bits minus one that are used in each entry for the inner-level index.
462     pub const INNER_INDEX_BIT_COUNT_MASK: Self = Self { bits: 0x0F };
463 
464     /// Mask for bits that indicate the size in bytes minus one of each entry.
465     pub const MAP_ENTRY_SIZE_MASK: Self = Self { bits: 0x30 };
466 }
467 
468 impl EntryFormat {
469     ///  Returns an empty set of flags.
470     #[inline]
empty() -> Self471     pub const fn empty() -> Self {
472         Self { bits: 0 }
473     }
474 
475     /// Returns the set containing all flags.
476     #[inline]
all() -> Self477     pub const fn all() -> Self {
478         Self {
479             bits: Self::INNER_INDEX_BIT_COUNT_MASK.bits | Self::MAP_ENTRY_SIZE_MASK.bits,
480         }
481     }
482 
483     /// Returns the raw value of the flags currently stored.
484     #[inline]
bits(&self) -> u8485     pub const fn bits(&self) -> u8 {
486         self.bits
487     }
488 
489     /// Convert from underlying bit representation, unless that
490     /// representation contains bits that do not correspond to a flag.
491     #[inline]
from_bits(bits: u8) -> Option<Self>492     pub const fn from_bits(bits: u8) -> Option<Self> {
493         if (bits & !Self::all().bits()) == 0 {
494             Some(Self { bits })
495         } else {
496             None
497         }
498     }
499 
500     /// Convert from underlying bit representation, dropping any bits
501     /// that do not correspond to flags.
502     #[inline]
from_bits_truncate(bits: u8) -> Self503     pub const fn from_bits_truncate(bits: u8) -> Self {
504         Self {
505             bits: bits & Self::all().bits,
506         }
507     }
508 
509     /// Returns `true` if no flags are currently stored.
510     #[inline]
is_empty(&self) -> bool511     pub const fn is_empty(&self) -> bool {
512         self.bits() == Self::empty().bits()
513     }
514 
515     /// Returns `true` if there are flags common to both `self` and `other`.
516     #[inline]
intersects(&self, other: Self) -> bool517     pub const fn intersects(&self, other: Self) -> bool {
518         !(Self {
519             bits: self.bits & other.bits,
520         })
521         .is_empty()
522     }
523 
524     /// Returns `true` if all of the flags in `other` are contained within `self`.
525     #[inline]
contains(&self, other: Self) -> bool526     pub const fn contains(&self, other: Self) -> bool {
527         (self.bits & other.bits) == other.bits
528     }
529 
530     /// Inserts the specified flags in-place.
531     #[inline]
insert(&mut self, other: Self)532     pub fn insert(&mut self, other: Self) {
533         self.bits |= other.bits;
534     }
535 
536     /// Removes the specified flags in-place.
537     #[inline]
remove(&mut self, other: Self)538     pub fn remove(&mut self, other: Self) {
539         self.bits &= !other.bits;
540     }
541 
542     /// Toggles the specified flags in-place.
543     #[inline]
toggle(&mut self, other: Self)544     pub fn toggle(&mut self, other: Self) {
545         self.bits ^= other.bits;
546     }
547 
548     /// Returns the intersection between the flags in `self` and
549     /// `other`.
550     ///
551     /// Specifically, the returned set contains only the flags which are
552     /// present in *both* `self` *and* `other`.
553     ///
554     /// This is equivalent to using the `&` operator (e.g.
555     /// [`ops::BitAnd`]), as in `flags & other`.
556     ///
557     /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
558     #[inline]
559     #[must_use]
intersection(self, other: Self) -> Self560     pub const fn intersection(self, other: Self) -> Self {
561         Self {
562             bits: self.bits & other.bits,
563         }
564     }
565 
566     /// Returns the union of between the flags in `self` and `other`.
567     ///
568     /// Specifically, the returned set contains all flags which are
569     /// present in *either* `self` *or* `other`, including any which are
570     /// present in both.
571     ///
572     /// This is equivalent to using the `|` operator (e.g.
573     /// [`ops::BitOr`]), as in `flags | other`.
574     ///
575     /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
576     #[inline]
577     #[must_use]
union(self, other: Self) -> Self578     pub const fn union(self, other: Self) -> Self {
579         Self {
580             bits: self.bits | other.bits,
581         }
582     }
583 
584     /// Returns the difference between the flags in `self` and `other`.
585     ///
586     /// Specifically, the returned set contains all flags present in
587     /// `self`, except for the ones present in `other`.
588     ///
589     /// It is also conceptually equivalent to the "bit-clear" operation:
590     /// `flags & !other` (and this syntax is also supported).
591     ///
592     /// This is equivalent to using the `-` operator (e.g.
593     /// [`ops::Sub`]), as in `flags - other`.
594     ///
595     /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
596     #[inline]
597     #[must_use]
difference(self, other: Self) -> Self598     pub const fn difference(self, other: Self) -> Self {
599         Self {
600             bits: self.bits & !other.bits,
601         }
602     }
603 }
604 
605 impl std::ops::BitOr for EntryFormat {
606     type Output = Self;
607 
608     /// Returns the union of the two sets of flags.
609     #[inline]
bitor(self, other: EntryFormat) -> Self610     fn bitor(self, other: EntryFormat) -> Self {
611         Self {
612             bits: self.bits | other.bits,
613         }
614     }
615 }
616 
617 impl std::ops::BitOrAssign for EntryFormat {
618     /// Adds the set of flags.
619     #[inline]
bitor_assign(&mut self, other: Self)620     fn bitor_assign(&mut self, other: Self) {
621         self.bits |= other.bits;
622     }
623 }
624 
625 impl std::ops::BitXor for EntryFormat {
626     type Output = Self;
627 
628     /// Returns the left flags, but with all the right flags toggled.
629     #[inline]
bitxor(self, other: Self) -> Self630     fn bitxor(self, other: Self) -> Self {
631         Self {
632             bits: self.bits ^ other.bits,
633         }
634     }
635 }
636 
637 impl std::ops::BitXorAssign for EntryFormat {
638     /// Toggles the set of flags.
639     #[inline]
bitxor_assign(&mut self, other: Self)640     fn bitxor_assign(&mut self, other: Self) {
641         self.bits ^= other.bits;
642     }
643 }
644 
645 impl std::ops::BitAnd for EntryFormat {
646     type Output = Self;
647 
648     /// Returns the intersection between the two sets of flags.
649     #[inline]
bitand(self, other: Self) -> Self650     fn bitand(self, other: Self) -> Self {
651         Self {
652             bits: self.bits & other.bits,
653         }
654     }
655 }
656 
657 impl std::ops::BitAndAssign for EntryFormat {
658     /// Disables all flags disabled in the set.
659     #[inline]
bitand_assign(&mut self, other: Self)660     fn bitand_assign(&mut self, other: Self) {
661         self.bits &= other.bits;
662     }
663 }
664 
665 impl std::ops::Sub for EntryFormat {
666     type Output = Self;
667 
668     /// Returns the set difference of the two sets of flags.
669     #[inline]
sub(self, other: Self) -> Self670     fn sub(self, other: Self) -> Self {
671         Self {
672             bits: self.bits & !other.bits,
673         }
674     }
675 }
676 
677 impl std::ops::SubAssign for EntryFormat {
678     /// Disables all flags enabled in the set.
679     #[inline]
sub_assign(&mut self, other: Self)680     fn sub_assign(&mut self, other: Self) {
681         self.bits &= !other.bits;
682     }
683 }
684 
685 impl std::ops::Not for EntryFormat {
686     type Output = Self;
687 
688     /// Returns the complement of this set of flags.
689     #[inline]
not(self) -> Self690     fn not(self) -> Self {
691         Self { bits: !self.bits } & Self::all()
692     }
693 }
694 
695 impl std::fmt::Debug for EntryFormat {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result696     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
697         let members: &[(&str, Self)] = &[
698             (
699                 "INNER_INDEX_BIT_COUNT_MASK",
700                 Self::INNER_INDEX_BIT_COUNT_MASK,
701             ),
702             ("MAP_ENTRY_SIZE_MASK", Self::MAP_ENTRY_SIZE_MASK),
703         ];
704         let mut first = true;
705         for (name, value) in members {
706             if self.contains(*value) {
707                 if !first {
708                     f.write_str(" | ")?;
709                 }
710                 first = false;
711                 f.write_str(name)?;
712             }
713         }
714         if first {
715             f.write_str("(empty)")?;
716         }
717         Ok(())
718     }
719 }
720 
721 impl std::fmt::Binary for EntryFormat {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result722     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
723         std::fmt::Binary::fmt(&self.bits, f)
724     }
725 }
726 
727 impl std::fmt::Octal for EntryFormat {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result728     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
729         std::fmt::Octal::fmt(&self.bits, f)
730     }
731 }
732 
733 impl std::fmt::LowerHex for EntryFormat {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result734     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
735         std::fmt::LowerHex::fmt(&self.bits, f)
736     }
737 }
738 
739 impl std::fmt::UpperHex for EntryFormat {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result740     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
741         std::fmt::UpperHex::fmt(&self.bits, f)
742     }
743 }
744 
745 impl font_types::Scalar for EntryFormat {
746     type Raw = <u8 as font_types::Scalar>::Raw;
to_raw(self) -> Self::Raw747     fn to_raw(self) -> Self::Raw {
748         self.bits().to_raw()
749     }
from_raw(raw: Self::Raw) -> Self750     fn from_raw(raw: Self::Raw) -> Self {
751         let t = <u8>::from_raw(raw);
752         Self::from_bits_truncate(t)
753     }
754 }
755 
756 #[cfg(feature = "traversal")]
757 impl<'a> From<EntryFormat> for FieldType<'a> {
from(src: EntryFormat) -> FieldType<'a>758     fn from(src: EntryFormat) -> FieldType<'a> {
759         src.bits().into()
760     }
761 }
762 
763 /// The [VariationRegionList](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) table
764 #[derive(Debug, Clone, Copy)]
765 #[doc(hidden)]
766 pub struct VariationRegionListMarker {
767     variation_regions_byte_len: usize,
768 }
769 
770 impl VariationRegionListMarker {
axis_count_byte_range(&self) -> Range<usize>771     fn axis_count_byte_range(&self) -> Range<usize> {
772         let start = 0;
773         start..start + u16::RAW_BYTE_LEN
774     }
region_count_byte_range(&self) -> Range<usize>775     fn region_count_byte_range(&self) -> Range<usize> {
776         let start = self.axis_count_byte_range().end;
777         start..start + u16::RAW_BYTE_LEN
778     }
variation_regions_byte_range(&self) -> Range<usize>779     fn variation_regions_byte_range(&self) -> Range<usize> {
780         let start = self.region_count_byte_range().end;
781         start..start + self.variation_regions_byte_len
782     }
783 }
784 
785 impl<'a> FontRead<'a> for VariationRegionList<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>786     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
787         let mut cursor = data.cursor();
788         let axis_count: u16 = cursor.read()?;
789         let region_count: u16 = cursor.read()?;
790         let variation_regions_byte_len =
791             region_count as usize * <VariationRegion as ComputeSize>::compute_size(&axis_count);
792         cursor.advance_by(variation_regions_byte_len);
793         cursor.finish(VariationRegionListMarker {
794             variation_regions_byte_len,
795         })
796     }
797 }
798 
799 /// The [VariationRegionList](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) table
800 pub type VariationRegionList<'a> = TableRef<'a, VariationRegionListMarker>;
801 
802 impl<'a> VariationRegionList<'a> {
803     /// The number of variation axes for this font. This must be the
804     /// same number as axisCount in the 'fvar' table.
axis_count(&self) -> u16805     pub fn axis_count(&self) -> u16 {
806         let range = self.shape.axis_count_byte_range();
807         self.data.read_at(range.start).unwrap()
808     }
809 
810     /// The number of variation region tables in the variation region
811     /// list. Must be less than 32,768.
region_count(&self) -> u16812     pub fn region_count(&self) -> u16 {
813         let range = self.shape.region_count_byte_range();
814         self.data.read_at(range.start).unwrap()
815     }
816 
817     /// Array of variation regions.
variation_regions(&self) -> ComputedArray<'a, VariationRegion<'a>>818     pub fn variation_regions(&self) -> ComputedArray<'a, VariationRegion<'a>> {
819         let range = self.shape.variation_regions_byte_range();
820         self.data.read_with_args(range, &self.axis_count()).unwrap()
821     }
822 }
823 
824 #[cfg(feature = "traversal")]
825 impl<'a> SomeTable<'a> for VariationRegionList<'a> {
type_name(&self) -> &str826     fn type_name(&self) -> &str {
827         "VariationRegionList"
828     }
get_field(&self, idx: usize) -> Option<Field<'a>>829     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
830         match idx {
831             0usize => Some(Field::new("axis_count", self.axis_count())),
832             1usize => Some(Field::new("region_count", self.region_count())),
833             2usize => Some(Field::new(
834                 "variation_regions",
835                 traversal::FieldType::computed_array(
836                     "VariationRegion",
837                     self.variation_regions(),
838                     self.offset_data(),
839                 ),
840             )),
841             _ => None,
842         }
843     }
844 }
845 
846 #[cfg(feature = "traversal")]
847 impl<'a> std::fmt::Debug for VariationRegionList<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result848     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
849         (self as &dyn SomeTable<'a>).fmt(f)
850     }
851 }
852 
853 /// The [VariationRegion](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) record
854 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
855 pub struct VariationRegion<'a> {
856     /// Array of region axis coordinates records, in the order of axes
857     /// given in the 'fvar' table.
858     pub region_axes: &'a [RegionAxisCoordinates],
859 }
860 
861 impl<'a> VariationRegion<'a> {
862     /// Array of region axis coordinates records, in the order of axes
863     /// given in the 'fvar' table.
region_axes(&self) -> &'a [RegionAxisCoordinates]864     pub fn region_axes(&self) -> &'a [RegionAxisCoordinates] {
865         self.region_axes
866     }
867 }
868 
869 impl ReadArgs for VariationRegion<'_> {
870     type Args = u16;
871 }
872 
873 impl ComputeSize for VariationRegion<'_> {
compute_size(args: &u16) -> usize874     fn compute_size(args: &u16) -> usize {
875         let axis_count = *args;
876         axis_count as usize * RegionAxisCoordinates::RAW_BYTE_LEN
877     }
878 }
879 
880 impl<'a> FontReadWithArgs<'a> for VariationRegion<'a> {
read_with_args(data: FontData<'a>, args: &u16) -> Result<Self, ReadError>881     fn read_with_args(data: FontData<'a>, args: &u16) -> Result<Self, ReadError> {
882         let mut cursor = data.cursor();
883         let axis_count = *args;
884         Ok(Self {
885             region_axes: cursor.read_array(axis_count as usize)?,
886         })
887     }
888 }
889 
890 impl<'a> VariationRegion<'a> {
891     /// A constructor that requires additional arguments.
892     ///
893     /// This type requires some external state in order to be
894     /// parsed.
read(data: FontData<'a>, axis_count: u16) -> Result<Self, ReadError>895     pub fn read(data: FontData<'a>, axis_count: u16) -> Result<Self, ReadError> {
896         let args = axis_count;
897         Self::read_with_args(data, &args)
898     }
899 }
900 
901 #[cfg(feature = "traversal")]
902 impl<'a> SomeRecord<'a> for VariationRegion<'a> {
traverse(self, data: FontData<'a>) -> RecordResolver<'a>903     fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
904         RecordResolver {
905             name: "VariationRegion",
906             get_field: Box::new(move |idx, _data| match idx {
907                 0usize => Some(Field::new(
908                     "region_axes",
909                     traversal::FieldType::array_of_records(
910                         stringify!(RegionAxisCoordinates),
911                         self.region_axes(),
912                         _data,
913                     ),
914                 )),
915                 _ => None,
916             }),
917             data,
918         }
919     }
920 }
921 
922 /// The [RegionAxisCoordinates](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) record
923 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
924 #[repr(C)]
925 #[repr(packed)]
926 pub struct RegionAxisCoordinates {
927     /// The region start coordinate value for the current axis.
928     pub start_coord: BigEndian<F2Dot14>,
929     /// The region peak coordinate value for the current axis.
930     pub peak_coord: BigEndian<F2Dot14>,
931     /// The region end coordinate value for the current axis.
932     pub end_coord: BigEndian<F2Dot14>,
933 }
934 
935 impl RegionAxisCoordinates {
936     /// The region start coordinate value for the current axis.
start_coord(&self) -> F2Dot14937     pub fn start_coord(&self) -> F2Dot14 {
938         self.start_coord.get()
939     }
940 
941     /// The region peak coordinate value for the current axis.
peak_coord(&self) -> F2Dot14942     pub fn peak_coord(&self) -> F2Dot14 {
943         self.peak_coord.get()
944     }
945 
946     /// The region end coordinate value for the current axis.
end_coord(&self) -> F2Dot14947     pub fn end_coord(&self) -> F2Dot14 {
948         self.end_coord.get()
949     }
950 }
951 
952 impl FixedSize for RegionAxisCoordinates {
953     const RAW_BYTE_LEN: usize =
954         F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN;
955 }
956 
957 impl sealed::Sealed for RegionAxisCoordinates {}
958 
959 /// SAFETY: see the [`FromBytes`] trait documentation.
960 unsafe impl FromBytes for RegionAxisCoordinates {
this_trait_should_only_be_implemented_in_generated_code()961     fn this_trait_should_only_be_implemented_in_generated_code() {}
962 }
963 
964 #[cfg(feature = "traversal")]
965 impl<'a> SomeRecord<'a> for RegionAxisCoordinates {
traverse(self, data: FontData<'a>) -> RecordResolver<'a>966     fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
967         RecordResolver {
968             name: "RegionAxisCoordinates",
969             get_field: Box::new(move |idx, _data| match idx {
970                 0usize => Some(Field::new("start_coord", self.start_coord())),
971                 1usize => Some(Field::new("peak_coord", self.peak_coord())),
972                 2usize => Some(Field::new("end_coord", self.end_coord())),
973                 _ => None,
974             }),
975             data,
976         }
977     }
978 }
979 
980 /// The [ItemVariationStore](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#item-variation-store-header-and-item-variation-data-subtables) table
981 #[derive(Debug, Clone, Copy)]
982 #[doc(hidden)]
983 pub struct ItemVariationStoreMarker {
984     item_variation_data_offsets_byte_len: usize,
985 }
986 
987 impl ItemVariationStoreMarker {
format_byte_range(&self) -> Range<usize>988     fn format_byte_range(&self) -> Range<usize> {
989         let start = 0;
990         start..start + u16::RAW_BYTE_LEN
991     }
variation_region_list_offset_byte_range(&self) -> Range<usize>992     fn variation_region_list_offset_byte_range(&self) -> Range<usize> {
993         let start = self.format_byte_range().end;
994         start..start + Offset32::RAW_BYTE_LEN
995     }
item_variation_data_count_byte_range(&self) -> Range<usize>996     fn item_variation_data_count_byte_range(&self) -> Range<usize> {
997         let start = self.variation_region_list_offset_byte_range().end;
998         start..start + u16::RAW_BYTE_LEN
999     }
item_variation_data_offsets_byte_range(&self) -> Range<usize>1000     fn item_variation_data_offsets_byte_range(&self) -> Range<usize> {
1001         let start = self.item_variation_data_count_byte_range().end;
1002         start..start + self.item_variation_data_offsets_byte_len
1003     }
1004 }
1005 
1006 impl<'a> FontRead<'a> for ItemVariationStore<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>1007     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
1008         let mut cursor = data.cursor();
1009         cursor.advance::<u16>();
1010         cursor.advance::<Offset32>();
1011         let item_variation_data_count: u16 = cursor.read()?;
1012         let item_variation_data_offsets_byte_len =
1013             item_variation_data_count as usize * Offset32::RAW_BYTE_LEN;
1014         cursor.advance_by(item_variation_data_offsets_byte_len);
1015         cursor.finish(ItemVariationStoreMarker {
1016             item_variation_data_offsets_byte_len,
1017         })
1018     }
1019 }
1020 
1021 /// The [ItemVariationStore](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#item-variation-store-header-and-item-variation-data-subtables) table
1022 pub type ItemVariationStore<'a> = TableRef<'a, ItemVariationStoreMarker>;
1023 
1024 impl<'a> ItemVariationStore<'a> {
1025     /// Format— set to 1
format(&self) -> u161026     pub fn format(&self) -> u16 {
1027         let range = self.shape.format_byte_range();
1028         self.data.read_at(range.start).unwrap()
1029     }
1030 
1031     /// Offset in bytes from the start of the item variation store to
1032     /// the variation region list.
variation_region_list_offset(&self) -> Offset321033     pub fn variation_region_list_offset(&self) -> Offset32 {
1034         let range = self.shape.variation_region_list_offset_byte_range();
1035         self.data.read_at(range.start).unwrap()
1036     }
1037 
1038     /// Attempt to resolve [`variation_region_list_offset`][Self::variation_region_list_offset].
variation_region_list(&self) -> Result<VariationRegionList<'a>, ReadError>1039     pub fn variation_region_list(&self) -> Result<VariationRegionList<'a>, ReadError> {
1040         let data = self.data;
1041         self.variation_region_list_offset().resolve(data)
1042     }
1043 
1044     /// The number of item variation data subtables.
item_variation_data_count(&self) -> u161045     pub fn item_variation_data_count(&self) -> u16 {
1046         let range = self.shape.item_variation_data_count_byte_range();
1047         self.data.read_at(range.start).unwrap()
1048     }
1049 
1050     /// Offsets in bytes from the start of the item variation store to
1051     /// each item variation data subtable.
item_variation_data_offsets(&self) -> &'a [BigEndian<Nullable<Offset32>>]1052     pub fn item_variation_data_offsets(&self) -> &'a [BigEndian<Nullable<Offset32>>] {
1053         let range = self.shape.item_variation_data_offsets_byte_range();
1054         self.data.read_array(range).unwrap()
1055     }
1056 
1057     /// A dynamically resolving wrapper for [`item_variation_data_offsets`][Self::item_variation_data_offsets].
item_variation_data( &self, ) -> ArrayOfNullableOffsets<'a, ItemVariationData<'a>, Offset32>1058     pub fn item_variation_data(
1059         &self,
1060     ) -> ArrayOfNullableOffsets<'a, ItemVariationData<'a>, Offset32> {
1061         let data = self.data;
1062         let offsets = self.item_variation_data_offsets();
1063         ArrayOfNullableOffsets::new(offsets, data, ())
1064     }
1065 }
1066 
1067 #[cfg(feature = "traversal")]
1068 impl<'a> SomeTable<'a> for ItemVariationStore<'a> {
type_name(&self) -> &str1069     fn type_name(&self) -> &str {
1070         "ItemVariationStore"
1071     }
get_field(&self, idx: usize) -> Option<Field<'a>>1072     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
1073         match idx {
1074             0usize => Some(Field::new("format", self.format())),
1075             1usize => Some(Field::new(
1076                 "variation_region_list_offset",
1077                 FieldType::offset(
1078                     self.variation_region_list_offset(),
1079                     self.variation_region_list(),
1080                 ),
1081             )),
1082             2usize => Some(Field::new(
1083                 "item_variation_data_count",
1084                 self.item_variation_data_count(),
1085             )),
1086             3usize => Some({
1087                 let data = self.data;
1088                 Field::new(
1089                     "item_variation_data_offsets",
1090                     FieldType::array_of_offsets(
1091                         better_type_name::<ItemVariationData>(),
1092                         self.item_variation_data_offsets(),
1093                         move |off| {
1094                             let target = off.get().resolve::<ItemVariationData>(data);
1095                             FieldType::offset(off.get(), target)
1096                         },
1097                     ),
1098                 )
1099             }),
1100             _ => None,
1101         }
1102     }
1103 }
1104 
1105 #[cfg(feature = "traversal")]
1106 impl<'a> std::fmt::Debug for ItemVariationStore<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1107     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1108         (self as &dyn SomeTable<'a>).fmt(f)
1109     }
1110 }
1111 
1112 /// The [ItemVariationData](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#item-variation-store-header-and-item-variation-data-subtables) subtable
1113 #[derive(Debug, Clone, Copy)]
1114 #[doc(hidden)]
1115 pub struct ItemVariationDataMarker {
1116     region_indexes_byte_len: usize,
1117     delta_sets_byte_len: usize,
1118 }
1119 
1120 impl ItemVariationDataMarker {
item_count_byte_range(&self) -> Range<usize>1121     fn item_count_byte_range(&self) -> Range<usize> {
1122         let start = 0;
1123         start..start + u16::RAW_BYTE_LEN
1124     }
word_delta_count_byte_range(&self) -> Range<usize>1125     fn word_delta_count_byte_range(&self) -> Range<usize> {
1126         let start = self.item_count_byte_range().end;
1127         start..start + u16::RAW_BYTE_LEN
1128     }
region_index_count_byte_range(&self) -> Range<usize>1129     fn region_index_count_byte_range(&self) -> Range<usize> {
1130         let start = self.word_delta_count_byte_range().end;
1131         start..start + u16::RAW_BYTE_LEN
1132     }
region_indexes_byte_range(&self) -> Range<usize>1133     fn region_indexes_byte_range(&self) -> Range<usize> {
1134         let start = self.region_index_count_byte_range().end;
1135         start..start + self.region_indexes_byte_len
1136     }
delta_sets_byte_range(&self) -> Range<usize>1137     fn delta_sets_byte_range(&self) -> Range<usize> {
1138         let start = self.region_indexes_byte_range().end;
1139         start..start + self.delta_sets_byte_len
1140     }
1141 }
1142 
1143 impl<'a> FontRead<'a> for ItemVariationData<'a> {
read(data: FontData<'a>) -> Result<Self, ReadError>1144     fn read(data: FontData<'a>) -> Result<Self, ReadError> {
1145         let mut cursor = data.cursor();
1146         cursor.advance::<u16>();
1147         cursor.advance::<u16>();
1148         let region_index_count: u16 = cursor.read()?;
1149         let region_indexes_byte_len = region_index_count as usize * u16::RAW_BYTE_LEN;
1150         cursor.advance_by(region_indexes_byte_len);
1151         let delta_sets_byte_len = cursor.remaining_bytes() / u8::RAW_BYTE_LEN * u8::RAW_BYTE_LEN;
1152         cursor.advance_by(delta_sets_byte_len);
1153         cursor.finish(ItemVariationDataMarker {
1154             region_indexes_byte_len,
1155             delta_sets_byte_len,
1156         })
1157     }
1158 }
1159 
1160 /// The [ItemVariationData](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#item-variation-store-header-and-item-variation-data-subtables) subtable
1161 pub type ItemVariationData<'a> = TableRef<'a, ItemVariationDataMarker>;
1162 
1163 impl<'a> ItemVariationData<'a> {
1164     /// The number of delta sets for distinct items.
item_count(&self) -> u161165     pub fn item_count(&self) -> u16 {
1166         let range = self.shape.item_count_byte_range();
1167         self.data.read_at(range.start).unwrap()
1168     }
1169 
1170     /// A packed field: the high bit is a flag—see details below.
word_delta_count(&self) -> u161171     pub fn word_delta_count(&self) -> u16 {
1172         let range = self.shape.word_delta_count_byte_range();
1173         self.data.read_at(range.start).unwrap()
1174     }
1175 
1176     /// The number of variation regions referenced.
region_index_count(&self) -> u161177     pub fn region_index_count(&self) -> u16 {
1178         let range = self.shape.region_index_count_byte_range();
1179         self.data.read_at(range.start).unwrap()
1180     }
1181 
1182     /// Array of indices into the variation region list for the regions
1183     /// referenced by this item variation data table.
region_indexes(&self) -> &'a [BigEndian<u16>]1184     pub fn region_indexes(&self) -> &'a [BigEndian<u16>] {
1185         let range = self.shape.region_indexes_byte_range();
1186         self.data.read_array(range).unwrap()
1187     }
1188 
1189     /// Delta-set rows.
delta_sets(&self) -> &'a [u8]1190     pub fn delta_sets(&self) -> &'a [u8] {
1191         let range = self.shape.delta_sets_byte_range();
1192         self.data.read_array(range).unwrap()
1193     }
1194 }
1195 
1196 #[cfg(feature = "traversal")]
1197 impl<'a> SomeTable<'a> for ItemVariationData<'a> {
type_name(&self) -> &str1198     fn type_name(&self) -> &str {
1199         "ItemVariationData"
1200     }
get_field(&self, idx: usize) -> Option<Field<'a>>1201     fn get_field(&self, idx: usize) -> Option<Field<'a>> {
1202         match idx {
1203             0usize => Some(Field::new("item_count", self.item_count())),
1204             1usize => Some(Field::new("word_delta_count", self.word_delta_count())),
1205             2usize => Some(Field::new("region_index_count", self.region_index_count())),
1206             3usize => Some(Field::new("region_indexes", self.region_indexes())),
1207             4usize => Some(Field::new("delta_sets", self.delta_sets())),
1208             _ => None,
1209         }
1210     }
1211 }
1212 
1213 #[cfg(feature = "traversal")]
1214 impl<'a> std::fmt::Debug for ItemVariationData<'a> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result1215     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1216         (self as &dyn SomeTable<'a>).fmt(f)
1217     }
1218 }
1219