1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for ScriptList<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self.script_records_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 ReadArgs for ScriptList<'_> {
19 type Args = ();
20}
21
22impl<'a> FontRead<'a> for ScriptList<'a> {
23 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
24 #[allow(clippy::absurd_extreme_comparisons)]
25 if data.len() < Self::MIN_SIZE {
26 return Err(ReadError::OutOfBounds);
27 }
28 let Some(data) = TableDataRef::new(data.as_bytes()) else {
29 return Err(ReadError::OutOfBounds);
30 };
31 Ok(Self { data })
32 }
33}
34
35#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
37#[repr(C, packed)]
38#[doc(hidden)]
39pub struct ScriptListFixedHeader {
40 pub script_count: BigEndian<u16>,
41}
42
43#[allow(clippy::absurd_extreme_comparisons)]
44const _: () = assert!(std::mem::size_of::<ScriptListFixedHeader>() <= ScriptList::MIN_SIZE);
45
46#[derive(Clone)]
48pub struct ScriptList<'a> {
49 data: TableDataRef<'a, ScriptListFixedHeader>,
50}
51
52#[allow(clippy::needless_lifetimes)]
53impl<'a> ScriptList<'a> {
54 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
55 basic_table_impls!(impl_the_methods);
56
57 pub fn script_count(&self) -> u16 {
59 self.data.header().script_count.get()
60 }
61
62 pub fn script_records(&self) -> &'a [ScriptRecord] {
64 let range = self.script_records_byte_range();
65 self.offset_data()
66 .read_array(range)
67 .ok()
68 .unwrap_or_default()
69 }
70
71 pub fn script_count_byte_range(&self) -> Range<usize> {
72 let start = 0usize;
73 let end = start.saturating_add(u16::RAW_BYTE_LEN);
74 start..end
75 }
76
77 pub fn script_records_byte_range(&self) -> Range<usize> {
78 let script_count = self.script_count();
79 let start = self.script_count_byte_range().end;
80 let end = start.saturating_add(
81 (transforms::to_usize(script_count)).saturating_mul(ScriptRecord::RAW_BYTE_LEN),
82 );
83 start..end
84 }
85}
86
87const _: () = assert!(FontData::default_data_long_enough(ScriptList::MIN_SIZE));
88
89impl Default for ScriptList<'_> {
90 fn default() -> Self {
91 Self {
92 data: TableDataRef::new(FontData::default_table_data().as_bytes())
93 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
94 }
95 }
96}
97
98#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
100#[repr(C)]
101#[repr(packed)]
102pub struct ScriptRecord {
103 pub script_tag: BigEndian<Tag>,
105 pub script_offset: BigEndian<Offset16>,
107}
108
109impl ScriptRecord {
110 pub fn script_tag(&self) -> Tag {
112 self.script_tag.get()
113 }
114
115 pub fn script_offset(&self) -> Offset16 {
117 self.script_offset.get()
118 }
119
120 pub fn script<'a>(&self, data: FontData<'a>) -> Result<Script<'a>, ReadError> {
125 self.script_offset().resolve(data)
126 }
127}
128
129impl FixedSize for ScriptRecord {
130 const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN;
131}
132
133impl<'a> MinByteRange<'a> for Script<'a> {
134 fn min_byte_range(&self) -> Range<usize> {
135 0..self.lang_sys_records_byte_range().end
136 }
137 fn min_table_bytes(&self) -> &'a [u8] {
138 let range = self.min_byte_range();
139 self.offset_data().as_bytes().get(range).unwrap_or_default()
140 }
141}
142
143impl ReadArgs for Script<'_> {
144 type Args = ();
145}
146
147impl<'a> FontRead<'a> for Script<'a> {
148 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
149 #[allow(clippy::absurd_extreme_comparisons)]
150 if data.len() < Self::MIN_SIZE {
151 return Err(ReadError::OutOfBounds);
152 }
153 let Some(data) = TableDataRef::new(data.as_bytes()) else {
154 return Err(ReadError::OutOfBounds);
155 };
156 Ok(Self { data })
157 }
158}
159
160#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
162#[repr(C, packed)]
163#[doc(hidden)]
164pub struct ScriptFixedHeader {
165 pub default_lang_sys_offset: BigEndian<Nullable<Offset16>>,
166 pub lang_sys_count: BigEndian<u16>,
167}
168
169#[allow(clippy::absurd_extreme_comparisons)]
170const _: () = assert!(std::mem::size_of::<ScriptFixedHeader>() <= Script::MIN_SIZE);
171
172#[derive(Clone)]
174pub struct Script<'a> {
175 data: TableDataRef<'a, ScriptFixedHeader>,
176}
177
178#[allow(clippy::needless_lifetimes)]
179impl<'a> Script<'a> {
180 pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
181 basic_table_impls!(impl_the_methods);
182
183 pub fn default_lang_sys_offset(&self) -> Nullable<Offset16> {
186 self.data.header().default_lang_sys_offset.get()
187 }
188
189 pub fn default_lang_sys(&self) -> Option<Result<LangSys<'a>, ReadError>> {
191 let data = self.offset_data();
192 self.default_lang_sys_offset().resolve(data)
193 }
194
195 pub fn lang_sys_count(&self) -> u16 {
198 self.data.header().lang_sys_count.get()
199 }
200
201 pub fn lang_sys_records(&self) -> &'a [LangSysRecord] {
203 let range = self.lang_sys_records_byte_range();
204 self.offset_data()
205 .read_array(range)
206 .ok()
207 .unwrap_or_default()
208 }
209
210 pub fn default_lang_sys_offset_byte_range(&self) -> Range<usize> {
211 let start = 0usize;
212 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
213 start..end
214 }
215
216 pub fn lang_sys_count_byte_range(&self) -> Range<usize> {
217 let start = self.default_lang_sys_offset_byte_range().end;
218 let end = start.saturating_add(u16::RAW_BYTE_LEN);
219 start..end
220 }
221
222 pub fn lang_sys_records_byte_range(&self) -> Range<usize> {
223 let lang_sys_count = self.lang_sys_count();
224 let start = self.lang_sys_count_byte_range().end;
225 let end = start.saturating_add(
226 (transforms::to_usize(lang_sys_count)).saturating_mul(LangSysRecord::RAW_BYTE_LEN),
227 );
228 start..end
229 }
230}
231
232const _: () = assert!(FontData::default_data_long_enough(Script::MIN_SIZE));
233
234impl Default for Script<'_> {
235 fn default() -> Self {
236 Self {
237 data: TableDataRef::new(FontData::default_table_data().as_bytes())
238 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
239 }
240 }
241}
242
243#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
244#[repr(C)]
245#[repr(packed)]
246pub struct LangSysRecord {
247 pub lang_sys_tag: BigEndian<Tag>,
249 pub lang_sys_offset: BigEndian<Offset16>,
251}
252
253impl LangSysRecord {
254 pub fn lang_sys_tag(&self) -> Tag {
256 self.lang_sys_tag.get()
257 }
258
259 pub fn lang_sys_offset(&self) -> Offset16 {
261 self.lang_sys_offset.get()
262 }
263
264 pub fn lang_sys<'a>(&self, data: FontData<'a>) -> Result<LangSys<'a>, ReadError> {
269 self.lang_sys_offset().resolve(data)
270 }
271}
272
273impl FixedSize for LangSysRecord {
274 const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN;
275}
276
277impl<'a> MinByteRange<'a> for LangSys<'a> {
278 fn min_byte_range(&self) -> Range<usize> {
279 0..self.feature_indices_byte_range().end
280 }
281 fn min_table_bytes(&self) -> &'a [u8] {
282 let range = self.min_byte_range();
283 self.offset_data().as_bytes().get(range).unwrap_or_default()
284 }
285}
286
287impl ReadArgs for LangSys<'_> {
288 type Args = ();
289}
290
291impl<'a> FontRead<'a> for LangSys<'a> {
292 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
293 #[allow(clippy::absurd_extreme_comparisons)]
294 if data.len() < Self::MIN_SIZE {
295 return Err(ReadError::OutOfBounds);
296 }
297 let Some(data) = TableDataRef::new(data.as_bytes()) else {
298 return Err(ReadError::OutOfBounds);
299 };
300 Ok(Self { data })
301 }
302}
303
304#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
306#[repr(C, packed)]
307#[doc(hidden)]
308pub struct LangSysFixedHeader {
309 pub lookup_order_offset: BigEndian<u16>,
310 pub required_feature_index: BigEndian<u16>,
311 pub feature_index_count: BigEndian<u16>,
312}
313
314#[allow(clippy::absurd_extreme_comparisons)]
315const _: () = assert!(std::mem::size_of::<LangSysFixedHeader>() <= LangSys::MIN_SIZE);
316
317#[derive(Clone)]
319pub struct LangSys<'a> {
320 data: TableDataRef<'a, LangSysFixedHeader>,
321}
322
323#[allow(clippy::needless_lifetimes)]
324impl<'a> LangSys<'a> {
325 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
326 basic_table_impls!(impl_the_methods);
327
328 pub fn required_feature_index(&self) -> u16 {
331 self.data.header().required_feature_index.get()
332 }
333
334 pub fn feature_index_count(&self) -> u16 {
337 self.data.header().feature_index_count.get()
338 }
339
340 pub fn feature_indices(&self) -> &'a [BigEndian<u16>] {
342 let range = self.feature_indices_byte_range();
343 self.offset_data()
344 .read_array(range)
345 .ok()
346 .unwrap_or_default()
347 }
348
349 pub fn lookup_order_offset_byte_range(&self) -> Range<usize> {
350 let start = 0usize;
351 let end = start.saturating_add(u16::RAW_BYTE_LEN);
352 start..end
353 }
354
355 pub fn required_feature_index_byte_range(&self) -> Range<usize> {
356 let start = self.lookup_order_offset_byte_range().end;
357 let end = start.saturating_add(u16::RAW_BYTE_LEN);
358 start..end
359 }
360
361 pub fn feature_index_count_byte_range(&self) -> Range<usize> {
362 let start = self.required_feature_index_byte_range().end;
363 let end = start.saturating_add(u16::RAW_BYTE_LEN);
364 start..end
365 }
366
367 pub fn feature_indices_byte_range(&self) -> Range<usize> {
368 let feature_index_count = self.feature_index_count();
369 let start = self.feature_index_count_byte_range().end;
370 let end = start.saturating_add(
371 (transforms::to_usize(feature_index_count)).saturating_mul(u16::RAW_BYTE_LEN),
372 );
373 start..end
374 }
375}
376
377const _: () = assert!(FontData::default_data_long_enough(LangSys::MIN_SIZE));
378
379impl Default for LangSys<'_> {
380 fn default() -> Self {
381 Self {
382 data: TableDataRef::new(FontData::default_table_data().as_bytes())
383 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
384 }
385 }
386}
387
388impl<'a> MinByteRange<'a> for FeatureList<'a> {
389 fn min_byte_range(&self) -> Range<usize> {
390 0..self.feature_records_byte_range().end
391 }
392 fn min_table_bytes(&self) -> &'a [u8] {
393 let range = self.min_byte_range();
394 self.offset_data().as_bytes().get(range).unwrap_or_default()
395 }
396}
397
398impl ReadArgs for FeatureList<'_> {
399 type Args = ();
400}
401
402impl<'a> FontRead<'a> for FeatureList<'a> {
403 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
404 #[allow(clippy::absurd_extreme_comparisons)]
405 if data.len() < Self::MIN_SIZE {
406 return Err(ReadError::OutOfBounds);
407 }
408 let Some(data) = TableDataRef::new(data.as_bytes()) else {
409 return Err(ReadError::OutOfBounds);
410 };
411 Ok(Self { data })
412 }
413}
414
415#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
417#[repr(C, packed)]
418#[doc(hidden)]
419pub struct FeatureListFixedHeader {
420 pub feature_count: BigEndian<u16>,
421}
422
423#[allow(clippy::absurd_extreme_comparisons)]
424const _: () = assert!(std::mem::size_of::<FeatureListFixedHeader>() <= FeatureList::MIN_SIZE);
425
426#[derive(Clone)]
428pub struct FeatureList<'a> {
429 data: TableDataRef<'a, FeatureListFixedHeader>,
430}
431
432#[allow(clippy::needless_lifetimes)]
433impl<'a> FeatureList<'a> {
434 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
435 basic_table_impls!(impl_the_methods);
436
437 pub fn feature_count(&self) -> u16 {
439 self.data.header().feature_count.get()
440 }
441
442 pub fn feature_records(&self) -> &'a [FeatureRecord] {
445 let range = self.feature_records_byte_range();
446 self.offset_data()
447 .read_array(range)
448 .ok()
449 .unwrap_or_default()
450 }
451
452 pub fn feature_count_byte_range(&self) -> Range<usize> {
453 let start = 0usize;
454 let end = start.saturating_add(u16::RAW_BYTE_LEN);
455 start..end
456 }
457
458 pub fn feature_records_byte_range(&self) -> Range<usize> {
459 let feature_count = self.feature_count();
460 let start = self.feature_count_byte_range().end;
461 let end = start.saturating_add(
462 (transforms::to_usize(feature_count)).saturating_mul(FeatureRecord::RAW_BYTE_LEN),
463 );
464 start..end
465 }
466}
467
468const _: () = assert!(FontData::default_data_long_enough(FeatureList::MIN_SIZE));
469
470impl Default for FeatureList<'_> {
471 fn default() -> Self {
472 Self {
473 data: TableDataRef::new(FontData::default_table_data().as_bytes())
474 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
475 }
476 }
477}
478
479#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
481#[repr(C)]
482#[repr(packed)]
483pub struct FeatureRecord {
484 pub feature_tag: BigEndian<Tag>,
486 pub feature_offset: BigEndian<Offset16>,
488}
489
490impl FeatureRecord {
491 pub fn feature_tag(&self) -> Tag {
493 self.feature_tag.get()
494 }
495
496 pub fn feature_offset(&self) -> Offset16 {
498 self.feature_offset.get()
499 }
500
501 pub fn feature<'a>(&self, data: FontData<'a>) -> Result<Feature<'a>, ReadError> {
506 let args = self.feature_tag();
507 self.feature_offset().resolve_with_args(data, args)
508 }
509}
510
511impl FixedSize for FeatureRecord {
512 const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN;
513}
514
515impl<'a> MinByteRange<'a> for Feature<'a> {
516 fn min_byte_range(&self) -> Range<usize> {
517 0..self.lookup_list_indices_byte_range().end
518 }
519 fn min_table_bytes(&self) -> &'a [u8] {
520 let range = self.min_byte_range();
521 self.offset_data().as_bytes().get(range).unwrap_or_default()
522 }
523}
524
525impl ReadArgs for Feature<'_> {
526 type Args = Tag;
527}
528
529impl<'a> FontRead<'a> for Feature<'a> {
530 fn read_with_args(data: FontData<'a>, args: Tag) -> Result<Self, ReadError> {
531 let feature_tag = args;
532
533 #[allow(clippy::absurd_extreme_comparisons)]
534 if data.len() < Self::MIN_SIZE {
535 return Err(ReadError::OutOfBounds);
536 }
537 let Some(data) = TableDataRef::new(data.as_bytes()) else {
538 return Err(ReadError::OutOfBounds);
539 };
540 Ok(Self { data, feature_tag })
541 }
542}
543
544impl<'a> Feature<'a> {
545 pub fn read(data: FontData<'a>, feature_tag: Tag) -> Result<Self, ReadError> {
550 let args = feature_tag;
551 Self::read_with_args(data, args)
552 }
553}
554
555#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
557#[repr(C, packed)]
558#[doc(hidden)]
559pub struct FeatureFixedHeader {
560 pub feature_params_offset: BigEndian<Nullable<Offset16>>,
561 pub lookup_index_count: BigEndian<u16>,
562}
563
564#[allow(clippy::absurd_extreme_comparisons)]
565const _: () = assert!(std::mem::size_of::<FeatureFixedHeader>() <= Feature::MIN_SIZE);
566
567#[derive(Clone)]
569pub struct Feature<'a> {
570 data: TableDataRef<'a, FeatureFixedHeader>,
571 feature_tag: Tag,
572}
573
574#[allow(clippy::needless_lifetimes)]
575impl<'a> Feature<'a> {
576 pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
577 basic_table_impls!(impl_the_methods);
578
579 pub fn feature_params_offset(&self) -> Nullable<Offset16> {
581 self.data.header().feature_params_offset.get()
582 }
583
584 pub fn feature_params(&self) -> Option<Result<FeatureParams<'a>, ReadError>> {
586 let data = self.offset_data();
587 let args = self.feature_tag();
588 self.feature_params_offset().resolve_with_args(data, args)
589 }
590
591 pub fn lookup_index_count(&self) -> u16 {
593 self.data.header().lookup_index_count.get()
594 }
595
596 pub fn lookup_list_indices(&self) -> &'a [BigEndian<u16>] {
599 let range = self.lookup_list_indices_byte_range();
600 self.offset_data()
601 .read_array(range)
602 .ok()
603 .unwrap_or_default()
604 }
605
606 pub(crate) fn feature_tag(&self) -> Tag {
607 self.feature_tag
608 }
609
610 pub fn feature_params_offset_byte_range(&self) -> Range<usize> {
611 let start = 0usize;
612 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
613 start..end
614 }
615
616 pub fn lookup_index_count_byte_range(&self) -> Range<usize> {
617 let start = self.feature_params_offset_byte_range().end;
618 let end = start.saturating_add(u16::RAW_BYTE_LEN);
619 start..end
620 }
621
622 pub fn lookup_list_indices_byte_range(&self) -> Range<usize> {
623 let lookup_index_count = self.lookup_index_count();
624 let start = self.lookup_index_count_byte_range().end;
625 let end = start.saturating_add(
626 (transforms::to_usize(lookup_index_count)).saturating_mul(u16::RAW_BYTE_LEN),
627 );
628 start..end
629 }
630}
631
632const _: () = assert!(FontData::default_data_long_enough(Feature::MIN_SIZE));
633
634impl Default for Feature<'_> {
635 fn default() -> Self {
636 Self {
637 data: TableDataRef::new(FontData::default_table_data().as_bytes())
638 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
639 feature_tag: Default::default(),
640 }
641 }
642}
643
644impl<'a, T> MinByteRange<'a> for LookupList<'a, T> {
645 fn min_byte_range(&self) -> Range<usize> {
646 0..self.lookup_offsets_byte_range().end
647 }
648 fn min_table_bytes(&self) -> &'a [u8] {
649 let range = self.min_byte_range();
650 self.offset_data().as_bytes().get(range).unwrap_or_default()
651 }
652}
653
654impl<T> ReadArgs for LookupList<'_, T> {
655 type Args = ();
656}
657
658impl<'a, T> FontRead<'a> for LookupList<'a, T> {
659 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
660 #[allow(clippy::absurd_extreme_comparisons)]
661 if data.len() < Self::MIN_SIZE {
662 return Err(ReadError::OutOfBounds);
663 }
664 let Some(data) = TableDataRef::new(data.as_bytes()) else {
665 return Err(ReadError::OutOfBounds);
666 };
667 Ok(Self {
668 data,
669 offset_type: std::marker::PhantomData,
670 })
671 }
672}
673
674impl<'a, T> LookupList<'a, T> {
675 #[allow(dead_code)]
676 pub(crate) fn of_unit_type(&self) -> LookupList<'a, ()> {
678 LookupList {
679 data: self.data,
680 offset_type: std::marker::PhantomData,
681 }
682 }
683}
684
685#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
687#[repr(C, packed)]
688#[doc(hidden)]
689pub struct LookupListFixedHeader {
690 pub lookup_count: BigEndian<u16>,
691}
692
693#[allow(clippy::absurd_extreme_comparisons)]
694const _: () = assert!(std::mem::size_of::<LookupListFixedHeader>() <= LookupList::<()>::MIN_SIZE);
695
696#[derive(Clone)]
698pub struct LookupList<'a, T = ()> {
699 data: TableDataRef<'a, LookupListFixedHeader>,
700 offset_type: std::marker::PhantomData<*const T>,
701}
702
703#[allow(clippy::needless_lifetimes)]
704impl<'a, T> LookupList<'a, T> {
705 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
706 basic_table_impls!(impl_the_methods);
707
708 pub fn lookup_count(&self) -> u16 {
710 self.data.header().lookup_count.get()
711 }
712
713 pub fn lookup_offsets(&self) -> &'a [BigEndian<Offset16>] {
716 let range = self.lookup_offsets_byte_range();
717 self.offset_data()
718 .read_array(range)
719 .ok()
720 .unwrap_or_default()
721 }
722
723 pub fn lookups(&self) -> ArrayOfOffsets<'a, T, Offset16>
725 where
726 T: FontRead<'a, Args = ()>,
727 {
728 let data = self.offset_data();
729 let offsets = self.lookup_offsets();
730 ArrayOfOffsets::new(offsets, data, ())
731 }
732
733 pub fn lookup_count_byte_range(&self) -> Range<usize> {
734 let start = 0usize;
735 let end = start.saturating_add(u16::RAW_BYTE_LEN);
736 start..end
737 }
738
739 pub fn lookup_offsets_byte_range(&self) -> Range<usize> {
740 let lookup_count = self.lookup_count();
741 let start = self.lookup_count_byte_range().end;
742 let end = start.saturating_add(
743 (transforms::to_usize(lookup_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
744 );
745 start..end
746 }
747}
748
749const _: () = assert!(FontData::default_data_long_enough(
750 LookupList::<()>::MIN_SIZE
751));
752
753impl<T> Default for LookupList<'_, T> {
754 fn default() -> Self {
755 Self {
756 data: TableDataRef::new(FontData::default_table_data().as_bytes())
757 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
758 offset_type: std::marker::PhantomData,
759 }
760 }
761}
762
763impl Discriminant for Lookup<'_, ()> {
764 fn read_discriminant(data: FontData<'_>) -> Result<u16, ReadError> {
765 data.read_at(0)
766 }
767}
768
769impl<'a, T> MinByteRange<'a> for Lookup<'a, T> {
770 fn min_byte_range(&self) -> Range<usize> {
771 0..self.subtable_offsets_byte_range().end
772 }
773 fn min_table_bytes(&self) -> &'a [u8] {
774 let range = self.min_byte_range();
775 self.offset_data().as_bytes().get(range).unwrap_or_default()
776 }
777}
778
779impl<T> ReadArgs for Lookup<'_, T> {
780 type Args = ();
781}
782
783impl<'a, T> FontRead<'a> for Lookup<'a, T> {
784 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
785 #[allow(clippy::absurd_extreme_comparisons)]
786 if data.len() < Self::MIN_SIZE {
787 return Err(ReadError::OutOfBounds);
788 }
789 let Some(data) = TableDataRef::new(data.as_bytes()) else {
790 return Err(ReadError::OutOfBounds);
791 };
792 Ok(Self {
793 data,
794 offset_type: std::marker::PhantomData,
795 })
796 }
797}
798
799impl<'a, T> Lookup<'a, T> {
800 #[allow(dead_code)]
801 pub(crate) fn of_unit_type(&self) -> Lookup<'a, ()> {
803 Lookup {
804 data: self.data,
805 offset_type: std::marker::PhantomData,
806 }
807 }
808}
809
810#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
812#[repr(C, packed)]
813#[doc(hidden)]
814pub struct LookupFixedHeader {
815 pub lookup_type: BigEndian<u16>,
816 pub lookup_flag: BigEndian<LookupFlag>,
817 pub sub_table_count: BigEndian<u16>,
818}
819
820#[allow(clippy::absurd_extreme_comparisons)]
821const _: () = assert!(std::mem::size_of::<LookupFixedHeader>() <= Lookup::<()>::MIN_SIZE);
822
823#[derive(Clone)]
825pub struct Lookup<'a, T = ()> {
826 data: TableDataRef<'a, LookupFixedHeader>,
827 offset_type: std::marker::PhantomData<*const T>,
828}
829
830#[allow(clippy::needless_lifetimes)]
831impl<'a, T> Lookup<'a, T> {
832 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + LookupFlag::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
833 basic_table_impls!(impl_the_methods);
834
835 pub fn lookup_type(&self) -> u16 {
837 self.data.header().lookup_type.get()
838 }
839
840 pub fn lookup_flag(&self) -> LookupFlag {
842 self.data.header().lookup_flag.get()
843 }
844
845 pub fn sub_table_count(&self) -> u16 {
847 self.data.header().sub_table_count.get()
848 }
849
850 pub fn subtable_offsets(&self) -> &'a [BigEndian<Offset16>] {
853 let range = self.subtable_offsets_byte_range();
854 self.offset_data()
855 .read_array(range)
856 .ok()
857 .unwrap_or_default()
858 }
859
860 pub fn subtables(&self) -> ArrayOfOffsets<'a, T, Offset16>
862 where
863 T: FontRead<'a, Args = ()>,
864 {
865 let data = self.offset_data();
866 let offsets = self.subtable_offsets();
867 ArrayOfOffsets::new(offsets, data, ())
868 }
869
870 pub fn mark_filtering_set(&self) -> Option<u16> {
874 let range = self.mark_filtering_set_byte_range();
875 (!range.is_empty())
876 .then(|| self.offset_data().read_at(range.start).ok())
877 .flatten()
878 }
879
880 pub fn lookup_type_byte_range(&self) -> Range<usize> {
881 let start = 0usize;
882 let end = start.saturating_add(u16::RAW_BYTE_LEN);
883 start..end
884 }
885
886 pub fn lookup_flag_byte_range(&self) -> Range<usize> {
887 let start = self.lookup_type_byte_range().end;
888 let end = start.saturating_add(LookupFlag::RAW_BYTE_LEN);
889 start..end
890 }
891
892 pub fn sub_table_count_byte_range(&self) -> Range<usize> {
893 let start = self.lookup_flag_byte_range().end;
894 let end = start.saturating_add(u16::RAW_BYTE_LEN);
895 start..end
896 }
897
898 pub fn subtable_offsets_byte_range(&self) -> Range<usize> {
899 let sub_table_count = self.sub_table_count();
900 let start = self.sub_table_count_byte_range().end;
901 let end = start.saturating_add(
902 (transforms::to_usize(sub_table_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
903 );
904 start..end
905 }
906
907 pub fn mark_filtering_set_byte_range(&self) -> Range<usize> {
908 let start = self.subtable_offsets_byte_range().end;
909 let end = if self
910 .lookup_flag()
911 .contains(LookupFlag::USE_MARK_FILTERING_SET)
912 {
913 start.saturating_add(u16::RAW_BYTE_LEN)
914 } else {
915 start
916 };
917 start..end
918 }
919}
920
921const _: () = assert!(FontData::default_data_long_enough(Lookup::<()>::MIN_SIZE));
922
923impl<T> Default for Lookup<'_, T> {
924 fn default() -> Self {
925 Self {
926 data: TableDataRef::new(FontData::default_table_data().as_bytes())
927 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
928 offset_type: std::marker::PhantomData,
929 }
930 }
931}
932
933impl Format<u16> for CoverageFormat1<'_> {
934 const FORMAT: u16 = 1;
935}
936
937impl<'a> MinByteRange<'a> for CoverageFormat1<'a> {
938 fn min_byte_range(&self) -> Range<usize> {
939 0..self.glyph_array_byte_range().end
940 }
941 fn min_table_bytes(&self) -> &'a [u8] {
942 let range = self.min_byte_range();
943 self.offset_data().as_bytes().get(range).unwrap_or_default()
944 }
945}
946
947impl ReadArgs for CoverageFormat1<'_> {
948 type Args = ();
949}
950
951impl<'a> FontRead<'a> for CoverageFormat1<'a> {
952 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
953 #[allow(clippy::absurd_extreme_comparisons)]
954 if data.len() < Self::MIN_SIZE {
955 return Err(ReadError::OutOfBounds);
956 }
957 let Some(data) = TableDataRef::new(data.as_bytes()) else {
958 return Err(ReadError::OutOfBounds);
959 };
960 Ok(Self { data })
961 }
962}
963
964#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
966#[repr(C, packed)]
967#[doc(hidden)]
968pub struct CoverageFormat1FixedHeader {
969 pub coverage_format: BigEndian<u16>,
970 pub glyph_count: BigEndian<u16>,
971}
972
973#[allow(clippy::absurd_extreme_comparisons)]
974const _: () =
975 assert!(std::mem::size_of::<CoverageFormat1FixedHeader>() <= CoverageFormat1::MIN_SIZE);
976
977#[derive(Clone)]
979pub struct CoverageFormat1<'a> {
980 data: TableDataRef<'a, CoverageFormat1FixedHeader>,
981}
982
983#[allow(clippy::needless_lifetimes)]
984impl<'a> CoverageFormat1<'a> {
985 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
986 basic_table_impls!(impl_the_methods);
987
988 pub fn coverage_format(&self) -> u16 {
990 self.data.header().coverage_format.get()
991 }
992
993 pub fn glyph_count(&self) -> u16 {
995 self.data.header().glyph_count.get()
996 }
997
998 pub fn glyph_array(&self) -> &'a [BigEndian<GlyphId16>] {
1000 let range = self.glyph_array_byte_range();
1001 self.offset_data()
1002 .read_array(range)
1003 .ok()
1004 .unwrap_or_default()
1005 }
1006
1007 pub fn coverage_format_byte_range(&self) -> Range<usize> {
1008 let start = 0usize;
1009 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1010 start..end
1011 }
1012
1013 pub fn glyph_count_byte_range(&self) -> Range<usize> {
1014 let start = self.coverage_format_byte_range().end;
1015 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1016 start..end
1017 }
1018
1019 pub fn glyph_array_byte_range(&self) -> Range<usize> {
1020 let glyph_count = self.glyph_count();
1021 let start = self.glyph_count_byte_range().end;
1022 let end = start.saturating_add(
1023 (transforms::to_usize(glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN),
1024 );
1025 start..end
1026 }
1027}
1028
1029const _: () = assert!(FontData::default_data_long_enough(
1030 CoverageFormat1::MIN_SIZE
1031));
1032
1033impl Default for CoverageFormat1<'_> {
1034 fn default() -> Self {
1035 Self {
1036 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
1037 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1038 }
1039 }
1040}
1041
1042impl Format<u16> for CoverageFormat2<'_> {
1043 const FORMAT: u16 = 2;
1044}
1045
1046impl<'a> MinByteRange<'a> for CoverageFormat2<'a> {
1047 fn min_byte_range(&self) -> Range<usize> {
1048 0..self.range_records_byte_range().end
1049 }
1050 fn min_table_bytes(&self) -> &'a [u8] {
1051 let range = self.min_byte_range();
1052 self.offset_data().as_bytes().get(range).unwrap_or_default()
1053 }
1054}
1055
1056impl ReadArgs for CoverageFormat2<'_> {
1057 type Args = ();
1058}
1059
1060impl<'a> FontRead<'a> for CoverageFormat2<'a> {
1061 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1062 #[allow(clippy::absurd_extreme_comparisons)]
1063 if data.len() < Self::MIN_SIZE {
1064 return Err(ReadError::OutOfBounds);
1065 }
1066 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1067 return Err(ReadError::OutOfBounds);
1068 };
1069 Ok(Self { data })
1070 }
1071}
1072
1073#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1075#[repr(C, packed)]
1076#[doc(hidden)]
1077pub struct CoverageFormat2FixedHeader {
1078 pub coverage_format: BigEndian<u16>,
1079 pub range_count: BigEndian<u16>,
1080}
1081
1082#[allow(clippy::absurd_extreme_comparisons)]
1083const _: () =
1084 assert!(std::mem::size_of::<CoverageFormat2FixedHeader>() <= CoverageFormat2::MIN_SIZE);
1085
1086#[derive(Clone)]
1088pub struct CoverageFormat2<'a> {
1089 data: TableDataRef<'a, CoverageFormat2FixedHeader>,
1090}
1091
1092#[allow(clippy::needless_lifetimes)]
1093impl<'a> CoverageFormat2<'a> {
1094 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1095 basic_table_impls!(impl_the_methods);
1096
1097 pub fn coverage_format(&self) -> u16 {
1099 self.data.header().coverage_format.get()
1100 }
1101
1102 pub fn range_count(&self) -> u16 {
1104 self.data.header().range_count.get()
1105 }
1106
1107 pub fn range_records(&self) -> &'a [RangeRecord] {
1109 let range = self.range_records_byte_range();
1110 self.offset_data()
1111 .read_array(range)
1112 .ok()
1113 .unwrap_or_default()
1114 }
1115
1116 pub fn coverage_format_byte_range(&self) -> Range<usize> {
1117 let start = 0usize;
1118 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1119 start..end
1120 }
1121
1122 pub fn range_count_byte_range(&self) -> Range<usize> {
1123 let start = self.coverage_format_byte_range().end;
1124 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1125 start..end
1126 }
1127
1128 pub fn range_records_byte_range(&self) -> Range<usize> {
1129 let range_count = self.range_count();
1130 let start = self.range_count_byte_range().end;
1131 let end = start.saturating_add(
1132 (transforms::to_usize(range_count)).saturating_mul(RangeRecord::RAW_BYTE_LEN),
1133 );
1134 start..end
1135 }
1136}
1137
1138#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1140#[repr(C)]
1141#[repr(packed)]
1142pub struct RangeRecord {
1143 pub start_glyph_id: BigEndian<GlyphId16>,
1145 pub end_glyph_id: BigEndian<GlyphId16>,
1147 pub start_coverage_index: BigEndian<u16>,
1149}
1150
1151impl RangeRecord {
1152 pub fn start_glyph_id(&self) -> GlyphId16 {
1154 self.start_glyph_id.get()
1155 }
1156
1157 pub fn end_glyph_id(&self) -> GlyphId16 {
1159 self.end_glyph_id.get()
1160 }
1161
1162 pub fn start_coverage_index(&self) -> u16 {
1164 self.start_coverage_index.get()
1165 }
1166}
1167
1168impl FixedSize for RangeRecord {
1169 const RAW_BYTE_LEN: usize =
1170 GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
1171}
1172
1173#[derive(Clone)]
1175pub enum CoverageTable<'a> {
1176 Format1(CoverageFormat1<'a>),
1177 Format2(CoverageFormat2<'a>),
1178 Format3(CoverageFormat3<'a>),
1179 Format4(CoverageFormat4<'a>),
1180}
1181
1182impl Default for CoverageTable<'_> {
1183 fn default() -> Self {
1184 Self::Format1(Default::default())
1185 }
1186}
1187
1188impl<'a> CoverageTable<'a> {
1189 pub fn offset_data(&self) -> FontData<'a> {
1191 match self {
1192 Self::Format1(item) => item.offset_data(),
1193 Self::Format2(item) => item.offset_data(),
1194 Self::Format3(item) => item.offset_data(),
1195 Self::Format4(item) => item.offset_data(),
1196 }
1197 }
1198
1199 pub fn coverage_format(&self) -> u16 {
1201 match self {
1202 Self::Format1(item) => item.coverage_format(),
1203 Self::Format2(item) => item.coverage_format(),
1204 Self::Format3(item) => item.coverage_format(),
1205 Self::Format4(item) => item.coverage_format(),
1206 }
1207 }
1208}
1209
1210impl ReadArgs for CoverageTable<'_> {
1211 type Args = ();
1212}
1213
1214impl<'a> FontRead<'a> for CoverageTable<'a> {
1215 #[inline]
1216 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1217 let format: u16 = data.read_at(0usize)?;
1218 match format {
1219 CoverageFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
1220 CoverageFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
1221 CoverageFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
1222 CoverageFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
1223 other => Err(ReadError::InvalidFormat(other.into())),
1224 }
1225 }
1226}
1227
1228impl<'a> MinByteRange<'a> for CoverageTable<'a> {
1229 fn min_byte_range(&self) -> Range<usize> {
1230 match self {
1231 Self::Format1(item) => item.min_byte_range(),
1232 Self::Format2(item) => item.min_byte_range(),
1233 Self::Format3(item) => item.min_byte_range(),
1234 Self::Format4(item) => item.min_byte_range(),
1235 }
1236 }
1237 fn min_table_bytes(&self) -> &'a [u8] {
1238 match self {
1239 Self::Format1(item) => item.min_table_bytes(),
1240 Self::Format2(item) => item.min_table_bytes(),
1241 Self::Format3(item) => item.min_table_bytes(),
1242 Self::Format4(item) => item.min_table_bytes(),
1243 }
1244 }
1245}
1246
1247impl Format<u16> for ClassDefFormat1<'_> {
1248 const FORMAT: u16 = 1;
1249}
1250
1251impl<'a> MinByteRange<'a> for ClassDefFormat1<'a> {
1252 fn min_byte_range(&self) -> Range<usize> {
1253 0..self.class_value_array_byte_range().end
1254 }
1255 fn min_table_bytes(&self) -> &'a [u8] {
1256 let range = self.min_byte_range();
1257 self.offset_data().as_bytes().get(range).unwrap_or_default()
1258 }
1259}
1260
1261impl ReadArgs for ClassDefFormat1<'_> {
1262 type Args = ();
1263}
1264
1265impl<'a> FontRead<'a> for ClassDefFormat1<'a> {
1266 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1267 #[allow(clippy::absurd_extreme_comparisons)]
1268 if data.len() < Self::MIN_SIZE {
1269 return Err(ReadError::OutOfBounds);
1270 }
1271 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1272 return Err(ReadError::OutOfBounds);
1273 };
1274 Ok(Self { data })
1275 }
1276}
1277
1278#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1280#[repr(C, packed)]
1281#[doc(hidden)]
1282pub struct ClassDefFormat1FixedHeader {
1283 pub class_format: BigEndian<u16>,
1284 pub start_glyph_id: BigEndian<GlyphId16>,
1285 pub glyph_count: BigEndian<u16>,
1286}
1287
1288#[allow(clippy::absurd_extreme_comparisons)]
1289const _: () =
1290 assert!(std::mem::size_of::<ClassDefFormat1FixedHeader>() <= ClassDefFormat1::MIN_SIZE);
1291
1292#[derive(Clone)]
1294pub struct ClassDefFormat1<'a> {
1295 data: TableDataRef<'a, ClassDefFormat1FixedHeader>,
1296}
1297
1298#[allow(clippy::needless_lifetimes)]
1299impl<'a> ClassDefFormat1<'a> {
1300 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1301 basic_table_impls!(impl_the_methods);
1302
1303 pub fn class_format(&self) -> u16 {
1305 self.data.header().class_format.get()
1306 }
1307
1308 pub fn start_glyph_id(&self) -> GlyphId16 {
1310 self.data.header().start_glyph_id.get()
1311 }
1312
1313 pub fn glyph_count(&self) -> u16 {
1315 self.data.header().glyph_count.get()
1316 }
1317
1318 pub fn class_value_array(&self) -> &'a [BigEndian<u16>] {
1320 let range = self.class_value_array_byte_range();
1321 self.offset_data()
1322 .read_array(range)
1323 .ok()
1324 .unwrap_or_default()
1325 }
1326
1327 pub fn class_format_byte_range(&self) -> Range<usize> {
1328 let start = 0usize;
1329 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1330 start..end
1331 }
1332
1333 pub fn start_glyph_id_byte_range(&self) -> Range<usize> {
1334 let start = self.class_format_byte_range().end;
1335 let end = start.saturating_add(GlyphId16::RAW_BYTE_LEN);
1336 start..end
1337 }
1338
1339 pub fn glyph_count_byte_range(&self) -> Range<usize> {
1340 let start = self.start_glyph_id_byte_range().end;
1341 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1342 start..end
1343 }
1344
1345 pub fn class_value_array_byte_range(&self) -> Range<usize> {
1346 let glyph_count = self.glyph_count();
1347 let start = self.glyph_count_byte_range().end;
1348 let end = start
1349 .saturating_add((transforms::to_usize(glyph_count)).saturating_mul(u16::RAW_BYTE_LEN));
1350 start..end
1351 }
1352}
1353
1354const _: () = assert!(FontData::default_data_long_enough(
1355 ClassDefFormat1::MIN_SIZE
1356));
1357
1358impl Default for ClassDefFormat1<'_> {
1359 fn default() -> Self {
1360 Self {
1361 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
1362 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1363 }
1364 }
1365}
1366
1367impl Format<u16> for ClassDefFormat2<'_> {
1368 const FORMAT: u16 = 2;
1369}
1370
1371impl<'a> MinByteRange<'a> for ClassDefFormat2<'a> {
1372 fn min_byte_range(&self) -> Range<usize> {
1373 0..self.class_range_records_byte_range().end
1374 }
1375 fn min_table_bytes(&self) -> &'a [u8] {
1376 let range = self.min_byte_range();
1377 self.offset_data().as_bytes().get(range).unwrap_or_default()
1378 }
1379}
1380
1381impl ReadArgs for ClassDefFormat2<'_> {
1382 type Args = ();
1383}
1384
1385impl<'a> FontRead<'a> for ClassDefFormat2<'a> {
1386 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1387 #[allow(clippy::absurd_extreme_comparisons)]
1388 if data.len() < Self::MIN_SIZE {
1389 return Err(ReadError::OutOfBounds);
1390 }
1391 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1392 return Err(ReadError::OutOfBounds);
1393 };
1394 Ok(Self { data })
1395 }
1396}
1397
1398#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1400#[repr(C, packed)]
1401#[doc(hidden)]
1402pub struct ClassDefFormat2FixedHeader {
1403 pub class_format: BigEndian<u16>,
1404 pub class_range_count: BigEndian<u16>,
1405}
1406
1407#[allow(clippy::absurd_extreme_comparisons)]
1408const _: () =
1409 assert!(std::mem::size_of::<ClassDefFormat2FixedHeader>() <= ClassDefFormat2::MIN_SIZE);
1410
1411#[derive(Clone)]
1413pub struct ClassDefFormat2<'a> {
1414 data: TableDataRef<'a, ClassDefFormat2FixedHeader>,
1415}
1416
1417#[allow(clippy::needless_lifetimes)]
1418impl<'a> ClassDefFormat2<'a> {
1419 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1420 basic_table_impls!(impl_the_methods);
1421
1422 pub fn class_format(&self) -> u16 {
1424 self.data.header().class_format.get()
1425 }
1426
1427 pub fn class_range_count(&self) -> u16 {
1429 self.data.header().class_range_count.get()
1430 }
1431
1432 pub fn class_range_records(&self) -> &'a [ClassRangeRecord] {
1434 let range = self.class_range_records_byte_range();
1435 self.offset_data()
1436 .read_array(range)
1437 .ok()
1438 .unwrap_or_default()
1439 }
1440
1441 pub fn class_format_byte_range(&self) -> Range<usize> {
1442 let start = 0usize;
1443 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1444 start..end
1445 }
1446
1447 pub fn class_range_count_byte_range(&self) -> Range<usize> {
1448 let start = self.class_format_byte_range().end;
1449 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1450 start..end
1451 }
1452
1453 pub fn class_range_records_byte_range(&self) -> Range<usize> {
1454 let class_range_count = self.class_range_count();
1455 let start = self.class_range_count_byte_range().end;
1456 let end = start.saturating_add(
1457 (transforms::to_usize(class_range_count))
1458 .saturating_mul(ClassRangeRecord::RAW_BYTE_LEN),
1459 );
1460 start..end
1461 }
1462}
1463
1464#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1466#[repr(C)]
1467#[repr(packed)]
1468pub struct ClassRangeRecord {
1469 pub start_glyph_id: BigEndian<GlyphId16>,
1471 pub end_glyph_id: BigEndian<GlyphId16>,
1473 pub class: BigEndian<u16>,
1475}
1476
1477impl ClassRangeRecord {
1478 pub fn start_glyph_id(&self) -> GlyphId16 {
1480 self.start_glyph_id.get()
1481 }
1482
1483 pub fn end_glyph_id(&self) -> GlyphId16 {
1485 self.end_glyph_id.get()
1486 }
1487
1488 pub fn class(&self) -> u16 {
1490 self.class.get()
1491 }
1492}
1493
1494impl FixedSize for ClassRangeRecord {
1495 const RAW_BYTE_LEN: usize =
1496 GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
1497}
1498
1499#[derive(Clone)]
1501pub enum ClassDef<'a> {
1502 Format1(ClassDefFormat1<'a>),
1503 Format2(ClassDefFormat2<'a>),
1504 Format3(ClassDefFormat3<'a>),
1505 Format4(ClassDefFormat4<'a>),
1506}
1507
1508impl Default for ClassDef<'_> {
1509 fn default() -> Self {
1510 Self::Format1(Default::default())
1511 }
1512}
1513
1514impl<'a> ClassDef<'a> {
1515 pub fn offset_data(&self) -> FontData<'a> {
1517 match self {
1518 Self::Format1(item) => item.offset_data(),
1519 Self::Format2(item) => item.offset_data(),
1520 Self::Format3(item) => item.offset_data(),
1521 Self::Format4(item) => item.offset_data(),
1522 }
1523 }
1524
1525 pub fn class_format(&self) -> u16 {
1527 match self {
1528 Self::Format1(item) => item.class_format(),
1529 Self::Format2(item) => item.class_format(),
1530 Self::Format3(item) => item.class_format(),
1531 Self::Format4(item) => item.class_format(),
1532 }
1533 }
1534}
1535
1536impl ReadArgs for ClassDef<'_> {
1537 type Args = ();
1538}
1539
1540impl<'a> FontRead<'a> for ClassDef<'a> {
1541 #[inline]
1542 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1543 let format: u16 = data.read_at(0usize)?;
1544 match format {
1545 ClassDefFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
1546 ClassDefFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
1547 ClassDefFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
1548 ClassDefFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
1549 other => Err(ReadError::InvalidFormat(other.into())),
1550 }
1551 }
1552}
1553
1554impl<'a> MinByteRange<'a> for ClassDef<'a> {
1555 fn min_byte_range(&self) -> Range<usize> {
1556 match self {
1557 Self::Format1(item) => item.min_byte_range(),
1558 Self::Format2(item) => item.min_byte_range(),
1559 Self::Format3(item) => item.min_byte_range(),
1560 Self::Format4(item) => item.min_byte_range(),
1561 }
1562 }
1563 fn min_table_bytes(&self) -> &'a [u8] {
1564 match self {
1565 Self::Format1(item) => item.min_table_bytes(),
1566 Self::Format2(item) => item.min_table_bytes(),
1567 Self::Format3(item) => item.min_table_bytes(),
1568 Self::Format4(item) => item.min_table_bytes(),
1569 }
1570 }
1571}
1572
1573#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1575#[repr(C)]
1576#[repr(packed)]
1577pub struct SequenceLookupRecord {
1578 pub sequence_index: BigEndian<u16>,
1580 pub lookup_list_index: BigEndian<u16>,
1582}
1583
1584impl SequenceLookupRecord {
1585 pub fn sequence_index(&self) -> u16 {
1587 self.sequence_index.get()
1588 }
1589
1590 pub fn lookup_list_index(&self) -> u16 {
1592 self.lookup_list_index.get()
1593 }
1594}
1595
1596impl FixedSize for SequenceLookupRecord {
1597 const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
1598}
1599
1600impl Format<u16> for SequenceContextFormat1<'_> {
1601 const FORMAT: u16 = 1;
1602}
1603
1604impl<'a> MinByteRange<'a> for SequenceContextFormat1<'a> {
1605 fn min_byte_range(&self) -> Range<usize> {
1606 0..self.seq_rule_set_offsets_byte_range().end
1607 }
1608 fn min_table_bytes(&self) -> &'a [u8] {
1609 let range = self.min_byte_range();
1610 self.offset_data().as_bytes().get(range).unwrap_or_default()
1611 }
1612}
1613
1614impl ReadArgs for SequenceContextFormat1<'_> {
1615 type Args = ();
1616}
1617
1618impl<'a> FontRead<'a> for SequenceContextFormat1<'a> {
1619 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1620 #[allow(clippy::absurd_extreme_comparisons)]
1621 if data.len() < Self::MIN_SIZE {
1622 return Err(ReadError::OutOfBounds);
1623 }
1624 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1625 return Err(ReadError::OutOfBounds);
1626 };
1627 Ok(Self { data })
1628 }
1629}
1630
1631#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1633#[repr(C, packed)]
1634#[doc(hidden)]
1635pub struct SequenceContextFormat1FixedHeader {
1636 pub format: BigEndian<u16>,
1637 pub coverage_offset: BigEndian<Offset16>,
1638 pub seq_rule_set_count: BigEndian<u16>,
1639}
1640
1641#[allow(clippy::absurd_extreme_comparisons)]
1642const _: () = assert!(
1643 std::mem::size_of::<SequenceContextFormat1FixedHeader>() <= SequenceContextFormat1::MIN_SIZE
1644);
1645
1646#[derive(Clone)]
1648pub struct SequenceContextFormat1<'a> {
1649 data: TableDataRef<'a, SequenceContextFormat1FixedHeader>,
1650}
1651
1652#[allow(clippy::needless_lifetimes)]
1653impl<'a> SequenceContextFormat1<'a> {
1654 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1655 basic_table_impls!(impl_the_methods);
1656
1657 pub fn format(&self) -> u16 {
1659 self.data.header().format.get()
1660 }
1661
1662 pub fn coverage_offset(&self) -> Offset16 {
1665 self.data.header().coverage_offset.get()
1666 }
1667
1668 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1670 let data = self.offset_data();
1671 self.coverage_offset().resolve(data)
1672 }
1673
1674 pub fn seq_rule_set_count(&self) -> u16 {
1676 self.data.header().seq_rule_set_count.get()
1677 }
1678
1679 pub fn seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] {
1682 let range = self.seq_rule_set_offsets_byte_range();
1683 self.offset_data()
1684 .read_array(range)
1685 .ok()
1686 .unwrap_or_default()
1687 }
1688
1689 pub fn seq_rule_sets(&self) -> ArrayOfNullableOffsets<'a, SequenceRuleSet<'a>, Offset16> {
1691 let data = self.offset_data();
1692 let offsets = self.seq_rule_set_offsets();
1693 ArrayOfNullableOffsets::new(offsets, data, ())
1694 }
1695
1696 pub fn format_byte_range(&self) -> Range<usize> {
1697 let start = 0usize;
1698 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1699 start..end
1700 }
1701
1702 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
1703 let start = self.format_byte_range().end;
1704 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1705 start..end
1706 }
1707
1708 pub fn seq_rule_set_count_byte_range(&self) -> Range<usize> {
1709 let start = self.coverage_offset_byte_range().end;
1710 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1711 start..end
1712 }
1713
1714 pub fn seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
1715 let seq_rule_set_count = self.seq_rule_set_count();
1716 let start = self.seq_rule_set_count_byte_range().end;
1717 let end = start.saturating_add(
1718 (transforms::to_usize(seq_rule_set_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
1719 );
1720 start..end
1721 }
1722}
1723
1724const _: () = assert!(FontData::default_data_long_enough(
1725 SequenceContextFormat1::MIN_SIZE
1726));
1727
1728impl Default for SequenceContextFormat1<'_> {
1729 fn default() -> Self {
1730 Self {
1731 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
1732 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1733 }
1734 }
1735}
1736
1737impl<'a> MinByteRange<'a> for SequenceRuleSet<'a> {
1738 fn min_byte_range(&self) -> Range<usize> {
1739 0..self.seq_rule_offsets_byte_range().end
1740 }
1741 fn min_table_bytes(&self) -> &'a [u8] {
1742 let range = self.min_byte_range();
1743 self.offset_data().as_bytes().get(range).unwrap_or_default()
1744 }
1745}
1746
1747impl ReadArgs for SequenceRuleSet<'_> {
1748 type Args = ();
1749}
1750
1751impl<'a> FontRead<'a> for SequenceRuleSet<'a> {
1752 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1753 #[allow(clippy::absurd_extreme_comparisons)]
1754 if data.len() < Self::MIN_SIZE {
1755 return Err(ReadError::OutOfBounds);
1756 }
1757 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1758 return Err(ReadError::OutOfBounds);
1759 };
1760 Ok(Self { data })
1761 }
1762}
1763
1764#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1766#[repr(C, packed)]
1767#[doc(hidden)]
1768pub struct SequenceRuleSetFixedHeader {
1769 pub seq_rule_count: BigEndian<u16>,
1770}
1771
1772#[allow(clippy::absurd_extreme_comparisons)]
1773const _: () =
1774 assert!(std::mem::size_of::<SequenceRuleSetFixedHeader>() <= SequenceRuleSet::MIN_SIZE);
1775
1776#[derive(Clone)]
1778pub struct SequenceRuleSet<'a> {
1779 data: TableDataRef<'a, SequenceRuleSetFixedHeader>,
1780}
1781
1782#[allow(clippy::needless_lifetimes)]
1783impl<'a> SequenceRuleSet<'a> {
1784 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
1785 basic_table_impls!(impl_the_methods);
1786
1787 pub fn seq_rule_count(&self) -> u16 {
1789 self.data.header().seq_rule_count.get()
1790 }
1791
1792 pub fn seq_rule_offsets(&self) -> &'a [BigEndian<Offset16>] {
1795 let range = self.seq_rule_offsets_byte_range();
1796 self.offset_data()
1797 .read_array(range)
1798 .ok()
1799 .unwrap_or_default()
1800 }
1801
1802 pub fn seq_rules(&self) -> ArrayOfOffsets<'a, SequenceRule<'a>, Offset16> {
1804 let data = self.offset_data();
1805 let offsets = self.seq_rule_offsets();
1806 ArrayOfOffsets::new(offsets, data, ())
1807 }
1808
1809 pub fn seq_rule_count_byte_range(&self) -> Range<usize> {
1810 let start = 0usize;
1811 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1812 start..end
1813 }
1814
1815 pub fn seq_rule_offsets_byte_range(&self) -> Range<usize> {
1816 let seq_rule_count = self.seq_rule_count();
1817 let start = self.seq_rule_count_byte_range().end;
1818 let end = start.saturating_add(
1819 (transforms::to_usize(seq_rule_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
1820 );
1821 start..end
1822 }
1823}
1824
1825const _: () = assert!(FontData::default_data_long_enough(
1826 SequenceRuleSet::MIN_SIZE
1827));
1828
1829impl Default for SequenceRuleSet<'_> {
1830 fn default() -> Self {
1831 Self {
1832 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1833 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1834 }
1835 }
1836}
1837
1838impl<'a> MinByteRange<'a> for SequenceRule<'a> {
1839 fn min_byte_range(&self) -> Range<usize> {
1840 0..self.seq_lookup_records_byte_range().end
1841 }
1842 fn min_table_bytes(&self) -> &'a [u8] {
1843 let range = self.min_byte_range();
1844 self.offset_data().as_bytes().get(range).unwrap_or_default()
1845 }
1846}
1847
1848impl ReadArgs for SequenceRule<'_> {
1849 type Args = ();
1850}
1851
1852impl<'a> FontRead<'a> for SequenceRule<'a> {
1853 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1854 #[allow(clippy::absurd_extreme_comparisons)]
1855 if data.len() < Self::MIN_SIZE {
1856 return Err(ReadError::OutOfBounds);
1857 }
1858 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1859 return Err(ReadError::OutOfBounds);
1860 };
1861 Ok(Self { data })
1862 }
1863}
1864
1865#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1867#[repr(C, packed)]
1868#[doc(hidden)]
1869pub struct SequenceRuleFixedHeader {
1870 pub glyph_count: BigEndian<u16>,
1871 pub seq_lookup_count: BigEndian<u16>,
1872}
1873
1874#[allow(clippy::absurd_extreme_comparisons)]
1875const _: () = assert!(std::mem::size_of::<SequenceRuleFixedHeader>() <= SequenceRule::MIN_SIZE);
1876
1877#[derive(Clone)]
1879pub struct SequenceRule<'a> {
1880 data: TableDataRef<'a, SequenceRuleFixedHeader>,
1881}
1882
1883#[allow(clippy::needless_lifetimes)]
1884impl<'a> SequenceRule<'a> {
1885 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1886 basic_table_impls!(impl_the_methods);
1887
1888 pub fn glyph_count(&self) -> u16 {
1890 self.data.header().glyph_count.get()
1891 }
1892
1893 pub fn seq_lookup_count(&self) -> u16 {
1895 self.data.header().seq_lookup_count.get()
1896 }
1897
1898 pub fn input_sequence(&self) -> &'a [BigEndian<GlyphId16>] {
1900 let range = self.input_sequence_byte_range();
1901 self.offset_data()
1902 .read_array(range)
1903 .ok()
1904 .unwrap_or_default()
1905 }
1906
1907 pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
1909 let range = self.seq_lookup_records_byte_range();
1910 self.offset_data()
1911 .read_array(range)
1912 .ok()
1913 .unwrap_or_default()
1914 }
1915
1916 pub fn glyph_count_byte_range(&self) -> Range<usize> {
1917 let start = 0usize;
1918 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1919 start..end
1920 }
1921
1922 pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
1923 let start = self.glyph_count_byte_range().end;
1924 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1925 start..end
1926 }
1927
1928 pub fn input_sequence_byte_range(&self) -> Range<usize> {
1929 let glyph_count = self.glyph_count();
1930 let start = self.seq_lookup_count_byte_range().end;
1931 let end = start.saturating_add(
1932 (transforms::subtract(glyph_count, 1_usize)).saturating_mul(GlyphId16::RAW_BYTE_LEN),
1933 );
1934 start..end
1935 }
1936
1937 pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
1938 let seq_lookup_count = self.seq_lookup_count();
1939 let start = self.input_sequence_byte_range().end;
1940 let end = start.saturating_add(
1941 (transforms::to_usize(seq_lookup_count))
1942 .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
1943 );
1944 start..end
1945 }
1946}
1947
1948const _: () = assert!(FontData::default_data_long_enough(SequenceRule::MIN_SIZE));
1949
1950impl Default for SequenceRule<'_> {
1951 fn default() -> Self {
1952 Self {
1953 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1954 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1955 }
1956 }
1957}
1958
1959impl Format<u16> for SequenceContextFormat2<'_> {
1960 const FORMAT: u16 = 2;
1961}
1962
1963impl<'a> MinByteRange<'a> for SequenceContextFormat2<'a> {
1964 fn min_byte_range(&self) -> Range<usize> {
1965 0..self.class_seq_rule_set_offsets_byte_range().end
1966 }
1967 fn min_table_bytes(&self) -> &'a [u8] {
1968 let range = self.min_byte_range();
1969 self.offset_data().as_bytes().get(range).unwrap_or_default()
1970 }
1971}
1972
1973impl ReadArgs for SequenceContextFormat2<'_> {
1974 type Args = ();
1975}
1976
1977impl<'a> FontRead<'a> for SequenceContextFormat2<'a> {
1978 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1979 #[allow(clippy::absurd_extreme_comparisons)]
1980 if data.len() < Self::MIN_SIZE {
1981 return Err(ReadError::OutOfBounds);
1982 }
1983 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1984 return Err(ReadError::OutOfBounds);
1985 };
1986 Ok(Self { data })
1987 }
1988}
1989
1990#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1992#[repr(C, packed)]
1993#[doc(hidden)]
1994pub struct SequenceContextFormat2FixedHeader {
1995 pub format: BigEndian<u16>,
1996 pub coverage_offset: BigEndian<Offset16>,
1997 pub class_def_offset: BigEndian<Offset16>,
1998 pub class_seq_rule_set_count: BigEndian<u16>,
1999}
2000
2001#[allow(clippy::absurd_extreme_comparisons)]
2002const _: () = assert!(
2003 std::mem::size_of::<SequenceContextFormat2FixedHeader>() <= SequenceContextFormat2::MIN_SIZE
2004);
2005
2006#[derive(Clone)]
2008pub struct SequenceContextFormat2<'a> {
2009 data: TableDataRef<'a, SequenceContextFormat2FixedHeader>,
2010}
2011
2012#[allow(clippy::needless_lifetimes)]
2013impl<'a> SequenceContextFormat2<'a> {
2014 pub const MIN_SIZE: usize =
2015 (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2016 basic_table_impls!(impl_the_methods);
2017
2018 pub fn format(&self) -> u16 {
2020 self.data.header().format.get()
2021 }
2022
2023 pub fn coverage_offset(&self) -> Offset16 {
2026 self.data.header().coverage_offset.get()
2027 }
2028
2029 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
2031 let data = self.offset_data();
2032 self.coverage_offset().resolve(data)
2033 }
2034
2035 pub fn class_def_offset(&self) -> Offset16 {
2038 self.data.header().class_def_offset.get()
2039 }
2040
2041 pub fn class_def(&self) -> Result<ClassDef<'a>, ReadError> {
2043 let data = self.offset_data();
2044 self.class_def_offset().resolve(data)
2045 }
2046
2047 pub fn class_seq_rule_set_count(&self) -> u16 {
2049 self.data.header().class_seq_rule_set_count.get()
2050 }
2051
2052 pub fn class_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] {
2055 let range = self.class_seq_rule_set_offsets_byte_range();
2056 self.offset_data()
2057 .read_array(range)
2058 .ok()
2059 .unwrap_or_default()
2060 }
2061
2062 pub fn class_seq_rule_sets(
2064 &self,
2065 ) -> ArrayOfNullableOffsets<'a, ClassSequenceRuleSet<'a>, Offset16> {
2066 let data = self.offset_data();
2067 let offsets = self.class_seq_rule_set_offsets();
2068 ArrayOfNullableOffsets::new(offsets, data, ())
2069 }
2070
2071 pub fn format_byte_range(&self) -> Range<usize> {
2072 let start = 0usize;
2073 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2074 start..end
2075 }
2076
2077 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
2078 let start = self.format_byte_range().end;
2079 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
2080 start..end
2081 }
2082
2083 pub fn class_def_offset_byte_range(&self) -> Range<usize> {
2084 let start = self.coverage_offset_byte_range().end;
2085 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
2086 start..end
2087 }
2088
2089 pub fn class_seq_rule_set_count_byte_range(&self) -> Range<usize> {
2090 let start = self.class_def_offset_byte_range().end;
2091 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2092 start..end
2093 }
2094
2095 pub fn class_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
2096 let class_seq_rule_set_count = self.class_seq_rule_set_count();
2097 let start = self.class_seq_rule_set_count_byte_range().end;
2098 let end = start.saturating_add(
2099 (transforms::to_usize(class_seq_rule_set_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
2100 );
2101 start..end
2102 }
2103}
2104
2105impl<'a> MinByteRange<'a> for ClassSequenceRuleSet<'a> {
2106 fn min_byte_range(&self) -> Range<usize> {
2107 0..self.class_seq_rule_offsets_byte_range().end
2108 }
2109 fn min_table_bytes(&self) -> &'a [u8] {
2110 let range = self.min_byte_range();
2111 self.offset_data().as_bytes().get(range).unwrap_or_default()
2112 }
2113}
2114
2115impl ReadArgs for ClassSequenceRuleSet<'_> {
2116 type Args = ();
2117}
2118
2119impl<'a> FontRead<'a> for ClassSequenceRuleSet<'a> {
2120 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2121 #[allow(clippy::absurd_extreme_comparisons)]
2122 if data.len() < Self::MIN_SIZE {
2123 return Err(ReadError::OutOfBounds);
2124 }
2125 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2126 return Err(ReadError::OutOfBounds);
2127 };
2128 Ok(Self { data })
2129 }
2130}
2131
2132#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2134#[repr(C, packed)]
2135#[doc(hidden)]
2136pub struct ClassSequenceRuleSetFixedHeader {
2137 pub class_seq_rule_count: BigEndian<u16>,
2138}
2139
2140#[allow(clippy::absurd_extreme_comparisons)]
2141const _: () = assert!(
2142 std::mem::size_of::<ClassSequenceRuleSetFixedHeader>() <= ClassSequenceRuleSet::MIN_SIZE
2143);
2144
2145#[derive(Clone)]
2147pub struct ClassSequenceRuleSet<'a> {
2148 data: TableDataRef<'a, ClassSequenceRuleSetFixedHeader>,
2149}
2150
2151#[allow(clippy::needless_lifetimes)]
2152impl<'a> ClassSequenceRuleSet<'a> {
2153 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
2154 basic_table_impls!(impl_the_methods);
2155
2156 pub fn class_seq_rule_count(&self) -> u16 {
2158 self.data.header().class_seq_rule_count.get()
2159 }
2160
2161 pub fn class_seq_rule_offsets(&self) -> &'a [BigEndian<Offset16>] {
2164 let range = self.class_seq_rule_offsets_byte_range();
2165 self.offset_data()
2166 .read_array(range)
2167 .ok()
2168 .unwrap_or_default()
2169 }
2170
2171 pub fn class_seq_rules(&self) -> ArrayOfOffsets<'a, ClassSequenceRule<'a>, Offset16> {
2173 let data = self.offset_data();
2174 let offsets = self.class_seq_rule_offsets();
2175 ArrayOfOffsets::new(offsets, data, ())
2176 }
2177
2178 pub fn class_seq_rule_count_byte_range(&self) -> Range<usize> {
2179 let start = 0usize;
2180 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2181 start..end
2182 }
2183
2184 pub fn class_seq_rule_offsets_byte_range(&self) -> Range<usize> {
2185 let class_seq_rule_count = self.class_seq_rule_count();
2186 let start = self.class_seq_rule_count_byte_range().end;
2187 let end = start.saturating_add(
2188 (transforms::to_usize(class_seq_rule_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
2189 );
2190 start..end
2191 }
2192}
2193
2194const _: () = assert!(FontData::default_data_long_enough(
2195 ClassSequenceRuleSet::MIN_SIZE
2196));
2197
2198impl Default for ClassSequenceRuleSet<'_> {
2199 fn default() -> Self {
2200 Self {
2201 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2202 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2203 }
2204 }
2205}
2206
2207impl<'a> MinByteRange<'a> for ClassSequenceRule<'a> {
2208 fn min_byte_range(&self) -> Range<usize> {
2209 0..self.seq_lookup_records_byte_range().end
2210 }
2211 fn min_table_bytes(&self) -> &'a [u8] {
2212 let range = self.min_byte_range();
2213 self.offset_data().as_bytes().get(range).unwrap_or_default()
2214 }
2215}
2216
2217impl ReadArgs for ClassSequenceRule<'_> {
2218 type Args = ();
2219}
2220
2221impl<'a> FontRead<'a> for ClassSequenceRule<'a> {
2222 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2223 #[allow(clippy::absurd_extreme_comparisons)]
2224 if data.len() < Self::MIN_SIZE {
2225 return Err(ReadError::OutOfBounds);
2226 }
2227 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2228 return Err(ReadError::OutOfBounds);
2229 };
2230 Ok(Self { data })
2231 }
2232}
2233
2234#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2236#[repr(C, packed)]
2237#[doc(hidden)]
2238pub struct ClassSequenceRuleFixedHeader {
2239 pub glyph_count: BigEndian<u16>,
2240 pub seq_lookup_count: BigEndian<u16>,
2241}
2242
2243#[allow(clippy::absurd_extreme_comparisons)]
2244const _: () =
2245 assert!(std::mem::size_of::<ClassSequenceRuleFixedHeader>() <= ClassSequenceRule::MIN_SIZE);
2246
2247#[derive(Clone)]
2249pub struct ClassSequenceRule<'a> {
2250 data: TableDataRef<'a, ClassSequenceRuleFixedHeader>,
2251}
2252
2253#[allow(clippy::needless_lifetimes)]
2254impl<'a> ClassSequenceRule<'a> {
2255 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2256 basic_table_impls!(impl_the_methods);
2257
2258 pub fn glyph_count(&self) -> u16 {
2260 self.data.header().glyph_count.get()
2261 }
2262
2263 pub fn seq_lookup_count(&self) -> u16 {
2265 self.data.header().seq_lookup_count.get()
2266 }
2267
2268 pub fn input_sequence(&self) -> &'a [BigEndian<u16>] {
2271 let range = self.input_sequence_byte_range();
2272 self.offset_data()
2273 .read_array(range)
2274 .ok()
2275 .unwrap_or_default()
2276 }
2277
2278 pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
2280 let range = self.seq_lookup_records_byte_range();
2281 self.offset_data()
2282 .read_array(range)
2283 .ok()
2284 .unwrap_or_default()
2285 }
2286
2287 pub fn glyph_count_byte_range(&self) -> Range<usize> {
2288 let start = 0usize;
2289 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2290 start..end
2291 }
2292
2293 pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
2294 let start = self.glyph_count_byte_range().end;
2295 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2296 start..end
2297 }
2298
2299 pub fn input_sequence_byte_range(&self) -> Range<usize> {
2300 let glyph_count = self.glyph_count();
2301 let start = self.seq_lookup_count_byte_range().end;
2302 let end = start.saturating_add(
2303 (transforms::subtract(glyph_count, 1_usize)).saturating_mul(u16::RAW_BYTE_LEN),
2304 );
2305 start..end
2306 }
2307
2308 pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
2309 let seq_lookup_count = self.seq_lookup_count();
2310 let start = self.input_sequence_byte_range().end;
2311 let end = start.saturating_add(
2312 (transforms::to_usize(seq_lookup_count))
2313 .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
2314 );
2315 start..end
2316 }
2317}
2318
2319const _: () = assert!(FontData::default_data_long_enough(
2320 ClassSequenceRule::MIN_SIZE
2321));
2322
2323impl Default for ClassSequenceRule<'_> {
2324 fn default() -> Self {
2325 Self {
2326 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2327 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2328 }
2329 }
2330}
2331
2332impl Format<u16> for SequenceContextFormat3<'_> {
2333 const FORMAT: u16 = 3;
2334}
2335
2336impl<'a> MinByteRange<'a> for SequenceContextFormat3<'a> {
2337 fn min_byte_range(&self) -> Range<usize> {
2338 0..self.seq_lookup_records_byte_range().end
2339 }
2340 fn min_table_bytes(&self) -> &'a [u8] {
2341 let range = self.min_byte_range();
2342 self.offset_data().as_bytes().get(range).unwrap_or_default()
2343 }
2344}
2345
2346impl ReadArgs for SequenceContextFormat3<'_> {
2347 type Args = ();
2348}
2349
2350impl<'a> FontRead<'a> for SequenceContextFormat3<'a> {
2351 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2352 #[allow(clippy::absurd_extreme_comparisons)]
2353 if data.len() < Self::MIN_SIZE {
2354 return Err(ReadError::OutOfBounds);
2355 }
2356 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2357 return Err(ReadError::OutOfBounds);
2358 };
2359 Ok(Self { data })
2360 }
2361}
2362
2363#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2365#[repr(C, packed)]
2366#[doc(hidden)]
2367pub struct SequenceContextFormat3FixedHeader {
2368 pub format: BigEndian<u16>,
2369 pub glyph_count: BigEndian<u16>,
2370 pub seq_lookup_count: BigEndian<u16>,
2371}
2372
2373#[allow(clippy::absurd_extreme_comparisons)]
2374const _: () = assert!(
2375 std::mem::size_of::<SequenceContextFormat3FixedHeader>() <= SequenceContextFormat3::MIN_SIZE
2376);
2377
2378#[derive(Clone)]
2380pub struct SequenceContextFormat3<'a> {
2381 data: TableDataRef<'a, SequenceContextFormat3FixedHeader>,
2382}
2383
2384#[allow(clippy::needless_lifetimes)]
2385impl<'a> SequenceContextFormat3<'a> {
2386 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2387 basic_table_impls!(impl_the_methods);
2388
2389 pub fn format(&self) -> u16 {
2391 self.data.header().format.get()
2392 }
2393
2394 pub fn glyph_count(&self) -> u16 {
2396 self.data.header().glyph_count.get()
2397 }
2398
2399 pub fn seq_lookup_count(&self) -> u16 {
2401 self.data.header().seq_lookup_count.get()
2402 }
2403
2404 pub fn coverage_offsets(&self) -> &'a [BigEndian<Offset16>] {
2407 let range = self.coverage_offsets_byte_range();
2408 self.offset_data()
2409 .read_array(range)
2410 .ok()
2411 .unwrap_or_default()
2412 }
2413
2414 pub fn coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> {
2416 let data = self.offset_data();
2417 let offsets = self.coverage_offsets();
2418 ArrayOfOffsets::new(offsets, data, ())
2419 }
2420
2421 pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
2423 let range = self.seq_lookup_records_byte_range();
2424 self.offset_data()
2425 .read_array(range)
2426 .ok()
2427 .unwrap_or_default()
2428 }
2429
2430 pub fn format_byte_range(&self) -> Range<usize> {
2431 let start = 0usize;
2432 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2433 start..end
2434 }
2435
2436 pub fn glyph_count_byte_range(&self) -> Range<usize> {
2437 let start = self.format_byte_range().end;
2438 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2439 start..end
2440 }
2441
2442 pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
2443 let start = self.glyph_count_byte_range().end;
2444 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2445 start..end
2446 }
2447
2448 pub fn coverage_offsets_byte_range(&self) -> Range<usize> {
2449 let glyph_count = self.glyph_count();
2450 let start = self.seq_lookup_count_byte_range().end;
2451 let end = start.saturating_add(
2452 (transforms::to_usize(glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
2453 );
2454 start..end
2455 }
2456
2457 pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
2458 let seq_lookup_count = self.seq_lookup_count();
2459 let start = self.coverage_offsets_byte_range().end;
2460 let end = start.saturating_add(
2461 (transforms::to_usize(seq_lookup_count))
2462 .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
2463 );
2464 start..end
2465 }
2466}
2467
2468#[derive(Clone)]
2469pub enum SequenceContext<'a> {
2470 Format1(SequenceContextFormat1<'a>),
2471 Format2(SequenceContextFormat2<'a>),
2472 Format3(SequenceContextFormat3<'a>),
2473 Format4(SequenceContextFormat4<'a>),
2474 Format5(SequenceContextFormat5<'a>),
2475 Format6(SequenceContextFormat6<'a>),
2476}
2477
2478impl Default for SequenceContext<'_> {
2479 fn default() -> Self {
2480 Self::Format1(Default::default())
2481 }
2482}
2483
2484impl<'a> SequenceContext<'a> {
2485 pub fn offset_data(&self) -> FontData<'a> {
2487 match self {
2488 Self::Format1(item) => item.offset_data(),
2489 Self::Format2(item) => item.offset_data(),
2490 Self::Format3(item) => item.offset_data(),
2491 Self::Format4(item) => item.offset_data(),
2492 Self::Format5(item) => item.offset_data(),
2493 Self::Format6(item) => item.offset_data(),
2494 }
2495 }
2496
2497 pub fn format(&self) -> u16 {
2499 match self {
2500 Self::Format1(item) => item.format(),
2501 Self::Format2(item) => item.format(),
2502 Self::Format3(item) => item.format(),
2503 Self::Format4(item) => item.format(),
2504 Self::Format5(item) => item.format(),
2505 Self::Format6(item) => item.format(),
2506 }
2507 }
2508}
2509
2510impl ReadArgs for SequenceContext<'_> {
2511 type Args = ();
2512}
2513
2514impl<'a> FontRead<'a> for SequenceContext<'a> {
2515 #[inline]
2516 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2517 let format: u16 = data.read_at(0usize)?;
2518 match format {
2519 SequenceContextFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
2520 SequenceContextFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
2521 SequenceContextFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
2522 SequenceContextFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
2523 SequenceContextFormat5::FORMAT => Ok(Self::Format5(FontRead::read(data)?)),
2524 SequenceContextFormat6::FORMAT => Ok(Self::Format6(FontRead::read(data)?)),
2525 other => Err(ReadError::InvalidFormat(other.into())),
2526 }
2527 }
2528}
2529
2530impl<'a> MinByteRange<'a> for SequenceContext<'a> {
2531 fn min_byte_range(&self) -> Range<usize> {
2532 match self {
2533 Self::Format1(item) => item.min_byte_range(),
2534 Self::Format2(item) => item.min_byte_range(),
2535 Self::Format3(item) => item.min_byte_range(),
2536 Self::Format4(item) => item.min_byte_range(),
2537 Self::Format5(item) => item.min_byte_range(),
2538 Self::Format6(item) => item.min_byte_range(),
2539 }
2540 }
2541 fn min_table_bytes(&self) -> &'a [u8] {
2542 match self {
2543 Self::Format1(item) => item.min_table_bytes(),
2544 Self::Format2(item) => item.min_table_bytes(),
2545 Self::Format3(item) => item.min_table_bytes(),
2546 Self::Format4(item) => item.min_table_bytes(),
2547 Self::Format5(item) => item.min_table_bytes(),
2548 Self::Format6(item) => item.min_table_bytes(),
2549 }
2550 }
2551}
2552
2553impl Format<u16> for ChainedSequenceContextFormat1<'_> {
2554 const FORMAT: u16 = 1;
2555}
2556
2557impl<'a> MinByteRange<'a> for ChainedSequenceContextFormat1<'a> {
2558 fn min_byte_range(&self) -> Range<usize> {
2559 0..self.chained_seq_rule_set_offsets_byte_range().end
2560 }
2561 fn min_table_bytes(&self) -> &'a [u8] {
2562 let range = self.min_byte_range();
2563 self.offset_data().as_bytes().get(range).unwrap_or_default()
2564 }
2565}
2566
2567impl ReadArgs for ChainedSequenceContextFormat1<'_> {
2568 type Args = ();
2569}
2570
2571impl<'a> FontRead<'a> for ChainedSequenceContextFormat1<'a> {
2572 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2573 #[allow(clippy::absurd_extreme_comparisons)]
2574 if data.len() < Self::MIN_SIZE {
2575 return Err(ReadError::OutOfBounds);
2576 }
2577 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2578 return Err(ReadError::OutOfBounds);
2579 };
2580 Ok(Self { data })
2581 }
2582}
2583
2584#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2586#[repr(C, packed)]
2587#[doc(hidden)]
2588pub struct ChainedSequenceContextFormat1FixedHeader {
2589 pub format: BigEndian<u16>,
2590 pub coverage_offset: BigEndian<Offset16>,
2591 pub chained_seq_rule_set_count: BigEndian<u16>,
2592}
2593
2594#[allow(clippy::absurd_extreme_comparisons)]
2595const _: () = assert!(
2596 std::mem::size_of::<ChainedSequenceContextFormat1FixedHeader>()
2597 <= ChainedSequenceContextFormat1::MIN_SIZE
2598);
2599
2600#[derive(Clone)]
2602pub struct ChainedSequenceContextFormat1<'a> {
2603 data: TableDataRef<'a, ChainedSequenceContextFormat1FixedHeader>,
2604}
2605
2606#[allow(clippy::needless_lifetimes)]
2607impl<'a> ChainedSequenceContextFormat1<'a> {
2608 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2609 basic_table_impls!(impl_the_methods);
2610
2611 pub fn format(&self) -> u16 {
2613 self.data.header().format.get()
2614 }
2615
2616 pub fn coverage_offset(&self) -> Offset16 {
2619 self.data.header().coverage_offset.get()
2620 }
2621
2622 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
2624 let data = self.offset_data();
2625 self.coverage_offset().resolve(data)
2626 }
2627
2628 pub fn chained_seq_rule_set_count(&self) -> u16 {
2630 self.data.header().chained_seq_rule_set_count.get()
2631 }
2632
2633 pub fn chained_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] {
2636 let range = self.chained_seq_rule_set_offsets_byte_range();
2637 self.offset_data()
2638 .read_array(range)
2639 .ok()
2640 .unwrap_or_default()
2641 }
2642
2643 pub fn chained_seq_rule_sets(
2645 &self,
2646 ) -> ArrayOfNullableOffsets<'a, ChainedSequenceRuleSet<'a>, Offset16> {
2647 let data = self.offset_data();
2648 let offsets = self.chained_seq_rule_set_offsets();
2649 ArrayOfNullableOffsets::new(offsets, data, ())
2650 }
2651
2652 pub fn format_byte_range(&self) -> Range<usize> {
2653 let start = 0usize;
2654 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2655 start..end
2656 }
2657
2658 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
2659 let start = self.format_byte_range().end;
2660 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
2661 start..end
2662 }
2663
2664 pub fn chained_seq_rule_set_count_byte_range(&self) -> Range<usize> {
2665 let start = self.coverage_offset_byte_range().end;
2666 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2667 start..end
2668 }
2669
2670 pub fn chained_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
2671 let chained_seq_rule_set_count = self.chained_seq_rule_set_count();
2672 let start = self.chained_seq_rule_set_count_byte_range().end;
2673 let end = start.saturating_add(
2674 (transforms::to_usize(chained_seq_rule_set_count))
2675 .saturating_mul(Offset16::RAW_BYTE_LEN),
2676 );
2677 start..end
2678 }
2679}
2680
2681const _: () = assert!(FontData::default_data_long_enough(
2682 ChainedSequenceContextFormat1::MIN_SIZE
2683));
2684
2685impl Default for ChainedSequenceContextFormat1<'_> {
2686 fn default() -> Self {
2687 Self {
2688 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
2689 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2690 }
2691 }
2692}
2693
2694impl<'a> MinByteRange<'a> for ChainedSequenceRuleSet<'a> {
2695 fn min_byte_range(&self) -> Range<usize> {
2696 0..self.chained_seq_rule_offsets_byte_range().end
2697 }
2698 fn min_table_bytes(&self) -> &'a [u8] {
2699 let range = self.min_byte_range();
2700 self.offset_data().as_bytes().get(range).unwrap_or_default()
2701 }
2702}
2703
2704impl ReadArgs for ChainedSequenceRuleSet<'_> {
2705 type Args = ();
2706}
2707
2708impl<'a> FontRead<'a> for ChainedSequenceRuleSet<'a> {
2709 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2710 #[allow(clippy::absurd_extreme_comparisons)]
2711 if data.len() < Self::MIN_SIZE {
2712 return Err(ReadError::OutOfBounds);
2713 }
2714 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2715 return Err(ReadError::OutOfBounds);
2716 };
2717 Ok(Self { data })
2718 }
2719}
2720
2721#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2723#[repr(C, packed)]
2724#[doc(hidden)]
2725pub struct ChainedSequenceRuleSetFixedHeader {
2726 pub chained_seq_rule_count: BigEndian<u16>,
2727}
2728
2729#[allow(clippy::absurd_extreme_comparisons)]
2730const _: () = assert!(
2731 std::mem::size_of::<ChainedSequenceRuleSetFixedHeader>() <= ChainedSequenceRuleSet::MIN_SIZE
2732);
2733
2734#[derive(Clone)]
2736pub struct ChainedSequenceRuleSet<'a> {
2737 data: TableDataRef<'a, ChainedSequenceRuleSetFixedHeader>,
2738}
2739
2740#[allow(clippy::needless_lifetimes)]
2741impl<'a> ChainedSequenceRuleSet<'a> {
2742 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
2743 basic_table_impls!(impl_the_methods);
2744
2745 pub fn chained_seq_rule_count(&self) -> u16 {
2747 self.data.header().chained_seq_rule_count.get()
2748 }
2749
2750 pub fn chained_seq_rule_offsets(&self) -> &'a [BigEndian<Offset16>] {
2753 let range = self.chained_seq_rule_offsets_byte_range();
2754 self.offset_data()
2755 .read_array(range)
2756 .ok()
2757 .unwrap_or_default()
2758 }
2759
2760 pub fn chained_seq_rules(&self) -> ArrayOfOffsets<'a, ChainedSequenceRule<'a>, Offset16> {
2762 let data = self.offset_data();
2763 let offsets = self.chained_seq_rule_offsets();
2764 ArrayOfOffsets::new(offsets, data, ())
2765 }
2766
2767 pub fn chained_seq_rule_count_byte_range(&self) -> Range<usize> {
2768 let start = 0usize;
2769 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2770 start..end
2771 }
2772
2773 pub fn chained_seq_rule_offsets_byte_range(&self) -> Range<usize> {
2774 let chained_seq_rule_count = self.chained_seq_rule_count();
2775 let start = self.chained_seq_rule_count_byte_range().end;
2776 let end = start.saturating_add(
2777 (transforms::to_usize(chained_seq_rule_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
2778 );
2779 start..end
2780 }
2781}
2782
2783const _: () = assert!(FontData::default_data_long_enough(
2784 ChainedSequenceRuleSet::MIN_SIZE
2785));
2786
2787impl Default for ChainedSequenceRuleSet<'_> {
2788 fn default() -> Self {
2789 Self {
2790 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2791 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2792 }
2793 }
2794}
2795
2796impl<'a> MinByteRange<'a> for ChainedSequenceRule<'a> {
2797 fn min_byte_range(&self) -> Range<usize> {
2798 0..self.seq_lookup_records_byte_range().end
2799 }
2800 fn min_table_bytes(&self) -> &'a [u8] {
2801 let range = self.min_byte_range();
2802 self.offset_data().as_bytes().get(range).unwrap_or_default()
2803 }
2804}
2805
2806impl ReadArgs for ChainedSequenceRule<'_> {
2807 type Args = ();
2808}
2809
2810impl<'a> FontRead<'a> for ChainedSequenceRule<'a> {
2811 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2812 #[allow(clippy::absurd_extreme_comparisons)]
2813 if data.len() < Self::MIN_SIZE {
2814 return Err(ReadError::OutOfBounds);
2815 }
2816 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2817 return Err(ReadError::OutOfBounds);
2818 };
2819 Ok(Self { data })
2820 }
2821}
2822
2823#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2825#[repr(C, packed)]
2826#[doc(hidden)]
2827pub struct ChainedSequenceRuleFixedHeader {
2828 pub backtrack_glyph_count: BigEndian<u16>,
2829}
2830
2831#[allow(clippy::absurd_extreme_comparisons)]
2832const _: () =
2833 assert!(std::mem::size_of::<ChainedSequenceRuleFixedHeader>() <= ChainedSequenceRule::MIN_SIZE);
2834
2835#[derive(Clone)]
2837pub struct ChainedSequenceRule<'a> {
2838 data: TableDataRef<'a, ChainedSequenceRuleFixedHeader>,
2839}
2840
2841#[allow(clippy::needless_lifetimes)]
2842impl<'a> ChainedSequenceRule<'a> {
2843 pub const MIN_SIZE: usize =
2844 (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2845 basic_table_impls!(impl_the_methods);
2846
2847 pub fn backtrack_glyph_count(&self) -> u16 {
2849 self.data.header().backtrack_glyph_count.get()
2850 }
2851
2852 pub fn backtrack_sequence(&self) -> &'a [BigEndian<GlyphId16>] {
2854 let range = self.backtrack_sequence_byte_range();
2855 self.offset_data()
2856 .read_array(range)
2857 .ok()
2858 .unwrap_or_default()
2859 }
2860
2861 pub fn input_glyph_count(&self) -> u16 {
2863 let range = self.input_glyph_count_byte_range();
2864 self.offset_data()
2865 .read_at(range.start)
2866 .ok()
2867 .unwrap_or_default()
2868 }
2869
2870 pub fn input_sequence(&self) -> &'a [BigEndian<GlyphId16>] {
2872 let range = self.input_sequence_byte_range();
2873 self.offset_data()
2874 .read_array(range)
2875 .ok()
2876 .unwrap_or_default()
2877 }
2878
2879 pub fn lookahead_glyph_count(&self) -> u16 {
2881 let range = self.lookahead_glyph_count_byte_range();
2882 self.offset_data()
2883 .read_at(range.start)
2884 .ok()
2885 .unwrap_or_default()
2886 }
2887
2888 pub fn lookahead_sequence(&self) -> &'a [BigEndian<GlyphId16>] {
2890 let range = self.lookahead_sequence_byte_range();
2891 self.offset_data()
2892 .read_array(range)
2893 .ok()
2894 .unwrap_or_default()
2895 }
2896
2897 pub fn seq_lookup_count(&self) -> u16 {
2899 let range = self.seq_lookup_count_byte_range();
2900 self.offset_data()
2901 .read_at(range.start)
2902 .ok()
2903 .unwrap_or_default()
2904 }
2905
2906 pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
2908 let range = self.seq_lookup_records_byte_range();
2909 self.offset_data()
2910 .read_array(range)
2911 .ok()
2912 .unwrap_or_default()
2913 }
2914
2915 pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> {
2916 let start = 0usize;
2917 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2918 start..end
2919 }
2920
2921 pub fn backtrack_sequence_byte_range(&self) -> Range<usize> {
2922 let backtrack_glyph_count = self.backtrack_glyph_count();
2923 let start = self.backtrack_glyph_count_byte_range().end;
2924 let end = start.saturating_add(
2925 (transforms::to_usize(backtrack_glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN),
2926 );
2927 start..end
2928 }
2929
2930 pub fn input_glyph_count_byte_range(&self) -> Range<usize> {
2931 let start = self.backtrack_sequence_byte_range().end;
2932 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2933 start..end
2934 }
2935
2936 pub fn input_sequence_byte_range(&self) -> Range<usize> {
2937 let input_glyph_count = self.input_glyph_count();
2938 let start = self.input_glyph_count_byte_range().end;
2939 let end = start.saturating_add(
2940 (transforms::subtract(input_glyph_count, 1_usize))
2941 .saturating_mul(GlyphId16::RAW_BYTE_LEN),
2942 );
2943 start..end
2944 }
2945
2946 pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> {
2947 let start = self.input_sequence_byte_range().end;
2948 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2949 start..end
2950 }
2951
2952 pub fn lookahead_sequence_byte_range(&self) -> Range<usize> {
2953 let lookahead_glyph_count = self.lookahead_glyph_count();
2954 let start = self.lookahead_glyph_count_byte_range().end;
2955 let end = start.saturating_add(
2956 (transforms::to_usize(lookahead_glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN),
2957 );
2958 start..end
2959 }
2960
2961 pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
2962 let start = self.lookahead_sequence_byte_range().end;
2963 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2964 start..end
2965 }
2966
2967 pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
2968 let seq_lookup_count = self.seq_lookup_count();
2969 let start = self.seq_lookup_count_byte_range().end;
2970 let end = start.saturating_add(
2971 (transforms::to_usize(seq_lookup_count))
2972 .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
2973 );
2974 start..end
2975 }
2976}
2977
2978const _: () = assert!(FontData::default_data_long_enough(
2979 ChainedSequenceRule::MIN_SIZE
2980));
2981
2982impl Default for ChainedSequenceRule<'_> {
2983 fn default() -> Self {
2984 Self {
2985 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2986 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2987 }
2988 }
2989}
2990
2991impl Format<u16> for ChainedSequenceContextFormat2<'_> {
2992 const FORMAT: u16 = 2;
2993}
2994
2995impl<'a> MinByteRange<'a> for ChainedSequenceContextFormat2<'a> {
2996 fn min_byte_range(&self) -> Range<usize> {
2997 0..self.chained_class_seq_rule_set_offsets_byte_range().end
2998 }
2999 fn min_table_bytes(&self) -> &'a [u8] {
3000 let range = self.min_byte_range();
3001 self.offset_data().as_bytes().get(range).unwrap_or_default()
3002 }
3003}
3004
3005impl ReadArgs for ChainedSequenceContextFormat2<'_> {
3006 type Args = ();
3007}
3008
3009impl<'a> FontRead<'a> for ChainedSequenceContextFormat2<'a> {
3010 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3011 #[allow(clippy::absurd_extreme_comparisons)]
3012 if data.len() < Self::MIN_SIZE {
3013 return Err(ReadError::OutOfBounds);
3014 }
3015 let Some(data) = TableDataRef::new(data.as_bytes()) else {
3016 return Err(ReadError::OutOfBounds);
3017 };
3018 Ok(Self { data })
3019 }
3020}
3021
3022#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3024#[repr(C, packed)]
3025#[doc(hidden)]
3026pub struct ChainedSequenceContextFormat2FixedHeader {
3027 pub format: BigEndian<u16>,
3028 pub coverage_offset: BigEndian<Offset16>,
3029 pub backtrack_class_def_offset: BigEndian<Offset16>,
3030 pub input_class_def_offset: BigEndian<Offset16>,
3031 pub lookahead_class_def_offset: BigEndian<Offset16>,
3032 pub chained_class_seq_rule_set_count: BigEndian<u16>,
3033}
3034
3035#[allow(clippy::absurd_extreme_comparisons)]
3036const _: () = assert!(
3037 std::mem::size_of::<ChainedSequenceContextFormat2FixedHeader>()
3038 <= ChainedSequenceContextFormat2::MIN_SIZE
3039);
3040
3041#[derive(Clone)]
3043pub struct ChainedSequenceContextFormat2<'a> {
3044 data: TableDataRef<'a, ChainedSequenceContextFormat2FixedHeader>,
3045}
3046
3047#[allow(clippy::needless_lifetimes)]
3048impl<'a> ChainedSequenceContextFormat2<'a> {
3049 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
3050 + Offset16::RAW_BYTE_LEN
3051 + Offset16::RAW_BYTE_LEN
3052 + Offset16::RAW_BYTE_LEN
3053 + Offset16::RAW_BYTE_LEN
3054 + u16::RAW_BYTE_LEN);
3055 basic_table_impls!(impl_the_methods);
3056
3057 pub fn format(&self) -> u16 {
3059 self.data.header().format.get()
3060 }
3061
3062 pub fn coverage_offset(&self) -> Offset16 {
3065 self.data.header().coverage_offset.get()
3066 }
3067
3068 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
3070 let data = self.offset_data();
3071 self.coverage_offset().resolve(data)
3072 }
3073
3074 pub fn backtrack_class_def_offset(&self) -> Offset16 {
3077 self.data.header().backtrack_class_def_offset.get()
3078 }
3079
3080 pub fn backtrack_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
3082 let data = self.offset_data();
3083 self.backtrack_class_def_offset().resolve(data)
3084 }
3085
3086 pub fn input_class_def_offset(&self) -> Offset16 {
3089 self.data.header().input_class_def_offset.get()
3090 }
3091
3092 pub fn input_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
3094 let data = self.offset_data();
3095 self.input_class_def_offset().resolve(data)
3096 }
3097
3098 pub fn lookahead_class_def_offset(&self) -> Offset16 {
3101 self.data.header().lookahead_class_def_offset.get()
3102 }
3103
3104 pub fn lookahead_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
3106 let data = self.offset_data();
3107 self.lookahead_class_def_offset().resolve(data)
3108 }
3109
3110 pub fn chained_class_seq_rule_set_count(&self) -> u16 {
3112 self.data.header().chained_class_seq_rule_set_count.get()
3113 }
3114
3115 pub fn chained_class_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] {
3118 let range = self.chained_class_seq_rule_set_offsets_byte_range();
3119 self.offset_data()
3120 .read_array(range)
3121 .ok()
3122 .unwrap_or_default()
3123 }
3124
3125 pub fn chained_class_seq_rule_sets(
3127 &self,
3128 ) -> ArrayOfNullableOffsets<'a, ChainedClassSequenceRuleSet<'a>, Offset16> {
3129 let data = self.offset_data();
3130 let offsets = self.chained_class_seq_rule_set_offsets();
3131 ArrayOfNullableOffsets::new(offsets, data, ())
3132 }
3133
3134 pub fn format_byte_range(&self) -> Range<usize> {
3135 let start = 0usize;
3136 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3137 start..end
3138 }
3139
3140 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
3141 let start = self.format_byte_range().end;
3142 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
3143 start..end
3144 }
3145
3146 pub fn backtrack_class_def_offset_byte_range(&self) -> Range<usize> {
3147 let start = self.coverage_offset_byte_range().end;
3148 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
3149 start..end
3150 }
3151
3152 pub fn input_class_def_offset_byte_range(&self) -> Range<usize> {
3153 let start = self.backtrack_class_def_offset_byte_range().end;
3154 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
3155 start..end
3156 }
3157
3158 pub fn lookahead_class_def_offset_byte_range(&self) -> Range<usize> {
3159 let start = self.input_class_def_offset_byte_range().end;
3160 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
3161 start..end
3162 }
3163
3164 pub fn chained_class_seq_rule_set_count_byte_range(&self) -> Range<usize> {
3165 let start = self.lookahead_class_def_offset_byte_range().end;
3166 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3167 start..end
3168 }
3169
3170 pub fn chained_class_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
3171 let chained_class_seq_rule_set_count = self.chained_class_seq_rule_set_count();
3172 let start = self.chained_class_seq_rule_set_count_byte_range().end;
3173 let end = start.saturating_add(
3174 (transforms::to_usize(chained_class_seq_rule_set_count))
3175 .saturating_mul(Offset16::RAW_BYTE_LEN),
3176 );
3177 start..end
3178 }
3179}
3180
3181impl<'a> MinByteRange<'a> for ChainedClassSequenceRuleSet<'a> {
3182 fn min_byte_range(&self) -> Range<usize> {
3183 0..self.chained_class_seq_rule_offsets_byte_range().end
3184 }
3185 fn min_table_bytes(&self) -> &'a [u8] {
3186 let range = self.min_byte_range();
3187 self.offset_data().as_bytes().get(range).unwrap_or_default()
3188 }
3189}
3190
3191impl ReadArgs for ChainedClassSequenceRuleSet<'_> {
3192 type Args = ();
3193}
3194
3195impl<'a> FontRead<'a> for ChainedClassSequenceRuleSet<'a> {
3196 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3197 #[allow(clippy::absurd_extreme_comparisons)]
3198 if data.len() < Self::MIN_SIZE {
3199 return Err(ReadError::OutOfBounds);
3200 }
3201 let Some(data) = TableDataRef::new(data.as_bytes()) else {
3202 return Err(ReadError::OutOfBounds);
3203 };
3204 Ok(Self { data })
3205 }
3206}
3207
3208#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3210#[repr(C, packed)]
3211#[doc(hidden)]
3212pub struct ChainedClassSequenceRuleSetFixedHeader {
3213 pub chained_class_seq_rule_count: BigEndian<u16>,
3214}
3215
3216#[allow(clippy::absurd_extreme_comparisons)]
3217const _: () = assert!(
3218 std::mem::size_of::<ChainedClassSequenceRuleSetFixedHeader>()
3219 <= ChainedClassSequenceRuleSet::MIN_SIZE
3220);
3221
3222#[derive(Clone)]
3224pub struct ChainedClassSequenceRuleSet<'a> {
3225 data: TableDataRef<'a, ChainedClassSequenceRuleSetFixedHeader>,
3226}
3227
3228#[allow(clippy::needless_lifetimes)]
3229impl<'a> ChainedClassSequenceRuleSet<'a> {
3230 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
3231 basic_table_impls!(impl_the_methods);
3232
3233 pub fn chained_class_seq_rule_count(&self) -> u16 {
3235 self.data.header().chained_class_seq_rule_count.get()
3236 }
3237
3238 pub fn chained_class_seq_rule_offsets(&self) -> &'a [BigEndian<Offset16>] {
3241 let range = self.chained_class_seq_rule_offsets_byte_range();
3242 self.offset_data()
3243 .read_array(range)
3244 .ok()
3245 .unwrap_or_default()
3246 }
3247
3248 pub fn chained_class_seq_rules(
3250 &self,
3251 ) -> ArrayOfOffsets<'a, ChainedClassSequenceRule<'a>, Offset16> {
3252 let data = self.offset_data();
3253 let offsets = self.chained_class_seq_rule_offsets();
3254 ArrayOfOffsets::new(offsets, data, ())
3255 }
3256
3257 pub fn chained_class_seq_rule_count_byte_range(&self) -> Range<usize> {
3258 let start = 0usize;
3259 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3260 start..end
3261 }
3262
3263 pub fn chained_class_seq_rule_offsets_byte_range(&self) -> Range<usize> {
3264 let chained_class_seq_rule_count = self.chained_class_seq_rule_count();
3265 let start = self.chained_class_seq_rule_count_byte_range().end;
3266 let end = start.saturating_add(
3267 (transforms::to_usize(chained_class_seq_rule_count))
3268 .saturating_mul(Offset16::RAW_BYTE_LEN),
3269 );
3270 start..end
3271 }
3272}
3273
3274const _: () = assert!(FontData::default_data_long_enough(
3275 ChainedClassSequenceRuleSet::MIN_SIZE
3276));
3277
3278impl Default for ChainedClassSequenceRuleSet<'_> {
3279 fn default() -> Self {
3280 Self {
3281 data: TableDataRef::new(FontData::default_table_data().as_bytes())
3282 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
3283 }
3284 }
3285}
3286
3287impl<'a> MinByteRange<'a> for ChainedClassSequenceRule<'a> {
3288 fn min_byte_range(&self) -> Range<usize> {
3289 0..self.seq_lookup_records_byte_range().end
3290 }
3291 fn min_table_bytes(&self) -> &'a [u8] {
3292 let range = self.min_byte_range();
3293 self.offset_data().as_bytes().get(range).unwrap_or_default()
3294 }
3295}
3296
3297impl ReadArgs for ChainedClassSequenceRule<'_> {
3298 type Args = ();
3299}
3300
3301impl<'a> FontRead<'a> for ChainedClassSequenceRule<'a> {
3302 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3303 #[allow(clippy::absurd_extreme_comparisons)]
3304 if data.len() < Self::MIN_SIZE {
3305 return Err(ReadError::OutOfBounds);
3306 }
3307 let Some(data) = TableDataRef::new(data.as_bytes()) else {
3308 return Err(ReadError::OutOfBounds);
3309 };
3310 Ok(Self { data })
3311 }
3312}
3313
3314#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3316#[repr(C, packed)]
3317#[doc(hidden)]
3318pub struct ChainedClassSequenceRuleFixedHeader {
3319 pub backtrack_glyph_count: BigEndian<u16>,
3320}
3321
3322#[allow(clippy::absurd_extreme_comparisons)]
3323const _: () = assert!(
3324 std::mem::size_of::<ChainedClassSequenceRuleFixedHeader>()
3325 <= ChainedClassSequenceRule::MIN_SIZE
3326);
3327
3328#[derive(Clone)]
3330pub struct ChainedClassSequenceRule<'a> {
3331 data: TableDataRef<'a, ChainedClassSequenceRuleFixedHeader>,
3332}
3333
3334#[allow(clippy::needless_lifetimes)]
3335impl<'a> ChainedClassSequenceRule<'a> {
3336 pub const MIN_SIZE: usize =
3337 (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
3338 basic_table_impls!(impl_the_methods);
3339
3340 pub fn backtrack_glyph_count(&self) -> u16 {
3342 self.data.header().backtrack_glyph_count.get()
3343 }
3344
3345 pub fn backtrack_sequence(&self) -> &'a [BigEndian<u16>] {
3347 let range = self.backtrack_sequence_byte_range();
3348 self.offset_data()
3349 .read_array(range)
3350 .ok()
3351 .unwrap_or_default()
3352 }
3353
3354 pub fn input_glyph_count(&self) -> u16 {
3356 let range = self.input_glyph_count_byte_range();
3357 self.offset_data()
3358 .read_at(range.start)
3359 .ok()
3360 .unwrap_or_default()
3361 }
3362
3363 pub fn input_sequence(&self) -> &'a [BigEndian<u16>] {
3366 let range = self.input_sequence_byte_range();
3367 self.offset_data()
3368 .read_array(range)
3369 .ok()
3370 .unwrap_or_default()
3371 }
3372
3373 pub fn lookahead_glyph_count(&self) -> u16 {
3375 let range = self.lookahead_glyph_count_byte_range();
3376 self.offset_data()
3377 .read_at(range.start)
3378 .ok()
3379 .unwrap_or_default()
3380 }
3381
3382 pub fn lookahead_sequence(&self) -> &'a [BigEndian<u16>] {
3384 let range = self.lookahead_sequence_byte_range();
3385 self.offset_data()
3386 .read_array(range)
3387 .ok()
3388 .unwrap_or_default()
3389 }
3390
3391 pub fn seq_lookup_count(&self) -> u16 {
3393 let range = self.seq_lookup_count_byte_range();
3394 self.offset_data()
3395 .read_at(range.start)
3396 .ok()
3397 .unwrap_or_default()
3398 }
3399
3400 pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
3402 let range = self.seq_lookup_records_byte_range();
3403 self.offset_data()
3404 .read_array(range)
3405 .ok()
3406 .unwrap_or_default()
3407 }
3408
3409 pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> {
3410 let start = 0usize;
3411 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3412 start..end
3413 }
3414
3415 pub fn backtrack_sequence_byte_range(&self) -> Range<usize> {
3416 let backtrack_glyph_count = self.backtrack_glyph_count();
3417 let start = self.backtrack_glyph_count_byte_range().end;
3418 let end = start.saturating_add(
3419 (transforms::to_usize(backtrack_glyph_count)).saturating_mul(u16::RAW_BYTE_LEN),
3420 );
3421 start..end
3422 }
3423
3424 pub fn input_glyph_count_byte_range(&self) -> Range<usize> {
3425 let start = self.backtrack_sequence_byte_range().end;
3426 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3427 start..end
3428 }
3429
3430 pub fn input_sequence_byte_range(&self) -> Range<usize> {
3431 let input_glyph_count = self.input_glyph_count();
3432 let start = self.input_glyph_count_byte_range().end;
3433 let end = start.saturating_add(
3434 (transforms::subtract(input_glyph_count, 1_usize)).saturating_mul(u16::RAW_BYTE_LEN),
3435 );
3436 start..end
3437 }
3438
3439 pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> {
3440 let start = self.input_sequence_byte_range().end;
3441 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3442 start..end
3443 }
3444
3445 pub fn lookahead_sequence_byte_range(&self) -> Range<usize> {
3446 let lookahead_glyph_count = self.lookahead_glyph_count();
3447 let start = self.lookahead_glyph_count_byte_range().end;
3448 let end = start.saturating_add(
3449 (transforms::to_usize(lookahead_glyph_count)).saturating_mul(u16::RAW_BYTE_LEN),
3450 );
3451 start..end
3452 }
3453
3454 pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
3455 let start = self.lookahead_sequence_byte_range().end;
3456 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3457 start..end
3458 }
3459
3460 pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
3461 let seq_lookup_count = self.seq_lookup_count();
3462 let start = self.seq_lookup_count_byte_range().end;
3463 let end = start.saturating_add(
3464 (transforms::to_usize(seq_lookup_count))
3465 .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
3466 );
3467 start..end
3468 }
3469}
3470
3471const _: () = assert!(FontData::default_data_long_enough(
3472 ChainedClassSequenceRule::MIN_SIZE
3473));
3474
3475impl Default for ChainedClassSequenceRule<'_> {
3476 fn default() -> Self {
3477 Self {
3478 data: TableDataRef::new(FontData::default_table_data().as_bytes())
3479 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
3480 }
3481 }
3482}
3483
3484impl Format<u16> for ChainedSequenceContextFormat3<'_> {
3485 const FORMAT: u16 = 3;
3486}
3487
3488impl<'a> MinByteRange<'a> for ChainedSequenceContextFormat3<'a> {
3489 fn min_byte_range(&self) -> Range<usize> {
3490 0..self.seq_lookup_records_byte_range().end
3491 }
3492 fn min_table_bytes(&self) -> &'a [u8] {
3493 let range = self.min_byte_range();
3494 self.offset_data().as_bytes().get(range).unwrap_or_default()
3495 }
3496}
3497
3498impl ReadArgs for ChainedSequenceContextFormat3<'_> {
3499 type Args = ();
3500}
3501
3502impl<'a> FontRead<'a> for ChainedSequenceContextFormat3<'a> {
3503 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3504 #[allow(clippy::absurd_extreme_comparisons)]
3505 if data.len() < Self::MIN_SIZE {
3506 return Err(ReadError::OutOfBounds);
3507 }
3508 let Some(data) = TableDataRef::new(data.as_bytes()) else {
3509 return Err(ReadError::OutOfBounds);
3510 };
3511 Ok(Self { data })
3512 }
3513}
3514
3515#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3517#[repr(C, packed)]
3518#[doc(hidden)]
3519pub struct ChainedSequenceContextFormat3FixedHeader {
3520 pub format: BigEndian<u16>,
3521 pub backtrack_glyph_count: BigEndian<u16>,
3522}
3523
3524#[allow(clippy::absurd_extreme_comparisons)]
3525const _: () = assert!(
3526 std::mem::size_of::<ChainedSequenceContextFormat3FixedHeader>()
3527 <= ChainedSequenceContextFormat3::MIN_SIZE
3528);
3529
3530#[derive(Clone)]
3532pub struct ChainedSequenceContextFormat3<'a> {
3533 data: TableDataRef<'a, ChainedSequenceContextFormat3FixedHeader>,
3534}
3535
3536#[allow(clippy::needless_lifetimes)]
3537impl<'a> ChainedSequenceContextFormat3<'a> {
3538 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
3539 + u16::RAW_BYTE_LEN
3540 + u16::RAW_BYTE_LEN
3541 + u16::RAW_BYTE_LEN
3542 + u16::RAW_BYTE_LEN);
3543 basic_table_impls!(impl_the_methods);
3544
3545 pub fn format(&self) -> u16 {
3547 self.data.header().format.get()
3548 }
3549
3550 pub fn backtrack_glyph_count(&self) -> u16 {
3552 self.data.header().backtrack_glyph_count.get()
3553 }
3554
3555 pub fn backtrack_coverage_offsets(&self) -> &'a [BigEndian<Offset16>] {
3557 let range = self.backtrack_coverage_offsets_byte_range();
3558 self.offset_data()
3559 .read_array(range)
3560 .ok()
3561 .unwrap_or_default()
3562 }
3563
3564 pub fn backtrack_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> {
3566 let data = self.offset_data();
3567 let offsets = self.backtrack_coverage_offsets();
3568 ArrayOfOffsets::new(offsets, data, ())
3569 }
3570
3571 pub fn input_glyph_count(&self) -> u16 {
3573 let range = self.input_glyph_count_byte_range();
3574 self.offset_data()
3575 .read_at(range.start)
3576 .ok()
3577 .unwrap_or_default()
3578 }
3579
3580 pub fn input_coverage_offsets(&self) -> &'a [BigEndian<Offset16>] {
3582 let range = self.input_coverage_offsets_byte_range();
3583 self.offset_data()
3584 .read_array(range)
3585 .ok()
3586 .unwrap_or_default()
3587 }
3588
3589 pub fn input_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> {
3591 let data = self.offset_data();
3592 let offsets = self.input_coverage_offsets();
3593 ArrayOfOffsets::new(offsets, data, ())
3594 }
3595
3596 pub fn lookahead_glyph_count(&self) -> u16 {
3598 let range = self.lookahead_glyph_count_byte_range();
3599 self.offset_data()
3600 .read_at(range.start)
3601 .ok()
3602 .unwrap_or_default()
3603 }
3604
3605 pub fn lookahead_coverage_offsets(&self) -> &'a [BigEndian<Offset16>] {
3607 let range = self.lookahead_coverage_offsets_byte_range();
3608 self.offset_data()
3609 .read_array(range)
3610 .ok()
3611 .unwrap_or_default()
3612 }
3613
3614 pub fn lookahead_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> {
3616 let data = self.offset_data();
3617 let offsets = self.lookahead_coverage_offsets();
3618 ArrayOfOffsets::new(offsets, data, ())
3619 }
3620
3621 pub fn seq_lookup_count(&self) -> u16 {
3623 let range = self.seq_lookup_count_byte_range();
3624 self.offset_data()
3625 .read_at(range.start)
3626 .ok()
3627 .unwrap_or_default()
3628 }
3629
3630 pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
3632 let range = self.seq_lookup_records_byte_range();
3633 self.offset_data()
3634 .read_array(range)
3635 .ok()
3636 .unwrap_or_default()
3637 }
3638
3639 pub fn format_byte_range(&self) -> Range<usize> {
3640 let start = 0usize;
3641 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3642 start..end
3643 }
3644
3645 pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> {
3646 let start = self.format_byte_range().end;
3647 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3648 start..end
3649 }
3650
3651 pub fn backtrack_coverage_offsets_byte_range(&self) -> Range<usize> {
3652 let backtrack_glyph_count = self.backtrack_glyph_count();
3653 let start = self.backtrack_glyph_count_byte_range().end;
3654 let end = start.saturating_add(
3655 (transforms::to_usize(backtrack_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
3656 );
3657 start..end
3658 }
3659
3660 pub fn input_glyph_count_byte_range(&self) -> Range<usize> {
3661 let start = self.backtrack_coverage_offsets_byte_range().end;
3662 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3663 start..end
3664 }
3665
3666 pub fn input_coverage_offsets_byte_range(&self) -> Range<usize> {
3667 let input_glyph_count = self.input_glyph_count();
3668 let start = self.input_glyph_count_byte_range().end;
3669 let end = start.saturating_add(
3670 (transforms::to_usize(input_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
3671 );
3672 start..end
3673 }
3674
3675 pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> {
3676 let start = self.input_coverage_offsets_byte_range().end;
3677 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3678 start..end
3679 }
3680
3681 pub fn lookahead_coverage_offsets_byte_range(&self) -> Range<usize> {
3682 let lookahead_glyph_count = self.lookahead_glyph_count();
3683 let start = self.lookahead_glyph_count_byte_range().end;
3684 let end = start.saturating_add(
3685 (transforms::to_usize(lookahead_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
3686 );
3687 start..end
3688 }
3689
3690 pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
3691 let start = self.lookahead_coverage_offsets_byte_range().end;
3692 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3693 start..end
3694 }
3695
3696 pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
3697 let seq_lookup_count = self.seq_lookup_count();
3698 let start = self.seq_lookup_count_byte_range().end;
3699 let end = start.saturating_add(
3700 (transforms::to_usize(seq_lookup_count))
3701 .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
3702 );
3703 start..end
3704 }
3705}
3706
3707#[derive(Clone)]
3708pub enum ChainedSequenceContext<'a> {
3709 Format1(ChainedSequenceContextFormat1<'a>),
3710 Format2(ChainedSequenceContextFormat2<'a>),
3711 Format3(ChainedSequenceContextFormat3<'a>),
3712 Format4(ChainedSequenceContextFormat4<'a>),
3713 Format5(ChainedSequenceContextFormat5<'a>),
3714}
3715
3716impl Default for ChainedSequenceContext<'_> {
3717 fn default() -> Self {
3718 Self::Format1(Default::default())
3719 }
3720}
3721
3722impl<'a> ChainedSequenceContext<'a> {
3723 pub fn offset_data(&self) -> FontData<'a> {
3725 match self {
3726 Self::Format1(item) => item.offset_data(),
3727 Self::Format2(item) => item.offset_data(),
3728 Self::Format3(item) => item.offset_data(),
3729 Self::Format4(item) => item.offset_data(),
3730 Self::Format5(item) => item.offset_data(),
3731 }
3732 }
3733
3734 pub fn format(&self) -> u16 {
3736 match self {
3737 Self::Format1(item) => item.format(),
3738 Self::Format2(item) => item.format(),
3739 Self::Format3(item) => item.format(),
3740 Self::Format4(item) => item.format(),
3741 Self::Format5(item) => item.format(),
3742 }
3743 }
3744}
3745
3746impl ReadArgs for ChainedSequenceContext<'_> {
3747 type Args = ();
3748}
3749
3750impl<'a> FontRead<'a> for ChainedSequenceContext<'a> {
3751 #[inline]
3752 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3753 let format: u16 = data.read_at(0usize)?;
3754 match format {
3755 ChainedSequenceContextFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
3756 ChainedSequenceContextFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
3757 ChainedSequenceContextFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
3758 ChainedSequenceContextFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
3759 ChainedSequenceContextFormat5::FORMAT => Ok(Self::Format5(FontRead::read(data)?)),
3760 other => Err(ReadError::InvalidFormat(other.into())),
3761 }
3762 }
3763}
3764
3765impl<'a> MinByteRange<'a> for ChainedSequenceContext<'a> {
3766 fn min_byte_range(&self) -> Range<usize> {
3767 match self {
3768 Self::Format1(item) => item.min_byte_range(),
3769 Self::Format2(item) => item.min_byte_range(),
3770 Self::Format3(item) => item.min_byte_range(),
3771 Self::Format4(item) => item.min_byte_range(),
3772 Self::Format5(item) => item.min_byte_range(),
3773 }
3774 }
3775 fn min_table_bytes(&self) -> &'a [u8] {
3776 match self {
3777 Self::Format1(item) => item.min_table_bytes(),
3778 Self::Format2(item) => item.min_table_bytes(),
3779 Self::Format3(item) => item.min_table_bytes(),
3780 Self::Format4(item) => item.min_table_bytes(),
3781 Self::Format5(item) => item.min_table_bytes(),
3782 }
3783 }
3784}
3785
3786#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
3789#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3790#[repr(u16)]
3791#[allow(clippy::manual_non_exhaustive)]
3792pub enum DeltaFormat {
3793 #[default]
3795 Local2BitDeltas = 0x0001,
3796 Local4BitDeltas = 0x0002,
3798 Local8BitDeltas = 0x0003,
3800 VariationIndex = 0x8000,
3802 #[doc(hidden)]
3803 Unknown,
3805}
3806
3807impl DeltaFormat {
3808 pub fn new(raw: u16) -> Self {
3812 match raw {
3813 0x0001 => Self::Local2BitDeltas,
3814 0x0002 => Self::Local4BitDeltas,
3815 0x0003 => Self::Local8BitDeltas,
3816 0x8000 => Self::VariationIndex,
3817 _ => Self::Unknown,
3818 }
3819 }
3820}
3821
3822impl font_types::Scalar for DeltaFormat {
3823 type Raw = <u16 as font_types::Scalar>::Raw;
3824 fn to_raw(self) -> Self::Raw {
3825 (self as u16).to_raw()
3826 }
3827 fn from_raw(raw: Self::Raw) -> Self {
3828 let t = <u16>::from_raw(raw);
3829 Self::new(t)
3830 }
3831}
3832
3833impl<'a> MinByteRange<'a> for Device<'a> {
3834 fn min_byte_range(&self) -> Range<usize> {
3835 0..self.delta_value_byte_range().end
3836 }
3837 fn min_table_bytes(&self) -> &'a [u8] {
3838 let range = self.min_byte_range();
3839 self.offset_data().as_bytes().get(range).unwrap_or_default()
3840 }
3841}
3842
3843impl ReadArgs for Device<'_> {
3844 type Args = ();
3845}
3846
3847impl<'a> FontRead<'a> for Device<'a> {
3848 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3849 #[allow(clippy::absurd_extreme_comparisons)]
3850 if data.len() < Self::MIN_SIZE {
3851 return Err(ReadError::OutOfBounds);
3852 }
3853 let Some(data) = TableDataRef::new(data.as_bytes()) else {
3854 return Err(ReadError::OutOfBounds);
3855 };
3856 Ok(Self { data })
3857 }
3858}
3859
3860#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3862#[repr(C, packed)]
3863#[doc(hidden)]
3864pub struct DeviceFixedHeader {
3865 pub start_size: BigEndian<u16>,
3866 pub end_size: BigEndian<u16>,
3867 pub delta_format: BigEndian<DeltaFormat>,
3868}
3869
3870#[allow(clippy::absurd_extreme_comparisons)]
3871const _: () = assert!(std::mem::size_of::<DeviceFixedHeader>() <= Device::MIN_SIZE);
3872
3873#[derive(Clone)]
3875pub struct Device<'a> {
3876 data: TableDataRef<'a, DeviceFixedHeader>,
3877}
3878
3879#[allow(clippy::needless_lifetimes)]
3880impl<'a> Device<'a> {
3881 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + DeltaFormat::RAW_BYTE_LEN);
3882 basic_table_impls!(impl_the_methods);
3883
3884 pub fn start_size(&self) -> u16 {
3886 self.data.header().start_size.get()
3887 }
3888
3889 pub fn end_size(&self) -> u16 {
3891 self.data.header().end_size.get()
3892 }
3893
3894 pub fn delta_format(&self) -> DeltaFormat {
3896 self.data.header().delta_format.get()
3897 }
3898
3899 pub fn delta_value(&self) -> &'a [BigEndian<u16>] {
3901 let range = self.delta_value_byte_range();
3902 self.offset_data()
3903 .read_array(range)
3904 .ok()
3905 .unwrap_or_default()
3906 }
3907
3908 pub fn start_size_byte_range(&self) -> Range<usize> {
3909 let start = 0usize;
3910 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3911 start..end
3912 }
3913
3914 pub fn end_size_byte_range(&self) -> Range<usize> {
3915 let start = self.start_size_byte_range().end;
3916 let end = start.saturating_add(u16::RAW_BYTE_LEN);
3917 start..end
3918 }
3919
3920 pub fn delta_format_byte_range(&self) -> Range<usize> {
3921 let start = self.end_size_byte_range().end;
3922 let end = start.saturating_add(DeltaFormat::RAW_BYTE_LEN);
3923 start..end
3924 }
3925
3926 pub fn delta_value_byte_range(&self) -> Range<usize> {
3927 let delta_format = self.delta_format();
3928 let start_size = self.start_size();
3929 let end_size = self.end_size();
3930 let start = self.delta_format_byte_range().end;
3931 let end = start.saturating_add(
3932 (DeltaFormat::value_count(delta_format, start_size, end_size))
3933 .saturating_mul(u16::RAW_BYTE_LEN),
3934 );
3935 start..end
3936 }
3937}
3938
3939const _: () = assert!(FontData::default_data_long_enough(Device::MIN_SIZE));
3940
3941impl Default for Device<'_> {
3942 fn default() -> Self {
3943 Self {
3944 data: TableDataRef::new(FontData::default_table_data().as_bytes())
3945 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
3946 }
3947 }
3948}
3949
3950impl<'a> MinByteRange<'a> for VariationIndex<'a> {
3951 fn min_byte_range(&self) -> Range<usize> {
3952 0..self.delta_format_byte_range().end
3953 }
3954 fn min_table_bytes(&self) -> &'a [u8] {
3955 let range = self.min_byte_range();
3956 self.offset_data().as_bytes().get(range).unwrap_or_default()
3957 }
3958}
3959
3960impl ReadArgs for VariationIndex<'_> {
3961 type Args = ();
3962}
3963
3964impl<'a> FontRead<'a> for VariationIndex<'a> {
3965 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3966 #[allow(clippy::absurd_extreme_comparisons)]
3967 if data.len() < Self::MIN_SIZE {
3968 return Err(ReadError::OutOfBounds);
3969 }
3970 let Some(data) = TableDataRef::new(data.as_bytes()) else {
3971 return Err(ReadError::OutOfBounds);
3972 };
3973 Ok(Self { data })
3974 }
3975}
3976
3977#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3979#[repr(C, packed)]
3980#[doc(hidden)]
3981pub struct VariationIndexFixedHeader {
3982 pub delta_set_outer_index: BigEndian<u16>,
3983 pub delta_set_inner_index: BigEndian<u16>,
3984 pub delta_format: BigEndian<DeltaFormat>,
3985}
3986
3987#[allow(clippy::absurd_extreme_comparisons)]
3988const _: () = assert!(std::mem::size_of::<VariationIndexFixedHeader>() <= VariationIndex::MIN_SIZE);
3989
3990#[derive(Clone)]
3992pub struct VariationIndex<'a> {
3993 data: TableDataRef<'a, VariationIndexFixedHeader>,
3994}
3995
3996#[allow(clippy::needless_lifetimes)]
3997impl<'a> VariationIndex<'a> {
3998 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + DeltaFormat::RAW_BYTE_LEN);
3999 basic_table_impls!(impl_the_methods);
4000
4001 pub fn delta_set_outer_index(&self) -> u16 {
4004 self.data.header().delta_set_outer_index.get()
4005 }
4006
4007 pub fn delta_set_inner_index(&self) -> u16 {
4010 self.data.header().delta_set_inner_index.get()
4011 }
4012
4013 pub fn delta_format(&self) -> DeltaFormat {
4015 self.data.header().delta_format.get()
4016 }
4017
4018 pub fn delta_set_outer_index_byte_range(&self) -> Range<usize> {
4019 let start = 0usize;
4020 let end = start.saturating_add(u16::RAW_BYTE_LEN);
4021 start..end
4022 }
4023
4024 pub fn delta_set_inner_index_byte_range(&self) -> Range<usize> {
4025 let start = self.delta_set_outer_index_byte_range().end;
4026 let end = start.saturating_add(u16::RAW_BYTE_LEN);
4027 start..end
4028 }
4029
4030 pub fn delta_format_byte_range(&self) -> Range<usize> {
4031 let start = self.delta_set_inner_index_byte_range().end;
4032 let end = start.saturating_add(DeltaFormat::RAW_BYTE_LEN);
4033 start..end
4034 }
4035}
4036
4037const _: () = assert!(FontData::default_data_long_enough(VariationIndex::MIN_SIZE));
4038
4039impl Default for VariationIndex<'_> {
4040 fn default() -> Self {
4041 Self {
4042 data: TableDataRef::new(FontData::default_table_data().as_bytes())
4043 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
4044 }
4045 }
4046}
4047
4048#[derive(Clone)]
4050pub enum DeviceOrVariationIndex<'a> {
4051 Device(Device<'a>),
4052 VariationIndex(VariationIndex<'a>),
4053}
4054
4055impl Default for DeviceOrVariationIndex<'_> {
4056 fn default() -> Self {
4057 Self::Device(Default::default())
4058 }
4059}
4060
4061impl<'a> DeviceOrVariationIndex<'a> {
4062 pub fn offset_data(&self) -> FontData<'a> {
4064 match self {
4065 Self::Device(item) => item.offset_data(),
4066 Self::VariationIndex(item) => item.offset_data(),
4067 }
4068 }
4069}
4070
4071impl ReadArgs for DeviceOrVariationIndex<'_> {
4072 type Args = ();
4073}
4074
4075impl<'a> FontRead<'a> for DeviceOrVariationIndex<'a> {
4076 #[inline]
4077 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4078 let format: DeltaFormat = data.read_at(4usize)?;
4079
4080 #[allow(clippy::redundant_guards)]
4081 match format {
4082 format if format != DeltaFormat::VariationIndex => {
4083 Ok(Self::Device(FontRead::read(data)?))
4084 }
4085 format if format == DeltaFormat::VariationIndex => {
4086 Ok(Self::VariationIndex(FontRead::read(data)?))
4087 }
4088 other => Err(ReadError::InvalidFormat(other.into())),
4089 }
4090 }
4091}
4092
4093impl<'a> MinByteRange<'a> for DeviceOrVariationIndex<'a> {
4094 fn min_byte_range(&self) -> Range<usize> {
4095 match self {
4096 Self::Device(item) => item.min_byte_range(),
4097 Self::VariationIndex(item) => item.min_byte_range(),
4098 }
4099 }
4100 fn min_table_bytes(&self) -> &'a [u8] {
4101 match self {
4102 Self::Device(item) => item.min_table_bytes(),
4103 Self::VariationIndex(item) => item.min_table_bytes(),
4104 }
4105 }
4106}
4107
4108impl<'a> MinByteRange<'a> for FeatureVariations<'a> {
4109 fn min_byte_range(&self) -> Range<usize> {
4110 0..self.feature_variation_records_byte_range().end
4111 }
4112 fn min_table_bytes(&self) -> &'a [u8] {
4113 let range = self.min_byte_range();
4114 self.offset_data().as_bytes().get(range).unwrap_or_default()
4115 }
4116}
4117
4118impl ReadArgs for FeatureVariations<'_> {
4119 type Args = ();
4120}
4121
4122impl<'a> FontRead<'a> for FeatureVariations<'a> {
4123 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4124 #[allow(clippy::absurd_extreme_comparisons)]
4125 if data.len() < Self::MIN_SIZE {
4126 return Err(ReadError::OutOfBounds);
4127 }
4128 let Some(data) = TableDataRef::new(data.as_bytes()) else {
4129 return Err(ReadError::OutOfBounds);
4130 };
4131 Ok(Self { data })
4132 }
4133}
4134
4135#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4137#[repr(C, packed)]
4138#[doc(hidden)]
4139pub struct FeatureVariationsFixedHeader {
4140 pub version: BigEndian<MajorMinor>,
4141 pub feature_variation_record_count: BigEndian<u32>,
4142}
4143
4144#[allow(clippy::absurd_extreme_comparisons)]
4145const _: () =
4146 assert!(std::mem::size_of::<FeatureVariationsFixedHeader>() <= FeatureVariations::MIN_SIZE);
4147
4148#[derive(Clone)]
4151pub struct FeatureVariations<'a> {
4152 data: TableDataRef<'a, FeatureVariationsFixedHeader>,
4153}
4154
4155#[allow(clippy::needless_lifetimes)]
4156impl<'a> FeatureVariations<'a> {
4157 pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
4158 basic_table_impls!(impl_the_methods);
4159
4160 pub fn version(&self) -> MajorMinor {
4161 self.data.header().version.get()
4162 }
4163
4164 pub fn feature_variation_record_count(&self) -> u32 {
4166 self.data.header().feature_variation_record_count.get()
4167 }
4168
4169 pub fn feature_variation_records(&self) -> &'a [FeatureVariationRecord] {
4171 let range = self.feature_variation_records_byte_range();
4172 self.offset_data()
4173 .read_array(range)
4174 .ok()
4175 .unwrap_or_default()
4176 }
4177
4178 pub fn lookup_variation_record_count(&self) -> Option<u32> {
4180 let range = self.lookup_variation_record_count_byte_range();
4181 (!range.is_empty())
4182 .then(|| self.offset_data().read_at(range.start).ok())
4183 .flatten()
4184 }
4185
4186 pub fn version_byte_range(&self) -> Range<usize> {
4187 let start = 0usize;
4188 let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
4189 start..end
4190 }
4191
4192 pub fn feature_variation_record_count_byte_range(&self) -> Range<usize> {
4193 let start = self.version_byte_range().end;
4194 let end = start.saturating_add(u32::RAW_BYTE_LEN);
4195 start..end
4196 }
4197
4198 pub fn feature_variation_records_byte_range(&self) -> Range<usize> {
4199 let feature_variation_record_count = self.feature_variation_record_count();
4200 let start = self.feature_variation_record_count_byte_range().end;
4201 let end = start.saturating_add(
4202 (transforms::to_usize(feature_variation_record_count))
4203 .saturating_mul(FeatureVariationRecord::RAW_BYTE_LEN),
4204 );
4205 start..end
4206 }
4207
4208 pub fn lookup_variation_record_count_byte_range(&self) -> Range<usize> {
4209 let start = self.feature_variation_records_byte_range().end;
4210 let end = if self.version().compatible((1u16, 1u16)) {
4211 start.saturating_add(u32::RAW_BYTE_LEN)
4212 } else {
4213 start
4214 };
4215 start..end
4216 }
4217
4218 pub fn lookup_variation_records_byte_range(&self) -> Range<usize> {
4219 let lookup_variation_record_count =
4220 self.lookup_variation_record_count().unwrap_or_default();
4221 let start = self.lookup_variation_record_count_byte_range().end;
4222 let end = if self.version().compatible((1u16, 1u16)) {
4223 start.saturating_add(
4224 (transforms::to_usize(lookup_variation_record_count))
4225 .saturating_mul(LookupVariationRecord::RAW_BYTE_LEN),
4226 )
4227 } else {
4228 start
4229 };
4230 start..end
4231 }
4232}
4233
4234const _: () = assert!(FontData::default_data_long_enough(
4235 FeatureVariations::MIN_SIZE
4236));
4237
4238impl Default for FeatureVariations<'_> {
4239 fn default() -> Self {
4240 Self {
4241 data: TableDataRef::new(FontData::default_table_data().as_bytes())
4242 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
4243 }
4244 }
4245}
4246
4247#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
4249#[repr(C)]
4250#[repr(packed)]
4251pub struct FeatureVariationRecord {
4252 pub condition_set_offset: BigEndian<Nullable<Offset32>>,
4255 pub feature_table_substitution_offset: BigEndian<Nullable<Offset32>>,
4258}
4259
4260impl FeatureVariationRecord {
4261 pub fn condition_set_offset(&self) -> Nullable<Offset32> {
4264 self.condition_set_offset.get()
4265 }
4266
4267 pub fn condition_set<'a>(
4273 &self,
4274 data: FontData<'a>,
4275 ) -> Option<Result<ConditionSet<'a>, ReadError>> {
4276 self.condition_set_offset().resolve(data)
4277 }
4278
4279 pub fn feature_table_substitution_offset(&self) -> Nullable<Offset32> {
4282 self.feature_table_substitution_offset.get()
4283 }
4284
4285 pub fn feature_table_substitution<'a>(
4291 &self,
4292 data: FontData<'a>,
4293 ) -> Option<Result<FeatureTableSubstitution<'a>, ReadError>> {
4294 self.feature_table_substitution_offset().resolve(data)
4295 }
4296}
4297
4298impl FixedSize for FeatureVariationRecord {
4299 const RAW_BYTE_LEN: usize = Offset32::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
4300}
4301
4302#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
4304#[repr(C)]
4305#[repr(packed)]
4306pub struct LookupVariationRecord {
4307 pub feature_index: BigEndian<u16>,
4308 pub feature_lookups_offset: BigEndian<Offset32>,
4310}
4311
4312impl LookupVariationRecord {
4313 pub fn feature_index(&self) -> u16 {
4314 self.feature_index.get()
4315 }
4316
4317 pub fn feature_lookups_offset(&self) -> Offset32 {
4319 self.feature_lookups_offset.get()
4320 }
4321
4322 pub fn feature_lookups<'a>(&self, data: FontData<'a>) -> Result<FeatureLookups<'a>, ReadError> {
4327 self.feature_lookups_offset().resolve(data)
4328 }
4329}
4330
4331impl FixedSize for LookupVariationRecord {
4332 const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
4333}
4334
4335impl<'a> MinByteRange<'a> for FeatureLookups<'a> {
4336 fn min_byte_range(&self) -> Range<usize> {
4337 0..self.lookup_condition_records_byte_range().end
4338 }
4339 fn min_table_bytes(&self) -> &'a [u8] {
4340 let range = self.min_byte_range();
4341 self.offset_data().as_bytes().get(range).unwrap_or_default()
4342 }
4343}
4344
4345impl ReadArgs for FeatureLookups<'_> {
4346 type Args = ();
4347}
4348
4349impl<'a> FontRead<'a> for FeatureLookups<'a> {
4350 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4351 #[allow(clippy::absurd_extreme_comparisons)]
4352 if data.len() < Self::MIN_SIZE {
4353 return Err(ReadError::OutOfBounds);
4354 }
4355 let Some(data) = TableDataRef::new(data.as_bytes()) else {
4356 return Err(ReadError::OutOfBounds);
4357 };
4358 Ok(Self { data })
4359 }
4360}
4361
4362#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4364#[repr(C, packed)]
4365#[doc(hidden)]
4366pub struct FeatureLookupsFixedHeader {
4367 pub version: BigEndian<MajorMinor>,
4368 pub flags: BigEndian<FeatureLookupsFlags>,
4369 pub lookup_condition_count: BigEndian<u32>,
4370}
4371
4372#[allow(clippy::absurd_extreme_comparisons)]
4373const _: () = assert!(std::mem::size_of::<FeatureLookupsFixedHeader>() <= FeatureLookups::MIN_SIZE);
4374
4375#[derive(Clone)]
4377pub struct FeatureLookups<'a> {
4378 data: TableDataRef<'a, FeatureLookupsFixedHeader>,
4379}
4380
4381#[allow(clippy::needless_lifetimes)]
4382impl<'a> FeatureLookups<'a> {
4383 pub const MIN_SIZE: usize =
4384 (MajorMinor::RAW_BYTE_LEN + FeatureLookupsFlags::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
4385 basic_table_impls!(impl_the_methods);
4386
4387 pub fn version(&self) -> MajorMinor {
4388 self.data.header().version.get()
4389 }
4390
4391 pub fn flags(&self) -> FeatureLookupsFlags {
4392 self.data.header().flags.get()
4393 }
4394
4395 pub fn lookup_condition_count(&self) -> u32 {
4396 self.data.header().lookup_condition_count.get()
4397 }
4398
4399 pub fn lookup_condition_records(&self) -> &'a [LookupConditionRecord] {
4400 let range = self.lookup_condition_records_byte_range();
4401 self.offset_data()
4402 .read_array(range)
4403 .ok()
4404 .unwrap_or_default()
4405 }
4406
4407 pub fn version_byte_range(&self) -> Range<usize> {
4408 let start = 0usize;
4409 let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
4410 start..end
4411 }
4412
4413 pub fn flags_byte_range(&self) -> Range<usize> {
4414 let start = self.version_byte_range().end;
4415 let end = start.saturating_add(FeatureLookupsFlags::RAW_BYTE_LEN);
4416 start..end
4417 }
4418
4419 pub fn lookup_condition_count_byte_range(&self) -> Range<usize> {
4420 let start = self.flags_byte_range().end;
4421 let end = start.saturating_add(u32::RAW_BYTE_LEN);
4422 start..end
4423 }
4424
4425 pub fn lookup_condition_records_byte_range(&self) -> Range<usize> {
4426 let lookup_condition_count = self.lookup_condition_count();
4427 let start = self.lookup_condition_count_byte_range().end;
4428 let end = start.saturating_add(
4429 (transforms::to_usize(lookup_condition_count))
4430 .saturating_mul(LookupConditionRecord::RAW_BYTE_LEN),
4431 );
4432 start..end
4433 }
4434}
4435
4436const _: () = assert!(FontData::default_data_long_enough(FeatureLookups::MIN_SIZE));
4437
4438impl Default for FeatureLookups<'_> {
4439 fn default() -> Self {
4440 Self {
4441 data: TableDataRef::new(FontData::default_table_data().as_bytes())
4442 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
4443 }
4444 }
4445}
4446
4447#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
4449#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4450#[repr(transparent)]
4451pub struct FeatureLookupsFlags {
4452 bits: u16,
4453}
4454
4455impl FeatureLookupsFlags {
4456 pub const ADD_DEFAULT_LOOKUPS: Self = Self { bits: 0x0001 };
4458}
4459
4460impl FeatureLookupsFlags {
4461 #[inline]
4463 pub const fn empty() -> Self {
4464 Self { bits: 0 }
4465 }
4466
4467 #[inline]
4469 pub const fn all() -> Self {
4470 Self {
4471 bits: Self::ADD_DEFAULT_LOOKUPS.bits,
4472 }
4473 }
4474
4475 #[inline]
4477 pub const fn bits(&self) -> u16 {
4478 self.bits
4479 }
4480
4481 #[inline]
4484 pub const fn from_bits(bits: u16) -> Option<Self> {
4485 if (bits & !Self::all().bits()) == 0 {
4486 Some(Self { bits })
4487 } else {
4488 None
4489 }
4490 }
4491
4492 #[inline]
4495 pub const fn from_bits_truncate(bits: u16) -> Self {
4496 Self {
4497 bits: bits & Self::all().bits,
4498 }
4499 }
4500
4501 #[inline]
4503 pub const fn is_empty(&self) -> bool {
4504 self.bits() == Self::empty().bits()
4505 }
4506
4507 #[inline]
4509 pub const fn intersects(&self, other: Self) -> bool {
4510 !(Self {
4511 bits: self.bits & other.bits,
4512 })
4513 .is_empty()
4514 }
4515
4516 #[inline]
4518 pub const fn contains(&self, other: Self) -> bool {
4519 (self.bits & other.bits) == other.bits
4520 }
4521
4522 #[inline]
4524 pub fn insert(&mut self, other: Self) {
4525 self.bits |= other.bits;
4526 }
4527
4528 #[inline]
4530 pub fn remove(&mut self, other: Self) {
4531 self.bits &= !other.bits;
4532 }
4533
4534 #[inline]
4536 pub fn toggle(&mut self, other: Self) {
4537 self.bits ^= other.bits;
4538 }
4539
4540 #[inline]
4551 #[must_use]
4552 pub const fn intersection(self, other: Self) -> Self {
4553 Self {
4554 bits: self.bits & other.bits,
4555 }
4556 }
4557
4558 #[inline]
4569 #[must_use]
4570 pub const fn union(self, other: Self) -> Self {
4571 Self {
4572 bits: self.bits | other.bits,
4573 }
4574 }
4575
4576 #[inline]
4589 #[must_use]
4590 pub const fn difference(self, other: Self) -> Self {
4591 Self {
4592 bits: self.bits & !other.bits,
4593 }
4594 }
4595}
4596
4597impl std::ops::BitOr for FeatureLookupsFlags {
4598 type Output = Self;
4599
4600 #[inline]
4602 fn bitor(self, other: FeatureLookupsFlags) -> Self {
4603 Self {
4604 bits: self.bits | other.bits,
4605 }
4606 }
4607}
4608
4609impl std::ops::BitOrAssign for FeatureLookupsFlags {
4610 #[inline]
4612 fn bitor_assign(&mut self, other: Self) {
4613 self.bits |= other.bits;
4614 }
4615}
4616
4617impl std::ops::BitXor for FeatureLookupsFlags {
4618 type Output = Self;
4619
4620 #[inline]
4622 fn bitxor(self, other: Self) -> Self {
4623 Self {
4624 bits: self.bits ^ other.bits,
4625 }
4626 }
4627}
4628
4629impl std::ops::BitXorAssign for FeatureLookupsFlags {
4630 #[inline]
4632 fn bitxor_assign(&mut self, other: Self) {
4633 self.bits ^= other.bits;
4634 }
4635}
4636
4637impl std::ops::BitAnd for FeatureLookupsFlags {
4638 type Output = Self;
4639
4640 #[inline]
4642 fn bitand(self, other: Self) -> Self {
4643 Self {
4644 bits: self.bits & other.bits,
4645 }
4646 }
4647}
4648
4649impl std::ops::BitAndAssign for FeatureLookupsFlags {
4650 #[inline]
4652 fn bitand_assign(&mut self, other: Self) {
4653 self.bits &= other.bits;
4654 }
4655}
4656
4657impl std::ops::Sub for FeatureLookupsFlags {
4658 type Output = Self;
4659
4660 #[inline]
4662 fn sub(self, other: Self) -> Self {
4663 Self {
4664 bits: self.bits & !other.bits,
4665 }
4666 }
4667}
4668
4669impl std::ops::SubAssign for FeatureLookupsFlags {
4670 #[inline]
4672 fn sub_assign(&mut self, other: Self) {
4673 self.bits &= !other.bits;
4674 }
4675}
4676
4677impl std::ops::Not for FeatureLookupsFlags {
4678 type Output = Self;
4679
4680 #[inline]
4682 fn not(self) -> Self {
4683 Self { bits: !self.bits } & Self::all()
4684 }
4685}
4686
4687impl std::fmt::Debug for FeatureLookupsFlags {
4688 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4689 let members: &[(&str, Self)] = &[("ADD_DEFAULT_LOOKUPS", Self::ADD_DEFAULT_LOOKUPS)];
4690 let mut first = true;
4691 for (name, value) in members {
4692 if self.contains(*value) {
4693 if !first {
4694 f.write_str(" | ")?;
4695 }
4696 first = false;
4697 f.write_str(name)?;
4698 }
4699 }
4700 if first {
4701 f.write_str("(empty)")?;
4702 }
4703 Ok(())
4704 }
4705}
4706
4707impl std::fmt::Binary for FeatureLookupsFlags {
4708 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4709 std::fmt::Binary::fmt(&self.bits, f)
4710 }
4711}
4712
4713impl std::fmt::Octal for FeatureLookupsFlags {
4714 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4715 std::fmt::Octal::fmt(&self.bits, f)
4716 }
4717}
4718
4719impl std::fmt::LowerHex for FeatureLookupsFlags {
4720 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4721 std::fmt::LowerHex::fmt(&self.bits, f)
4722 }
4723}
4724
4725impl std::fmt::UpperHex for FeatureLookupsFlags {
4726 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4727 std::fmt::UpperHex::fmt(&self.bits, f)
4728 }
4729}
4730
4731impl font_types::Scalar for FeatureLookupsFlags {
4732 type Raw = <u16 as font_types::Scalar>::Raw;
4733 fn to_raw(self) -> Self::Raw {
4734 self.bits().to_raw()
4735 }
4736 fn from_raw(raw: Self::Raw) -> Self {
4737 let t = <u16>::from_raw(raw);
4738 Self::from_bits_truncate(t)
4739 }
4740}
4741
4742#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
4744#[repr(C)]
4745#[repr(packed)]
4746pub struct LookupConditionRecord {
4747 pub condition_offset: BigEndian<Nullable<Offset32>>,
4749 pub lookup_index_list_offset: BigEndian<Offset32>,
4751}
4752
4753impl LookupConditionRecord {
4754 pub fn condition_offset(&self) -> Nullable<Offset32> {
4756 self.condition_offset.get()
4757 }
4758
4759 pub fn condition<'a>(&self, data: FontData<'a>) -> Option<Result<Condition<'a>, ReadError>> {
4764 self.condition_offset().resolve(data)
4765 }
4766
4767 pub fn lookup_index_list_offset(&self) -> Offset32 {
4769 self.lookup_index_list_offset.get()
4770 }
4771
4772 pub fn lookup_index_list<'a>(
4777 &self,
4778 data: FontData<'a>,
4779 ) -> Result<LookupIndexList<'a>, ReadError> {
4780 self.lookup_index_list_offset().resolve(data)
4781 }
4782}
4783
4784impl FixedSize for LookupConditionRecord {
4785 const RAW_BYTE_LEN: usize = Offset32::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
4786}
4787
4788impl<'a> MinByteRange<'a> for LookupIndexList<'a> {
4789 fn min_byte_range(&self) -> Range<usize> {
4790 0..self.lookup_indices_byte_range().end
4791 }
4792 fn min_table_bytes(&self) -> &'a [u8] {
4793 let range = self.min_byte_range();
4794 self.offset_data().as_bytes().get(range).unwrap_or_default()
4795 }
4796}
4797
4798impl ReadArgs for LookupIndexList<'_> {
4799 type Args = ();
4800}
4801
4802impl<'a> FontRead<'a> for LookupIndexList<'a> {
4803 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4804 #[allow(clippy::absurd_extreme_comparisons)]
4805 if data.len() < Self::MIN_SIZE {
4806 return Err(ReadError::OutOfBounds);
4807 }
4808 let Some(data) = TableDataRef::new(data.as_bytes()) else {
4809 return Err(ReadError::OutOfBounds);
4810 };
4811 Ok(Self { data })
4812 }
4813}
4814
4815#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4817#[repr(C, packed)]
4818#[doc(hidden)]
4819pub struct LookupIndexListFixedHeader {
4820 pub lookup_index_count: BigEndian<u16>,
4821}
4822
4823#[allow(clippy::absurd_extreme_comparisons)]
4824const _: () =
4825 assert!(std::mem::size_of::<LookupIndexListFixedHeader>() <= LookupIndexList::MIN_SIZE);
4826
4827#[derive(Clone)]
4829pub struct LookupIndexList<'a> {
4830 data: TableDataRef<'a, LookupIndexListFixedHeader>,
4831}
4832
4833#[allow(clippy::needless_lifetimes)]
4834impl<'a> LookupIndexList<'a> {
4835 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
4836 basic_table_impls!(impl_the_methods);
4837
4838 pub fn lookup_index_count(&self) -> u16 {
4839 self.data.header().lookup_index_count.get()
4840 }
4841
4842 pub fn lookup_indices(&self) -> &'a [BigEndian<u16>] {
4843 let range = self.lookup_indices_byte_range();
4844 self.offset_data()
4845 .read_array(range)
4846 .ok()
4847 .unwrap_or_default()
4848 }
4849
4850 pub fn lookup_index_count_byte_range(&self) -> Range<usize> {
4851 let start = 0usize;
4852 let end = start.saturating_add(u16::RAW_BYTE_LEN);
4853 start..end
4854 }
4855
4856 pub fn lookup_indices_byte_range(&self) -> Range<usize> {
4857 let lookup_index_count = self.lookup_index_count();
4858 let start = self.lookup_index_count_byte_range().end;
4859 let end = start.saturating_add(
4860 (transforms::to_usize(lookup_index_count)).saturating_mul(u16::RAW_BYTE_LEN),
4861 );
4862 start..end
4863 }
4864}
4865
4866const _: () = assert!(FontData::default_data_long_enough(
4867 LookupIndexList::MIN_SIZE
4868));
4869
4870impl Default for LookupIndexList<'_> {
4871 fn default() -> Self {
4872 Self {
4873 data: TableDataRef::new(FontData::default_table_data().as_bytes())
4874 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
4875 }
4876 }
4877}
4878
4879impl<'a> MinByteRange<'a> for ConditionSet<'a> {
4880 fn min_byte_range(&self) -> Range<usize> {
4881 0..self.condition_offsets_byte_range().end
4882 }
4883 fn min_table_bytes(&self) -> &'a [u8] {
4884 let range = self.min_byte_range();
4885 self.offset_data().as_bytes().get(range).unwrap_or_default()
4886 }
4887}
4888
4889impl ReadArgs for ConditionSet<'_> {
4890 type Args = ();
4891}
4892
4893impl<'a> FontRead<'a> for ConditionSet<'a> {
4894 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4895 #[allow(clippy::absurd_extreme_comparisons)]
4896 if data.len() < Self::MIN_SIZE {
4897 return Err(ReadError::OutOfBounds);
4898 }
4899 let Some(data) = TableDataRef::new(data.as_bytes()) else {
4900 return Err(ReadError::OutOfBounds);
4901 };
4902 Ok(Self { data })
4903 }
4904}
4905
4906#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4908#[repr(C, packed)]
4909#[doc(hidden)]
4910pub struct ConditionSetFixedHeader {
4911 pub condition_count: BigEndian<u16>,
4912}
4913
4914#[allow(clippy::absurd_extreme_comparisons)]
4915const _: () = assert!(std::mem::size_of::<ConditionSetFixedHeader>() <= ConditionSet::MIN_SIZE);
4916
4917#[derive(Clone)]
4919pub struct ConditionSet<'a> {
4920 data: TableDataRef<'a, ConditionSetFixedHeader>,
4921}
4922
4923#[allow(clippy::needless_lifetimes)]
4924impl<'a> ConditionSet<'a> {
4925 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
4926 basic_table_impls!(impl_the_methods);
4927
4928 pub fn condition_count(&self) -> u16 {
4930 self.data.header().condition_count.get()
4931 }
4932
4933 pub fn condition_offsets(&self) -> &'a [BigEndian<Offset32>] {
4936 let range = self.condition_offsets_byte_range();
4937 self.offset_data()
4938 .read_array(range)
4939 .ok()
4940 .unwrap_or_default()
4941 }
4942
4943 pub fn conditions(&self) -> ArrayOfOffsets<'a, Condition<'a>, Offset32> {
4945 let data = self.offset_data();
4946 let offsets = self.condition_offsets();
4947 ArrayOfOffsets::new(offsets, data, ())
4948 }
4949
4950 pub fn condition_count_byte_range(&self) -> Range<usize> {
4951 let start = 0usize;
4952 let end = start.saturating_add(u16::RAW_BYTE_LEN);
4953 start..end
4954 }
4955
4956 pub fn condition_offsets_byte_range(&self) -> Range<usize> {
4957 let condition_count = self.condition_count();
4958 let start = self.condition_count_byte_range().end;
4959 let end = start.saturating_add(
4960 (transforms::to_usize(condition_count)).saturating_mul(Offset32::RAW_BYTE_LEN),
4961 );
4962 start..end
4963 }
4964}
4965
4966const _: () = assert!(FontData::default_data_long_enough(ConditionSet::MIN_SIZE));
4967
4968impl Default for ConditionSet<'_> {
4969 fn default() -> Self {
4970 Self {
4971 data: TableDataRef::new(FontData::default_table_data().as_bytes())
4972 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
4973 }
4974 }
4975}
4976
4977#[derive(Clone)]
4981pub enum Condition<'a> {
4982 Format1AxisRange(ConditionFormat1<'a>),
4983 Format2VariableValue(ConditionFormat2<'a>),
4984 Format3And(ConditionFormat3<'a>),
4985 Format4Or(ConditionFormat4<'a>),
4986 Format5Negate(ConditionFormat5<'a>),
4987}
4988
4989impl Default for Condition<'_> {
4990 fn default() -> Self {
4991 Self::Format1AxisRange(Default::default())
4992 }
4993}
4994
4995impl<'a> Condition<'a> {
4996 pub fn offset_data(&self) -> FontData<'a> {
4998 match self {
4999 Self::Format1AxisRange(item) => item.offset_data(),
5000 Self::Format2VariableValue(item) => item.offset_data(),
5001 Self::Format3And(item) => item.offset_data(),
5002 Self::Format4Or(item) => item.offset_data(),
5003 Self::Format5Negate(item) => item.offset_data(),
5004 }
5005 }
5006
5007 pub fn format(&self) -> u16 {
5009 match self {
5010 Self::Format1AxisRange(item) => item.format(),
5011 Self::Format2VariableValue(item) => item.format(),
5012 Self::Format3And(item) => item.format(),
5013 Self::Format4Or(item) => item.format(),
5014 Self::Format5Negate(item) => item.format(),
5015 }
5016 }
5017}
5018
5019impl ReadArgs for Condition<'_> {
5020 type Args = ();
5021}
5022
5023impl<'a> FontRead<'a> for Condition<'a> {
5024 #[inline]
5025 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5026 let format: u16 = data.read_at(0usize)?;
5027 match format {
5028 ConditionFormat1::FORMAT => Ok(Self::Format1AxisRange(FontRead::read(data)?)),
5029 ConditionFormat2::FORMAT => Ok(Self::Format2VariableValue(FontRead::read(data)?)),
5030 ConditionFormat3::FORMAT => Ok(Self::Format3And(FontRead::read(data)?)),
5031 ConditionFormat4::FORMAT => Ok(Self::Format4Or(FontRead::read(data)?)),
5032 ConditionFormat5::FORMAT => Ok(Self::Format5Negate(FontRead::read(data)?)),
5033 other => Err(ReadError::InvalidFormat(other.into())),
5034 }
5035 }
5036}
5037
5038impl<'a> MinByteRange<'a> for Condition<'a> {
5039 fn min_byte_range(&self) -> Range<usize> {
5040 match self {
5041 Self::Format1AxisRange(item) => item.min_byte_range(),
5042 Self::Format2VariableValue(item) => item.min_byte_range(),
5043 Self::Format3And(item) => item.min_byte_range(),
5044 Self::Format4Or(item) => item.min_byte_range(),
5045 Self::Format5Negate(item) => item.min_byte_range(),
5046 }
5047 }
5048 fn min_table_bytes(&self) -> &'a [u8] {
5049 match self {
5050 Self::Format1AxisRange(item) => item.min_table_bytes(),
5051 Self::Format2VariableValue(item) => item.min_table_bytes(),
5052 Self::Format3And(item) => item.min_table_bytes(),
5053 Self::Format4Or(item) => item.min_table_bytes(),
5054 Self::Format5Negate(item) => item.min_table_bytes(),
5055 }
5056 }
5057}
5058
5059impl Format<u16> for ConditionFormat1<'_> {
5060 const FORMAT: u16 = 1;
5061}
5062
5063impl<'a> MinByteRange<'a> for ConditionFormat1<'a> {
5064 fn min_byte_range(&self) -> Range<usize> {
5065 0..self.filter_range_max_value_byte_range().end
5066 }
5067 fn min_table_bytes(&self) -> &'a [u8] {
5068 let range = self.min_byte_range();
5069 self.offset_data().as_bytes().get(range).unwrap_or_default()
5070 }
5071}
5072
5073impl ReadArgs for ConditionFormat1<'_> {
5074 type Args = ();
5075}
5076
5077impl<'a> FontRead<'a> for ConditionFormat1<'a> {
5078 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5079 #[allow(clippy::absurd_extreme_comparisons)]
5080 if data.len() < Self::MIN_SIZE {
5081 return Err(ReadError::OutOfBounds);
5082 }
5083 let Some(data) = TableDataRef::new(data.as_bytes()) else {
5084 return Err(ReadError::OutOfBounds);
5085 };
5086 Ok(Self { data })
5087 }
5088}
5089
5090#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5092#[repr(C, packed)]
5093#[doc(hidden)]
5094pub struct ConditionFormat1FixedHeader {
5095 pub format: BigEndian<u16>,
5096 pub axis_index: BigEndian<u16>,
5097 pub filter_range_min_value: BigEndian<F2Dot14>,
5098 pub filter_range_max_value: BigEndian<F2Dot14>,
5099}
5100
5101#[allow(clippy::absurd_extreme_comparisons)]
5102const _: () =
5103 assert!(std::mem::size_of::<ConditionFormat1FixedHeader>() <= ConditionFormat1::MIN_SIZE);
5104
5105#[derive(Clone)]
5107pub struct ConditionFormat1<'a> {
5108 data: TableDataRef<'a, ConditionFormat1FixedHeader>,
5109}
5110
5111#[allow(clippy::needless_lifetimes)]
5112impl<'a> ConditionFormat1<'a> {
5113 pub const MIN_SIZE: usize =
5114 (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN);
5115 basic_table_impls!(impl_the_methods);
5116
5117 pub fn format(&self) -> u16 {
5119 self.data.header().format.get()
5120 }
5121
5122 pub fn axis_index(&self) -> u16 {
5125 self.data.header().axis_index.get()
5126 }
5127
5128 pub fn filter_range_min_value(&self) -> F2Dot14 {
5131 self.data.header().filter_range_min_value.get()
5132 }
5133
5134 pub fn filter_range_max_value(&self) -> F2Dot14 {
5137 self.data.header().filter_range_max_value.get()
5138 }
5139
5140 pub fn format_byte_range(&self) -> Range<usize> {
5141 let start = 0usize;
5142 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5143 start..end
5144 }
5145
5146 pub fn axis_index_byte_range(&self) -> Range<usize> {
5147 let start = self.format_byte_range().end;
5148 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5149 start..end
5150 }
5151
5152 pub fn filter_range_min_value_byte_range(&self) -> Range<usize> {
5153 let start = self.axis_index_byte_range().end;
5154 let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5155 start..end
5156 }
5157
5158 pub fn filter_range_max_value_byte_range(&self) -> Range<usize> {
5159 let start = self.filter_range_min_value_byte_range().end;
5160 let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5161 start..end
5162 }
5163}
5164
5165const _: () = assert!(FontData::default_data_long_enough(
5166 ConditionFormat1::MIN_SIZE
5167));
5168
5169impl Default for ConditionFormat1<'_> {
5170 fn default() -> Self {
5171 Self {
5172 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
5173 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
5174 }
5175 }
5176}
5177
5178impl Format<u16> for ConditionFormat2<'_> {
5179 const FORMAT: u16 = 2;
5180}
5181
5182impl<'a> MinByteRange<'a> for ConditionFormat2<'a> {
5183 fn min_byte_range(&self) -> Range<usize> {
5184 0..self.var_index_byte_range().end
5185 }
5186 fn min_table_bytes(&self) -> &'a [u8] {
5187 let range = self.min_byte_range();
5188 self.offset_data().as_bytes().get(range).unwrap_or_default()
5189 }
5190}
5191
5192impl ReadArgs for ConditionFormat2<'_> {
5193 type Args = ();
5194}
5195
5196impl<'a> FontRead<'a> for ConditionFormat2<'a> {
5197 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5198 #[allow(clippy::absurd_extreme_comparisons)]
5199 if data.len() < Self::MIN_SIZE {
5200 return Err(ReadError::OutOfBounds);
5201 }
5202 let Some(data) = TableDataRef::new(data.as_bytes()) else {
5203 return Err(ReadError::OutOfBounds);
5204 };
5205 Ok(Self { data })
5206 }
5207}
5208
5209#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5211#[repr(C, packed)]
5212#[doc(hidden)]
5213pub struct ConditionFormat2FixedHeader {
5214 pub format: BigEndian<u16>,
5215 pub default_value: BigEndian<i16>,
5216 pub var_index: BigEndian<u32>,
5217}
5218
5219#[allow(clippy::absurd_extreme_comparisons)]
5220const _: () =
5221 assert!(std::mem::size_of::<ConditionFormat2FixedHeader>() <= ConditionFormat2::MIN_SIZE);
5222
5223#[derive(Clone)]
5225pub struct ConditionFormat2<'a> {
5226 data: TableDataRef<'a, ConditionFormat2FixedHeader>,
5227}
5228
5229#[allow(clippy::needless_lifetimes)]
5230impl<'a> ConditionFormat2<'a> {
5231 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
5232 basic_table_impls!(impl_the_methods);
5233
5234 pub fn format(&self) -> u16 {
5236 self.data.header().format.get()
5237 }
5238
5239 pub fn default_value(&self) -> i16 {
5241 self.data.header().default_value.get()
5242 }
5243
5244 pub fn var_index(&self) -> u32 {
5246 self.data.header().var_index.get()
5247 }
5248
5249 pub fn format_byte_range(&self) -> Range<usize> {
5250 let start = 0usize;
5251 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5252 start..end
5253 }
5254
5255 pub fn default_value_byte_range(&self) -> Range<usize> {
5256 let start = self.format_byte_range().end;
5257 let end = start.saturating_add(i16::RAW_BYTE_LEN);
5258 start..end
5259 }
5260
5261 pub fn var_index_byte_range(&self) -> Range<usize> {
5262 let start = self.default_value_byte_range().end;
5263 let end = start.saturating_add(u32::RAW_BYTE_LEN);
5264 start..end
5265 }
5266}
5267
5268impl Format<u16> for ConditionFormat3<'_> {
5269 const FORMAT: u16 = 3;
5270}
5271
5272impl<'a> MinByteRange<'a> for ConditionFormat3<'a> {
5273 fn min_byte_range(&self) -> Range<usize> {
5274 0..self.condition_offsets_byte_range().end
5275 }
5276 fn min_table_bytes(&self) -> &'a [u8] {
5277 let range = self.min_byte_range();
5278 self.offset_data().as_bytes().get(range).unwrap_or_default()
5279 }
5280}
5281
5282impl ReadArgs for ConditionFormat3<'_> {
5283 type Args = ();
5284}
5285
5286impl<'a> FontRead<'a> for ConditionFormat3<'a> {
5287 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5288 #[allow(clippy::absurd_extreme_comparisons)]
5289 if data.len() < Self::MIN_SIZE {
5290 return Err(ReadError::OutOfBounds);
5291 }
5292 let Some(data) = TableDataRef::new(data.as_bytes()) else {
5293 return Err(ReadError::OutOfBounds);
5294 };
5295 Ok(Self { data })
5296 }
5297}
5298
5299#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5301#[repr(C, packed)]
5302#[doc(hidden)]
5303pub struct ConditionFormat3FixedHeader {
5304 pub format: BigEndian<u16>,
5305 pub condition_count: u8,
5306}
5307
5308#[allow(clippy::absurd_extreme_comparisons)]
5309const _: () =
5310 assert!(std::mem::size_of::<ConditionFormat3FixedHeader>() <= ConditionFormat3::MIN_SIZE);
5311
5312#[derive(Clone)]
5314pub struct ConditionFormat3<'a> {
5315 data: TableDataRef<'a, ConditionFormat3FixedHeader>,
5316}
5317
5318#[allow(clippy::needless_lifetimes)]
5319impl<'a> ConditionFormat3<'a> {
5320 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u8::RAW_BYTE_LEN);
5321 basic_table_impls!(impl_the_methods);
5322
5323 pub fn format(&self) -> u16 {
5325 self.data.header().format.get()
5326 }
5327
5328 pub fn condition_count(&self) -> u8 {
5330 self.data.header().condition_count
5331 }
5332
5333 pub fn condition_offsets(&self) -> &'a [BigEndian<Offset24>] {
5335 let range = self.condition_offsets_byte_range();
5336 self.offset_data()
5337 .read_array(range)
5338 .ok()
5339 .unwrap_or_default()
5340 }
5341
5342 pub fn conditions(&self) -> ArrayOfOffsets<'a, Condition<'a>, Offset24> {
5344 let data = self.offset_data();
5345 let offsets = self.condition_offsets();
5346 ArrayOfOffsets::new(offsets, data, ())
5347 }
5348
5349 pub fn format_byte_range(&self) -> Range<usize> {
5350 let start = 0usize;
5351 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5352 start..end
5353 }
5354
5355 pub fn condition_count_byte_range(&self) -> Range<usize> {
5356 let start = self.format_byte_range().end;
5357 let end = start.saturating_add(u8::RAW_BYTE_LEN);
5358 start..end
5359 }
5360
5361 pub fn condition_offsets_byte_range(&self) -> Range<usize> {
5362 let condition_count = self.condition_count();
5363 let start = self.condition_count_byte_range().end;
5364 let end = start.saturating_add(
5365 (transforms::to_usize(condition_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
5366 );
5367 start..end
5368 }
5369}
5370
5371impl Format<u16> for ConditionFormat4<'_> {
5372 const FORMAT: u16 = 4;
5373}
5374
5375impl<'a> MinByteRange<'a> for ConditionFormat4<'a> {
5376 fn min_byte_range(&self) -> Range<usize> {
5377 0..self.condition_offsets_byte_range().end
5378 }
5379 fn min_table_bytes(&self) -> &'a [u8] {
5380 let range = self.min_byte_range();
5381 self.offset_data().as_bytes().get(range).unwrap_or_default()
5382 }
5383}
5384
5385impl ReadArgs for ConditionFormat4<'_> {
5386 type Args = ();
5387}
5388
5389impl<'a> FontRead<'a> for ConditionFormat4<'a> {
5390 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5391 #[allow(clippy::absurd_extreme_comparisons)]
5392 if data.len() < Self::MIN_SIZE {
5393 return Err(ReadError::OutOfBounds);
5394 }
5395 let Some(data) = TableDataRef::new(data.as_bytes()) else {
5396 return Err(ReadError::OutOfBounds);
5397 };
5398 Ok(Self { data })
5399 }
5400}
5401
5402#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5404#[repr(C, packed)]
5405#[doc(hidden)]
5406pub struct ConditionFormat4FixedHeader {
5407 pub format: BigEndian<u16>,
5408 pub condition_count: u8,
5409}
5410
5411#[allow(clippy::absurd_extreme_comparisons)]
5412const _: () =
5413 assert!(std::mem::size_of::<ConditionFormat4FixedHeader>() <= ConditionFormat4::MIN_SIZE);
5414
5415#[derive(Clone)]
5417pub struct ConditionFormat4<'a> {
5418 data: TableDataRef<'a, ConditionFormat4FixedHeader>,
5419}
5420
5421#[allow(clippy::needless_lifetimes)]
5422impl<'a> ConditionFormat4<'a> {
5423 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u8::RAW_BYTE_LEN);
5424 basic_table_impls!(impl_the_methods);
5425
5426 pub fn format(&self) -> u16 {
5428 self.data.header().format.get()
5429 }
5430
5431 pub fn condition_count(&self) -> u8 {
5433 self.data.header().condition_count
5434 }
5435
5436 pub fn condition_offsets(&self) -> &'a [BigEndian<Offset24>] {
5438 let range = self.condition_offsets_byte_range();
5439 self.offset_data()
5440 .read_array(range)
5441 .ok()
5442 .unwrap_or_default()
5443 }
5444
5445 pub fn conditions(&self) -> ArrayOfOffsets<'a, Condition<'a>, Offset24> {
5447 let data = self.offset_data();
5448 let offsets = self.condition_offsets();
5449 ArrayOfOffsets::new(offsets, data, ())
5450 }
5451
5452 pub fn format_byte_range(&self) -> Range<usize> {
5453 let start = 0usize;
5454 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5455 start..end
5456 }
5457
5458 pub fn condition_count_byte_range(&self) -> Range<usize> {
5459 let start = self.format_byte_range().end;
5460 let end = start.saturating_add(u8::RAW_BYTE_LEN);
5461 start..end
5462 }
5463
5464 pub fn condition_offsets_byte_range(&self) -> Range<usize> {
5465 let condition_count = self.condition_count();
5466 let start = self.condition_count_byte_range().end;
5467 let end = start.saturating_add(
5468 (transforms::to_usize(condition_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
5469 );
5470 start..end
5471 }
5472}
5473
5474impl Format<u16> for ConditionFormat5<'_> {
5475 const FORMAT: u16 = 5;
5476}
5477
5478impl<'a> MinByteRange<'a> for ConditionFormat5<'a> {
5479 fn min_byte_range(&self) -> Range<usize> {
5480 0..self.condition_offset_byte_range().end
5481 }
5482 fn min_table_bytes(&self) -> &'a [u8] {
5483 let range = self.min_byte_range();
5484 self.offset_data().as_bytes().get(range).unwrap_or_default()
5485 }
5486}
5487
5488impl ReadArgs for ConditionFormat5<'_> {
5489 type Args = ();
5490}
5491
5492impl<'a> FontRead<'a> for ConditionFormat5<'a> {
5493 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5494 #[allow(clippy::absurd_extreme_comparisons)]
5495 if data.len() < Self::MIN_SIZE {
5496 return Err(ReadError::OutOfBounds);
5497 }
5498 let Some(data) = TableDataRef::new(data.as_bytes()) else {
5499 return Err(ReadError::OutOfBounds);
5500 };
5501 Ok(Self { data })
5502 }
5503}
5504
5505#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5507#[repr(C, packed)]
5508#[doc(hidden)]
5509pub struct ConditionFormat5FixedHeader {
5510 pub format: BigEndian<u16>,
5511 pub condition_offset: BigEndian<Offset24>,
5512}
5513
5514#[allow(clippy::absurd_extreme_comparisons)]
5515const _: () =
5516 assert!(std::mem::size_of::<ConditionFormat5FixedHeader>() <= ConditionFormat5::MIN_SIZE);
5517
5518#[derive(Clone)]
5520pub struct ConditionFormat5<'a> {
5521 data: TableDataRef<'a, ConditionFormat5FixedHeader>,
5522}
5523
5524#[allow(clippy::needless_lifetimes)]
5525impl<'a> ConditionFormat5<'a> {
5526 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN);
5527 basic_table_impls!(impl_the_methods);
5528
5529 pub fn format(&self) -> u16 {
5531 self.data.header().format.get()
5532 }
5533
5534 pub fn condition_offset(&self) -> Offset24 {
5536 self.data.header().condition_offset.get()
5537 }
5538
5539 pub fn condition(&self) -> Result<Condition<'a>, ReadError> {
5541 let data = self.offset_data();
5542 self.condition_offset().resolve(data)
5543 }
5544
5545 pub fn format_byte_range(&self) -> Range<usize> {
5546 let start = 0usize;
5547 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5548 start..end
5549 }
5550
5551 pub fn condition_offset_byte_range(&self) -> Range<usize> {
5552 let start = self.format_byte_range().end;
5553 let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5554 start..end
5555 }
5556}
5557
5558impl<'a> MinByteRange<'a> for FeatureTableSubstitution<'a> {
5559 fn min_byte_range(&self) -> Range<usize> {
5560 0..self.substitutions_byte_range().end
5561 }
5562 fn min_table_bytes(&self) -> &'a [u8] {
5563 let range = self.min_byte_range();
5564 self.offset_data().as_bytes().get(range).unwrap_or_default()
5565 }
5566}
5567
5568impl ReadArgs for FeatureTableSubstitution<'_> {
5569 type Args = ();
5570}
5571
5572impl<'a> FontRead<'a> for FeatureTableSubstitution<'a> {
5573 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5574 #[allow(clippy::absurd_extreme_comparisons)]
5575 if data.len() < Self::MIN_SIZE {
5576 return Err(ReadError::OutOfBounds);
5577 }
5578 let Some(data) = TableDataRef::new(data.as_bytes()) else {
5579 return Err(ReadError::OutOfBounds);
5580 };
5581 Ok(Self { data })
5582 }
5583}
5584
5585#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5587#[repr(C, packed)]
5588#[doc(hidden)]
5589pub struct FeatureTableSubstitutionFixedHeader {
5590 pub version: BigEndian<MajorMinor>,
5591 pub substitution_count: BigEndian<u16>,
5592}
5593
5594#[allow(clippy::absurd_extreme_comparisons)]
5595const _: () = assert!(
5596 std::mem::size_of::<FeatureTableSubstitutionFixedHeader>()
5597 <= FeatureTableSubstitution::MIN_SIZE
5598);
5599
5600#[derive(Clone)]
5602pub struct FeatureTableSubstitution<'a> {
5603 data: TableDataRef<'a, FeatureTableSubstitutionFixedHeader>,
5604}
5605
5606#[allow(clippy::needless_lifetimes)]
5607impl<'a> FeatureTableSubstitution<'a> {
5608 pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
5609 basic_table_impls!(impl_the_methods);
5610
5611 pub fn version(&self) -> MajorMinor {
5613 self.data.header().version.get()
5614 }
5615
5616 pub fn substitution_count(&self) -> u16 {
5618 self.data.header().substitution_count.get()
5619 }
5620
5621 pub fn substitutions(&self) -> &'a [FeatureTableSubstitutionRecord] {
5623 let range = self.substitutions_byte_range();
5624 self.offset_data()
5625 .read_array(range)
5626 .ok()
5627 .unwrap_or_default()
5628 }
5629
5630 pub fn version_byte_range(&self) -> Range<usize> {
5631 let start = 0usize;
5632 let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
5633 start..end
5634 }
5635
5636 pub fn substitution_count_byte_range(&self) -> Range<usize> {
5637 let start = self.version_byte_range().end;
5638 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5639 start..end
5640 }
5641
5642 pub fn substitutions_byte_range(&self) -> Range<usize> {
5643 let substitution_count = self.substitution_count();
5644 let start = self.substitution_count_byte_range().end;
5645 let end = start.saturating_add(
5646 (transforms::to_usize(substitution_count))
5647 .saturating_mul(FeatureTableSubstitutionRecord::RAW_BYTE_LEN),
5648 );
5649 start..end
5650 }
5651}
5652
5653const _: () = assert!(FontData::default_data_long_enough(
5654 FeatureTableSubstitution::MIN_SIZE
5655));
5656
5657impl Default for FeatureTableSubstitution<'_> {
5658 fn default() -> Self {
5659 Self {
5660 data: TableDataRef::new(FontData::default_table_data().as_bytes())
5661 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
5662 }
5663 }
5664}
5665
5666#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
5668#[repr(C)]
5669#[repr(packed)]
5670pub struct FeatureTableSubstitutionRecord {
5671 pub feature_index: BigEndian<u16>,
5673 pub alternate_feature_offset: BigEndian<Offset32>,
5676}
5677
5678impl FeatureTableSubstitutionRecord {
5679 pub fn feature_index(&self) -> u16 {
5681 self.feature_index.get()
5682 }
5683
5684 pub fn alternate_feature_offset(&self) -> Offset32 {
5687 self.alternate_feature_offset.get()
5688 }
5689}
5690
5691impl FixedSize for FeatureTableSubstitutionRecord {
5692 const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
5693}
5694
5695impl<'a> MinByteRange<'a> for SizeParams<'a> {
5696 fn min_byte_range(&self) -> Range<usize> {
5697 0..self.range_end_byte_range().end
5698 }
5699 fn min_table_bytes(&self) -> &'a [u8] {
5700 let range = self.min_byte_range();
5701 self.offset_data().as_bytes().get(range).unwrap_or_default()
5702 }
5703}
5704
5705impl ReadArgs for SizeParams<'_> {
5706 type Args = ();
5707}
5708
5709impl<'a> FontRead<'a> for SizeParams<'a> {
5710 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5711 #[allow(clippy::absurd_extreme_comparisons)]
5712 if data.len() < Self::MIN_SIZE {
5713 return Err(ReadError::OutOfBounds);
5714 }
5715 let Some(data) = TableDataRef::new(data.as_bytes()) else {
5716 return Err(ReadError::OutOfBounds);
5717 };
5718 Ok(Self { data })
5719 }
5720}
5721
5722#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5724#[repr(C, packed)]
5725#[doc(hidden)]
5726pub struct SizeParamsFixedHeader {
5727 pub design_size: BigEndian<u16>,
5728 pub identifier: BigEndian<u16>,
5729 pub name_entry: BigEndian<u16>,
5730 pub range_start: BigEndian<u16>,
5731 pub range_end: BigEndian<u16>,
5732}
5733
5734#[allow(clippy::absurd_extreme_comparisons)]
5735const _: () = assert!(std::mem::size_of::<SizeParamsFixedHeader>() <= SizeParams::MIN_SIZE);
5736
5737#[derive(Clone)]
5738pub struct SizeParams<'a> {
5739 data: TableDataRef<'a, SizeParamsFixedHeader>,
5740}
5741
5742#[allow(clippy::needless_lifetimes)]
5743impl<'a> SizeParams<'a> {
5744 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
5745 + u16::RAW_BYTE_LEN
5746 + u16::RAW_BYTE_LEN
5747 + u16::RAW_BYTE_LEN
5748 + u16::RAW_BYTE_LEN);
5749 basic_table_impls!(impl_the_methods);
5750
5751 pub fn design_size(&self) -> u16 {
5756 self.data.header().design_size.get()
5757 }
5758
5759 pub fn identifier(&self) -> u16 {
5766 self.data.header().identifier.get()
5767 }
5768
5769 pub fn name_entry(&self) -> u16 {
5780 self.data.header().name_entry.get()
5781 }
5782
5783 pub fn range_start(&self) -> u16 {
5789 self.data.header().range_start.get()
5790 }
5791
5792 pub fn range_end(&self) -> u16 {
5793 self.data.header().range_end.get()
5794 }
5795
5796 pub fn design_size_byte_range(&self) -> Range<usize> {
5797 let start = 0usize;
5798 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5799 start..end
5800 }
5801
5802 pub fn identifier_byte_range(&self) -> Range<usize> {
5803 let start = self.design_size_byte_range().end;
5804 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5805 start..end
5806 }
5807
5808 pub fn name_entry_byte_range(&self) -> Range<usize> {
5809 let start = self.identifier_byte_range().end;
5810 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5811 start..end
5812 }
5813
5814 pub fn range_start_byte_range(&self) -> Range<usize> {
5815 let start = self.name_entry_byte_range().end;
5816 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5817 start..end
5818 }
5819
5820 pub fn range_end_byte_range(&self) -> Range<usize> {
5821 let start = self.range_start_byte_range().end;
5822 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5823 start..end
5824 }
5825}
5826
5827const _: () = assert!(FontData::default_data_long_enough(SizeParams::MIN_SIZE));
5828
5829impl Default for SizeParams<'_> {
5830 fn default() -> Self {
5831 Self {
5832 data: TableDataRef::new(FontData::default_table_data().as_bytes())
5833 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
5834 }
5835 }
5836}
5837
5838impl<'a> MinByteRange<'a> for StylisticSetParams<'a> {
5839 fn min_byte_range(&self) -> Range<usize> {
5840 0..self.ui_name_id_byte_range().end
5841 }
5842 fn min_table_bytes(&self) -> &'a [u8] {
5843 let range = self.min_byte_range();
5844 self.offset_data().as_bytes().get(range).unwrap_or_default()
5845 }
5846}
5847
5848impl ReadArgs for StylisticSetParams<'_> {
5849 type Args = ();
5850}
5851
5852impl<'a> FontRead<'a> for StylisticSetParams<'a> {
5853 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5854 #[allow(clippy::absurd_extreme_comparisons)]
5855 if data.len() < Self::MIN_SIZE {
5856 return Err(ReadError::OutOfBounds);
5857 }
5858 let Some(data) = TableDataRef::new(data.as_bytes()) else {
5859 return Err(ReadError::OutOfBounds);
5860 };
5861 Ok(Self { data })
5862 }
5863}
5864
5865#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5867#[repr(C, packed)]
5868#[doc(hidden)]
5869pub struct StylisticSetParamsFixedHeader {
5870 pub version: BigEndian<u16>,
5871 pub ui_name_id: BigEndian<NameId>,
5872}
5873
5874#[allow(clippy::absurd_extreme_comparisons)]
5875const _: () =
5876 assert!(std::mem::size_of::<StylisticSetParamsFixedHeader>() <= StylisticSetParams::MIN_SIZE);
5877
5878#[derive(Clone)]
5879pub struct StylisticSetParams<'a> {
5880 data: TableDataRef<'a, StylisticSetParamsFixedHeader>,
5881}
5882
5883#[allow(clippy::needless_lifetimes)]
5884impl<'a> StylisticSetParams<'a> {
5885 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + NameId::RAW_BYTE_LEN);
5886 basic_table_impls!(impl_the_methods);
5887
5888 pub fn version(&self) -> u16 {
5889 self.data.header().version.get()
5890 }
5891
5892 pub fn ui_name_id(&self) -> NameId {
5902 self.data.header().ui_name_id.get()
5903 }
5904
5905 pub fn version_byte_range(&self) -> Range<usize> {
5906 let start = 0usize;
5907 let end = start.saturating_add(u16::RAW_BYTE_LEN);
5908 start..end
5909 }
5910
5911 pub fn ui_name_id_byte_range(&self) -> Range<usize> {
5912 let start = self.version_byte_range().end;
5913 let end = start.saturating_add(NameId::RAW_BYTE_LEN);
5914 start..end
5915 }
5916}
5917
5918const _: () = assert!(FontData::default_data_long_enough(
5919 StylisticSetParams::MIN_SIZE
5920));
5921
5922impl Default for StylisticSetParams<'_> {
5923 fn default() -> Self {
5924 Self {
5925 data: TableDataRef::new(FontData::default_table_data().as_bytes())
5926 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
5927 }
5928 }
5929}
5930
5931impl Format<u16> for CharacterVariantParams<'_> {
5932 const FORMAT: u16 = 0;
5933}
5934
5935impl<'a> MinByteRange<'a> for CharacterVariantParams<'a> {
5936 fn min_byte_range(&self) -> Range<usize> {
5937 0..self.character_byte_range().end
5938 }
5939 fn min_table_bytes(&self) -> &'a [u8] {
5940 let range = self.min_byte_range();
5941 self.offset_data().as_bytes().get(range).unwrap_or_default()
5942 }
5943}
5944
5945impl ReadArgs for CharacterVariantParams<'_> {
5946 type Args = ();
5947}
5948
5949impl<'a> FontRead<'a> for CharacterVariantParams<'a> {
5950 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5951 #[allow(clippy::absurd_extreme_comparisons)]
5952 if data.len() < Self::MIN_SIZE {
5953 return Err(ReadError::OutOfBounds);
5954 }
5955 let Some(data) = TableDataRef::new(data.as_bytes()) else {
5956 return Err(ReadError::OutOfBounds);
5957 };
5958 Ok(Self { data })
5959 }
5960}
5961
5962#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5964#[repr(C, packed)]
5965#[doc(hidden)]
5966pub struct CharacterVariantParamsFixedHeader {
5967 pub format: BigEndian<u16>,
5968 pub feat_ui_label_name_id: BigEndian<NameId>,
5969 pub feat_ui_tooltip_text_name_id: BigEndian<NameId>,
5970 pub sample_text_name_id: BigEndian<NameId>,
5971 pub num_named_parameters: BigEndian<u16>,
5972 pub first_param_ui_label_name_id: BigEndian<NameId>,
5973 pub char_count: BigEndian<u16>,
5974}
5975
5976#[allow(clippy::absurd_extreme_comparisons)]
5977const _: () = assert!(
5978 std::mem::size_of::<CharacterVariantParamsFixedHeader>() <= CharacterVariantParams::MIN_SIZE
5979);
5980
5981#[derive(Clone)]
5983pub struct CharacterVariantParams<'a> {
5984 data: TableDataRef<'a, CharacterVariantParamsFixedHeader>,
5985}
5986
5987#[allow(clippy::needless_lifetimes)]
5988impl<'a> CharacterVariantParams<'a> {
5989 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
5990 + NameId::RAW_BYTE_LEN
5991 + NameId::RAW_BYTE_LEN
5992 + NameId::RAW_BYTE_LEN
5993 + u16::RAW_BYTE_LEN
5994 + NameId::RAW_BYTE_LEN
5995 + u16::RAW_BYTE_LEN);
5996 basic_table_impls!(impl_the_methods);
5997
5998 pub fn format(&self) -> u16 {
6000 self.data.header().format.get()
6001 }
6002
6003 pub fn feat_ui_label_name_id(&self) -> NameId {
6007 self.data.header().feat_ui_label_name_id.get()
6008 }
6009
6010 pub fn feat_ui_tooltip_text_name_id(&self) -> NameId {
6014 self.data.header().feat_ui_tooltip_text_name_id.get()
6015 }
6016
6017 pub fn sample_text_name_id(&self) -> NameId {
6020 self.data.header().sample_text_name_id.get()
6021 }
6022
6023 pub fn num_named_parameters(&self) -> u16 {
6025 self.data.header().num_named_parameters.get()
6026 }
6027
6028 pub fn first_param_ui_label_name_id(&self) -> NameId {
6032 self.data.header().first_param_ui_label_name_id.get()
6033 }
6034
6035 pub fn char_count(&self) -> u16 {
6038 self.data.header().char_count.get()
6039 }
6040
6041 pub fn character(&self) -> &'a [BigEndian<Uint24>] {
6044 let range = self.character_byte_range();
6045 self.offset_data()
6046 .read_array(range)
6047 .ok()
6048 .unwrap_or_default()
6049 }
6050
6051 pub fn format_byte_range(&self) -> Range<usize> {
6052 let start = 0usize;
6053 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6054 start..end
6055 }
6056
6057 pub fn feat_ui_label_name_id_byte_range(&self) -> Range<usize> {
6058 let start = self.format_byte_range().end;
6059 let end = start.saturating_add(NameId::RAW_BYTE_LEN);
6060 start..end
6061 }
6062
6063 pub fn feat_ui_tooltip_text_name_id_byte_range(&self) -> Range<usize> {
6064 let start = self.feat_ui_label_name_id_byte_range().end;
6065 let end = start.saturating_add(NameId::RAW_BYTE_LEN);
6066 start..end
6067 }
6068
6069 pub fn sample_text_name_id_byte_range(&self) -> Range<usize> {
6070 let start = self.feat_ui_tooltip_text_name_id_byte_range().end;
6071 let end = start.saturating_add(NameId::RAW_BYTE_LEN);
6072 start..end
6073 }
6074
6075 pub fn num_named_parameters_byte_range(&self) -> Range<usize> {
6076 let start = self.sample_text_name_id_byte_range().end;
6077 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6078 start..end
6079 }
6080
6081 pub fn first_param_ui_label_name_id_byte_range(&self) -> Range<usize> {
6082 let start = self.num_named_parameters_byte_range().end;
6083 let end = start.saturating_add(NameId::RAW_BYTE_LEN);
6084 start..end
6085 }
6086
6087 pub fn char_count_byte_range(&self) -> Range<usize> {
6088 let start = self.first_param_ui_label_name_id_byte_range().end;
6089 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6090 start..end
6091 }
6092
6093 pub fn character_byte_range(&self) -> Range<usize> {
6094 let char_count = self.char_count();
6095 let start = self.char_count_byte_range().end;
6096 let end = start.saturating_add(
6097 (transforms::to_usize(char_count)).saturating_mul(Uint24::RAW_BYTE_LEN),
6098 );
6099 start..end
6100 }
6101}
6102
6103const _: () = assert!(FontData::default_data_long_enough(
6104 CharacterVariantParams::MIN_SIZE
6105));
6106
6107impl Default for CharacterVariantParams<'_> {
6108 fn default() -> Self {
6109 Self {
6110 data: TableDataRef::new(FontData::default_table_data().as_bytes())
6111 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
6112 }
6113 }
6114}
6115
6116impl Format<u16> for CoverageFormat3<'_> {
6117 const FORMAT: u16 = 3;
6118}
6119
6120impl<'a> MinByteRange<'a> for CoverageFormat3<'a> {
6121 fn min_byte_range(&self) -> Range<usize> {
6122 0..self.glyph_array_byte_range().end
6123 }
6124 fn min_table_bytes(&self) -> &'a [u8] {
6125 let range = self.min_byte_range();
6126 self.offset_data().as_bytes().get(range).unwrap_or_default()
6127 }
6128}
6129
6130impl ReadArgs for CoverageFormat3<'_> {
6131 type Args = ();
6132}
6133
6134impl<'a> FontRead<'a> for CoverageFormat3<'a> {
6135 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6136 #[allow(clippy::absurd_extreme_comparisons)]
6137 if data.len() < Self::MIN_SIZE {
6138 return Err(ReadError::OutOfBounds);
6139 }
6140 let Some(data) = TableDataRef::new(data.as_bytes()) else {
6141 return Err(ReadError::OutOfBounds);
6142 };
6143 Ok(Self { data })
6144 }
6145}
6146
6147#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6149#[repr(C, packed)]
6150#[doc(hidden)]
6151pub struct CoverageFormat3FixedHeader {
6152 pub coverage_format: BigEndian<u16>,
6153 pub glyph_count: BigEndian<Uint24>,
6154}
6155
6156#[allow(clippy::absurd_extreme_comparisons)]
6157const _: () =
6158 assert!(std::mem::size_of::<CoverageFormat3FixedHeader>() <= CoverageFormat3::MIN_SIZE);
6159
6160#[derive(Clone)]
6162pub struct CoverageFormat3<'a> {
6163 data: TableDataRef<'a, CoverageFormat3FixedHeader>,
6164}
6165
6166#[allow(clippy::needless_lifetimes)]
6167impl<'a> CoverageFormat3<'a> {
6168 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
6169 basic_table_impls!(impl_the_methods);
6170
6171 pub fn coverage_format(&self) -> u16 {
6173 self.data.header().coverage_format.get()
6174 }
6175
6176 pub fn glyph_count(&self) -> Uint24 {
6178 self.data.header().glyph_count.get()
6179 }
6180
6181 pub fn glyph_array(&self) -> &'a [BigEndian<GlyphId24>] {
6183 let range = self.glyph_array_byte_range();
6184 self.offset_data()
6185 .read_array(range)
6186 .ok()
6187 .unwrap_or_default()
6188 }
6189
6190 pub fn coverage_format_byte_range(&self) -> Range<usize> {
6191 let start = 0usize;
6192 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6193 start..end
6194 }
6195
6196 pub fn glyph_count_byte_range(&self) -> Range<usize> {
6197 let start = self.coverage_format_byte_range().end;
6198 let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
6199 start..end
6200 }
6201
6202 pub fn glyph_array_byte_range(&self) -> Range<usize> {
6203 let glyph_count = self.glyph_count();
6204 let start = self.glyph_count_byte_range().end;
6205 let end = start.saturating_add(
6206 (transforms::to_usize(glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN),
6207 );
6208 start..end
6209 }
6210}
6211
6212impl Format<u16> for CoverageFormat4<'_> {
6213 const FORMAT: u16 = 4;
6214}
6215
6216impl<'a> MinByteRange<'a> for CoverageFormat4<'a> {
6217 fn min_byte_range(&self) -> Range<usize> {
6218 0..self.range_records_byte_range().end
6219 }
6220 fn min_table_bytes(&self) -> &'a [u8] {
6221 let range = self.min_byte_range();
6222 self.offset_data().as_bytes().get(range).unwrap_or_default()
6223 }
6224}
6225
6226impl ReadArgs for CoverageFormat4<'_> {
6227 type Args = ();
6228}
6229
6230impl<'a> FontRead<'a> for CoverageFormat4<'a> {
6231 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6232 #[allow(clippy::absurd_extreme_comparisons)]
6233 if data.len() < Self::MIN_SIZE {
6234 return Err(ReadError::OutOfBounds);
6235 }
6236 let Some(data) = TableDataRef::new(data.as_bytes()) else {
6237 return Err(ReadError::OutOfBounds);
6238 };
6239 Ok(Self { data })
6240 }
6241}
6242
6243#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6245#[repr(C, packed)]
6246#[doc(hidden)]
6247pub struct CoverageFormat4FixedHeader {
6248 pub coverage_format: BigEndian<u16>,
6249 pub range_count: BigEndian<Uint24>,
6250}
6251
6252#[allow(clippy::absurd_extreme_comparisons)]
6253const _: () =
6254 assert!(std::mem::size_of::<CoverageFormat4FixedHeader>() <= CoverageFormat4::MIN_SIZE);
6255
6256#[derive(Clone)]
6258pub struct CoverageFormat4<'a> {
6259 data: TableDataRef<'a, CoverageFormat4FixedHeader>,
6260}
6261
6262#[allow(clippy::needless_lifetimes)]
6263impl<'a> CoverageFormat4<'a> {
6264 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
6265 basic_table_impls!(impl_the_methods);
6266
6267 pub fn coverage_format(&self) -> u16 {
6269 self.data.header().coverage_format.get()
6270 }
6271
6272 pub fn range_count(&self) -> Uint24 {
6274 self.data.header().range_count.get()
6275 }
6276
6277 pub fn range_records(&self) -> &'a [RangeRecord2] {
6279 let range = self.range_records_byte_range();
6280 self.offset_data()
6281 .read_array(range)
6282 .ok()
6283 .unwrap_or_default()
6284 }
6285
6286 pub fn coverage_format_byte_range(&self) -> Range<usize> {
6287 let start = 0usize;
6288 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6289 start..end
6290 }
6291
6292 pub fn range_count_byte_range(&self) -> Range<usize> {
6293 let start = self.coverage_format_byte_range().end;
6294 let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
6295 start..end
6296 }
6297
6298 pub fn range_records_byte_range(&self) -> Range<usize> {
6299 let range_count = self.range_count();
6300 let start = self.range_count_byte_range().end;
6301 let end = start.saturating_add(
6302 (transforms::to_usize(range_count)).saturating_mul(RangeRecord2::RAW_BYTE_LEN),
6303 );
6304 start..end
6305 }
6306}
6307
6308#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
6310#[repr(C)]
6311#[repr(packed)]
6312pub struct RangeRecord2 {
6313 pub start_glyph_id: BigEndian<GlyphId24>,
6315 pub end_glyph_id: BigEndian<GlyphId24>,
6317 pub start_coverage_index: BigEndian<Uint24>,
6319}
6320
6321impl RangeRecord2 {
6322 pub fn start_glyph_id(&self) -> GlyphId24 {
6324 self.start_glyph_id.get()
6325 }
6326
6327 pub fn end_glyph_id(&self) -> GlyphId24 {
6329 self.end_glyph_id.get()
6330 }
6331
6332 pub fn start_coverage_index(&self) -> Uint24 {
6334 self.start_coverage_index.get()
6335 }
6336}
6337
6338impl FixedSize for RangeRecord2 {
6339 const RAW_BYTE_LEN: usize =
6340 GlyphId24::RAW_BYTE_LEN + GlyphId24::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN;
6341}
6342
6343impl Format<u16> for ClassDefFormat3<'_> {
6344 const FORMAT: u16 = 3;
6345}
6346
6347impl<'a> MinByteRange<'a> for ClassDefFormat3<'a> {
6348 fn min_byte_range(&self) -> Range<usize> {
6349 0..self.class_value_array_byte_range().end
6350 }
6351 fn min_table_bytes(&self) -> &'a [u8] {
6352 let range = self.min_byte_range();
6353 self.offset_data().as_bytes().get(range).unwrap_or_default()
6354 }
6355}
6356
6357impl ReadArgs for ClassDefFormat3<'_> {
6358 type Args = ();
6359}
6360
6361impl<'a> FontRead<'a> for ClassDefFormat3<'a> {
6362 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6363 #[allow(clippy::absurd_extreme_comparisons)]
6364 if data.len() < Self::MIN_SIZE {
6365 return Err(ReadError::OutOfBounds);
6366 }
6367 let Some(data) = TableDataRef::new(data.as_bytes()) else {
6368 return Err(ReadError::OutOfBounds);
6369 };
6370 Ok(Self { data })
6371 }
6372}
6373
6374#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6376#[repr(C, packed)]
6377#[doc(hidden)]
6378pub struct ClassDefFormat3FixedHeader {
6379 pub class_format: BigEndian<u16>,
6380 pub start_glyph_id: BigEndian<GlyphId24>,
6381 pub glyph_count: BigEndian<Uint24>,
6382}
6383
6384#[allow(clippy::absurd_extreme_comparisons)]
6385const _: () =
6386 assert!(std::mem::size_of::<ClassDefFormat3FixedHeader>() <= ClassDefFormat3::MIN_SIZE);
6387
6388#[derive(Clone)]
6390pub struct ClassDefFormat3<'a> {
6391 data: TableDataRef<'a, ClassDefFormat3FixedHeader>,
6392}
6393
6394#[allow(clippy::needless_lifetimes)]
6395impl<'a> ClassDefFormat3<'a> {
6396 pub const MIN_SIZE: usize =
6397 (u16::RAW_BYTE_LEN + GlyphId24::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
6398 basic_table_impls!(impl_the_methods);
6399
6400 pub fn class_format(&self) -> u16 {
6402 self.data.header().class_format.get()
6403 }
6404
6405 pub fn start_glyph_id(&self) -> GlyphId24 {
6407 self.data.header().start_glyph_id.get()
6408 }
6409
6410 pub fn glyph_count(&self) -> Uint24 {
6412 self.data.header().glyph_count.get()
6413 }
6414
6415 pub fn class_value_array(&self) -> &'a [BigEndian<Uint24>] {
6417 let range = self.class_value_array_byte_range();
6418 self.offset_data()
6419 .read_array(range)
6420 .ok()
6421 .unwrap_or_default()
6422 }
6423
6424 pub fn class_format_byte_range(&self) -> Range<usize> {
6425 let start = 0usize;
6426 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6427 start..end
6428 }
6429
6430 pub fn start_glyph_id_byte_range(&self) -> Range<usize> {
6431 let start = self.class_format_byte_range().end;
6432 let end = start.saturating_add(GlyphId24::RAW_BYTE_LEN);
6433 start..end
6434 }
6435
6436 pub fn glyph_count_byte_range(&self) -> Range<usize> {
6437 let start = self.start_glyph_id_byte_range().end;
6438 let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
6439 start..end
6440 }
6441
6442 pub fn class_value_array_byte_range(&self) -> Range<usize> {
6443 let glyph_count = self.glyph_count();
6444 let start = self.glyph_count_byte_range().end;
6445 let end = start.saturating_add(
6446 (transforms::to_usize(glyph_count)).saturating_mul(Uint24::RAW_BYTE_LEN),
6447 );
6448 start..end
6449 }
6450}
6451
6452impl Format<u16> for ClassDefFormat4<'_> {
6453 const FORMAT: u16 = 4;
6454}
6455
6456impl<'a> MinByteRange<'a> for ClassDefFormat4<'a> {
6457 fn min_byte_range(&self) -> Range<usize> {
6458 0..self.class_range_records_byte_range().end
6459 }
6460 fn min_table_bytes(&self) -> &'a [u8] {
6461 let range = self.min_byte_range();
6462 self.offset_data().as_bytes().get(range).unwrap_or_default()
6463 }
6464}
6465
6466impl ReadArgs for ClassDefFormat4<'_> {
6467 type Args = ();
6468}
6469
6470impl<'a> FontRead<'a> for ClassDefFormat4<'a> {
6471 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6472 #[allow(clippy::absurd_extreme_comparisons)]
6473 if data.len() < Self::MIN_SIZE {
6474 return Err(ReadError::OutOfBounds);
6475 }
6476 let Some(data) = TableDataRef::new(data.as_bytes()) else {
6477 return Err(ReadError::OutOfBounds);
6478 };
6479 Ok(Self { data })
6480 }
6481}
6482
6483#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6485#[repr(C, packed)]
6486#[doc(hidden)]
6487pub struct ClassDefFormat4FixedHeader {
6488 pub class_format: BigEndian<u16>,
6489 pub class_range_count: BigEndian<Uint24>,
6490}
6491
6492#[allow(clippy::absurd_extreme_comparisons)]
6493const _: () =
6494 assert!(std::mem::size_of::<ClassDefFormat4FixedHeader>() <= ClassDefFormat4::MIN_SIZE);
6495
6496#[derive(Clone)]
6498pub struct ClassDefFormat4<'a> {
6499 data: TableDataRef<'a, ClassDefFormat4FixedHeader>,
6500}
6501
6502#[allow(clippy::needless_lifetimes)]
6503impl<'a> ClassDefFormat4<'a> {
6504 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
6505 basic_table_impls!(impl_the_methods);
6506
6507 pub fn class_format(&self) -> u16 {
6509 self.data.header().class_format.get()
6510 }
6511
6512 pub fn class_range_count(&self) -> Uint24 {
6514 self.data.header().class_range_count.get()
6515 }
6516
6517 pub fn class_range_records(&self) -> &'a [ClassRangeRecord2] {
6519 let range = self.class_range_records_byte_range();
6520 self.offset_data()
6521 .read_array(range)
6522 .ok()
6523 .unwrap_or_default()
6524 }
6525
6526 pub fn class_format_byte_range(&self) -> Range<usize> {
6527 let start = 0usize;
6528 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6529 start..end
6530 }
6531
6532 pub fn class_range_count_byte_range(&self) -> Range<usize> {
6533 let start = self.class_format_byte_range().end;
6534 let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
6535 start..end
6536 }
6537
6538 pub fn class_range_records_byte_range(&self) -> Range<usize> {
6539 let class_range_count = self.class_range_count();
6540 let start = self.class_range_count_byte_range().end;
6541 let end = start.saturating_add(
6542 (transforms::to_usize(class_range_count))
6543 .saturating_mul(ClassRangeRecord2::RAW_BYTE_LEN),
6544 );
6545 start..end
6546 }
6547}
6548
6549#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
6551#[repr(C)]
6552#[repr(packed)]
6553pub struct ClassRangeRecord2 {
6554 pub start_glyph_id: BigEndian<GlyphId24>,
6556 pub end_glyph_id: BigEndian<GlyphId24>,
6558 pub class: BigEndian<u16>,
6560}
6561
6562impl ClassRangeRecord2 {
6563 pub fn start_glyph_id(&self) -> GlyphId24 {
6565 self.start_glyph_id.get()
6566 }
6567
6568 pub fn end_glyph_id(&self) -> GlyphId24 {
6570 self.end_glyph_id.get()
6571 }
6572
6573 pub fn class(&self) -> u16 {
6575 self.class.get()
6576 }
6577}
6578
6579impl FixedSize for ClassRangeRecord2 {
6580 const RAW_BYTE_LEN: usize =
6581 GlyphId24::RAW_BYTE_LEN + GlyphId24::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
6582}
6583
6584impl Format<u16> for SequenceContextFormat4<'_> {
6585 const FORMAT: u16 = 4;
6586}
6587
6588impl<'a> MinByteRange<'a> for SequenceContextFormat4<'a> {
6589 fn min_byte_range(&self) -> Range<usize> {
6590 0..self.seq_rule_set_offsets_byte_range().end
6591 }
6592 fn min_table_bytes(&self) -> &'a [u8] {
6593 let range = self.min_byte_range();
6594 self.offset_data().as_bytes().get(range).unwrap_or_default()
6595 }
6596}
6597
6598impl ReadArgs for SequenceContextFormat4<'_> {
6599 type Args = ();
6600}
6601
6602impl<'a> FontRead<'a> for SequenceContextFormat4<'a> {
6603 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6604 #[allow(clippy::absurd_extreme_comparisons)]
6605 if data.len() < Self::MIN_SIZE {
6606 return Err(ReadError::OutOfBounds);
6607 }
6608 let Some(data) = TableDataRef::new(data.as_bytes()) else {
6609 return Err(ReadError::OutOfBounds);
6610 };
6611 Ok(Self { data })
6612 }
6613}
6614
6615#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6617#[repr(C, packed)]
6618#[doc(hidden)]
6619pub struct SequenceContextFormat4FixedHeader {
6620 pub format: BigEndian<u16>,
6621 pub coverage_offset: BigEndian<Offset32>,
6622 pub seq_rule_set_count: BigEndian<Uint24>,
6623}
6624
6625#[allow(clippy::absurd_extreme_comparisons)]
6626const _: () = assert!(
6627 std::mem::size_of::<SequenceContextFormat4FixedHeader>() <= SequenceContextFormat4::MIN_SIZE
6628);
6629
6630#[derive(Clone)]
6632pub struct SequenceContextFormat4<'a> {
6633 data: TableDataRef<'a, SequenceContextFormat4FixedHeader>,
6634}
6635
6636#[allow(clippy::needless_lifetimes)]
6637impl<'a> SequenceContextFormat4<'a> {
6638 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
6639 basic_table_impls!(impl_the_methods);
6640
6641 pub fn format(&self) -> u16 {
6643 self.data.header().format.get()
6644 }
6645
6646 pub fn coverage_offset(&self) -> Offset32 {
6649 self.data.header().coverage_offset.get()
6650 }
6651
6652 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
6654 let data = self.offset_data();
6655 self.coverage_offset().resolve(data)
6656 }
6657
6658 pub fn seq_rule_set_count(&self) -> Uint24 {
6660 self.data.header().seq_rule_set_count.get()
6661 }
6662
6663 pub fn seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] {
6666 let range = self.seq_rule_set_offsets_byte_range();
6667 self.offset_data()
6668 .read_array(range)
6669 .ok()
6670 .unwrap_or_default()
6671 }
6672
6673 pub fn seq_rule_sets(&self) -> ArrayOfNullableOffsets<'a, SequenceRuleSet2<'a>, Offset24> {
6675 let data = self.offset_data();
6676 let offsets = self.seq_rule_set_offsets();
6677 ArrayOfNullableOffsets::new(offsets, data, ())
6678 }
6679
6680 pub fn format_byte_range(&self) -> Range<usize> {
6681 let start = 0usize;
6682 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6683 start..end
6684 }
6685
6686 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
6687 let start = self.format_byte_range().end;
6688 let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
6689 start..end
6690 }
6691
6692 pub fn seq_rule_set_count_byte_range(&self) -> Range<usize> {
6693 let start = self.coverage_offset_byte_range().end;
6694 let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
6695 start..end
6696 }
6697
6698 pub fn seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
6699 let seq_rule_set_count = self.seq_rule_set_count();
6700 let start = self.seq_rule_set_count_byte_range().end;
6701 let end = start.saturating_add(
6702 (transforms::to_usize(seq_rule_set_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
6703 );
6704 start..end
6705 }
6706}
6707
6708impl<'a> MinByteRange<'a> for SequenceRuleSet2<'a> {
6709 fn min_byte_range(&self) -> Range<usize> {
6710 0..self.seq_rule_offsets_byte_range().end
6711 }
6712 fn min_table_bytes(&self) -> &'a [u8] {
6713 let range = self.min_byte_range();
6714 self.offset_data().as_bytes().get(range).unwrap_or_default()
6715 }
6716}
6717
6718impl ReadArgs for SequenceRuleSet2<'_> {
6719 type Args = ();
6720}
6721
6722impl<'a> FontRead<'a> for SequenceRuleSet2<'a> {
6723 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6724 #[allow(clippy::absurd_extreme_comparisons)]
6725 if data.len() < Self::MIN_SIZE {
6726 return Err(ReadError::OutOfBounds);
6727 }
6728 let Some(data) = TableDataRef::new(data.as_bytes()) else {
6729 return Err(ReadError::OutOfBounds);
6730 };
6731 Ok(Self { data })
6732 }
6733}
6734
6735#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6737#[repr(C, packed)]
6738#[doc(hidden)]
6739pub struct SequenceRuleSet2FixedHeader {
6740 pub seq_rule_count: BigEndian<u16>,
6741}
6742
6743#[allow(clippy::absurd_extreme_comparisons)]
6744const _: () =
6745 assert!(std::mem::size_of::<SequenceRuleSet2FixedHeader>() <= SequenceRuleSet2::MIN_SIZE);
6746
6747#[derive(Clone)]
6749pub struct SequenceRuleSet2<'a> {
6750 data: TableDataRef<'a, SequenceRuleSet2FixedHeader>,
6751}
6752
6753#[allow(clippy::needless_lifetimes)]
6754impl<'a> SequenceRuleSet2<'a> {
6755 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
6756 basic_table_impls!(impl_the_methods);
6757
6758 pub fn seq_rule_count(&self) -> u16 {
6760 self.data.header().seq_rule_count.get()
6761 }
6762
6763 pub fn seq_rule_offsets(&self) -> &'a [BigEndian<Offset16>] {
6766 let range = self.seq_rule_offsets_byte_range();
6767 self.offset_data()
6768 .read_array(range)
6769 .ok()
6770 .unwrap_or_default()
6771 }
6772
6773 pub fn seq_rules(&self) -> ArrayOfOffsets<'a, SequenceRule2<'a>, Offset16> {
6775 let data = self.offset_data();
6776 let offsets = self.seq_rule_offsets();
6777 ArrayOfOffsets::new(offsets, data, ())
6778 }
6779
6780 pub fn seq_rule_count_byte_range(&self) -> Range<usize> {
6781 let start = 0usize;
6782 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6783 start..end
6784 }
6785
6786 pub fn seq_rule_offsets_byte_range(&self) -> Range<usize> {
6787 let seq_rule_count = self.seq_rule_count();
6788 let start = self.seq_rule_count_byte_range().end;
6789 let end = start.saturating_add(
6790 (transforms::to_usize(seq_rule_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
6791 );
6792 start..end
6793 }
6794}
6795
6796const _: () = assert!(FontData::default_data_long_enough(
6797 SequenceRuleSet2::MIN_SIZE
6798));
6799
6800impl Default for SequenceRuleSet2<'_> {
6801 fn default() -> Self {
6802 Self {
6803 data: TableDataRef::new(FontData::default_table_data().as_bytes())
6804 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
6805 }
6806 }
6807}
6808
6809impl<'a> MinByteRange<'a> for SequenceRule2<'a> {
6810 fn min_byte_range(&self) -> Range<usize> {
6811 0..self.seq_lookup_records_byte_range().end
6812 }
6813 fn min_table_bytes(&self) -> &'a [u8] {
6814 let range = self.min_byte_range();
6815 self.offset_data().as_bytes().get(range).unwrap_or_default()
6816 }
6817}
6818
6819impl ReadArgs for SequenceRule2<'_> {
6820 type Args = ();
6821}
6822
6823impl<'a> FontRead<'a> for SequenceRule2<'a> {
6824 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6825 #[allow(clippy::absurd_extreme_comparisons)]
6826 if data.len() < Self::MIN_SIZE {
6827 return Err(ReadError::OutOfBounds);
6828 }
6829 let Some(data) = TableDataRef::new(data.as_bytes()) else {
6830 return Err(ReadError::OutOfBounds);
6831 };
6832 Ok(Self { data })
6833 }
6834}
6835
6836#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6838#[repr(C, packed)]
6839#[doc(hidden)]
6840pub struct SequenceRule2FixedHeader {
6841 pub glyph_count: BigEndian<u16>,
6842 pub seq_lookup_count: BigEndian<u16>,
6843}
6844
6845#[allow(clippy::absurd_extreme_comparisons)]
6846const _: () = assert!(std::mem::size_of::<SequenceRule2FixedHeader>() <= SequenceRule2::MIN_SIZE);
6847
6848#[derive(Clone)]
6850pub struct SequenceRule2<'a> {
6851 data: TableDataRef<'a, SequenceRule2FixedHeader>,
6852}
6853
6854#[allow(clippy::needless_lifetimes)]
6855impl<'a> SequenceRule2<'a> {
6856 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
6857 basic_table_impls!(impl_the_methods);
6858
6859 pub fn glyph_count(&self) -> u16 {
6861 self.data.header().glyph_count.get()
6862 }
6863
6864 pub fn seq_lookup_count(&self) -> u16 {
6866 self.data.header().seq_lookup_count.get()
6867 }
6868
6869 pub fn input_sequence(&self) -> &'a [BigEndian<GlyphId24>] {
6871 let range = self.input_sequence_byte_range();
6872 self.offset_data()
6873 .read_array(range)
6874 .ok()
6875 .unwrap_or_default()
6876 }
6877
6878 pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
6880 let range = self.seq_lookup_records_byte_range();
6881 self.offset_data()
6882 .read_array(range)
6883 .ok()
6884 .unwrap_or_default()
6885 }
6886
6887 pub fn glyph_count_byte_range(&self) -> Range<usize> {
6888 let start = 0usize;
6889 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6890 start..end
6891 }
6892
6893 pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
6894 let start = self.glyph_count_byte_range().end;
6895 let end = start.saturating_add(u16::RAW_BYTE_LEN);
6896 start..end
6897 }
6898
6899 pub fn input_sequence_byte_range(&self) -> Range<usize> {
6900 let glyph_count = self.glyph_count();
6901 let start = self.seq_lookup_count_byte_range().end;
6902 let end = start.saturating_add(
6903 (transforms::subtract(glyph_count, 1_usize)).saturating_mul(GlyphId24::RAW_BYTE_LEN),
6904 );
6905 start..end
6906 }
6907
6908 pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
6909 let seq_lookup_count = self.seq_lookup_count();
6910 let start = self.input_sequence_byte_range().end;
6911 let end = start.saturating_add(
6912 (transforms::to_usize(seq_lookup_count))
6913 .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
6914 );
6915 start..end
6916 }
6917}
6918
6919const _: () = assert!(FontData::default_data_long_enough(SequenceRule2::MIN_SIZE));
6920
6921impl Default for SequenceRule2<'_> {
6922 fn default() -> Self {
6923 Self {
6924 data: TableDataRef::new(FontData::default_table_data().as_bytes())
6925 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
6926 }
6927 }
6928}
6929
6930impl Format<u16> for SequenceContextFormat5<'_> {
6931 const FORMAT: u16 = 5;
6932}
6933
6934impl<'a> MinByteRange<'a> for SequenceContextFormat5<'a> {
6935 fn min_byte_range(&self) -> Range<usize> {
6936 0..self.class_seq_rule_set_offsets_byte_range().end
6937 }
6938 fn min_table_bytes(&self) -> &'a [u8] {
6939 let range = self.min_byte_range();
6940 self.offset_data().as_bytes().get(range).unwrap_or_default()
6941 }
6942}
6943
6944impl ReadArgs for SequenceContextFormat5<'_> {
6945 type Args = ();
6946}
6947
6948impl<'a> FontRead<'a> for SequenceContextFormat5<'a> {
6949 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6950 #[allow(clippy::absurd_extreme_comparisons)]
6951 if data.len() < Self::MIN_SIZE {
6952 return Err(ReadError::OutOfBounds);
6953 }
6954 let Some(data) = TableDataRef::new(data.as_bytes()) else {
6955 return Err(ReadError::OutOfBounds);
6956 };
6957 Ok(Self { data })
6958 }
6959}
6960
6961#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6963#[repr(C, packed)]
6964#[doc(hidden)]
6965pub struct SequenceContextFormat5FixedHeader {
6966 pub format: BigEndian<u16>,
6967 pub coverage_offset: BigEndian<Offset32>,
6968 pub class_def_offset: BigEndian<Offset32>,
6969 pub class_seq_rule_set_count: BigEndian<Uint24>,
6970}
6971
6972#[allow(clippy::absurd_extreme_comparisons)]
6973const _: () = assert!(
6974 std::mem::size_of::<SequenceContextFormat5FixedHeader>() <= SequenceContextFormat5::MIN_SIZE
6975);
6976
6977#[derive(Clone)]
6979pub struct SequenceContextFormat5<'a> {
6980 data: TableDataRef<'a, SequenceContextFormat5FixedHeader>,
6981}
6982
6983#[allow(clippy::needless_lifetimes)]
6984impl<'a> SequenceContextFormat5<'a> {
6985 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
6986 + Offset32::RAW_BYTE_LEN
6987 + Offset32::RAW_BYTE_LEN
6988 + Uint24::RAW_BYTE_LEN);
6989 basic_table_impls!(impl_the_methods);
6990
6991 pub fn format(&self) -> u16 {
6993 self.data.header().format.get()
6994 }
6995
6996 pub fn coverage_offset(&self) -> Offset32 {
6999 self.data.header().coverage_offset.get()
7000 }
7001
7002 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
7004 let data = self.offset_data();
7005 self.coverage_offset().resolve(data)
7006 }
7007
7008 pub fn class_def_offset(&self) -> Offset32 {
7011 self.data.header().class_def_offset.get()
7012 }
7013
7014 pub fn class_def(&self) -> Result<ClassDef<'a>, ReadError> {
7016 let data = self.offset_data();
7017 self.class_def_offset().resolve(data)
7018 }
7019
7020 pub fn class_seq_rule_set_count(&self) -> Uint24 {
7022 self.data.header().class_seq_rule_set_count.get()
7023 }
7024
7025 pub fn class_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] {
7028 let range = self.class_seq_rule_set_offsets_byte_range();
7029 self.offset_data()
7030 .read_array(range)
7031 .ok()
7032 .unwrap_or_default()
7033 }
7034
7035 pub fn class_seq_rule_sets(
7037 &self,
7038 ) -> ArrayOfNullableOffsets<'a, ClassSequenceRuleSet2<'a>, Offset24> {
7039 let data = self.offset_data();
7040 let offsets = self.class_seq_rule_set_offsets();
7041 ArrayOfNullableOffsets::new(offsets, data, ())
7042 }
7043
7044 pub fn format_byte_range(&self) -> Range<usize> {
7045 let start = 0usize;
7046 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7047 start..end
7048 }
7049
7050 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
7051 let start = self.format_byte_range().end;
7052 let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7053 start..end
7054 }
7055
7056 pub fn class_def_offset_byte_range(&self) -> Range<usize> {
7057 let start = self.coverage_offset_byte_range().end;
7058 let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7059 start..end
7060 }
7061
7062 pub fn class_seq_rule_set_count_byte_range(&self) -> Range<usize> {
7063 let start = self.class_def_offset_byte_range().end;
7064 let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
7065 start..end
7066 }
7067
7068 pub fn class_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
7069 let class_seq_rule_set_count = self.class_seq_rule_set_count();
7070 let start = self.class_seq_rule_set_count_byte_range().end;
7071 let end = start.saturating_add(
7072 (transforms::to_usize(class_seq_rule_set_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
7073 );
7074 start..end
7075 }
7076}
7077
7078impl<'a> MinByteRange<'a> for ClassSequenceRuleSet2<'a> {
7079 fn min_byte_range(&self) -> Range<usize> {
7080 0..self.class_seq_rule_offsets_byte_range().end
7081 }
7082 fn min_table_bytes(&self) -> &'a [u8] {
7083 let range = self.min_byte_range();
7084 self.offset_data().as_bytes().get(range).unwrap_or_default()
7085 }
7086}
7087
7088impl ReadArgs for ClassSequenceRuleSet2<'_> {
7089 type Args = ();
7090}
7091
7092impl<'a> FontRead<'a> for ClassSequenceRuleSet2<'a> {
7093 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7094 #[allow(clippy::absurd_extreme_comparisons)]
7095 if data.len() < Self::MIN_SIZE {
7096 return Err(ReadError::OutOfBounds);
7097 }
7098 let Some(data) = TableDataRef::new(data.as_bytes()) else {
7099 return Err(ReadError::OutOfBounds);
7100 };
7101 Ok(Self { data })
7102 }
7103}
7104
7105#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7107#[repr(C, packed)]
7108#[doc(hidden)]
7109pub struct ClassSequenceRuleSet2FixedHeader {
7110 pub class_seq_rule_count: BigEndian<u16>,
7111}
7112
7113#[allow(clippy::absurd_extreme_comparisons)]
7114const _: () = assert!(
7115 std::mem::size_of::<ClassSequenceRuleSet2FixedHeader>() <= ClassSequenceRuleSet2::MIN_SIZE
7116);
7117
7118#[derive(Clone)]
7120pub struct ClassSequenceRuleSet2<'a> {
7121 data: TableDataRef<'a, ClassSequenceRuleSet2FixedHeader>,
7122}
7123
7124#[allow(clippy::needless_lifetimes)]
7125impl<'a> ClassSequenceRuleSet2<'a> {
7126 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
7127 basic_table_impls!(impl_the_methods);
7128
7129 pub fn class_seq_rule_count(&self) -> u16 {
7131 self.data.header().class_seq_rule_count.get()
7132 }
7133
7134 pub fn class_seq_rule_offsets(&self) -> &'a [BigEndian<Offset24>] {
7137 let range = self.class_seq_rule_offsets_byte_range();
7138 self.offset_data()
7139 .read_array(range)
7140 .ok()
7141 .unwrap_or_default()
7142 }
7143
7144 pub fn class_seq_rules(&self) -> ArrayOfOffsets<'a, ClassSequenceRule<'a>, Offset24> {
7146 let data = self.offset_data();
7147 let offsets = self.class_seq_rule_offsets();
7148 ArrayOfOffsets::new(offsets, data, ())
7149 }
7150
7151 pub fn class_seq_rule_count_byte_range(&self) -> Range<usize> {
7152 let start = 0usize;
7153 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7154 start..end
7155 }
7156
7157 pub fn class_seq_rule_offsets_byte_range(&self) -> Range<usize> {
7158 let class_seq_rule_count = self.class_seq_rule_count();
7159 let start = self.class_seq_rule_count_byte_range().end;
7160 let end = start.saturating_add(
7161 (transforms::to_usize(class_seq_rule_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
7162 );
7163 start..end
7164 }
7165}
7166
7167const _: () = assert!(FontData::default_data_long_enough(
7168 ClassSequenceRuleSet2::MIN_SIZE
7169));
7170
7171impl Default for ClassSequenceRuleSet2<'_> {
7172 fn default() -> Self {
7173 Self {
7174 data: TableDataRef::new(FontData::default_table_data().as_bytes())
7175 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
7176 }
7177 }
7178}
7179
7180impl Format<u16> for SequenceContextFormat6<'_> {
7181 const FORMAT: u16 = 6;
7182}
7183
7184impl<'a> MinByteRange<'a> for SequenceContextFormat6<'a> {
7185 fn min_byte_range(&self) -> Range<usize> {
7186 0..self.seq_lookup_records_byte_range().end
7187 }
7188 fn min_table_bytes(&self) -> &'a [u8] {
7189 let range = self.min_byte_range();
7190 self.offset_data().as_bytes().get(range).unwrap_or_default()
7191 }
7192}
7193
7194impl ReadArgs for SequenceContextFormat6<'_> {
7195 type Args = ();
7196}
7197
7198impl<'a> FontRead<'a> for SequenceContextFormat6<'a> {
7199 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7200 #[allow(clippy::absurd_extreme_comparisons)]
7201 if data.len() < Self::MIN_SIZE {
7202 return Err(ReadError::OutOfBounds);
7203 }
7204 let Some(data) = TableDataRef::new(data.as_bytes()) else {
7205 return Err(ReadError::OutOfBounds);
7206 };
7207 Ok(Self { data })
7208 }
7209}
7210
7211#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7213#[repr(C, packed)]
7214#[doc(hidden)]
7215pub struct SequenceContextFormat6FixedHeader {
7216 pub format: BigEndian<u16>,
7217 pub glyph_count: BigEndian<u16>,
7218 pub seq_lookup_count: BigEndian<u16>,
7219}
7220
7221#[allow(clippy::absurd_extreme_comparisons)]
7222const _: () = assert!(
7223 std::mem::size_of::<SequenceContextFormat6FixedHeader>() <= SequenceContextFormat6::MIN_SIZE
7224);
7225
7226#[derive(Clone)]
7228pub struct SequenceContextFormat6<'a> {
7229 data: TableDataRef<'a, SequenceContextFormat6FixedHeader>,
7230}
7231
7232#[allow(clippy::needless_lifetimes)]
7233impl<'a> SequenceContextFormat6<'a> {
7234 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
7235 basic_table_impls!(impl_the_methods);
7236
7237 pub fn format(&self) -> u16 {
7239 self.data.header().format.get()
7240 }
7241
7242 pub fn glyph_count(&self) -> u16 {
7244 self.data.header().glyph_count.get()
7245 }
7246
7247 pub fn seq_lookup_count(&self) -> u16 {
7249 self.data.header().seq_lookup_count.get()
7250 }
7251
7252 pub fn coverage_offsets(&self) -> &'a [BigEndian<Offset24>] {
7255 let range = self.coverage_offsets_byte_range();
7256 self.offset_data()
7257 .read_array(range)
7258 .ok()
7259 .unwrap_or_default()
7260 }
7261
7262 pub fn coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset24> {
7264 let data = self.offset_data();
7265 let offsets = self.coverage_offsets();
7266 ArrayOfOffsets::new(offsets, data, ())
7267 }
7268
7269 pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
7271 let range = self.seq_lookup_records_byte_range();
7272 self.offset_data()
7273 .read_array(range)
7274 .ok()
7275 .unwrap_or_default()
7276 }
7277
7278 pub fn format_byte_range(&self) -> Range<usize> {
7279 let start = 0usize;
7280 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7281 start..end
7282 }
7283
7284 pub fn glyph_count_byte_range(&self) -> Range<usize> {
7285 let start = self.format_byte_range().end;
7286 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7287 start..end
7288 }
7289
7290 pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
7291 let start = self.glyph_count_byte_range().end;
7292 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7293 start..end
7294 }
7295
7296 pub fn coverage_offsets_byte_range(&self) -> Range<usize> {
7297 let glyph_count = self.glyph_count();
7298 let start = self.seq_lookup_count_byte_range().end;
7299 let end = start.saturating_add(
7300 (transforms::to_usize(glyph_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
7301 );
7302 start..end
7303 }
7304
7305 pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
7306 let seq_lookup_count = self.seq_lookup_count();
7307 let start = self.coverage_offsets_byte_range().end;
7308 let end = start.saturating_add(
7309 (transforms::to_usize(seq_lookup_count))
7310 .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
7311 );
7312 start..end
7313 }
7314}
7315
7316impl Format<u16> for ChainedSequenceContextFormat4<'_> {
7317 const FORMAT: u16 = 4;
7318}
7319
7320impl<'a> MinByteRange<'a> for ChainedSequenceContextFormat4<'a> {
7321 fn min_byte_range(&self) -> Range<usize> {
7322 0..self.chained_seq_rule_set_offsets_byte_range().end
7323 }
7324 fn min_table_bytes(&self) -> &'a [u8] {
7325 let range = self.min_byte_range();
7326 self.offset_data().as_bytes().get(range).unwrap_or_default()
7327 }
7328}
7329
7330impl ReadArgs for ChainedSequenceContextFormat4<'_> {
7331 type Args = ();
7332}
7333
7334impl<'a> FontRead<'a> for ChainedSequenceContextFormat4<'a> {
7335 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7336 #[allow(clippy::absurd_extreme_comparisons)]
7337 if data.len() < Self::MIN_SIZE {
7338 return Err(ReadError::OutOfBounds);
7339 }
7340 let Some(data) = TableDataRef::new(data.as_bytes()) else {
7341 return Err(ReadError::OutOfBounds);
7342 };
7343 Ok(Self { data })
7344 }
7345}
7346
7347#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7349#[repr(C, packed)]
7350#[doc(hidden)]
7351pub struct ChainedSequenceContextFormat4FixedHeader {
7352 pub format: BigEndian<u16>,
7353 pub coverage_offset: BigEndian<Offset32>,
7354 pub chained_seq_rule_set_count: BigEndian<Uint24>,
7355}
7356
7357#[allow(clippy::absurd_extreme_comparisons)]
7358const _: () = assert!(
7359 std::mem::size_of::<ChainedSequenceContextFormat4FixedHeader>()
7360 <= ChainedSequenceContextFormat4::MIN_SIZE
7361);
7362
7363#[derive(Clone)]
7365pub struct ChainedSequenceContextFormat4<'a> {
7366 data: TableDataRef<'a, ChainedSequenceContextFormat4FixedHeader>,
7367}
7368
7369#[allow(clippy::needless_lifetimes)]
7370impl<'a> ChainedSequenceContextFormat4<'a> {
7371 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
7372 basic_table_impls!(impl_the_methods);
7373
7374 pub fn format(&self) -> u16 {
7376 self.data.header().format.get()
7377 }
7378
7379 pub fn coverage_offset(&self) -> Offset32 {
7382 self.data.header().coverage_offset.get()
7383 }
7384
7385 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
7387 let data = self.offset_data();
7388 self.coverage_offset().resolve(data)
7389 }
7390
7391 pub fn chained_seq_rule_set_count(&self) -> Uint24 {
7393 self.data.header().chained_seq_rule_set_count.get()
7394 }
7395
7396 pub fn chained_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] {
7399 let range = self.chained_seq_rule_set_offsets_byte_range();
7400 self.offset_data()
7401 .read_array(range)
7402 .ok()
7403 .unwrap_or_default()
7404 }
7405
7406 pub fn chained_seq_rule_sets(
7408 &self,
7409 ) -> ArrayOfNullableOffsets<'a, ChainedSequenceRuleSet2<'a>, Offset24> {
7410 let data = self.offset_data();
7411 let offsets = self.chained_seq_rule_set_offsets();
7412 ArrayOfNullableOffsets::new(offsets, data, ())
7413 }
7414
7415 pub fn format_byte_range(&self) -> Range<usize> {
7416 let start = 0usize;
7417 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7418 start..end
7419 }
7420
7421 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
7422 let start = self.format_byte_range().end;
7423 let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7424 start..end
7425 }
7426
7427 pub fn chained_seq_rule_set_count_byte_range(&self) -> Range<usize> {
7428 let start = self.coverage_offset_byte_range().end;
7429 let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
7430 start..end
7431 }
7432
7433 pub fn chained_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
7434 let chained_seq_rule_set_count = self.chained_seq_rule_set_count();
7435 let start = self.chained_seq_rule_set_count_byte_range().end;
7436 let end = start.saturating_add(
7437 (transforms::to_usize(chained_seq_rule_set_count))
7438 .saturating_mul(Offset24::RAW_BYTE_LEN),
7439 );
7440 start..end
7441 }
7442}
7443
7444impl<'a> MinByteRange<'a> for ChainedSequenceRuleSet2<'a> {
7445 fn min_byte_range(&self) -> Range<usize> {
7446 0..self.chained_seq_rule_offsets_byte_range().end
7447 }
7448 fn min_table_bytes(&self) -> &'a [u8] {
7449 let range = self.min_byte_range();
7450 self.offset_data().as_bytes().get(range).unwrap_or_default()
7451 }
7452}
7453
7454impl ReadArgs for ChainedSequenceRuleSet2<'_> {
7455 type Args = ();
7456}
7457
7458impl<'a> FontRead<'a> for ChainedSequenceRuleSet2<'a> {
7459 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7460 #[allow(clippy::absurd_extreme_comparisons)]
7461 if data.len() < Self::MIN_SIZE {
7462 return Err(ReadError::OutOfBounds);
7463 }
7464 let Some(data) = TableDataRef::new(data.as_bytes()) else {
7465 return Err(ReadError::OutOfBounds);
7466 };
7467 Ok(Self { data })
7468 }
7469}
7470
7471#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7473#[repr(C, packed)]
7474#[doc(hidden)]
7475pub struct ChainedSequenceRuleSet2FixedHeader {
7476 pub chained_seq_rule_count: BigEndian<u16>,
7477}
7478
7479#[allow(clippy::absurd_extreme_comparisons)]
7480const _: () = assert!(
7481 std::mem::size_of::<ChainedSequenceRuleSet2FixedHeader>() <= ChainedSequenceRuleSet2::MIN_SIZE
7482);
7483
7484#[derive(Clone)]
7486pub struct ChainedSequenceRuleSet2<'a> {
7487 data: TableDataRef<'a, ChainedSequenceRuleSet2FixedHeader>,
7488}
7489
7490#[allow(clippy::needless_lifetimes)]
7491impl<'a> ChainedSequenceRuleSet2<'a> {
7492 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
7493 basic_table_impls!(impl_the_methods);
7494
7495 pub fn chained_seq_rule_count(&self) -> u16 {
7497 self.data.header().chained_seq_rule_count.get()
7498 }
7499
7500 pub fn chained_seq_rule_offsets(&self) -> &'a [BigEndian<Offset24>] {
7503 let range = self.chained_seq_rule_offsets_byte_range();
7504 self.offset_data()
7505 .read_array(range)
7506 .ok()
7507 .unwrap_or_default()
7508 }
7509
7510 pub fn chained_seq_rules(&self) -> ArrayOfOffsets<'a, ChainedSequenceRule2<'a>, Offset24> {
7512 let data = self.offset_data();
7513 let offsets = self.chained_seq_rule_offsets();
7514 ArrayOfOffsets::new(offsets, data, ())
7515 }
7516
7517 pub fn chained_seq_rule_count_byte_range(&self) -> Range<usize> {
7518 let start = 0usize;
7519 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7520 start..end
7521 }
7522
7523 pub fn chained_seq_rule_offsets_byte_range(&self) -> Range<usize> {
7524 let chained_seq_rule_count = self.chained_seq_rule_count();
7525 let start = self.chained_seq_rule_count_byte_range().end;
7526 let end = start.saturating_add(
7527 (transforms::to_usize(chained_seq_rule_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
7528 );
7529 start..end
7530 }
7531}
7532
7533const _: () = assert!(FontData::default_data_long_enough(
7534 ChainedSequenceRuleSet2::MIN_SIZE
7535));
7536
7537impl Default for ChainedSequenceRuleSet2<'_> {
7538 fn default() -> Self {
7539 Self {
7540 data: TableDataRef::new(FontData::default_table_data().as_bytes())
7541 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
7542 }
7543 }
7544}
7545
7546impl<'a> MinByteRange<'a> for ChainedSequenceRule2<'a> {
7547 fn min_byte_range(&self) -> Range<usize> {
7548 0..self.seq_lookup_records_byte_range().end
7549 }
7550 fn min_table_bytes(&self) -> &'a [u8] {
7551 let range = self.min_byte_range();
7552 self.offset_data().as_bytes().get(range).unwrap_or_default()
7553 }
7554}
7555
7556impl ReadArgs for ChainedSequenceRule2<'_> {
7557 type Args = ();
7558}
7559
7560impl<'a> FontRead<'a> for ChainedSequenceRule2<'a> {
7561 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7562 #[allow(clippy::absurd_extreme_comparisons)]
7563 if data.len() < Self::MIN_SIZE {
7564 return Err(ReadError::OutOfBounds);
7565 }
7566 let Some(data) = TableDataRef::new(data.as_bytes()) else {
7567 return Err(ReadError::OutOfBounds);
7568 };
7569 Ok(Self { data })
7570 }
7571}
7572
7573#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7575#[repr(C, packed)]
7576#[doc(hidden)]
7577pub struct ChainedSequenceRule2FixedHeader {
7578 pub backtrack_glyph_count: BigEndian<u16>,
7579}
7580
7581#[allow(clippy::absurd_extreme_comparisons)]
7582const _: () = assert!(
7583 std::mem::size_of::<ChainedSequenceRule2FixedHeader>() <= ChainedSequenceRule2::MIN_SIZE
7584);
7585
7586#[derive(Clone)]
7588pub struct ChainedSequenceRule2<'a> {
7589 data: TableDataRef<'a, ChainedSequenceRule2FixedHeader>,
7590}
7591
7592#[allow(clippy::needless_lifetimes)]
7593impl<'a> ChainedSequenceRule2<'a> {
7594 pub const MIN_SIZE: usize =
7595 (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
7596 basic_table_impls!(impl_the_methods);
7597
7598 pub fn backtrack_glyph_count(&self) -> u16 {
7600 self.data.header().backtrack_glyph_count.get()
7601 }
7602
7603 pub fn backtrack_sequence(&self) -> &'a [BigEndian<GlyphId24>] {
7605 let range = self.backtrack_sequence_byte_range();
7606 self.offset_data()
7607 .read_array(range)
7608 .ok()
7609 .unwrap_or_default()
7610 }
7611
7612 pub fn input_glyph_count(&self) -> u16 {
7614 let range = self.input_glyph_count_byte_range();
7615 self.offset_data()
7616 .read_at(range.start)
7617 .ok()
7618 .unwrap_or_default()
7619 }
7620
7621 pub fn input_sequence(&self) -> &'a [BigEndian<GlyphId24>] {
7623 let range = self.input_sequence_byte_range();
7624 self.offset_data()
7625 .read_array(range)
7626 .ok()
7627 .unwrap_or_default()
7628 }
7629
7630 pub fn lookahead_glyph_count(&self) -> u16 {
7632 let range = self.lookahead_glyph_count_byte_range();
7633 self.offset_data()
7634 .read_at(range.start)
7635 .ok()
7636 .unwrap_or_default()
7637 }
7638
7639 pub fn lookahead_sequence(&self) -> &'a [BigEndian<GlyphId24>] {
7641 let range = self.lookahead_sequence_byte_range();
7642 self.offset_data()
7643 .read_array(range)
7644 .ok()
7645 .unwrap_or_default()
7646 }
7647
7648 pub fn seq_lookup_count(&self) -> u16 {
7650 let range = self.seq_lookup_count_byte_range();
7651 self.offset_data()
7652 .read_at(range.start)
7653 .ok()
7654 .unwrap_or_default()
7655 }
7656
7657 pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
7659 let range = self.seq_lookup_records_byte_range();
7660 self.offset_data()
7661 .read_array(range)
7662 .ok()
7663 .unwrap_or_default()
7664 }
7665
7666 pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> {
7667 let start = 0usize;
7668 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7669 start..end
7670 }
7671
7672 pub fn backtrack_sequence_byte_range(&self) -> Range<usize> {
7673 let backtrack_glyph_count = self.backtrack_glyph_count();
7674 let start = self.backtrack_glyph_count_byte_range().end;
7675 let end = start.saturating_add(
7676 (transforms::to_usize(backtrack_glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN),
7677 );
7678 start..end
7679 }
7680
7681 pub fn input_glyph_count_byte_range(&self) -> Range<usize> {
7682 let start = self.backtrack_sequence_byte_range().end;
7683 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7684 start..end
7685 }
7686
7687 pub fn input_sequence_byte_range(&self) -> Range<usize> {
7688 let input_glyph_count = self.input_glyph_count();
7689 let start = self.input_glyph_count_byte_range().end;
7690 let end = start.saturating_add(
7691 (transforms::subtract(input_glyph_count, 1_usize))
7692 .saturating_mul(GlyphId24::RAW_BYTE_LEN),
7693 );
7694 start..end
7695 }
7696
7697 pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> {
7698 let start = self.input_sequence_byte_range().end;
7699 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7700 start..end
7701 }
7702
7703 pub fn lookahead_sequence_byte_range(&self) -> Range<usize> {
7704 let lookahead_glyph_count = self.lookahead_glyph_count();
7705 let start = self.lookahead_glyph_count_byte_range().end;
7706 let end = start.saturating_add(
7707 (transforms::to_usize(lookahead_glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN),
7708 );
7709 start..end
7710 }
7711
7712 pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
7713 let start = self.lookahead_sequence_byte_range().end;
7714 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7715 start..end
7716 }
7717
7718 pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
7719 let seq_lookup_count = self.seq_lookup_count();
7720 let start = self.seq_lookup_count_byte_range().end;
7721 let end = start.saturating_add(
7722 (transforms::to_usize(seq_lookup_count))
7723 .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
7724 );
7725 start..end
7726 }
7727}
7728
7729const _: () = assert!(FontData::default_data_long_enough(
7730 ChainedSequenceRule2::MIN_SIZE
7731));
7732
7733impl Default for ChainedSequenceRule2<'_> {
7734 fn default() -> Self {
7735 Self {
7736 data: TableDataRef::new(FontData::default_table_data().as_bytes())
7737 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
7738 }
7739 }
7740}
7741
7742impl Format<u16> for ChainedSequenceContextFormat5<'_> {
7743 const FORMAT: u16 = 5;
7744}
7745
7746impl<'a> MinByteRange<'a> for ChainedSequenceContextFormat5<'a> {
7747 fn min_byte_range(&self) -> Range<usize> {
7748 0..self.chained_class_seq_rule_set_offsets_byte_range().end
7749 }
7750 fn min_table_bytes(&self) -> &'a [u8] {
7751 let range = self.min_byte_range();
7752 self.offset_data().as_bytes().get(range).unwrap_or_default()
7753 }
7754}
7755
7756impl ReadArgs for ChainedSequenceContextFormat5<'_> {
7757 type Args = ();
7758}
7759
7760impl<'a> FontRead<'a> for ChainedSequenceContextFormat5<'a> {
7761 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7762 #[allow(clippy::absurd_extreme_comparisons)]
7763 if data.len() < Self::MIN_SIZE {
7764 return Err(ReadError::OutOfBounds);
7765 }
7766 let Some(data) = TableDataRef::new(data.as_bytes()) else {
7767 return Err(ReadError::OutOfBounds);
7768 };
7769 Ok(Self { data })
7770 }
7771}
7772
7773#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7775#[repr(C, packed)]
7776#[doc(hidden)]
7777pub struct ChainedSequenceContextFormat5FixedHeader {
7778 pub format: BigEndian<u16>,
7779 pub coverage_offset: BigEndian<Offset32>,
7780 pub backtrack_class_def_offset: BigEndian<Offset32>,
7781 pub input_class_def_offset: BigEndian<Offset32>,
7782 pub lookahead_class_def_offset: BigEndian<Offset32>,
7783 pub chained_class_seq_rule_set_count: BigEndian<u16>,
7784}
7785
7786#[allow(clippy::absurd_extreme_comparisons)]
7787const _: () = assert!(
7788 std::mem::size_of::<ChainedSequenceContextFormat5FixedHeader>()
7789 <= ChainedSequenceContextFormat5::MIN_SIZE
7790);
7791
7792#[derive(Clone)]
7794pub struct ChainedSequenceContextFormat5<'a> {
7795 data: TableDataRef<'a, ChainedSequenceContextFormat5FixedHeader>,
7796}
7797
7798#[allow(clippy::needless_lifetimes)]
7799impl<'a> ChainedSequenceContextFormat5<'a> {
7800 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
7801 + Offset32::RAW_BYTE_LEN
7802 + Offset32::RAW_BYTE_LEN
7803 + Offset32::RAW_BYTE_LEN
7804 + Offset32::RAW_BYTE_LEN
7805 + u16::RAW_BYTE_LEN);
7806 basic_table_impls!(impl_the_methods);
7807
7808 pub fn format(&self) -> u16 {
7810 self.data.header().format.get()
7811 }
7812
7813 pub fn coverage_offset(&self) -> Offset32 {
7816 self.data.header().coverage_offset.get()
7817 }
7818
7819 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
7821 let data = self.offset_data();
7822 self.coverage_offset().resolve(data)
7823 }
7824
7825 pub fn backtrack_class_def_offset(&self) -> Offset32 {
7828 self.data.header().backtrack_class_def_offset.get()
7829 }
7830
7831 pub fn backtrack_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
7833 let data = self.offset_data();
7834 self.backtrack_class_def_offset().resolve(data)
7835 }
7836
7837 pub fn input_class_def_offset(&self) -> Offset32 {
7840 self.data.header().input_class_def_offset.get()
7841 }
7842
7843 pub fn input_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
7845 let data = self.offset_data();
7846 self.input_class_def_offset().resolve(data)
7847 }
7848
7849 pub fn lookahead_class_def_offset(&self) -> Offset32 {
7852 self.data.header().lookahead_class_def_offset.get()
7853 }
7854
7855 pub fn lookahead_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
7857 let data = self.offset_data();
7858 self.lookahead_class_def_offset().resolve(data)
7859 }
7860
7861 pub fn chained_class_seq_rule_set_count(&self) -> u16 {
7863 self.data.header().chained_class_seq_rule_set_count.get()
7864 }
7865
7866 pub fn chained_class_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] {
7869 let range = self.chained_class_seq_rule_set_offsets_byte_range();
7870 self.offset_data()
7871 .read_array(range)
7872 .ok()
7873 .unwrap_or_default()
7874 }
7875
7876 pub fn chained_class_seq_rule_sets(
7878 &self,
7879 ) -> ArrayOfNullableOffsets<'a, ChainedClassSequenceRuleSet2<'a>, Offset24> {
7880 let data = self.offset_data();
7881 let offsets = self.chained_class_seq_rule_set_offsets();
7882 ArrayOfNullableOffsets::new(offsets, data, ())
7883 }
7884
7885 pub fn format_byte_range(&self) -> Range<usize> {
7886 let start = 0usize;
7887 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7888 start..end
7889 }
7890
7891 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
7892 let start = self.format_byte_range().end;
7893 let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7894 start..end
7895 }
7896
7897 pub fn backtrack_class_def_offset_byte_range(&self) -> Range<usize> {
7898 let start = self.coverage_offset_byte_range().end;
7899 let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7900 start..end
7901 }
7902
7903 pub fn input_class_def_offset_byte_range(&self) -> Range<usize> {
7904 let start = self.backtrack_class_def_offset_byte_range().end;
7905 let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7906 start..end
7907 }
7908
7909 pub fn lookahead_class_def_offset_byte_range(&self) -> Range<usize> {
7910 let start = self.input_class_def_offset_byte_range().end;
7911 let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7912 start..end
7913 }
7914
7915 pub fn chained_class_seq_rule_set_count_byte_range(&self) -> Range<usize> {
7916 let start = self.lookahead_class_def_offset_byte_range().end;
7917 let end = start.saturating_add(u16::RAW_BYTE_LEN);
7918 start..end
7919 }
7920
7921 pub fn chained_class_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
7922 let chained_class_seq_rule_set_count = self.chained_class_seq_rule_set_count();
7923 let start = self.chained_class_seq_rule_set_count_byte_range().end;
7924 let end = start.saturating_add(
7925 (transforms::to_usize(chained_class_seq_rule_set_count))
7926 .saturating_mul(Offset24::RAW_BYTE_LEN),
7927 );
7928 start..end
7929 }
7930}
7931
7932impl<'a> MinByteRange<'a> for ChainedClassSequenceRuleSet2<'a> {
7933 fn min_byte_range(&self) -> Range<usize> {
7934 0..self.chained_class_seq_rule_offsets_byte_range().end
7935 }
7936 fn min_table_bytes(&self) -> &'a [u8] {
7937 let range = self.min_byte_range();
7938 self.offset_data().as_bytes().get(range).unwrap_or_default()
7939 }
7940}
7941
7942impl ReadArgs for ChainedClassSequenceRuleSet2<'_> {
7943 type Args = ();
7944}
7945
7946impl<'a> FontRead<'a> for ChainedClassSequenceRuleSet2<'a> {
7947 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7948 #[allow(clippy::absurd_extreme_comparisons)]
7949 if data.len() < Self::MIN_SIZE {
7950 return Err(ReadError::OutOfBounds);
7951 }
7952 let Some(data) = TableDataRef::new(data.as_bytes()) else {
7953 return Err(ReadError::OutOfBounds);
7954 };
7955 Ok(Self { data })
7956 }
7957}
7958
7959#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7961#[repr(C, packed)]
7962#[doc(hidden)]
7963pub struct ChainedClassSequenceRuleSet2FixedHeader {
7964 pub chained_class_seq_rule_count: BigEndian<u16>,
7965}
7966
7967#[allow(clippy::absurd_extreme_comparisons)]
7968const _: () = assert!(
7969 std::mem::size_of::<ChainedClassSequenceRuleSet2FixedHeader>()
7970 <= ChainedClassSequenceRuleSet2::MIN_SIZE
7971);
7972
7973#[derive(Clone)]
7975pub struct ChainedClassSequenceRuleSet2<'a> {
7976 data: TableDataRef<'a, ChainedClassSequenceRuleSet2FixedHeader>,
7977}
7978
7979#[allow(clippy::needless_lifetimes)]
7980impl<'a> ChainedClassSequenceRuleSet2<'a> {
7981 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
7982 basic_table_impls!(impl_the_methods);
7983
7984 pub fn chained_class_seq_rule_count(&self) -> u16 {
7986 self.data.header().chained_class_seq_rule_count.get()
7987 }
7988
7989 pub fn chained_class_seq_rule_offsets(&self) -> &'a [BigEndian<Offset24>] {
7992 let range = self.chained_class_seq_rule_offsets_byte_range();
7993 self.offset_data()
7994 .read_array(range)
7995 .ok()
7996 .unwrap_or_default()
7997 }
7998
7999 pub fn chained_class_seq_rules(
8001 &self,
8002 ) -> ArrayOfOffsets<'a, ChainedClassSequenceRule<'a>, Offset24> {
8003 let data = self.offset_data();
8004 let offsets = self.chained_class_seq_rule_offsets();
8005 ArrayOfOffsets::new(offsets, data, ())
8006 }
8007
8008 pub fn chained_class_seq_rule_count_byte_range(&self) -> Range<usize> {
8009 let start = 0usize;
8010 let end = start.saturating_add(u16::RAW_BYTE_LEN);
8011 start..end
8012 }
8013
8014 pub fn chained_class_seq_rule_offsets_byte_range(&self) -> Range<usize> {
8015 let chained_class_seq_rule_count = self.chained_class_seq_rule_count();
8016 let start = self.chained_class_seq_rule_count_byte_range().end;
8017 let end = start.saturating_add(
8018 (transforms::to_usize(chained_class_seq_rule_count))
8019 .saturating_mul(Offset24::RAW_BYTE_LEN),
8020 );
8021 start..end
8022 }
8023}
8024
8025const _: () = assert!(FontData::default_data_long_enough(
8026 ChainedClassSequenceRuleSet2::MIN_SIZE
8027));
8028
8029impl Default for ChainedClassSequenceRuleSet2<'_> {
8030 fn default() -> Self {
8031 Self {
8032 data: TableDataRef::new(FontData::default_table_data().as_bytes())
8033 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
8034 }
8035 }
8036}
8037
8038impl<'a, T> MinByteRange<'a> for LookupList2<'a, T> {
8039 fn min_byte_range(&self) -> Range<usize> {
8040 0..self.lookup_offsets_byte_range().end
8041 }
8042 fn min_table_bytes(&self) -> &'a [u8] {
8043 let range = self.min_byte_range();
8044 self.offset_data().as_bytes().get(range).unwrap_or_default()
8045 }
8046}
8047
8048impl<T> ReadArgs for LookupList2<'_, T> {
8049 type Args = ();
8050}
8051
8052impl<'a, T> FontRead<'a> for LookupList2<'a, T> {
8053 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
8054 #[allow(clippy::absurd_extreme_comparisons)]
8055 if data.len() < Self::MIN_SIZE {
8056 return Err(ReadError::OutOfBounds);
8057 }
8058 let Some(data) = TableDataRef::new(data.as_bytes()) else {
8059 return Err(ReadError::OutOfBounds);
8060 };
8061 Ok(Self {
8062 data,
8063 offset_type: std::marker::PhantomData,
8064 })
8065 }
8066}
8067
8068impl<'a, T> LookupList2<'a, T> {
8069 #[allow(dead_code)]
8070 pub(crate) fn of_unit_type(&self) -> LookupList2<'a, ()> {
8072 LookupList2 {
8073 data: self.data,
8074 offset_type: std::marker::PhantomData,
8075 }
8076 }
8077}
8078
8079#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
8081#[repr(C, packed)]
8082#[doc(hidden)]
8083pub struct LookupList2FixedHeader {
8084 pub lookup_count: BigEndian<u16>,
8085}
8086
8087#[allow(clippy::absurd_extreme_comparisons)]
8088const _: () = assert!(std::mem::size_of::<LookupList2FixedHeader>() <= LookupList2::<()>::MIN_SIZE);
8089
8090#[derive(Clone)]
8092pub struct LookupList2<'a, T = ()> {
8093 data: TableDataRef<'a, LookupList2FixedHeader>,
8094 offset_type: std::marker::PhantomData<*const T>,
8095}
8096
8097#[allow(clippy::needless_lifetimes)]
8098impl<'a, T> LookupList2<'a, T> {
8099 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
8100 basic_table_impls!(impl_the_methods);
8101
8102 pub fn lookup_count(&self) -> u16 {
8104 self.data.header().lookup_count.get()
8105 }
8106
8107 pub fn lookup_offsets(&self) -> &'a [BigEndian<Offset32>] {
8110 let range = self.lookup_offsets_byte_range();
8111 self.offset_data()
8112 .read_array(range)
8113 .ok()
8114 .unwrap_or_default()
8115 }
8116
8117 pub fn lookups(&self) -> ArrayOfOffsets<'a, T, Offset32>
8119 where
8120 T: FontRead<'a, Args = ()>,
8121 {
8122 let data = self.offset_data();
8123 let offsets = self.lookup_offsets();
8124 ArrayOfOffsets::new(offsets, data, ())
8125 }
8126
8127 pub fn lookup_count_byte_range(&self) -> Range<usize> {
8128 let start = 0usize;
8129 let end = start.saturating_add(u16::RAW_BYTE_LEN);
8130 start..end
8131 }
8132
8133 pub fn lookup_offsets_byte_range(&self) -> Range<usize> {
8134 let lookup_count = self.lookup_count();
8135 let start = self.lookup_count_byte_range().end;
8136 let end = start.saturating_add(
8137 (transforms::to_usize(lookup_count)).saturating_mul(Offset32::RAW_BYTE_LEN),
8138 );
8139 start..end
8140 }
8141}
8142
8143const _: () = assert!(FontData::default_data_long_enough(
8144 LookupList2::<()>::MIN_SIZE
8145));
8146
8147impl<T> Default for LookupList2<'_, T> {
8148 fn default() -> Self {
8149 Self {
8150 data: TableDataRef::new(FontData::default_table_data().as_bytes())
8151 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
8152 offset_type: std::marker::PhantomData,
8153 }
8154 }
8155}