1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Gvar<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self.glyph_variation_data_offsets_byte_range().end
11 }
12 fn min_table_bytes(&self) -> &'a [u8] {
13 let range = self.min_byte_range();
14 self.offset_data().as_bytes().get(range).unwrap_or_default()
15 }
16}
17
18impl TopLevelTable for Gvar<'_> {
19 const TAG: Tag = Tag::new(b"gvar");
21}
22
23impl ReadArgs for Gvar<'_> {
24 type Args = ();
25}
26
27impl<'a> FontRead<'a> for Gvar<'a> {
28 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29 #[allow(clippy::absurd_extreme_comparisons)]
30 if data.len() < Self::MIN_SIZE {
31 return Err(ReadError::OutOfBounds);
32 }
33 let Some(data) = TableDataRef::new(data.as_bytes()) else {
34 return Err(ReadError::OutOfBounds);
35 };
36 Ok(Self { data })
37 }
38}
39
40#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42#[repr(C, packed)]
43#[doc(hidden)]
44pub struct GvarFixedHeader {
45 pub version: BigEndian<MajorMinor>,
46 pub axis_count: BigEndian<u16>,
47 pub shared_tuple_count: BigEndian<u16>,
48 pub shared_tuples_offset: BigEndian<Offset32>,
49 pub glyph_count: BigEndian<u16>,
50 pub flags: BigEndian<GvarFlags>,
51 pub glyph_variation_data_array_offset: BigEndian<u32>,
52}
53
54#[allow(clippy::absurd_extreme_comparisons)]
55const _: () = assert!(std::mem::size_of::<GvarFixedHeader>() <= Gvar::MIN_SIZE);
56
57#[derive(Clone)]
59pub struct Gvar<'a> {
60 data: TableDataRef<'a, GvarFixedHeader>,
61}
62
63#[allow(clippy::needless_lifetimes)]
64impl<'a> Gvar<'a> {
65 pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
66 + u16::RAW_BYTE_LEN
67 + u16::RAW_BYTE_LEN
68 + Offset32::RAW_BYTE_LEN
69 + u16::RAW_BYTE_LEN
70 + GvarFlags::RAW_BYTE_LEN
71 + u32::RAW_BYTE_LEN);
72 basic_table_impls!(impl_the_methods);
73
74 pub fn version(&self) -> MajorMinor {
76 self.data.header().version.get()
77 }
78
79 pub fn axis_count(&self) -> u16 {
82 self.data.header().axis_count.get()
83 }
84
85 pub fn shared_tuple_count(&self) -> u16 {
90 self.data.header().shared_tuple_count.get()
91 }
92
93 pub fn glyph_count(&self) -> u16 {
96 self.data.header().glyph_count.get()
97 }
98
99 pub fn flags(&self) -> GvarFlags {
103 self.data.header().flags.get()
104 }
105
106 pub fn glyph_variation_data_array_offset(&self) -> u32 {
109 self.data.header().glyph_variation_data_array_offset.get()
110 }
111
112 pub fn glyph_variation_data_offsets(&self) -> ComputedArray<'a, U16Or32> {
115 let range = self.glyph_variation_data_offsets_byte_range();
116 ComputedArray::new(self.offset_data(), range, self.flags()).unwrap_or_default()
117 }
118
119 pub fn version_byte_range(&self) -> Range<usize> {
120 let start = 0;
121 let end = start + MajorMinor::RAW_BYTE_LEN;
122 start..end
123 }
124
125 pub fn axis_count_byte_range(&self) -> Range<usize> {
126 let start = self.version_byte_range().end;
127 let end = start + u16::RAW_BYTE_LEN;
128 start..end
129 }
130
131 pub fn shared_tuple_count_byte_range(&self) -> Range<usize> {
132 let start = self.axis_count_byte_range().end;
133 let end = start + u16::RAW_BYTE_LEN;
134 start..end
135 }
136
137 pub fn shared_tuples_offset_byte_range(&self) -> Range<usize> {
138 let start = self.shared_tuple_count_byte_range().end;
139 let end = start + Offset32::RAW_BYTE_LEN;
140 start..end
141 }
142
143 pub fn glyph_count_byte_range(&self) -> Range<usize> {
144 let start = self.shared_tuples_offset_byte_range().end;
145 let end = start + u16::RAW_BYTE_LEN;
146 start..end
147 }
148
149 pub fn flags_byte_range(&self) -> Range<usize> {
150 let start = self.glyph_count_byte_range().end;
151 let end = start + GvarFlags::RAW_BYTE_LEN;
152 start..end
153 }
154
155 pub fn glyph_variation_data_array_offset_byte_range(&self) -> Range<usize> {
156 let start = self.flags_byte_range().end;
157 let end = start + u32::RAW_BYTE_LEN;
158 start..end
159 }
160
161 pub fn glyph_variation_data_offsets_byte_range(&self) -> Range<usize> {
162 let glyph_count = self.glyph_count();
163 let start = self.glyph_variation_data_array_offset_byte_range().end;
164 let end = start
165 + (transforms::add(glyph_count, 1_usize))
166 .saturating_mul(<U16Or32 as ComputeSize>::compute_size(self.flags()).unwrap_or(0));
167 start..end
168 }
169}
170
171const _: () = assert!(FontData::default_data_long_enough(Gvar::MIN_SIZE));
172
173impl Default for Gvar<'_> {
174 fn default() -> Self {
175 Self {
176 data: TableDataRef::new(FontData::default_table_data().as_bytes())
177 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
178 }
179 }
180}
181
182impl<'a> MinByteRange<'a> for GvarExtended<'a> {
183 fn min_byte_range(&self) -> Range<usize> {
184 0..self.glyph_variation_data_offsets_byte_range().end
185 }
186 fn min_table_bytes(&self) -> &'a [u8] {
187 let range = self.min_byte_range();
188 self.offset_data().as_bytes().get(range).unwrap_or_default()
189 }
190}
191
192impl TopLevelTable for GvarExtended<'_> {
193 const TAG: Tag = Tag::new(b"GVAR");
195}
196
197impl ReadArgs for GvarExtended<'_> {
198 type Args = ();
199}
200
201impl<'a> FontRead<'a> for GvarExtended<'a> {
202 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
203 #[allow(clippy::absurd_extreme_comparisons)]
204 if data.len() < Self::MIN_SIZE {
205 return Err(ReadError::OutOfBounds);
206 }
207 let Some(data) = TableDataRef::new(data.as_bytes()) else {
208 return Err(ReadError::OutOfBounds);
209 };
210 Ok(Self { data })
211 }
212}
213
214#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
216#[repr(C, packed)]
217#[doc(hidden)]
218pub struct GvarExtendedFixedHeader {
219 pub version: BigEndian<MajorMinor>,
220 pub axis_count: BigEndian<u16>,
221 pub shared_tuple_count: BigEndian<u16>,
222 pub shared_tuples_offset: BigEndian<Offset32>,
223 pub glyph_count: BigEndian<Uint24>,
224 pub flags: BigEndian<GvarFlags>,
225 pub glyph_variation_data_array_offset: BigEndian<u32>,
226}
227
228#[allow(clippy::absurd_extreme_comparisons)]
229const _: () = assert!(std::mem::size_of::<GvarExtendedFixedHeader>() <= GvarExtended::MIN_SIZE);
230
231#[derive(Clone)]
233pub struct GvarExtended<'a> {
234 data: TableDataRef<'a, GvarExtendedFixedHeader>,
235}
236
237#[allow(clippy::needless_lifetimes)]
238impl<'a> GvarExtended<'a> {
239 pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
240 + u16::RAW_BYTE_LEN
241 + u16::RAW_BYTE_LEN
242 + Offset32::RAW_BYTE_LEN
243 + Uint24::RAW_BYTE_LEN
244 + GvarFlags::RAW_BYTE_LEN
245 + u32::RAW_BYTE_LEN);
246 basic_table_impls!(impl_the_methods);
247
248 pub fn version(&self) -> MajorMinor {
249 self.data.header().version.get()
250 }
251
252 pub fn axis_count(&self) -> u16 {
253 self.data.header().axis_count.get()
254 }
255
256 pub fn shared_tuple_count(&self) -> u16 {
257 self.data.header().shared_tuple_count.get()
258 }
259
260 pub fn glyph_count(&self) -> Uint24 {
262 self.data.header().glyph_count.get()
263 }
264
265 pub fn flags(&self) -> GvarFlags {
266 self.data.header().flags.get()
267 }
268
269 pub fn glyph_variation_data_array_offset(&self) -> u32 {
270 self.data.header().glyph_variation_data_array_offset.get()
271 }
272
273 pub fn glyph_variation_data_offsets(&self) -> ComputedArray<'a, U16Or32> {
274 let range = self.glyph_variation_data_offsets_byte_range();
275 ComputedArray::new(self.offset_data(), range, self.flags()).unwrap_or_default()
276 }
277
278 pub fn version_byte_range(&self) -> Range<usize> {
279 let start = 0;
280 let end = start + MajorMinor::RAW_BYTE_LEN;
281 start..end
282 }
283
284 pub fn axis_count_byte_range(&self) -> Range<usize> {
285 let start = self.version_byte_range().end;
286 let end = start + u16::RAW_BYTE_LEN;
287 start..end
288 }
289
290 pub fn shared_tuple_count_byte_range(&self) -> Range<usize> {
291 let start = self.axis_count_byte_range().end;
292 let end = start + u16::RAW_BYTE_LEN;
293 start..end
294 }
295
296 pub fn shared_tuples_offset_byte_range(&self) -> Range<usize> {
297 let start = self.shared_tuple_count_byte_range().end;
298 let end = start + Offset32::RAW_BYTE_LEN;
299 start..end
300 }
301
302 pub fn glyph_count_byte_range(&self) -> Range<usize> {
303 let start = self.shared_tuples_offset_byte_range().end;
304 let end = start + Uint24::RAW_BYTE_LEN;
305 start..end
306 }
307
308 pub fn flags_byte_range(&self) -> Range<usize> {
309 let start = self.glyph_count_byte_range().end;
310 let end = start + GvarFlags::RAW_BYTE_LEN;
311 start..end
312 }
313
314 pub fn glyph_variation_data_array_offset_byte_range(&self) -> Range<usize> {
315 let start = self.flags_byte_range().end;
316 let end = start + u32::RAW_BYTE_LEN;
317 start..end
318 }
319
320 pub fn glyph_variation_data_offsets_byte_range(&self) -> Range<usize> {
321 let glyph_count = self.glyph_count();
322 let start = self.glyph_variation_data_array_offset_byte_range().end;
323 let end = start
324 + (transforms::add(glyph_count, 1_usize))
325 .saturating_mul(<U16Or32 as ComputeSize>::compute_size(self.flags()).unwrap_or(0));
326 start..end
327 }
328}
329
330const _: () = assert!(FontData::default_data_long_enough(GvarExtended::MIN_SIZE));
331
332impl Default for GvarExtended<'_> {
333 fn default() -> Self {
334 Self {
335 data: TableDataRef::new(FontData::default_table_data().as_bytes())
336 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
337 }
338 }
339}
340
341#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
342#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
343#[repr(transparent)]
344pub struct GvarFlags {
345 bits: u16,
346}
347
348impl GvarFlags {
349 pub const LONG_OFFSETS: Self = Self { bits: 1 };
351}
352
353impl GvarFlags {
354 #[inline]
356 pub const fn empty() -> Self {
357 Self { bits: 0 }
358 }
359
360 #[inline]
362 pub const fn all() -> Self {
363 Self {
364 bits: Self::LONG_OFFSETS.bits,
365 }
366 }
367
368 #[inline]
370 pub const fn bits(&self) -> u16 {
371 self.bits
372 }
373
374 #[inline]
377 pub const fn from_bits(bits: u16) -> Option<Self> {
378 if (bits & !Self::all().bits()) == 0 {
379 Some(Self { bits })
380 } else {
381 None
382 }
383 }
384
385 #[inline]
388 pub const fn from_bits_truncate(bits: u16) -> Self {
389 Self {
390 bits: bits & Self::all().bits,
391 }
392 }
393
394 #[inline]
396 pub const fn is_empty(&self) -> bool {
397 self.bits() == Self::empty().bits()
398 }
399
400 #[inline]
402 pub const fn intersects(&self, other: Self) -> bool {
403 !(Self {
404 bits: self.bits & other.bits,
405 })
406 .is_empty()
407 }
408
409 #[inline]
411 pub const fn contains(&self, other: Self) -> bool {
412 (self.bits & other.bits) == other.bits
413 }
414
415 #[inline]
417 pub fn insert(&mut self, other: Self) {
418 self.bits |= other.bits;
419 }
420
421 #[inline]
423 pub fn remove(&mut self, other: Self) {
424 self.bits &= !other.bits;
425 }
426
427 #[inline]
429 pub fn toggle(&mut self, other: Self) {
430 self.bits ^= other.bits;
431 }
432
433 #[inline]
444 #[must_use]
445 pub const fn intersection(self, other: Self) -> Self {
446 Self {
447 bits: self.bits & other.bits,
448 }
449 }
450
451 #[inline]
462 #[must_use]
463 pub const fn union(self, other: Self) -> Self {
464 Self {
465 bits: self.bits | other.bits,
466 }
467 }
468
469 #[inline]
482 #[must_use]
483 pub const fn difference(self, other: Self) -> Self {
484 Self {
485 bits: self.bits & !other.bits,
486 }
487 }
488}
489
490impl std::ops::BitOr for GvarFlags {
491 type Output = Self;
492
493 #[inline]
495 fn bitor(self, other: GvarFlags) -> Self {
496 Self {
497 bits: self.bits | other.bits,
498 }
499 }
500}
501
502impl std::ops::BitOrAssign for GvarFlags {
503 #[inline]
505 fn bitor_assign(&mut self, other: Self) {
506 self.bits |= other.bits;
507 }
508}
509
510impl std::ops::BitXor for GvarFlags {
511 type Output = Self;
512
513 #[inline]
515 fn bitxor(self, other: Self) -> Self {
516 Self {
517 bits: self.bits ^ other.bits,
518 }
519 }
520}
521
522impl std::ops::BitXorAssign for GvarFlags {
523 #[inline]
525 fn bitxor_assign(&mut self, other: Self) {
526 self.bits ^= other.bits;
527 }
528}
529
530impl std::ops::BitAnd for GvarFlags {
531 type Output = Self;
532
533 #[inline]
535 fn bitand(self, other: Self) -> Self {
536 Self {
537 bits: self.bits & other.bits,
538 }
539 }
540}
541
542impl std::ops::BitAndAssign for GvarFlags {
543 #[inline]
545 fn bitand_assign(&mut self, other: Self) {
546 self.bits &= other.bits;
547 }
548}
549
550impl std::ops::Sub for GvarFlags {
551 type Output = Self;
552
553 #[inline]
555 fn sub(self, other: Self) -> Self {
556 Self {
557 bits: self.bits & !other.bits,
558 }
559 }
560}
561
562impl std::ops::SubAssign for GvarFlags {
563 #[inline]
565 fn sub_assign(&mut self, other: Self) {
566 self.bits &= !other.bits;
567 }
568}
569
570impl std::ops::Not for GvarFlags {
571 type Output = Self;
572
573 #[inline]
575 fn not(self) -> Self {
576 Self { bits: !self.bits } & Self::all()
577 }
578}
579
580impl std::fmt::Debug for GvarFlags {
581 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
582 let members: &[(&str, Self)] = &[("LONG_OFFSETS", Self::LONG_OFFSETS)];
583 let mut first = true;
584 for (name, value) in members {
585 if self.contains(*value) {
586 if !first {
587 f.write_str(" | ")?;
588 }
589 first = false;
590 f.write_str(name)?;
591 }
592 }
593 if first {
594 f.write_str("(empty)")?;
595 }
596 Ok(())
597 }
598}
599
600impl std::fmt::Binary for GvarFlags {
601 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
602 std::fmt::Binary::fmt(&self.bits, f)
603 }
604}
605
606impl std::fmt::Octal for GvarFlags {
607 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
608 std::fmt::Octal::fmt(&self.bits, f)
609 }
610}
611
612impl std::fmt::LowerHex for GvarFlags {
613 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
614 std::fmt::LowerHex::fmt(&self.bits, f)
615 }
616}
617
618impl std::fmt::UpperHex for GvarFlags {
619 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
620 std::fmt::UpperHex::fmt(&self.bits, f)
621 }
622}
623
624impl font_types::Scalar for GvarFlags {
625 type Raw = <u16 as font_types::Scalar>::Raw;
626 fn to_raw(self) -> Self::Raw {
627 self.bits().to_raw()
628 }
629 fn from_raw(raw: Self::Raw) -> Self {
630 let t = <u16>::from_raw(raw);
631 Self::from_bits_truncate(t)
632 }
633}
634
635impl<'a> MinByteRange<'a> for SharedTuples<'a> {
636 fn min_byte_range(&self) -> Range<usize> {
637 0..self.tuples_byte_range().end
638 }
639 fn min_table_bytes(&self) -> &'a [u8] {
640 let range = self.min_byte_range();
641 self.offset_data().as_bytes().get(range).unwrap_or_default()
642 }
643}
644
645impl ReadArgs for SharedTuples<'_> {
646 type Args = (u16, u16);
647}
648
649impl<'a> FontRead<'a> for SharedTuples<'a> {
650 fn read_with_args(data: FontData<'a>, args: (u16, u16)) -> Result<Self, ReadError> {
651 let (shared_tuple_count, axis_count) = args;
652
653 #[allow(clippy::absurd_extreme_comparisons)]
654 if data.len() < Self::MIN_SIZE {
655 return Err(ReadError::OutOfBounds);
656 }
657 let Some(data) = TableDataRef::new(data.as_bytes()) else {
658 return Err(ReadError::OutOfBounds);
659 };
660 Ok(Self {
661 data,
662 shared_tuple_count,
663 axis_count,
664 })
665 }
666}
667
668impl<'a> SharedTuples<'a> {
669 pub fn read(
674 data: FontData<'a>,
675 shared_tuple_count: u16,
676 axis_count: u16,
677 ) -> Result<Self, ReadError> {
678 let args = (shared_tuple_count, axis_count);
679 Self::read_with_args(data, args)
680 }
681}
682
683#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
685#[repr(C, packed)]
686#[doc(hidden)]
687pub struct SharedTuplesFixedHeader {}
688
689#[allow(clippy::absurd_extreme_comparisons)]
690const _: () = assert!(std::mem::size_of::<SharedTuplesFixedHeader>() <= SharedTuples::MIN_SIZE);
691
692#[derive(Clone)]
694pub struct SharedTuples<'a> {
695 data: TableDataRef<'a, SharedTuplesFixedHeader>,
696 shared_tuple_count: u16,
697 axis_count: u16,
698}
699
700#[allow(clippy::needless_lifetimes)]
701impl<'a> SharedTuples<'a> {
702 pub const MIN_SIZE: usize = 0;
703 basic_table_impls!(impl_the_methods);
704
705 pub fn tuples(&self) -> ComputedArray<'a, Tuple<'a>> {
706 let range = self.tuples_byte_range();
707 ComputedArray::new(self.offset_data(), range, self.axis_count()).unwrap_or_default()
708 }
709
710 pub(crate) fn shared_tuple_count(&self) -> u16 {
711 self.shared_tuple_count
712 }
713
714 pub(crate) fn axis_count(&self) -> u16 {
715 self.axis_count
716 }
717
718 pub fn tuples_byte_range(&self) -> Range<usize> {
719 let shared_tuple_count = self.shared_tuple_count();
720 let start = 0;
721 let end = start
722 + (transforms::to_usize(shared_tuple_count)).saturating_mul(
723 <Tuple as ComputeSize>::compute_size(self.axis_count()).unwrap_or(0),
724 );
725 start..end
726 }
727}
728
729#[allow(clippy::absurd_extreme_comparisons)]
730const _: () = assert!(FontData::default_data_long_enough(SharedTuples::MIN_SIZE));
731
732impl Default for SharedTuples<'_> {
733 fn default() -> Self {
734 Self {
735 data: TableDataRef::new(FontData::default_table_data().as_bytes())
736 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
737 shared_tuple_count: Default::default(),
738 axis_count: Default::default(),
739 }
740 }
741}
742
743impl<'a> MinByteRange<'a> for GlyphVariationDataHeader<'a> {
744 fn min_byte_range(&self) -> Range<usize> {
745 0..self.tuple_variation_headers_byte_range().end
746 }
747 fn min_table_bytes(&self) -> &'a [u8] {
748 let range = self.min_byte_range();
749 self.offset_data().as_bytes().get(range).unwrap_or_default()
750 }
751}
752
753impl ReadArgs for GlyphVariationDataHeader<'_> {
754 type Args = ();
755}
756
757impl<'a> FontRead<'a> for GlyphVariationDataHeader<'a> {
758 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
759 #[allow(clippy::absurd_extreme_comparisons)]
760 if data.len() < Self::MIN_SIZE {
761 return Err(ReadError::OutOfBounds);
762 }
763 let Some(data) = TableDataRef::new(data.as_bytes()) else {
764 return Err(ReadError::OutOfBounds);
765 };
766 Ok(Self { data })
767 }
768}
769
770#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
772#[repr(C, packed)]
773#[doc(hidden)]
774pub struct GlyphVariationDataHeaderFixedHeader {
775 pub tuple_variation_count: BigEndian<TupleVariationCount>,
776 pub serialized_data_offset: BigEndian<Offset16>,
777}
778
779#[allow(clippy::absurd_extreme_comparisons)]
780const _: () = assert!(
781 std::mem::size_of::<GlyphVariationDataHeaderFixedHeader>()
782 <= GlyphVariationDataHeader::MIN_SIZE
783);
784
785#[derive(Clone)]
787pub struct GlyphVariationDataHeader<'a> {
788 data: TableDataRef<'a, GlyphVariationDataHeaderFixedHeader>,
789}
790
791#[allow(clippy::needless_lifetimes)]
792impl<'a> GlyphVariationDataHeader<'a> {
793 pub const MIN_SIZE: usize = (TupleVariationCount::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN);
794 basic_table_impls!(impl_the_methods);
795
796 pub fn tuple_variation_count(&self) -> TupleVariationCount {
801 self.data.header().tuple_variation_count.get()
802 }
803
804 pub fn serialized_data_offset(&self) -> Offset16 {
807 self.data.header().serialized_data_offset.get()
808 }
809
810 pub fn serialized_data(&self) -> Result<FontData<'a>, ReadError> {
812 let data = self.offset_data();
813 self.serialized_data_offset().resolve(data)
814 }
815
816 pub fn tuple_variation_headers(&self) -> VarLenArray<'a, TupleVariationHeader<'a>> {
818 let range = self.tuple_variation_headers_byte_range();
819 self.offset_data()
820 .split_off(range.start)
821 .and_then(|d| VarLenArray::read(d).ok())
822 .unwrap_or_default()
823 }
824
825 pub fn tuple_variation_count_byte_range(&self) -> Range<usize> {
826 let start = 0;
827 let end = start + TupleVariationCount::RAW_BYTE_LEN;
828 start..end
829 }
830
831 pub fn serialized_data_offset_byte_range(&self) -> Range<usize> {
832 let start = self.tuple_variation_count_byte_range().end;
833 let end = start + Offset16::RAW_BYTE_LEN;
834 start..end
835 }
836
837 pub fn tuple_variation_headers_byte_range(&self) -> Range<usize> {
838 let start = self.serialized_data_offset_byte_range().end;
839 let end = start + self.offset_data().len().saturating_sub(start);
840 start..end
841 }
842}
843
844const _: () = assert!(FontData::default_data_long_enough(
845 GlyphVariationDataHeader::MIN_SIZE
846));
847
848impl Default for GlyphVariationDataHeader<'_> {
849 fn default() -> Self {
850 Self {
851 data: TableDataRef::new(FontData::default_table_data().as_bytes())
852 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
853 }
854 }
855}
856
857impl<'a> MinByteRange<'a> for GlyphVariationDataHeaderExtended<'a> {
858 fn min_byte_range(&self) -> Range<usize> {
859 0..self.tuple_variation_headers_byte_range().end
860 }
861 fn min_table_bytes(&self) -> &'a [u8] {
862 let range = self.min_byte_range();
863 self.offset_data().as_bytes().get(range).unwrap_or_default()
864 }
865}
866
867impl ReadArgs for GlyphVariationDataHeaderExtended<'_> {
868 type Args = ();
869}
870
871impl<'a> FontRead<'a> for GlyphVariationDataHeaderExtended<'a> {
872 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
873 #[allow(clippy::absurd_extreme_comparisons)]
874 if data.len() < Self::MIN_SIZE {
875 return Err(ReadError::OutOfBounds);
876 }
877 let Some(data) = TableDataRef::new(data.as_bytes()) else {
878 return Err(ReadError::OutOfBounds);
879 };
880 Ok(Self { data })
881 }
882}
883
884#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
886#[repr(C, packed)]
887#[doc(hidden)]
888pub struct GlyphVariationDataHeaderExtendedFixedHeader {
889 pub tuple_variation_count: BigEndian<TupleVariationCount>,
890 pub serialized_data_offset: BigEndian<Offset24>,
891}
892
893#[allow(clippy::absurd_extreme_comparisons)]
894const _: () = assert!(
895 std::mem::size_of::<GlyphVariationDataHeaderExtendedFixedHeader>()
896 <= GlyphVariationDataHeaderExtended::MIN_SIZE
897);
898
899#[derive(Clone)]
901pub struct GlyphVariationDataHeaderExtended<'a> {
902 data: TableDataRef<'a, GlyphVariationDataHeaderExtendedFixedHeader>,
903}
904
905#[allow(clippy::needless_lifetimes)]
906impl<'a> GlyphVariationDataHeaderExtended<'a> {
907 pub const MIN_SIZE: usize = (TupleVariationCount::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN);
908 basic_table_impls!(impl_the_methods);
909
910 pub fn tuple_variation_count(&self) -> TupleVariationCount {
911 self.data.header().tuple_variation_count.get()
912 }
913
914 pub fn serialized_data_offset(&self) -> Offset24 {
915 self.data.header().serialized_data_offset.get()
916 }
917
918 pub fn serialized_data(&self) -> Result<FontData<'a>, ReadError> {
920 let data = self.offset_data();
921 self.serialized_data_offset().resolve(data)
922 }
923
924 pub fn tuple_variation_headers(&self) -> VarLenArray<'a, TupleVariationHeader<'a>> {
925 let range = self.tuple_variation_headers_byte_range();
926 self.offset_data()
927 .split_off(range.start)
928 .and_then(|d| VarLenArray::read(d).ok())
929 .unwrap_or_default()
930 }
931
932 pub fn tuple_variation_count_byte_range(&self) -> Range<usize> {
933 let start = 0;
934 let end = start + TupleVariationCount::RAW_BYTE_LEN;
935 start..end
936 }
937
938 pub fn serialized_data_offset_byte_range(&self) -> Range<usize> {
939 let start = self.tuple_variation_count_byte_range().end;
940 let end = start + Offset24::RAW_BYTE_LEN;
941 start..end
942 }
943
944 pub fn tuple_variation_headers_byte_range(&self) -> Range<usize> {
945 let start = self.serialized_data_offset_byte_range().end;
946 let end = start + self.offset_data().len().saturating_sub(start);
947 start..end
948 }
949}
950
951const _: () = assert!(FontData::default_data_long_enough(
952 GlyphVariationDataHeaderExtended::MIN_SIZE
953));
954
955impl Default for GlyphVariationDataHeaderExtended<'_> {
956 fn default() -> Self {
957 Self {
958 data: TableDataRef::new(FontData::default_table_data().as_bytes())
959 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
960 }
961 }
962}