1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Varc<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self.var_composite_glyphs_offset_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 Varc<'_> {
19 const TAG: Tag = Tag::new(b"VARC");
21}
22
23impl ReadArgs for Varc<'_> {
24 type Args = ();
25}
26
27impl<'a> FontRead<'a> for Varc<'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 VarcFixedHeader {
45 pub version: BigEndian<MajorMinor>,
46 pub coverage_offset: BigEndian<Offset32>,
47 pub multi_var_store_offset: BigEndian<Nullable<Offset32>>,
48 pub condition_list_offset: BigEndian<Nullable<Offset32>>,
49 pub axis_indices_list_offset: BigEndian<Nullable<Offset32>>,
50 pub var_composite_glyphs_offset: BigEndian<Offset32>,
51}
52
53#[allow(clippy::absurd_extreme_comparisons)]
54const _: () = assert!(std::mem::size_of::<VarcFixedHeader>() <= Varc::MIN_SIZE);
55
56#[derive(Clone)]
60pub struct Varc<'a> {
61 data: TableDataRef<'a, VarcFixedHeader>,
62}
63
64#[allow(clippy::needless_lifetimes)]
65impl<'a> Varc<'a> {
66 pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
67 + Offset32::RAW_BYTE_LEN
68 + Offset32::RAW_BYTE_LEN
69 + Offset32::RAW_BYTE_LEN
70 + Offset32::RAW_BYTE_LEN
71 + Offset32::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 coverage_offset(&self) -> Offset32 {
80 self.data.header().coverage_offset.get()
81 }
82
83 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
85 let data = self.offset_data();
86 self.coverage_offset().resolve(data)
87 }
88
89 pub fn multi_var_store_offset(&self) -> Nullable<Offset32> {
90 self.data.header().multi_var_store_offset.get()
91 }
92
93 pub fn multi_var_store(&self) -> Option<Result<MultiItemVariationStore<'a>, ReadError>> {
95 let data = self.offset_data();
96 self.multi_var_store_offset().resolve(data)
97 }
98
99 pub fn condition_list_offset(&self) -> Nullable<Offset32> {
100 self.data.header().condition_list_offset.get()
101 }
102
103 pub fn condition_list(&self) -> Option<Result<ConditionList<'a>, ReadError>> {
105 let data = self.offset_data();
106 self.condition_list_offset().resolve(data)
107 }
108
109 pub fn axis_indices_list_offset(&self) -> Nullable<Offset32> {
110 self.data.header().axis_indices_list_offset.get()
111 }
112
113 pub fn axis_indices_list(&self) -> Option<Result<Index2<'a>, ReadError>> {
115 let data = self.offset_data();
116 self.axis_indices_list_offset().resolve(data)
117 }
118
119 pub fn var_composite_glyphs_offset(&self) -> Offset32 {
120 self.data.header().var_composite_glyphs_offset.get()
121 }
122
123 pub fn var_composite_glyphs(&self) -> Result<Index2<'a>, ReadError> {
125 let data = self.offset_data();
126 self.var_composite_glyphs_offset().resolve(data)
127 }
128
129 pub fn version_byte_range(&self) -> Range<usize> {
130 let start = 0;
131 let end = start + MajorMinor::RAW_BYTE_LEN;
132 start..end
133 }
134
135 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
136 let start = self.version_byte_range().end;
137 let end = start + Offset32::RAW_BYTE_LEN;
138 start..end
139 }
140
141 pub fn multi_var_store_offset_byte_range(&self) -> Range<usize> {
142 let start = self.coverage_offset_byte_range().end;
143 let end = start + Offset32::RAW_BYTE_LEN;
144 start..end
145 }
146
147 pub fn condition_list_offset_byte_range(&self) -> Range<usize> {
148 let start = self.multi_var_store_offset_byte_range().end;
149 let end = start + Offset32::RAW_BYTE_LEN;
150 start..end
151 }
152
153 pub fn axis_indices_list_offset_byte_range(&self) -> Range<usize> {
154 let start = self.condition_list_offset_byte_range().end;
155 let end = start + Offset32::RAW_BYTE_LEN;
156 start..end
157 }
158
159 pub fn var_composite_glyphs_offset_byte_range(&self) -> Range<usize> {
160 let start = self.axis_indices_list_offset_byte_range().end;
161 let end = start + Offset32::RAW_BYTE_LEN;
162 start..end
163 }
164}
165
166const _: () = assert!(FontData::default_data_long_enough(Varc::MIN_SIZE));
167
168impl Default for Varc<'_> {
169 fn default() -> Self {
170 Self {
171 data: TableDataRef::new(FontData::default_table_data().as_bytes())
172 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
173 }
174 }
175}
176
177impl Format<u16> for MultiItemVariationStore<'_> {
178 const FORMAT: u16 = 1;
179}
180
181impl<'a> MinByteRange<'a> for MultiItemVariationStore<'a> {
182 fn min_byte_range(&self) -> Range<usize> {
183 0..self.variation_data_offsets_byte_range().end
184 }
185 fn min_table_bytes(&self) -> &'a [u8] {
186 let range = self.min_byte_range();
187 self.offset_data().as_bytes().get(range).unwrap_or_default()
188 }
189}
190
191impl ReadArgs for MultiItemVariationStore<'_> {
192 type Args = ();
193}
194
195impl<'a> FontRead<'a> for MultiItemVariationStore<'a> {
196 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
197 #[allow(clippy::absurd_extreme_comparisons)]
198 if data.len() < Self::MIN_SIZE {
199 return Err(ReadError::OutOfBounds);
200 }
201 let Some(data) = TableDataRef::new(data.as_bytes()) else {
202 return Err(ReadError::OutOfBounds);
203 };
204 Ok(Self { data })
205 }
206}
207
208#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
210#[repr(C, packed)]
211#[doc(hidden)]
212pub struct MultiItemVariationStoreFixedHeader {
213 pub format: BigEndian<u16>,
214 pub region_list_offset: BigEndian<Offset32>,
215 pub variation_data_count: BigEndian<u16>,
216}
217
218#[allow(clippy::absurd_extreme_comparisons)]
219const _: () = assert!(
220 std::mem::size_of::<MultiItemVariationStoreFixedHeader>() <= MultiItemVariationStore::MIN_SIZE
221);
222
223#[derive(Clone)]
226pub struct MultiItemVariationStore<'a> {
227 data: TableDataRef<'a, MultiItemVariationStoreFixedHeader>,
228}
229
230#[allow(clippy::needless_lifetimes)]
231impl<'a> MultiItemVariationStore<'a> {
232 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
233 basic_table_impls!(impl_the_methods);
234
235 pub fn format(&self) -> u16 {
236 self.data.header().format.get()
237 }
238
239 pub fn region_list_offset(&self) -> Offset32 {
240 self.data.header().region_list_offset.get()
241 }
242
243 pub fn region_list(&self) -> Result<SparseVariationRegionList<'a>, ReadError> {
245 let data = self.offset_data();
246 self.region_list_offset().resolve(data)
247 }
248
249 pub fn variation_data_count(&self) -> u16 {
250 self.data.header().variation_data_count.get()
251 }
252
253 pub fn variation_data_offsets(&self) -> &'a [BigEndian<Offset32>] {
254 let range = self.variation_data_offsets_byte_range();
255 self.offset_data()
256 .read_array(range)
257 .ok()
258 .unwrap_or_default()
259 }
260
261 pub fn variation_data(&self) -> ArrayOfOffsets<'a, MultiItemVariationData<'a>, Offset32> {
263 let data = self.offset_data();
264 let offsets = self.variation_data_offsets();
265 ArrayOfOffsets::new(offsets, data, ())
266 }
267
268 pub fn format_byte_range(&self) -> Range<usize> {
269 let start = 0;
270 let end = start + u16::RAW_BYTE_LEN;
271 start..end
272 }
273
274 pub fn region_list_offset_byte_range(&self) -> Range<usize> {
275 let start = self.format_byte_range().end;
276 let end = start + Offset32::RAW_BYTE_LEN;
277 start..end
278 }
279
280 pub fn variation_data_count_byte_range(&self) -> Range<usize> {
281 let start = self.region_list_offset_byte_range().end;
282 let end = start + u16::RAW_BYTE_LEN;
283 start..end
284 }
285
286 pub fn variation_data_offsets_byte_range(&self) -> Range<usize> {
287 let variation_data_count = self.variation_data_count();
288 let start = self.variation_data_count_byte_range().end;
289 let end = start
290 + (transforms::to_usize(variation_data_count)).saturating_mul(Offset32::RAW_BYTE_LEN);
291 start..end
292 }
293}
294
295const _: () = assert!(FontData::default_data_long_enough(
296 MultiItemVariationStore::MIN_SIZE
297));
298
299impl Default for MultiItemVariationStore<'_> {
300 fn default() -> Self {
301 Self {
302 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
303 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
304 }
305 }
306}
307
308impl<'a> MinByteRange<'a> for SparseVariationRegionList<'a> {
309 fn min_byte_range(&self) -> Range<usize> {
310 0..self.region_offsets_byte_range().end
311 }
312 fn min_table_bytes(&self) -> &'a [u8] {
313 let range = self.min_byte_range();
314 self.offset_data().as_bytes().get(range).unwrap_or_default()
315 }
316}
317
318impl ReadArgs for SparseVariationRegionList<'_> {
319 type Args = ();
320}
321
322impl<'a> FontRead<'a> for SparseVariationRegionList<'a> {
323 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
324 #[allow(clippy::absurd_extreme_comparisons)]
325 if data.len() < Self::MIN_SIZE {
326 return Err(ReadError::OutOfBounds);
327 }
328 let Some(data) = TableDataRef::new(data.as_bytes()) else {
329 return Err(ReadError::OutOfBounds);
330 };
331 Ok(Self { data })
332 }
333}
334
335#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
337#[repr(C, packed)]
338#[doc(hidden)]
339pub struct SparseVariationRegionListFixedHeader {
340 pub region_count: BigEndian<u32>,
341}
342
343#[allow(clippy::absurd_extreme_comparisons)]
344const _: () = assert!(
345 std::mem::size_of::<SparseVariationRegionListFixedHeader>()
346 <= SparseVariationRegionList::MIN_SIZE
347);
348
349#[derive(Clone)]
350pub struct SparseVariationRegionList<'a> {
351 data: TableDataRef<'a, SparseVariationRegionListFixedHeader>,
352}
353
354#[allow(clippy::needless_lifetimes)]
355impl<'a> SparseVariationRegionList<'a> {
356 pub const MIN_SIZE: usize = u32::RAW_BYTE_LEN;
357 basic_table_impls!(impl_the_methods);
358
359 pub fn region_count(&self) -> u32 {
360 self.data.header().region_count.get()
361 }
362
363 pub fn region_offsets(&self) -> &'a [BigEndian<Offset32>] {
364 let range = self.region_offsets_byte_range();
365 self.offset_data()
366 .read_array(range)
367 .ok()
368 .unwrap_or_default()
369 }
370
371 pub fn regions(&self) -> ArrayOfOffsets<'a, SparseVariationRegion<'a>, Offset32> {
373 let data = self.offset_data();
374 let offsets = self.region_offsets();
375 ArrayOfOffsets::new(offsets, data, ())
376 }
377
378 pub fn region_count_byte_range(&self) -> Range<usize> {
379 let start = 0;
380 let end = start + u32::RAW_BYTE_LEN;
381 start..end
382 }
383
384 pub fn region_offsets_byte_range(&self) -> Range<usize> {
385 let region_count = self.region_count();
386 let start = self.region_count_byte_range().end;
387 let end =
388 start + (transforms::to_usize(region_count)).saturating_mul(Offset32::RAW_BYTE_LEN);
389 start..end
390 }
391}
392
393const _: () = assert!(FontData::default_data_long_enough(
394 SparseVariationRegionList::MIN_SIZE
395));
396
397impl Default for SparseVariationRegionList<'_> {
398 fn default() -> Self {
399 Self {
400 data: TableDataRef::new(FontData::default_table_data().as_bytes())
401 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
402 }
403 }
404}
405
406impl<'a> MinByteRange<'a> for SparseVariationRegion<'a> {
407 fn min_byte_range(&self) -> Range<usize> {
408 0..self.axis_coordinate_offsets_byte_range().end
409 }
410 fn min_table_bytes(&self) -> &'a [u8] {
411 let range = self.min_byte_range();
412 self.offset_data().as_bytes().get(range).unwrap_or_default()
413 }
414}
415
416impl ReadArgs for SparseVariationRegion<'_> {
417 type Args = ();
418}
419
420impl<'a> FontRead<'a> for SparseVariationRegion<'a> {
421 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
422 #[allow(clippy::absurd_extreme_comparisons)]
423 if data.len() < Self::MIN_SIZE {
424 return Err(ReadError::OutOfBounds);
425 }
426 let Some(data) = TableDataRef::new(data.as_bytes()) else {
427 return Err(ReadError::OutOfBounds);
428 };
429 Ok(Self { data })
430 }
431}
432
433#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
435#[repr(C, packed)]
436#[doc(hidden)]
437pub struct SparseVariationRegionFixedHeader {
438 pub region_axis_count: BigEndian<u16>,
439}
440
441#[allow(clippy::absurd_extreme_comparisons)]
442const _: () = assert!(
443 std::mem::size_of::<SparseVariationRegionFixedHeader>() <= SparseVariationRegion::MIN_SIZE
444);
445
446#[derive(Clone)]
447pub struct SparseVariationRegion<'a> {
448 data: TableDataRef<'a, SparseVariationRegionFixedHeader>,
449}
450
451#[allow(clippy::needless_lifetimes)]
452impl<'a> SparseVariationRegion<'a> {
453 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
454 basic_table_impls!(impl_the_methods);
455
456 pub fn region_axis_count(&self) -> u16 {
457 self.data.header().region_axis_count.get()
458 }
459
460 pub fn axis_coordinate_offsets(&self) -> &'a [BigEndian<Offset32>] {
461 let range = self.axis_coordinate_offsets_byte_range();
462 self.offset_data()
463 .read_array(range)
464 .ok()
465 .unwrap_or_default()
466 }
467
468 pub fn axis_coordinates(
470 &self,
471 ) -> ArrayOfOffsets<'a, SparseRegionAxisCoordinates<'a>, Offset32> {
472 let data = self.offset_data();
473 let offsets = self.axis_coordinate_offsets();
474 ArrayOfOffsets::new(offsets, data, ())
475 }
476
477 pub fn region_axis_count_byte_range(&self) -> Range<usize> {
478 let start = 0;
479 let end = start + u16::RAW_BYTE_LEN;
480 start..end
481 }
482
483 pub fn axis_coordinate_offsets_byte_range(&self) -> Range<usize> {
484 let region_axis_count = self.region_axis_count();
485 let start = self.region_axis_count_byte_range().end;
486 let end = start
487 + (transforms::to_usize(region_axis_count)).saturating_mul(Offset32::RAW_BYTE_LEN);
488 start..end
489 }
490}
491
492const _: () = assert!(FontData::default_data_long_enough(
493 SparseVariationRegion::MIN_SIZE
494));
495
496impl Default for SparseVariationRegion<'_> {
497 fn default() -> Self {
498 Self {
499 data: TableDataRef::new(FontData::default_table_data().as_bytes())
500 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
501 }
502 }
503}
504
505impl<'a> MinByteRange<'a> for SparseRegionAxisCoordinates<'a> {
506 fn min_byte_range(&self) -> Range<usize> {
507 0..self.end_byte_range().end
508 }
509 fn min_table_bytes(&self) -> &'a [u8] {
510 let range = self.min_byte_range();
511 self.offset_data().as_bytes().get(range).unwrap_or_default()
512 }
513}
514
515impl ReadArgs for SparseRegionAxisCoordinates<'_> {
516 type Args = ();
517}
518
519impl<'a> FontRead<'a> for SparseRegionAxisCoordinates<'a> {
520 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
521 #[allow(clippy::absurd_extreme_comparisons)]
522 if data.len() < Self::MIN_SIZE {
523 return Err(ReadError::OutOfBounds);
524 }
525 let Some(data) = TableDataRef::new(data.as_bytes()) else {
526 return Err(ReadError::OutOfBounds);
527 };
528 Ok(Self { data })
529 }
530}
531
532#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
534#[repr(C, packed)]
535#[doc(hidden)]
536pub struct SparseRegionAxisCoordinatesFixedHeader {
537 pub axis_index: BigEndian<u16>,
538 pub start: BigEndian<F2Dot14>,
539 pub peak: BigEndian<F2Dot14>,
540 pub end: BigEndian<F2Dot14>,
541}
542
543#[allow(clippy::absurd_extreme_comparisons)]
544const _: () = assert!(
545 std::mem::size_of::<SparseRegionAxisCoordinatesFixedHeader>()
546 <= SparseRegionAxisCoordinates::MIN_SIZE
547);
548
549#[derive(Clone)]
550pub struct SparseRegionAxisCoordinates<'a> {
551 data: TableDataRef<'a, SparseRegionAxisCoordinatesFixedHeader>,
552}
553
554#[allow(clippy::needless_lifetimes)]
555impl<'a> SparseRegionAxisCoordinates<'a> {
556 pub const MIN_SIZE: usize =
557 (u16::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN);
558 basic_table_impls!(impl_the_methods);
559
560 pub fn axis_index(&self) -> u16 {
561 self.data.header().axis_index.get()
562 }
563
564 pub fn start(&self) -> F2Dot14 {
565 self.data.header().start.get()
566 }
567
568 pub fn peak(&self) -> F2Dot14 {
569 self.data.header().peak.get()
570 }
571
572 pub fn end(&self) -> F2Dot14 {
573 self.data.header().end.get()
574 }
575
576 pub fn axis_index_byte_range(&self) -> Range<usize> {
577 let start = 0;
578 let end = start + u16::RAW_BYTE_LEN;
579 start..end
580 }
581
582 pub fn start_byte_range(&self) -> Range<usize> {
583 let start = self.axis_index_byte_range().end;
584 let end = start + F2Dot14::RAW_BYTE_LEN;
585 start..end
586 }
587
588 pub fn peak_byte_range(&self) -> Range<usize> {
589 let start = self.start_byte_range().end;
590 let end = start + F2Dot14::RAW_BYTE_LEN;
591 start..end
592 }
593
594 pub fn end_byte_range(&self) -> Range<usize> {
595 let start = self.peak_byte_range().end;
596 let end = start + F2Dot14::RAW_BYTE_LEN;
597 start..end
598 }
599}
600
601const _: () = assert!(FontData::default_data_long_enough(
602 SparseRegionAxisCoordinates::MIN_SIZE
603));
604
605impl Default for SparseRegionAxisCoordinates<'_> {
606 fn default() -> Self {
607 Self {
608 data: TableDataRef::new(FontData::default_table_data().as_bytes())
609 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
610 }
611 }
612}
613
614impl Format<u8> for MultiItemVariationData<'_> {
615 const FORMAT: u8 = 1;
616}
617
618impl<'a> MinByteRange<'a> for MultiItemVariationData<'a> {
619 fn min_byte_range(&self) -> Range<usize> {
620 0..self.delta_sets_offset_byte_range().end
621 }
622 fn min_table_bytes(&self) -> &'a [u8] {
623 let range = self.min_byte_range();
624 self.offset_data().as_bytes().get(range).unwrap_or_default()
625 }
626}
627
628impl ReadArgs for MultiItemVariationData<'_> {
629 type Args = ();
630}
631
632impl<'a> FontRead<'a> for MultiItemVariationData<'a> {
633 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
634 #[allow(clippy::absurd_extreme_comparisons)]
635 if data.len() < Self::MIN_SIZE {
636 return Err(ReadError::OutOfBounds);
637 }
638 let Some(data) = TableDataRef::new(data.as_bytes()) else {
639 return Err(ReadError::OutOfBounds);
640 };
641 Ok(Self { data })
642 }
643}
644
645#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
647#[repr(C, packed)]
648#[doc(hidden)]
649pub struct MultiItemVariationDataFixedHeader {
650 pub format: u8,
651 pub region_index_count: BigEndian<u16>,
652}
653
654#[allow(clippy::absurd_extreme_comparisons)]
655const _: () = assert!(
656 std::mem::size_of::<MultiItemVariationDataFixedHeader>() <= MultiItemVariationData::MIN_SIZE
657);
658
659#[derive(Clone)]
660pub struct MultiItemVariationData<'a> {
661 data: TableDataRef<'a, MultiItemVariationDataFixedHeader>,
662}
663
664#[allow(clippy::needless_lifetimes)]
665impl<'a> MultiItemVariationData<'a> {
666 pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN);
667 basic_table_impls!(impl_the_methods);
668
669 pub fn format(&self) -> u8 {
670 self.data.header().format
671 }
672
673 pub fn region_index_count(&self) -> u16 {
674 self.data.header().region_index_count.get()
675 }
676
677 pub fn region_indices(&self) -> &'a [BigEndian<u16>] {
678 let range = self.region_indices_byte_range();
679 self.offset_data()
680 .read_array(range)
681 .ok()
682 .unwrap_or_default()
683 }
684
685 pub fn delta_sets_offset(&self) -> Offset32 {
686 let range = self.delta_sets_offset_byte_range();
687 self.offset_data()
688 .read_at(range.start)
689 .ok()
690 .unwrap_or(Offset32::new(Default::default()))
691 }
692
693 pub fn delta_sets(&self) -> Result<Index2<'a>, ReadError> {
695 let data = self.offset_data();
696 self.delta_sets_offset().resolve(data)
697 }
698
699 pub fn format_byte_range(&self) -> Range<usize> {
700 let start = 0;
701 let end = start + u8::RAW_BYTE_LEN;
702 start..end
703 }
704
705 pub fn region_index_count_byte_range(&self) -> Range<usize> {
706 let start = self.format_byte_range().end;
707 let end = start + u16::RAW_BYTE_LEN;
708 start..end
709 }
710
711 pub fn region_indices_byte_range(&self) -> Range<usize> {
712 let region_index_count = self.region_index_count();
713 let start = self.region_index_count_byte_range().end;
714 let end =
715 start + (transforms::to_usize(region_index_count)).saturating_mul(u16::RAW_BYTE_LEN);
716 start..end
717 }
718
719 pub fn delta_sets_offset_byte_range(&self) -> Range<usize> {
720 let start = self.region_indices_byte_range().end;
721 let end = start + Offset32::RAW_BYTE_LEN;
722 start..end
723 }
724}
725
726const _: () = assert!(FontData::default_data_long_enough(
727 MultiItemVariationData::MIN_SIZE
728));
729
730impl Default for MultiItemVariationData<'_> {
731 fn default() -> Self {
732 Self {
733 data: TableDataRef::new(FontData::default_format_1_u8_table_data().as_bytes())
734 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
735 }
736 }
737}
738
739impl<'a> MinByteRange<'a> for ConditionList<'a> {
740 fn min_byte_range(&self) -> Range<usize> {
741 0..self.condition_offsets_byte_range().end
742 }
743 fn min_table_bytes(&self) -> &'a [u8] {
744 let range = self.min_byte_range();
745 self.offset_data().as_bytes().get(range).unwrap_or_default()
746 }
747}
748
749impl ReadArgs for ConditionList<'_> {
750 type Args = ();
751}
752
753impl<'a> FontRead<'a> for ConditionList<'a> {
754 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
755 #[allow(clippy::absurd_extreme_comparisons)]
756 if data.len() < Self::MIN_SIZE {
757 return Err(ReadError::OutOfBounds);
758 }
759 let Some(data) = TableDataRef::new(data.as_bytes()) else {
760 return Err(ReadError::OutOfBounds);
761 };
762 Ok(Self { data })
763 }
764}
765
766#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
768#[repr(C, packed)]
769#[doc(hidden)]
770pub struct ConditionListFixedHeader {
771 pub condition_count: BigEndian<u32>,
772}
773
774#[allow(clippy::absurd_extreme_comparisons)]
775const _: () = assert!(std::mem::size_of::<ConditionListFixedHeader>() <= ConditionList::MIN_SIZE);
776
777#[derive(Clone)]
778pub struct ConditionList<'a> {
779 data: TableDataRef<'a, ConditionListFixedHeader>,
780}
781
782#[allow(clippy::needless_lifetimes)]
783impl<'a> ConditionList<'a> {
784 pub const MIN_SIZE: usize = u32::RAW_BYTE_LEN;
785 basic_table_impls!(impl_the_methods);
786
787 pub fn condition_count(&self) -> u32 {
788 self.data.header().condition_count.get()
789 }
790
791 pub fn condition_offsets(&self) -> &'a [BigEndian<Offset32>] {
792 let range = self.condition_offsets_byte_range();
793 self.offset_data()
794 .read_array(range)
795 .ok()
796 .unwrap_or_default()
797 }
798
799 pub fn conditions(&self) -> ArrayOfOffsets<'a, Condition<'a>, Offset32> {
801 let data = self.offset_data();
802 let offsets = self.condition_offsets();
803 ArrayOfOffsets::new(offsets, data, ())
804 }
805
806 pub fn condition_count_byte_range(&self) -> Range<usize> {
807 let start = 0;
808 let end = start + u32::RAW_BYTE_LEN;
809 start..end
810 }
811
812 pub fn condition_offsets_byte_range(&self) -> Range<usize> {
813 let condition_count = self.condition_count();
814 let start = self.condition_count_byte_range().end;
815 let end =
816 start + (transforms::to_usize(condition_count)).saturating_mul(Offset32::RAW_BYTE_LEN);
817 start..end
818 }
819}
820
821const _: () = assert!(FontData::default_data_long_enough(ConditionList::MIN_SIZE));
822
823impl Default for ConditionList<'_> {
824 fn default() -> Self {
825 Self {
826 data: TableDataRef::new(FontData::default_table_data().as_bytes())
827 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
828 }
829 }
830}
831
832#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
836#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
837#[repr(transparent)]
838pub struct VarcFlags {
839 bits: u32,
840}
841
842impl VarcFlags {
843 pub const RESET_UNSPECIFIED_AXES: Self = Self {
844 bits: 0b0000_0000_0000_0001,
845 };
846
847 pub const HAVE_AXES: Self = Self {
848 bits: 0b0000_0000_0000_0010,
849 };
850
851 pub const AXIS_VALUES_HAVE_VARIATION: Self = Self {
852 bits: 0b0000_0000_0000_0100,
853 };
854
855 pub const TRANSFORM_HAS_VARIATION: Self = Self {
856 bits: 0b0000_0000_0000_1000,
857 };
858
859 pub const HAVE_TRANSLATE_X: Self = Self {
860 bits: 0b0000_0000_0001_0000,
861 };
862
863 pub const HAVE_TRANSLATE_Y: Self = Self {
864 bits: 0b0000_0000_0010_0000,
865 };
866
867 pub const HAVE_ROTATION: Self = Self {
868 bits: 0b0000_0000_0100_0000,
869 };
870
871 pub const HAVE_CONDITION: Self = Self {
872 bits: 0b0000_0000_1000_0000,
873 };
874
875 pub const HAVE_SCALE_X: Self = Self {
876 bits: 0b0000_0001_0000_0000,
877 };
878
879 pub const HAVE_SCALE_Y: Self = Self {
880 bits: 0b0000_0010_0000_0000,
881 };
882
883 pub const HAVE_TCENTER_X: Self = Self {
884 bits: 0b0000_0100_0000_0000,
885 };
886
887 pub const HAVE_TCENTER_Y: Self = Self {
888 bits: 0b0000_1000_0000_0000,
889 };
890
891 pub const GID_IS_24BIT: Self = Self {
892 bits: 0b0001_0000_0000_0000,
893 };
894
895 pub const HAVE_SKEW_X: Self = Self {
896 bits: 0b0010_0000_0000_0000,
897 };
898
899 pub const HAVE_SKEW_Y: Self = Self {
900 bits: 0b0100_0000_0000_0000,
901 };
902
903 pub const RESERVED_MASK: Self = Self { bits: 0xFFFF8000 };
904}
905
906impl VarcFlags {
907 #[inline]
909 pub const fn empty() -> Self {
910 Self { bits: 0 }
911 }
912
913 #[inline]
915 pub const fn all() -> Self {
916 Self {
917 bits: Self::RESET_UNSPECIFIED_AXES.bits
918 | Self::HAVE_AXES.bits
919 | Self::AXIS_VALUES_HAVE_VARIATION.bits
920 | Self::TRANSFORM_HAS_VARIATION.bits
921 | Self::HAVE_TRANSLATE_X.bits
922 | Self::HAVE_TRANSLATE_Y.bits
923 | Self::HAVE_ROTATION.bits
924 | Self::HAVE_CONDITION.bits
925 | Self::HAVE_SCALE_X.bits
926 | Self::HAVE_SCALE_Y.bits
927 | Self::HAVE_TCENTER_X.bits
928 | Self::HAVE_TCENTER_Y.bits
929 | Self::GID_IS_24BIT.bits
930 | Self::HAVE_SKEW_X.bits
931 | Self::HAVE_SKEW_Y.bits
932 | Self::RESERVED_MASK.bits,
933 }
934 }
935
936 #[inline]
938 pub const fn bits(&self) -> u32 {
939 self.bits
940 }
941
942 #[inline]
945 pub const fn from_bits(bits: u32) -> Option<Self> {
946 if (bits & !Self::all().bits()) == 0 {
947 Some(Self { bits })
948 } else {
949 None
950 }
951 }
952
953 #[inline]
956 pub const fn from_bits_truncate(bits: u32) -> Self {
957 Self {
958 bits: bits & Self::all().bits,
959 }
960 }
961
962 #[inline]
964 pub const fn is_empty(&self) -> bool {
965 self.bits() == Self::empty().bits()
966 }
967
968 #[inline]
970 pub const fn intersects(&self, other: Self) -> bool {
971 !(Self {
972 bits: self.bits & other.bits,
973 })
974 .is_empty()
975 }
976
977 #[inline]
979 pub const fn contains(&self, other: Self) -> bool {
980 (self.bits & other.bits) == other.bits
981 }
982
983 #[inline]
985 pub fn insert(&mut self, other: Self) {
986 self.bits |= other.bits;
987 }
988
989 #[inline]
991 pub fn remove(&mut self, other: Self) {
992 self.bits &= !other.bits;
993 }
994
995 #[inline]
997 pub fn toggle(&mut self, other: Self) {
998 self.bits ^= other.bits;
999 }
1000
1001 #[inline]
1012 #[must_use]
1013 pub const fn intersection(self, other: Self) -> Self {
1014 Self {
1015 bits: self.bits & other.bits,
1016 }
1017 }
1018
1019 #[inline]
1030 #[must_use]
1031 pub const fn union(self, other: Self) -> Self {
1032 Self {
1033 bits: self.bits | other.bits,
1034 }
1035 }
1036
1037 #[inline]
1050 #[must_use]
1051 pub const fn difference(self, other: Self) -> Self {
1052 Self {
1053 bits: self.bits & !other.bits,
1054 }
1055 }
1056}
1057
1058impl std::ops::BitOr for VarcFlags {
1059 type Output = Self;
1060
1061 #[inline]
1063 fn bitor(self, other: VarcFlags) -> Self {
1064 Self {
1065 bits: self.bits | other.bits,
1066 }
1067 }
1068}
1069
1070impl std::ops::BitOrAssign for VarcFlags {
1071 #[inline]
1073 fn bitor_assign(&mut self, other: Self) {
1074 self.bits |= other.bits;
1075 }
1076}
1077
1078impl std::ops::BitXor for VarcFlags {
1079 type Output = Self;
1080
1081 #[inline]
1083 fn bitxor(self, other: Self) -> Self {
1084 Self {
1085 bits: self.bits ^ other.bits,
1086 }
1087 }
1088}
1089
1090impl std::ops::BitXorAssign for VarcFlags {
1091 #[inline]
1093 fn bitxor_assign(&mut self, other: Self) {
1094 self.bits ^= other.bits;
1095 }
1096}
1097
1098impl std::ops::BitAnd for VarcFlags {
1099 type Output = Self;
1100
1101 #[inline]
1103 fn bitand(self, other: Self) -> Self {
1104 Self {
1105 bits: self.bits & other.bits,
1106 }
1107 }
1108}
1109
1110impl std::ops::BitAndAssign for VarcFlags {
1111 #[inline]
1113 fn bitand_assign(&mut self, other: Self) {
1114 self.bits &= other.bits;
1115 }
1116}
1117
1118impl std::ops::Sub for VarcFlags {
1119 type Output = Self;
1120
1121 #[inline]
1123 fn sub(self, other: Self) -> Self {
1124 Self {
1125 bits: self.bits & !other.bits,
1126 }
1127 }
1128}
1129
1130impl std::ops::SubAssign for VarcFlags {
1131 #[inline]
1133 fn sub_assign(&mut self, other: Self) {
1134 self.bits &= !other.bits;
1135 }
1136}
1137
1138impl std::ops::Not for VarcFlags {
1139 type Output = Self;
1140
1141 #[inline]
1143 fn not(self) -> Self {
1144 Self { bits: !self.bits } & Self::all()
1145 }
1146}
1147
1148impl std::fmt::Debug for VarcFlags {
1149 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1150 let members: &[(&str, Self)] = &[
1151 ("RESET_UNSPECIFIED_AXES", Self::RESET_UNSPECIFIED_AXES),
1152 ("HAVE_AXES", Self::HAVE_AXES),
1153 (
1154 "AXIS_VALUES_HAVE_VARIATION",
1155 Self::AXIS_VALUES_HAVE_VARIATION,
1156 ),
1157 ("TRANSFORM_HAS_VARIATION", Self::TRANSFORM_HAS_VARIATION),
1158 ("HAVE_TRANSLATE_X", Self::HAVE_TRANSLATE_X),
1159 ("HAVE_TRANSLATE_Y", Self::HAVE_TRANSLATE_Y),
1160 ("HAVE_ROTATION", Self::HAVE_ROTATION),
1161 ("HAVE_CONDITION", Self::HAVE_CONDITION),
1162 ("HAVE_SCALE_X", Self::HAVE_SCALE_X),
1163 ("HAVE_SCALE_Y", Self::HAVE_SCALE_Y),
1164 ("HAVE_TCENTER_X", Self::HAVE_TCENTER_X),
1165 ("HAVE_TCENTER_Y", Self::HAVE_TCENTER_Y),
1166 ("GID_IS_24BIT", Self::GID_IS_24BIT),
1167 ("HAVE_SKEW_X", Self::HAVE_SKEW_X),
1168 ("HAVE_SKEW_Y", Self::HAVE_SKEW_Y),
1169 ("RESERVED_MASK", Self::RESERVED_MASK),
1170 ];
1171 let mut first = true;
1172 for (name, value) in members {
1173 if self.contains(*value) {
1174 if !first {
1175 f.write_str(" | ")?;
1176 }
1177 first = false;
1178 f.write_str(name)?;
1179 }
1180 }
1181 if first {
1182 f.write_str("(empty)")?;
1183 }
1184 Ok(())
1185 }
1186}
1187
1188impl std::fmt::Binary for VarcFlags {
1189 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1190 std::fmt::Binary::fmt(&self.bits, f)
1191 }
1192}
1193
1194impl std::fmt::Octal for VarcFlags {
1195 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1196 std::fmt::Octal::fmt(&self.bits, f)
1197 }
1198}
1199
1200impl std::fmt::LowerHex for VarcFlags {
1201 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1202 std::fmt::LowerHex::fmt(&self.bits, f)
1203 }
1204}
1205
1206impl std::fmt::UpperHex for VarcFlags {
1207 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1208 std::fmt::UpperHex::fmt(&self.bits, f)
1209 }
1210}
1211
1212impl font_types::Scalar for VarcFlags {
1213 type Raw = <u32 as font_types::Scalar>::Raw;
1214 fn to_raw(self) -> Self::Raw {
1215 self.bits().to_raw()
1216 }
1217 fn from_raw(raw: Self::Raw) -> Self {
1218 let t = <u32>::from_raw(raw);
1219 Self::from_bits_truncate(t)
1220 }
1221}