1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Gsub<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self.lookup_list_offset_byte_range().end
11 }
12 fn min_table_bytes(&self) -> &'a [u8] {
13 let range = self.min_byte_range();
14 self.offset_data().as_bytes().get(range).unwrap_or_default()
15 }
16}
17
18impl TopLevelTable for Gsub<'_> {
19 const TAG: Tag = Tag::new(b"GSUB");
21}
22
23impl ReadArgs for Gsub<'_> {
24 type Args = ();
25}
26
27impl<'a> FontRead<'a> for Gsub<'a> {
28 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29 #[allow(clippy::absurd_extreme_comparisons)]
30 if data.len() < Self::MIN_SIZE {
31 return Err(ReadError::OutOfBounds);
32 }
33 let Some(data) = TableDataRef::new(data.as_bytes()) else {
34 return Err(ReadError::OutOfBounds);
35 };
36 Ok(Self { data })
37 }
38}
39
40#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42#[repr(C, packed)]
43#[doc(hidden)]
44pub struct GsubFixedHeader {
45 pub version: BigEndian<MajorMinor>,
46 pub script_list_offset: BigEndian<Nullable<Offset16>>,
47 pub feature_list_offset: BigEndian<Nullable<Offset16>>,
48 pub lookup_list_offset: BigEndian<Nullable<Offset16>>,
49}
50
51#[allow(clippy::absurd_extreme_comparisons)]
52const _: () = assert!(std::mem::size_of::<GsubFixedHeader>() <= Gsub::MIN_SIZE);
53
54#[derive(Clone)]
56pub struct Gsub<'a> {
57 data: TableDataRef<'a, GsubFixedHeader>,
58}
59
60#[allow(clippy::needless_lifetimes)]
61impl<'a> Gsub<'a> {
62 pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
63 + Offset16::RAW_BYTE_LEN
64 + Offset16::RAW_BYTE_LEN
65 + Offset16::RAW_BYTE_LEN);
66 basic_table_impls!(impl_the_methods);
67
68 pub fn version(&self) -> MajorMinor {
70 self.data.header().version.get()
71 }
72
73 pub fn script_list_offset(&self) -> Nullable<Offset16> {
75 self.data.header().script_list_offset.get()
76 }
77
78 pub fn feature_list_offset(&self) -> Nullable<Offset16> {
80 self.data.header().feature_list_offset.get()
81 }
82
83 pub fn lookup_list_offset(&self) -> Nullable<Offset16> {
85 self.data.header().lookup_list_offset.get()
86 }
87
88 pub fn feature_variations_offset(&self) -> Option<Nullable<Offset32>> {
91 let range = self.feature_variations_offset_byte_range();
92 (!range.is_empty())
93 .then(|| self.offset_data().read_at(range.start).ok())
94 .flatten()
95 }
96
97 pub fn feature_variations(&self) -> Option<Result<FeatureVariations<'a>, ReadError>> {
99 let data = self.offset_data();
100 self.feature_variations_offset().map(|x| x.resolve(data))?
101 }
102
103 pub fn script_list2_offset(&self) -> Option<Nullable<Offset32>> {
105 let range = self.script_list2_offset_byte_range();
106 (!range.is_empty())
107 .then(|| self.offset_data().read_at(range.start).ok())
108 .flatten()
109 }
110
111 pub fn script_list2(&self) -> Option<Result<ScriptList<'a>, ReadError>> {
113 let data = self.offset_data();
114 self.script_list2_offset().map(|x| x.resolve(data))?
115 }
116
117 pub fn feature_list2_offset(&self) -> Option<Nullable<Offset32>> {
119 let range = self.feature_list2_offset_byte_range();
120 (!range.is_empty())
121 .then(|| self.offset_data().read_at(range.start).ok())
122 .flatten()
123 }
124
125 pub fn feature_list2(&self) -> Option<Result<FeatureList<'a>, ReadError>> {
127 let data = self.offset_data();
128 self.feature_list2_offset().map(|x| x.resolve(data))?
129 }
130
131 pub fn lookup_list2_offset(&self) -> Option<Nullable<Offset32>> {
133 let range = self.lookup_list2_offset_byte_range();
134 (!range.is_empty())
135 .then(|| self.offset_data().read_at(range.start).ok())
136 .flatten()
137 }
138
139 pub fn lookup_list2(&self) -> Option<Result<SubstitutionLookupList2<'a>, ReadError>> {
141 let data = self.offset_data();
142 self.lookup_list2_offset().map(|x| x.resolve(data))?
143 }
144
145 pub fn version_byte_range(&self) -> Range<usize> {
146 let start = 0;
147 let end = start + MajorMinor::RAW_BYTE_LEN;
148 start..end
149 }
150
151 pub fn script_list_offset_byte_range(&self) -> Range<usize> {
152 let start = self.version_byte_range().end;
153 let end = start + Offset16::RAW_BYTE_LEN;
154 start..end
155 }
156
157 pub fn feature_list_offset_byte_range(&self) -> Range<usize> {
158 let start = self.script_list_offset_byte_range().end;
159 let end = start + Offset16::RAW_BYTE_LEN;
160 start..end
161 }
162
163 pub fn lookup_list_offset_byte_range(&self) -> Range<usize> {
164 let start = self.feature_list_offset_byte_range().end;
165 let end = start + Offset16::RAW_BYTE_LEN;
166 start..end
167 }
168
169 pub fn feature_variations_offset_byte_range(&self) -> Range<usize> {
170 let start = self.lookup_list_offset_byte_range().end;
171 let end = if self.version().compatible((1u16, 1u16)) {
172 start + Offset32::RAW_BYTE_LEN
173 } else {
174 start
175 };
176 start..end
177 }
178
179 pub fn script_list2_offset_byte_range(&self) -> Range<usize> {
180 let start = self.feature_variations_offset_byte_range().end;
181 let end = if self.version().compatible((1u16, 2u16)) {
182 start + Offset32::RAW_BYTE_LEN
183 } else {
184 start
185 };
186 start..end
187 }
188
189 pub fn feature_list2_offset_byte_range(&self) -> Range<usize> {
190 let start = self.script_list2_offset_byte_range().end;
191 let end = if self.version().compatible((1u16, 2u16)) {
192 start + Offset32::RAW_BYTE_LEN
193 } else {
194 start
195 };
196 start..end
197 }
198
199 pub fn lookup_list2_offset_byte_range(&self) -> Range<usize> {
200 let start = self.feature_list2_offset_byte_range().end;
201 let end = if self.version().compatible((1u16, 2u16)) {
202 start + Offset32::RAW_BYTE_LEN
203 } else {
204 start
205 };
206 start..end
207 }
208}
209
210const _: () = assert!(FontData::default_data_long_enough(Gsub::MIN_SIZE));
211
212impl Default for Gsub<'_> {
213 fn default() -> Self {
214 Self {
215 data: TableDataRef::new(FontData::default_table_data().as_bytes())
216 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
217 }
218 }
219}
220
221pub enum SubstitutionLookup<'a> {
223 Single(Lookup<'a, SingleSubst<'a>>),
224 Multiple(Lookup<'a, MultipleSubst<'a>>),
225 Alternate(Lookup<'a, AlternateSubst<'a>>),
226 Ligature(Lookup<'a, LigatureSubst<'a>>),
227 Contextual(Lookup<'a, SubstitutionSequenceContext<'a>>),
228 ChainContextual(Lookup<'a, SubstitutionChainContext<'a>>),
229 Extension(Lookup<'a, ExtensionSubtable<'a>>),
230 Reverse(Lookup<'a, ReverseChainSingleSubst<'a>>),
231}
232
233impl Default for SubstitutionLookup<'_> {
234 fn default() -> Self {
235 Self::Single(Default::default())
236 }
237}
238
239impl ReadArgs for SubstitutionLookup<'_> {
240 type Args = ();
241}
242
243impl<'a> FontRead<'a> for SubstitutionLookup<'a> {
244 fn read_with_args(bytes: FontData<'a>, _: ()) -> Result<Self, ReadError> {
245 let discriminant = Lookup::read_discriminant(bytes)?;
246 match discriminant {
247 1 => Ok(SubstitutionLookup::Single(FontRead::read(bytes)?)),
248 2 => Ok(SubstitutionLookup::Multiple(FontRead::read(bytes)?)),
249 3 => Ok(SubstitutionLookup::Alternate(FontRead::read(bytes)?)),
250 4 => Ok(SubstitutionLookup::Ligature(FontRead::read(bytes)?)),
251 5 => Ok(SubstitutionLookup::Contextual(FontRead::read(bytes)?)),
252 6 => Ok(SubstitutionLookup::ChainContextual(FontRead::read(bytes)?)),
253 7 => Ok(SubstitutionLookup::Extension(FontRead::read(bytes)?)),
254 8 => Ok(SubstitutionLookup::Reverse(FontRead::read(bytes)?)),
255 other => Err(ReadError::InvalidFormat(other.into())),
256 }
257 }
258}
259
260impl<'a> SubstitutionLookup<'a> {
261 #[allow(dead_code)]
262 pub(crate) fn of_unit_type(&self) -> Lookup<'a, ()> {
266 match self {
267 SubstitutionLookup::Single(inner) => inner.of_unit_type(),
268 SubstitutionLookup::Multiple(inner) => inner.of_unit_type(),
269 SubstitutionLookup::Alternate(inner) => inner.of_unit_type(),
270 SubstitutionLookup::Ligature(inner) => inner.of_unit_type(),
271 SubstitutionLookup::Contextual(inner) => inner.of_unit_type(),
272 SubstitutionLookup::ChainContextual(inner) => inner.of_unit_type(),
273 SubstitutionLookup::Extension(inner) => inner.of_unit_type(),
274 SubstitutionLookup::Reverse(inner) => inner.of_unit_type(),
275 }
276 }
277}
278
279#[derive(Clone)]
281pub enum SingleSubst<'a> {
282 Format1(SingleSubstFormat1<'a>),
283 Format2(SingleSubstFormat2<'a>),
284 Format3(SingleSubstFormat3<'a>),
285 Format4(SingleSubstFormat4<'a>),
286}
287
288impl Default for SingleSubst<'_> {
289 fn default() -> Self {
290 Self::Format1(Default::default())
291 }
292}
293
294impl<'a> SingleSubst<'a> {
295 pub fn offset_data(&self) -> FontData<'a> {
297 match self {
298 Self::Format1(item) => item.offset_data(),
299 Self::Format2(item) => item.offset_data(),
300 Self::Format3(item) => item.offset_data(),
301 Self::Format4(item) => item.offset_data(),
302 }
303 }
304
305 pub fn subst_format(&self) -> u16 {
307 match self {
308 Self::Format1(item) => item.subst_format(),
309 Self::Format2(item) => item.subst_format(),
310 Self::Format3(item) => item.subst_format(),
311 Self::Format4(item) => item.subst_format(),
312 }
313 }
314}
315
316impl ReadArgs for SingleSubst<'_> {
317 type Args = ();
318}
319
320impl<'a> FontRead<'a> for SingleSubst<'a> {
321 #[inline]
322 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
323 let format: u16 = data.read_at(0usize)?;
324 match format {
325 SingleSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
326 SingleSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
327 SingleSubstFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
328 SingleSubstFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
329 other => Err(ReadError::InvalidFormat(other.into())),
330 }
331 }
332}
333
334impl<'a> MinByteRange<'a> for SingleSubst<'a> {
335 fn min_byte_range(&self) -> Range<usize> {
336 match self {
337 Self::Format1(item) => item.min_byte_range(),
338 Self::Format2(item) => item.min_byte_range(),
339 Self::Format3(item) => item.min_byte_range(),
340 Self::Format4(item) => item.min_byte_range(),
341 }
342 }
343 fn min_table_bytes(&self) -> &'a [u8] {
344 match self {
345 Self::Format1(item) => item.min_table_bytes(),
346 Self::Format2(item) => item.min_table_bytes(),
347 Self::Format3(item) => item.min_table_bytes(),
348 Self::Format4(item) => item.min_table_bytes(),
349 }
350 }
351}
352
353impl Format<u16> for SingleSubstFormat1<'_> {
354 const FORMAT: u16 = 1;
355}
356
357impl<'a> MinByteRange<'a> for SingleSubstFormat1<'a> {
358 fn min_byte_range(&self) -> Range<usize> {
359 0..self.delta_glyph_id_byte_range().end
360 }
361 fn min_table_bytes(&self) -> &'a [u8] {
362 let range = self.min_byte_range();
363 self.offset_data().as_bytes().get(range).unwrap_or_default()
364 }
365}
366
367impl ReadArgs for SingleSubstFormat1<'_> {
368 type Args = ();
369}
370
371impl<'a> FontRead<'a> for SingleSubstFormat1<'a> {
372 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
373 #[allow(clippy::absurd_extreme_comparisons)]
374 if data.len() < Self::MIN_SIZE {
375 return Err(ReadError::OutOfBounds);
376 }
377 let Some(data) = TableDataRef::new(data.as_bytes()) else {
378 return Err(ReadError::OutOfBounds);
379 };
380 Ok(Self { data })
381 }
382}
383
384#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
386#[repr(C, packed)]
387#[doc(hidden)]
388pub struct SingleSubstFormat1FixedHeader {
389 pub subst_format: BigEndian<u16>,
390 pub coverage_offset: BigEndian<Offset16>,
391 pub delta_glyph_id: BigEndian<i16>,
392}
393
394#[allow(clippy::absurd_extreme_comparisons)]
395const _: () =
396 assert!(std::mem::size_of::<SingleSubstFormat1FixedHeader>() <= SingleSubstFormat1::MIN_SIZE);
397
398#[derive(Clone)]
400pub struct SingleSubstFormat1<'a> {
401 data: TableDataRef<'a, SingleSubstFormat1FixedHeader>,
402}
403
404#[allow(clippy::needless_lifetimes)]
405impl<'a> SingleSubstFormat1<'a> {
406 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN);
407 basic_table_impls!(impl_the_methods);
408
409 pub fn subst_format(&self) -> u16 {
411 self.data.header().subst_format.get()
412 }
413
414 pub fn coverage_offset(&self) -> Offset16 {
417 self.data.header().coverage_offset.get()
418 }
419
420 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
422 let data = self.offset_data();
423 self.coverage_offset().resolve(data)
424 }
425
426 pub fn delta_glyph_id(&self) -> i16 {
428 self.data.header().delta_glyph_id.get()
429 }
430
431 pub fn subst_format_byte_range(&self) -> Range<usize> {
432 let start = 0;
433 let end = start + u16::RAW_BYTE_LEN;
434 start..end
435 }
436
437 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
438 let start = self.subst_format_byte_range().end;
439 let end = start + Offset16::RAW_BYTE_LEN;
440 start..end
441 }
442
443 pub fn delta_glyph_id_byte_range(&self) -> Range<usize> {
444 let start = self.coverage_offset_byte_range().end;
445 let end = start + i16::RAW_BYTE_LEN;
446 start..end
447 }
448}
449
450const _: () = assert!(FontData::default_data_long_enough(
451 SingleSubstFormat1::MIN_SIZE
452));
453
454impl Default for SingleSubstFormat1<'_> {
455 fn default() -> Self {
456 Self {
457 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
458 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
459 }
460 }
461}
462
463impl Format<u16> for SingleSubstFormat2<'_> {
464 const FORMAT: u16 = 2;
465}
466
467impl<'a> MinByteRange<'a> for SingleSubstFormat2<'a> {
468 fn min_byte_range(&self) -> Range<usize> {
469 0..self.substitute_glyph_ids_byte_range().end
470 }
471 fn min_table_bytes(&self) -> &'a [u8] {
472 let range = self.min_byte_range();
473 self.offset_data().as_bytes().get(range).unwrap_or_default()
474 }
475}
476
477impl ReadArgs for SingleSubstFormat2<'_> {
478 type Args = ();
479}
480
481impl<'a> FontRead<'a> for SingleSubstFormat2<'a> {
482 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
483 #[allow(clippy::absurd_extreme_comparisons)]
484 if data.len() < Self::MIN_SIZE {
485 return Err(ReadError::OutOfBounds);
486 }
487 let Some(data) = TableDataRef::new(data.as_bytes()) else {
488 return Err(ReadError::OutOfBounds);
489 };
490 Ok(Self { data })
491 }
492}
493
494#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
496#[repr(C, packed)]
497#[doc(hidden)]
498pub struct SingleSubstFormat2FixedHeader {
499 pub subst_format: BigEndian<u16>,
500 pub coverage_offset: BigEndian<Offset16>,
501 pub glyph_count: BigEndian<u16>,
502}
503
504#[allow(clippy::absurd_extreme_comparisons)]
505const _: () =
506 assert!(std::mem::size_of::<SingleSubstFormat2FixedHeader>() <= SingleSubstFormat2::MIN_SIZE);
507
508#[derive(Clone)]
510pub struct SingleSubstFormat2<'a> {
511 data: TableDataRef<'a, SingleSubstFormat2FixedHeader>,
512}
513
514#[allow(clippy::needless_lifetimes)]
515impl<'a> SingleSubstFormat2<'a> {
516 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
517 basic_table_impls!(impl_the_methods);
518
519 pub fn subst_format(&self) -> u16 {
521 self.data.header().subst_format.get()
522 }
523
524 pub fn coverage_offset(&self) -> Offset16 {
527 self.data.header().coverage_offset.get()
528 }
529
530 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
532 let data = self.offset_data();
533 self.coverage_offset().resolve(data)
534 }
535
536 pub fn glyph_count(&self) -> u16 {
538 self.data.header().glyph_count.get()
539 }
540
541 pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId16>] {
543 let range = self.substitute_glyph_ids_byte_range();
544 self.offset_data()
545 .read_array(range)
546 .ok()
547 .unwrap_or_default()
548 }
549
550 pub fn subst_format_byte_range(&self) -> Range<usize> {
551 let start = 0;
552 let end = start + u16::RAW_BYTE_LEN;
553 start..end
554 }
555
556 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
557 let start = self.subst_format_byte_range().end;
558 let end = start + Offset16::RAW_BYTE_LEN;
559 start..end
560 }
561
562 pub fn glyph_count_byte_range(&self) -> Range<usize> {
563 let start = self.coverage_offset_byte_range().end;
564 let end = start + u16::RAW_BYTE_LEN;
565 start..end
566 }
567
568 pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> {
569 let glyph_count = self.glyph_count();
570 let start = self.glyph_count_byte_range().end;
571 let end =
572 start + (transforms::to_usize(glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN);
573 start..end
574 }
575}
576
577impl Format<u16> for MultipleSubstFormat1<'_> {
578 const FORMAT: u16 = 1;
579}
580
581impl<'a> MinByteRange<'a> for MultipleSubstFormat1<'a> {
582 fn min_byte_range(&self) -> Range<usize> {
583 0..self.sequence_offsets_byte_range().end
584 }
585 fn min_table_bytes(&self) -> &'a [u8] {
586 let range = self.min_byte_range();
587 self.offset_data().as_bytes().get(range).unwrap_or_default()
588 }
589}
590
591impl ReadArgs for MultipleSubstFormat1<'_> {
592 type Args = ();
593}
594
595impl<'a> FontRead<'a> for MultipleSubstFormat1<'a> {
596 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
597 #[allow(clippy::absurd_extreme_comparisons)]
598 if data.len() < Self::MIN_SIZE {
599 return Err(ReadError::OutOfBounds);
600 }
601 let Some(data) = TableDataRef::new(data.as_bytes()) else {
602 return Err(ReadError::OutOfBounds);
603 };
604 Ok(Self { data })
605 }
606}
607
608#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
610#[repr(C, packed)]
611#[doc(hidden)]
612pub struct MultipleSubstFormat1FixedHeader {
613 pub subst_format: BigEndian<u16>,
614 pub coverage_offset: BigEndian<Offset16>,
615 pub sequence_count: BigEndian<u16>,
616}
617
618#[allow(clippy::absurd_extreme_comparisons)]
619const _: () = assert!(
620 std::mem::size_of::<MultipleSubstFormat1FixedHeader>() <= MultipleSubstFormat1::MIN_SIZE
621);
622
623#[derive(Clone)]
625pub struct MultipleSubstFormat1<'a> {
626 data: TableDataRef<'a, MultipleSubstFormat1FixedHeader>,
627}
628
629#[allow(clippy::needless_lifetimes)]
630impl<'a> MultipleSubstFormat1<'a> {
631 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
632 basic_table_impls!(impl_the_methods);
633
634 pub fn subst_format(&self) -> u16 {
636 self.data.header().subst_format.get()
637 }
638
639 pub fn coverage_offset(&self) -> Offset16 {
642 self.data.header().coverage_offset.get()
643 }
644
645 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
647 let data = self.offset_data();
648 self.coverage_offset().resolve(data)
649 }
650
651 pub fn sequence_count(&self) -> u16 {
653 self.data.header().sequence_count.get()
654 }
655
656 pub fn sequence_offsets(&self) -> &'a [BigEndian<Offset16>] {
659 let range = self.sequence_offsets_byte_range();
660 self.offset_data()
661 .read_array(range)
662 .ok()
663 .unwrap_or_default()
664 }
665
666 pub fn sequences(&self) -> ArrayOfOffsets<'a, Sequence<'a>, Offset16> {
668 let data = self.offset_data();
669 let offsets = self.sequence_offsets();
670 ArrayOfOffsets::new(offsets, data, ())
671 }
672
673 pub fn subst_format_byte_range(&self) -> Range<usize> {
674 let start = 0;
675 let end = start + u16::RAW_BYTE_LEN;
676 start..end
677 }
678
679 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
680 let start = self.subst_format_byte_range().end;
681 let end = start + Offset16::RAW_BYTE_LEN;
682 start..end
683 }
684
685 pub fn sequence_count_byte_range(&self) -> Range<usize> {
686 let start = self.coverage_offset_byte_range().end;
687 let end = start + u16::RAW_BYTE_LEN;
688 start..end
689 }
690
691 pub fn sequence_offsets_byte_range(&self) -> Range<usize> {
692 let sequence_count = self.sequence_count();
693 let start = self.sequence_count_byte_range().end;
694 let end =
695 start + (transforms::to_usize(sequence_count)).saturating_mul(Offset16::RAW_BYTE_LEN);
696 start..end
697 }
698}
699
700const _: () = assert!(FontData::default_data_long_enough(
701 MultipleSubstFormat1::MIN_SIZE
702));
703
704impl Default for MultipleSubstFormat1<'_> {
705 fn default() -> Self {
706 Self {
707 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
708 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
709 }
710 }
711}
712
713impl<'a> MinByteRange<'a> for Sequence<'a> {
714 fn min_byte_range(&self) -> Range<usize> {
715 0..self.substitute_glyph_ids_byte_range().end
716 }
717 fn min_table_bytes(&self) -> &'a [u8] {
718 let range = self.min_byte_range();
719 self.offset_data().as_bytes().get(range).unwrap_or_default()
720 }
721}
722
723impl ReadArgs for Sequence<'_> {
724 type Args = ();
725}
726
727impl<'a> FontRead<'a> for Sequence<'a> {
728 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
729 #[allow(clippy::absurd_extreme_comparisons)]
730 if data.len() < Self::MIN_SIZE {
731 return Err(ReadError::OutOfBounds);
732 }
733 let Some(data) = TableDataRef::new(data.as_bytes()) else {
734 return Err(ReadError::OutOfBounds);
735 };
736 Ok(Self { data })
737 }
738}
739
740#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
742#[repr(C, packed)]
743#[doc(hidden)]
744pub struct SequenceFixedHeader {
745 pub glyph_count: BigEndian<u16>,
746}
747
748#[allow(clippy::absurd_extreme_comparisons)]
749const _: () = assert!(std::mem::size_of::<SequenceFixedHeader>() <= Sequence::MIN_SIZE);
750
751#[derive(Clone)]
753pub struct Sequence<'a> {
754 data: TableDataRef<'a, SequenceFixedHeader>,
755}
756
757#[allow(clippy::needless_lifetimes)]
758impl<'a> Sequence<'a> {
759 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
760 basic_table_impls!(impl_the_methods);
761
762 pub fn glyph_count(&self) -> u16 {
765 self.data.header().glyph_count.get()
766 }
767
768 pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId16>] {
770 let range = self.substitute_glyph_ids_byte_range();
771 self.offset_data()
772 .read_array(range)
773 .ok()
774 .unwrap_or_default()
775 }
776
777 pub fn glyph_count_byte_range(&self) -> Range<usize> {
778 let start = 0;
779 let end = start + u16::RAW_BYTE_LEN;
780 start..end
781 }
782
783 pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> {
784 let glyph_count = self.glyph_count();
785 let start = self.glyph_count_byte_range().end;
786 let end =
787 start + (transforms::to_usize(glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN);
788 start..end
789 }
790}
791
792const _: () = assert!(FontData::default_data_long_enough(Sequence::MIN_SIZE));
793
794impl Default for Sequence<'_> {
795 fn default() -> Self {
796 Self {
797 data: TableDataRef::new(FontData::default_table_data().as_bytes())
798 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
799 }
800 }
801}
802
803impl Format<u16> for AlternateSubstFormat1<'_> {
804 const FORMAT: u16 = 1;
805}
806
807impl<'a> MinByteRange<'a> for AlternateSubstFormat1<'a> {
808 fn min_byte_range(&self) -> Range<usize> {
809 0..self.alternate_set_offsets_byte_range().end
810 }
811 fn min_table_bytes(&self) -> &'a [u8] {
812 let range = self.min_byte_range();
813 self.offset_data().as_bytes().get(range).unwrap_or_default()
814 }
815}
816
817impl ReadArgs for AlternateSubstFormat1<'_> {
818 type Args = ();
819}
820
821impl<'a> FontRead<'a> for AlternateSubstFormat1<'a> {
822 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
823 #[allow(clippy::absurd_extreme_comparisons)]
824 if data.len() < Self::MIN_SIZE {
825 return Err(ReadError::OutOfBounds);
826 }
827 let Some(data) = TableDataRef::new(data.as_bytes()) else {
828 return Err(ReadError::OutOfBounds);
829 };
830 Ok(Self { data })
831 }
832}
833
834#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
836#[repr(C, packed)]
837#[doc(hidden)]
838pub struct AlternateSubstFormat1FixedHeader {
839 pub subst_format: BigEndian<u16>,
840 pub coverage_offset: BigEndian<Offset16>,
841 pub alternate_set_count: BigEndian<u16>,
842}
843
844#[allow(clippy::absurd_extreme_comparisons)]
845const _: () = assert!(
846 std::mem::size_of::<AlternateSubstFormat1FixedHeader>() <= AlternateSubstFormat1::MIN_SIZE
847);
848
849#[derive(Clone)]
851pub struct AlternateSubstFormat1<'a> {
852 data: TableDataRef<'a, AlternateSubstFormat1FixedHeader>,
853}
854
855#[allow(clippy::needless_lifetimes)]
856impl<'a> AlternateSubstFormat1<'a> {
857 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
858 basic_table_impls!(impl_the_methods);
859
860 pub fn subst_format(&self) -> u16 {
862 self.data.header().subst_format.get()
863 }
864
865 pub fn coverage_offset(&self) -> Offset16 {
868 self.data.header().coverage_offset.get()
869 }
870
871 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
873 let data = self.offset_data();
874 self.coverage_offset().resolve(data)
875 }
876
877 pub fn alternate_set_count(&self) -> u16 {
879 self.data.header().alternate_set_count.get()
880 }
881
882 pub fn alternate_set_offsets(&self) -> &'a [BigEndian<Offset16>] {
885 let range = self.alternate_set_offsets_byte_range();
886 self.offset_data()
887 .read_array(range)
888 .ok()
889 .unwrap_or_default()
890 }
891
892 pub fn alternate_sets(&self) -> ArrayOfOffsets<'a, AlternateSet<'a>, Offset16> {
894 let data = self.offset_data();
895 let offsets = self.alternate_set_offsets();
896 ArrayOfOffsets::new(offsets, data, ())
897 }
898
899 pub fn subst_format_byte_range(&self) -> Range<usize> {
900 let start = 0;
901 let end = start + u16::RAW_BYTE_LEN;
902 start..end
903 }
904
905 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
906 let start = self.subst_format_byte_range().end;
907 let end = start + Offset16::RAW_BYTE_LEN;
908 start..end
909 }
910
911 pub fn alternate_set_count_byte_range(&self) -> Range<usize> {
912 let start = self.coverage_offset_byte_range().end;
913 let end = start + u16::RAW_BYTE_LEN;
914 start..end
915 }
916
917 pub fn alternate_set_offsets_byte_range(&self) -> Range<usize> {
918 let alternate_set_count = self.alternate_set_count();
919 let start = self.alternate_set_count_byte_range().end;
920 let end = start
921 + (transforms::to_usize(alternate_set_count)).saturating_mul(Offset16::RAW_BYTE_LEN);
922 start..end
923 }
924}
925
926const _: () = assert!(FontData::default_data_long_enough(
927 AlternateSubstFormat1::MIN_SIZE
928));
929
930impl Default for AlternateSubstFormat1<'_> {
931 fn default() -> Self {
932 Self {
933 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
934 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
935 }
936 }
937}
938
939impl<'a> MinByteRange<'a> for AlternateSet<'a> {
940 fn min_byte_range(&self) -> Range<usize> {
941 0..self.alternate_glyph_ids_byte_range().end
942 }
943 fn min_table_bytes(&self) -> &'a [u8] {
944 let range = self.min_byte_range();
945 self.offset_data().as_bytes().get(range).unwrap_or_default()
946 }
947}
948
949impl ReadArgs for AlternateSet<'_> {
950 type Args = ();
951}
952
953impl<'a> FontRead<'a> for AlternateSet<'a> {
954 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
955 #[allow(clippy::absurd_extreme_comparisons)]
956 if data.len() < Self::MIN_SIZE {
957 return Err(ReadError::OutOfBounds);
958 }
959 let Some(data) = TableDataRef::new(data.as_bytes()) else {
960 return Err(ReadError::OutOfBounds);
961 };
962 Ok(Self { data })
963 }
964}
965
966#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
968#[repr(C, packed)]
969#[doc(hidden)]
970pub struct AlternateSetFixedHeader {
971 pub glyph_count: BigEndian<u16>,
972}
973
974#[allow(clippy::absurd_extreme_comparisons)]
975const _: () = assert!(std::mem::size_of::<AlternateSetFixedHeader>() <= AlternateSet::MIN_SIZE);
976
977#[derive(Clone)]
979pub struct AlternateSet<'a> {
980 data: TableDataRef<'a, AlternateSetFixedHeader>,
981}
982
983#[allow(clippy::needless_lifetimes)]
984impl<'a> AlternateSet<'a> {
985 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
986 basic_table_impls!(impl_the_methods);
987
988 pub fn glyph_count(&self) -> u16 {
990 self.data.header().glyph_count.get()
991 }
992
993 pub fn alternate_glyph_ids(&self) -> &'a [BigEndian<GlyphId16>] {
995 let range = self.alternate_glyph_ids_byte_range();
996 self.offset_data()
997 .read_array(range)
998 .ok()
999 .unwrap_or_default()
1000 }
1001
1002 pub fn glyph_count_byte_range(&self) -> Range<usize> {
1003 let start = 0;
1004 let end = start + u16::RAW_BYTE_LEN;
1005 start..end
1006 }
1007
1008 pub fn alternate_glyph_ids_byte_range(&self) -> Range<usize> {
1009 let glyph_count = self.glyph_count();
1010 let start = self.glyph_count_byte_range().end;
1011 let end =
1012 start + (transforms::to_usize(glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN);
1013 start..end
1014 }
1015}
1016
1017const _: () = assert!(FontData::default_data_long_enough(AlternateSet::MIN_SIZE));
1018
1019impl Default for AlternateSet<'_> {
1020 fn default() -> Self {
1021 Self {
1022 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1023 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1024 }
1025 }
1026}
1027
1028impl Format<u16> for LigatureSubstFormat1<'_> {
1029 const FORMAT: u16 = 1;
1030}
1031
1032impl<'a> MinByteRange<'a> for LigatureSubstFormat1<'a> {
1033 fn min_byte_range(&self) -> Range<usize> {
1034 0..self.ligature_set_offsets_byte_range().end
1035 }
1036 fn min_table_bytes(&self) -> &'a [u8] {
1037 let range = self.min_byte_range();
1038 self.offset_data().as_bytes().get(range).unwrap_or_default()
1039 }
1040}
1041
1042impl ReadArgs for LigatureSubstFormat1<'_> {
1043 type Args = ();
1044}
1045
1046impl<'a> FontRead<'a> for LigatureSubstFormat1<'a> {
1047 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1048 #[allow(clippy::absurd_extreme_comparisons)]
1049 if data.len() < Self::MIN_SIZE {
1050 return Err(ReadError::OutOfBounds);
1051 }
1052 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1053 return Err(ReadError::OutOfBounds);
1054 };
1055 Ok(Self { data })
1056 }
1057}
1058
1059#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1061#[repr(C, packed)]
1062#[doc(hidden)]
1063pub struct LigatureSubstFormat1FixedHeader {
1064 pub subst_format: BigEndian<u16>,
1065 pub coverage_offset: BigEndian<Offset16>,
1066 pub ligature_set_count: BigEndian<u16>,
1067}
1068
1069#[allow(clippy::absurd_extreme_comparisons)]
1070const _: () = assert!(
1071 std::mem::size_of::<LigatureSubstFormat1FixedHeader>() <= LigatureSubstFormat1::MIN_SIZE
1072);
1073
1074#[derive(Clone)]
1076pub struct LigatureSubstFormat1<'a> {
1077 data: TableDataRef<'a, LigatureSubstFormat1FixedHeader>,
1078}
1079
1080#[allow(clippy::needless_lifetimes)]
1081impl<'a> LigatureSubstFormat1<'a> {
1082 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1083 basic_table_impls!(impl_the_methods);
1084
1085 pub fn subst_format(&self) -> u16 {
1087 self.data.header().subst_format.get()
1088 }
1089
1090 pub fn coverage_offset(&self) -> Offset16 {
1093 self.data.header().coverage_offset.get()
1094 }
1095
1096 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1098 let data = self.offset_data();
1099 self.coverage_offset().resolve(data)
1100 }
1101
1102 pub fn ligature_set_count(&self) -> u16 {
1104 self.data.header().ligature_set_count.get()
1105 }
1106
1107 pub fn ligature_set_offsets(&self) -> &'a [BigEndian<Offset16>] {
1110 let range = self.ligature_set_offsets_byte_range();
1111 self.offset_data()
1112 .read_array(range)
1113 .ok()
1114 .unwrap_or_default()
1115 }
1116
1117 pub fn ligature_sets(&self) -> ArrayOfOffsets<'a, LigatureSet<'a>, Offset16> {
1119 let data = self.offset_data();
1120 let offsets = self.ligature_set_offsets();
1121 ArrayOfOffsets::new(offsets, data, ())
1122 }
1123
1124 pub fn subst_format_byte_range(&self) -> Range<usize> {
1125 let start = 0;
1126 let end = start + u16::RAW_BYTE_LEN;
1127 start..end
1128 }
1129
1130 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
1131 let start = self.subst_format_byte_range().end;
1132 let end = start + Offset16::RAW_BYTE_LEN;
1133 start..end
1134 }
1135
1136 pub fn ligature_set_count_byte_range(&self) -> Range<usize> {
1137 let start = self.coverage_offset_byte_range().end;
1138 let end = start + u16::RAW_BYTE_LEN;
1139 start..end
1140 }
1141
1142 pub fn ligature_set_offsets_byte_range(&self) -> Range<usize> {
1143 let ligature_set_count = self.ligature_set_count();
1144 let start = self.ligature_set_count_byte_range().end;
1145 let end = start
1146 + (transforms::to_usize(ligature_set_count)).saturating_mul(Offset16::RAW_BYTE_LEN);
1147 start..end
1148 }
1149}
1150
1151const _: () = assert!(FontData::default_data_long_enough(
1152 LigatureSubstFormat1::MIN_SIZE
1153));
1154
1155impl Default for LigatureSubstFormat1<'_> {
1156 fn default() -> Self {
1157 Self {
1158 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
1159 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1160 }
1161 }
1162}
1163
1164impl<'a> MinByteRange<'a> for LigatureSet<'a> {
1165 fn min_byte_range(&self) -> Range<usize> {
1166 0..self.ligature_offsets_byte_range().end
1167 }
1168 fn min_table_bytes(&self) -> &'a [u8] {
1169 let range = self.min_byte_range();
1170 self.offset_data().as_bytes().get(range).unwrap_or_default()
1171 }
1172}
1173
1174impl ReadArgs for LigatureSet<'_> {
1175 type Args = ();
1176}
1177
1178impl<'a> FontRead<'a> for LigatureSet<'a> {
1179 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1180 #[allow(clippy::absurd_extreme_comparisons)]
1181 if data.len() < Self::MIN_SIZE {
1182 return Err(ReadError::OutOfBounds);
1183 }
1184 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1185 return Err(ReadError::OutOfBounds);
1186 };
1187 Ok(Self { data })
1188 }
1189}
1190
1191#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1193#[repr(C, packed)]
1194#[doc(hidden)]
1195pub struct LigatureSetFixedHeader {
1196 pub ligature_count: BigEndian<u16>,
1197}
1198
1199#[allow(clippy::absurd_extreme_comparisons)]
1200const _: () = assert!(std::mem::size_of::<LigatureSetFixedHeader>() <= LigatureSet::MIN_SIZE);
1201
1202#[derive(Clone)]
1204pub struct LigatureSet<'a> {
1205 data: TableDataRef<'a, LigatureSetFixedHeader>,
1206}
1207
1208#[allow(clippy::needless_lifetimes)]
1209impl<'a> LigatureSet<'a> {
1210 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
1211 basic_table_impls!(impl_the_methods);
1212
1213 pub fn ligature_count(&self) -> u16 {
1215 self.data.header().ligature_count.get()
1216 }
1217
1218 pub fn ligature_offsets(&self) -> &'a [BigEndian<Offset16>] {
1221 let range = self.ligature_offsets_byte_range();
1222 self.offset_data()
1223 .read_array(range)
1224 .ok()
1225 .unwrap_or_default()
1226 }
1227
1228 pub fn ligatures(&self) -> ArrayOfOffsets<'a, Ligature<'a>, Offset16> {
1230 let data = self.offset_data();
1231 let offsets = self.ligature_offsets();
1232 ArrayOfOffsets::new(offsets, data, ())
1233 }
1234
1235 pub fn ligature_count_byte_range(&self) -> Range<usize> {
1236 let start = 0;
1237 let end = start + u16::RAW_BYTE_LEN;
1238 start..end
1239 }
1240
1241 pub fn ligature_offsets_byte_range(&self) -> Range<usize> {
1242 let ligature_count = self.ligature_count();
1243 let start = self.ligature_count_byte_range().end;
1244 let end =
1245 start + (transforms::to_usize(ligature_count)).saturating_mul(Offset16::RAW_BYTE_LEN);
1246 start..end
1247 }
1248}
1249
1250const _: () = assert!(FontData::default_data_long_enough(LigatureSet::MIN_SIZE));
1251
1252impl Default for LigatureSet<'_> {
1253 fn default() -> Self {
1254 Self {
1255 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1256 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1257 }
1258 }
1259}
1260
1261impl<'a> MinByteRange<'a> for Ligature<'a> {
1262 fn min_byte_range(&self) -> Range<usize> {
1263 0..self.component_glyph_ids_byte_range().end
1264 }
1265 fn min_table_bytes(&self) -> &'a [u8] {
1266 let range = self.min_byte_range();
1267 self.offset_data().as_bytes().get(range).unwrap_or_default()
1268 }
1269}
1270
1271impl ReadArgs for Ligature<'_> {
1272 type Args = ();
1273}
1274
1275impl<'a> FontRead<'a> for Ligature<'a> {
1276 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1277 #[allow(clippy::absurd_extreme_comparisons)]
1278 if data.len() < Self::MIN_SIZE {
1279 return Err(ReadError::OutOfBounds);
1280 }
1281 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1282 return Err(ReadError::OutOfBounds);
1283 };
1284 Ok(Self { data })
1285 }
1286}
1287
1288#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1290#[repr(C, packed)]
1291#[doc(hidden)]
1292pub struct LigatureFixedHeader {
1293 pub ligature_glyph: BigEndian<GlyphId16>,
1294 pub component_count: BigEndian<u16>,
1295}
1296
1297#[allow(clippy::absurd_extreme_comparisons)]
1298const _: () = assert!(std::mem::size_of::<LigatureFixedHeader>() <= Ligature::MIN_SIZE);
1299
1300#[derive(Clone)]
1302pub struct Ligature<'a> {
1303 data: TableDataRef<'a, LigatureFixedHeader>,
1304}
1305
1306#[allow(clippy::needless_lifetimes)]
1307impl<'a> Ligature<'a> {
1308 pub const MIN_SIZE: usize = (GlyphId16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1309 basic_table_impls!(impl_the_methods);
1310
1311 pub fn ligature_glyph(&self) -> GlyphId16 {
1313 self.data.header().ligature_glyph.get()
1314 }
1315
1316 pub fn component_count(&self) -> u16 {
1318 self.data.header().component_count.get()
1319 }
1320
1321 pub fn component_glyph_ids(&self) -> &'a [BigEndian<GlyphId16>] {
1324 let range = self.component_glyph_ids_byte_range();
1325 self.offset_data()
1326 .read_array(range)
1327 .ok()
1328 .unwrap_or_default()
1329 }
1330
1331 pub fn ligature_glyph_byte_range(&self) -> Range<usize> {
1332 let start = 0;
1333 let end = start + GlyphId16::RAW_BYTE_LEN;
1334 start..end
1335 }
1336
1337 pub fn component_count_byte_range(&self) -> Range<usize> {
1338 let start = self.ligature_glyph_byte_range().end;
1339 let end = start + u16::RAW_BYTE_LEN;
1340 start..end
1341 }
1342
1343 pub fn component_glyph_ids_byte_range(&self) -> Range<usize> {
1344 let component_count = self.component_count();
1345 let start = self.component_count_byte_range().end;
1346 let end = start
1347 + (transforms::subtract(component_count, 1_usize))
1348 .saturating_mul(GlyphId16::RAW_BYTE_LEN);
1349 start..end
1350 }
1351}
1352
1353const _: () = assert!(FontData::default_data_long_enough(Ligature::MIN_SIZE));
1354
1355impl Default for Ligature<'_> {
1356 fn default() -> Self {
1357 Self {
1358 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1359 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1360 }
1361 }
1362}
1363
1364impl Format<u16> for ExtensionSubstFormat1<'_> {
1365 const FORMAT: u16 = 1;
1366}
1367
1368impl Discriminant for ExtensionSubstFormat1<'_, ()> {
1369 fn read_discriminant(data: FontData<'_>) -> Result<u16, ReadError> {
1370 data.read_at(u16::RAW_BYTE_LEN)
1371 }
1372}
1373
1374impl<'a, T> MinByteRange<'a> for ExtensionSubstFormat1<'a, T> {
1375 fn min_byte_range(&self) -> Range<usize> {
1376 0..self.extension_offset_byte_range().end
1377 }
1378 fn min_table_bytes(&self) -> &'a [u8] {
1379 let range = self.min_byte_range();
1380 self.offset_data().as_bytes().get(range).unwrap_or_default()
1381 }
1382}
1383
1384impl<T> ReadArgs for ExtensionSubstFormat1<'_, T> {
1385 type Args = ();
1386}
1387
1388impl<'a, T> FontRead<'a> for ExtensionSubstFormat1<'a, T> {
1389 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1390 #[allow(clippy::absurd_extreme_comparisons)]
1391 if data.len() < Self::MIN_SIZE {
1392 return Err(ReadError::OutOfBounds);
1393 }
1394 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1395 return Err(ReadError::OutOfBounds);
1396 };
1397 Ok(Self {
1398 data,
1399 offset_type: std::marker::PhantomData,
1400 })
1401 }
1402}
1403
1404impl<'a, T> ExtensionSubstFormat1<'a, T> {
1405 #[allow(dead_code)]
1406 pub(crate) fn of_unit_type(&self) -> ExtensionSubstFormat1<'a, ()> {
1408 ExtensionSubstFormat1 {
1409 data: self.data,
1410 offset_type: std::marker::PhantomData,
1411 }
1412 }
1413}
1414
1415#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1417#[repr(C, packed)]
1418#[doc(hidden)]
1419pub struct ExtensionSubstFormat1FixedHeader {
1420 pub subst_format: BigEndian<u16>,
1421 pub extension_lookup_type: BigEndian<u16>,
1422 pub extension_offset: BigEndian<Offset32>,
1423}
1424
1425#[allow(clippy::absurd_extreme_comparisons)]
1426const _: () = assert!(
1427 std::mem::size_of::<ExtensionSubstFormat1FixedHeader>()
1428 <= ExtensionSubstFormat1::<()>::MIN_SIZE
1429);
1430
1431#[derive(Clone)]
1433pub struct ExtensionSubstFormat1<'a, T = ()> {
1434 data: TableDataRef<'a, ExtensionSubstFormat1FixedHeader>,
1435 offset_type: std::marker::PhantomData<*const T>,
1436}
1437
1438#[allow(clippy::needless_lifetimes)]
1439impl<'a, T> ExtensionSubstFormat1<'a, T> {
1440 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN);
1441 basic_table_impls!(impl_the_methods);
1442
1443 pub fn subst_format(&self) -> u16 {
1445 self.data.header().subst_format.get()
1446 }
1447
1448 pub fn extension_lookup_type(&self) -> u16 {
1451 self.data.header().extension_lookup_type.get()
1452 }
1453
1454 pub fn extension_offset(&self) -> Offset32 {
1458 self.data.header().extension_offset.get()
1459 }
1460
1461 pub fn extension(&self) -> Result<T, ReadError>
1463 where
1464 T: FontRead<'a, Args = ()>,
1465 {
1466 let data = self.offset_data();
1467 self.extension_offset().resolve(data)
1468 }
1469
1470 pub fn subst_format_byte_range(&self) -> Range<usize> {
1471 let start = 0;
1472 let end = start + u16::RAW_BYTE_LEN;
1473 start..end
1474 }
1475
1476 pub fn extension_lookup_type_byte_range(&self) -> Range<usize> {
1477 let start = self.subst_format_byte_range().end;
1478 let end = start + u16::RAW_BYTE_LEN;
1479 start..end
1480 }
1481
1482 pub fn extension_offset_byte_range(&self) -> Range<usize> {
1483 let start = self.extension_lookup_type_byte_range().end;
1484 let end = start + Offset32::RAW_BYTE_LEN;
1485 start..end
1486 }
1487}
1488
1489const _: () = assert!(FontData::default_data_long_enough(
1490 ExtensionSubstFormat1::<()>::MIN_SIZE
1491));
1492
1493impl<T> Default for ExtensionSubstFormat1<'_, T> {
1494 fn default() -> Self {
1495 Self {
1496 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
1497 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1498 offset_type: std::marker::PhantomData,
1499 }
1500 }
1501}
1502
1503pub enum ExtensionSubtable<'a> {
1505 Single(ExtensionSubstFormat1<'a, SingleSubst<'a>>),
1506 Multiple(ExtensionSubstFormat1<'a, MultipleSubst<'a>>),
1507 Alternate(ExtensionSubstFormat1<'a, AlternateSubst<'a>>),
1508 Ligature(ExtensionSubstFormat1<'a, LigatureSubst<'a>>),
1509 Contextual(ExtensionSubstFormat1<'a, SubstitutionSequenceContext<'a>>),
1510 ChainContextual(ExtensionSubstFormat1<'a, SubstitutionChainContext<'a>>),
1511 Reverse(ExtensionSubstFormat1<'a, ReverseChainSingleSubst<'a>>),
1512}
1513
1514impl Default for ExtensionSubtable<'_> {
1515 fn default() -> Self {
1516 Self::Single(Default::default())
1517 }
1518}
1519
1520impl ReadArgs for ExtensionSubtable<'_> {
1521 type Args = ();
1522}
1523
1524impl<'a> FontRead<'a> for ExtensionSubtable<'a> {
1525 fn read_with_args(bytes: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1526 let discriminant = ExtensionSubstFormat1::read_discriminant(bytes)?;
1527 match discriminant {
1528 1 => Ok(ExtensionSubtable::Single(FontRead::read(bytes)?)),
1529 2 => Ok(ExtensionSubtable::Multiple(FontRead::read(bytes)?)),
1530 3 => Ok(ExtensionSubtable::Alternate(FontRead::read(bytes)?)),
1531 4 => Ok(ExtensionSubtable::Ligature(FontRead::read(bytes)?)),
1532 5 => Ok(ExtensionSubtable::Contextual(FontRead::read(bytes)?)),
1533 6 => Ok(ExtensionSubtable::ChainContextual(FontRead::read(bytes)?)),
1534 8 => Ok(ExtensionSubtable::Reverse(FontRead::read(bytes)?)),
1535 other => Err(ReadError::InvalidFormat(other.into())),
1536 }
1537 }
1538}
1539
1540impl<'a> ExtensionSubtable<'a> {
1541 #[allow(dead_code)]
1542 pub(crate) fn of_unit_type(&self) -> ExtensionSubstFormat1<'a, ()> {
1546 match self {
1547 ExtensionSubtable::Single(inner) => inner.of_unit_type(),
1548 ExtensionSubtable::Multiple(inner) => inner.of_unit_type(),
1549 ExtensionSubtable::Alternate(inner) => inner.of_unit_type(),
1550 ExtensionSubtable::Ligature(inner) => inner.of_unit_type(),
1551 ExtensionSubtable::Contextual(inner) => inner.of_unit_type(),
1552 ExtensionSubtable::ChainContextual(inner) => inner.of_unit_type(),
1553 ExtensionSubtable::Reverse(inner) => inner.of_unit_type(),
1554 }
1555 }
1556}
1557
1558impl Format<u16> for ReverseChainSingleSubstFormat1<'_> {
1559 const FORMAT: u16 = 1;
1560}
1561
1562impl<'a> MinByteRange<'a> for ReverseChainSingleSubstFormat1<'a> {
1563 fn min_byte_range(&self) -> Range<usize> {
1564 0..self.substitute_glyph_ids_byte_range().end
1565 }
1566 fn min_table_bytes(&self) -> &'a [u8] {
1567 let range = self.min_byte_range();
1568 self.offset_data().as_bytes().get(range).unwrap_or_default()
1569 }
1570}
1571
1572impl ReadArgs for ReverseChainSingleSubstFormat1<'_> {
1573 type Args = ();
1574}
1575
1576impl<'a> FontRead<'a> for ReverseChainSingleSubstFormat1<'a> {
1577 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1578 #[allow(clippy::absurd_extreme_comparisons)]
1579 if data.len() < Self::MIN_SIZE {
1580 return Err(ReadError::OutOfBounds);
1581 }
1582 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1583 return Err(ReadError::OutOfBounds);
1584 };
1585 Ok(Self { data })
1586 }
1587}
1588
1589#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1591#[repr(C, packed)]
1592#[doc(hidden)]
1593pub struct ReverseChainSingleSubstFormat1FixedHeader {
1594 pub subst_format: BigEndian<u16>,
1595 pub coverage_offset: BigEndian<Offset16>,
1596 pub backtrack_glyph_count: BigEndian<u16>,
1597}
1598
1599#[allow(clippy::absurd_extreme_comparisons)]
1600const _: () = assert!(
1601 std::mem::size_of::<ReverseChainSingleSubstFormat1FixedHeader>()
1602 <= ReverseChainSingleSubstFormat1::MIN_SIZE
1603);
1604
1605#[derive(Clone)]
1607pub struct ReverseChainSingleSubstFormat1<'a> {
1608 data: TableDataRef<'a, ReverseChainSingleSubstFormat1FixedHeader>,
1609}
1610
1611#[allow(clippy::needless_lifetimes)]
1612impl<'a> ReverseChainSingleSubstFormat1<'a> {
1613 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
1614 + Offset16::RAW_BYTE_LEN
1615 + u16::RAW_BYTE_LEN
1616 + u16::RAW_BYTE_LEN
1617 + u16::RAW_BYTE_LEN);
1618 basic_table_impls!(impl_the_methods);
1619
1620 pub fn subst_format(&self) -> u16 {
1622 self.data.header().subst_format.get()
1623 }
1624
1625 pub fn coverage_offset(&self) -> Offset16 {
1628 self.data.header().coverage_offset.get()
1629 }
1630
1631 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1633 let data = self.offset_data();
1634 self.coverage_offset().resolve(data)
1635 }
1636
1637 pub fn backtrack_glyph_count(&self) -> u16 {
1639 self.data.header().backtrack_glyph_count.get()
1640 }
1641
1642 pub fn backtrack_coverage_offsets(&self) -> &'a [BigEndian<Offset16>] {
1645 let range = self.backtrack_coverage_offsets_byte_range();
1646 self.offset_data()
1647 .read_array(range)
1648 .ok()
1649 .unwrap_or_default()
1650 }
1651
1652 pub fn backtrack_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> {
1654 let data = self.offset_data();
1655 let offsets = self.backtrack_coverage_offsets();
1656 ArrayOfOffsets::new(offsets, data, ())
1657 }
1658
1659 pub fn lookahead_glyph_count(&self) -> u16 {
1661 let range = self.lookahead_glyph_count_byte_range();
1662 self.offset_data()
1663 .read_at(range.start)
1664 .ok()
1665 .unwrap_or_default()
1666 }
1667
1668 pub fn lookahead_coverage_offsets(&self) -> &'a [BigEndian<Offset16>] {
1671 let range = self.lookahead_coverage_offsets_byte_range();
1672 self.offset_data()
1673 .read_array(range)
1674 .ok()
1675 .unwrap_or_default()
1676 }
1677
1678 pub fn lookahead_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> {
1680 let data = self.offset_data();
1681 let offsets = self.lookahead_coverage_offsets();
1682 ArrayOfOffsets::new(offsets, data, ())
1683 }
1684
1685 pub fn glyph_count(&self) -> u16 {
1687 let range = self.glyph_count_byte_range();
1688 self.offset_data()
1689 .read_at(range.start)
1690 .ok()
1691 .unwrap_or_default()
1692 }
1693
1694 pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId16>] {
1696 let range = self.substitute_glyph_ids_byte_range();
1697 self.offset_data()
1698 .read_array(range)
1699 .ok()
1700 .unwrap_or_default()
1701 }
1702
1703 pub fn subst_format_byte_range(&self) -> Range<usize> {
1704 let start = 0;
1705 let end = start + u16::RAW_BYTE_LEN;
1706 start..end
1707 }
1708
1709 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
1710 let start = self.subst_format_byte_range().end;
1711 let end = start + Offset16::RAW_BYTE_LEN;
1712 start..end
1713 }
1714
1715 pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> {
1716 let start = self.coverage_offset_byte_range().end;
1717 let end = start + u16::RAW_BYTE_LEN;
1718 start..end
1719 }
1720
1721 pub fn backtrack_coverage_offsets_byte_range(&self) -> Range<usize> {
1722 let backtrack_glyph_count = self.backtrack_glyph_count();
1723 let start = self.backtrack_glyph_count_byte_range().end;
1724 let end = start
1725 + (transforms::to_usize(backtrack_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN);
1726 start..end
1727 }
1728
1729 pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> {
1730 let start = self.backtrack_coverage_offsets_byte_range().end;
1731 let end = start + u16::RAW_BYTE_LEN;
1732 start..end
1733 }
1734
1735 pub fn lookahead_coverage_offsets_byte_range(&self) -> Range<usize> {
1736 let lookahead_glyph_count = self.lookahead_glyph_count();
1737 let start = self.lookahead_glyph_count_byte_range().end;
1738 let end = start
1739 + (transforms::to_usize(lookahead_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN);
1740 start..end
1741 }
1742
1743 pub fn glyph_count_byte_range(&self) -> Range<usize> {
1744 let start = self.lookahead_coverage_offsets_byte_range().end;
1745 let end = start + u16::RAW_BYTE_LEN;
1746 start..end
1747 }
1748
1749 pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> {
1750 let glyph_count = self.glyph_count();
1751 let start = self.glyph_count_byte_range().end;
1752 let end =
1753 start + (transforms::to_usize(glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN);
1754 start..end
1755 }
1756}
1757
1758const _: () = assert!(FontData::default_data_long_enough(
1759 ReverseChainSingleSubstFormat1::MIN_SIZE
1760));
1761
1762impl Default for ReverseChainSingleSubstFormat1<'_> {
1763 fn default() -> Self {
1764 Self {
1765 data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
1766 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1767 }
1768 }
1769}
1770
1771impl Format<u16> for SingleSubstFormat3<'_> {
1772 const FORMAT: u16 = 3;
1773}
1774
1775impl<'a> MinByteRange<'a> for SingleSubstFormat3<'a> {
1776 fn min_byte_range(&self) -> Range<usize> {
1777 0..self.delta_glyph_id_byte_range().end
1778 }
1779 fn min_table_bytes(&self) -> &'a [u8] {
1780 let range = self.min_byte_range();
1781 self.offset_data().as_bytes().get(range).unwrap_or_default()
1782 }
1783}
1784
1785impl ReadArgs for SingleSubstFormat3<'_> {
1786 type Args = ();
1787}
1788
1789impl<'a> FontRead<'a> for SingleSubstFormat3<'a> {
1790 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1791 #[allow(clippy::absurd_extreme_comparisons)]
1792 if data.len() < Self::MIN_SIZE {
1793 return Err(ReadError::OutOfBounds);
1794 }
1795 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1796 return Err(ReadError::OutOfBounds);
1797 };
1798 Ok(Self { data })
1799 }
1800}
1801
1802#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1804#[repr(C, packed)]
1805#[doc(hidden)]
1806pub struct SingleSubstFormat3FixedHeader {
1807 pub subst_format: BigEndian<u16>,
1808 pub coverage_offset: BigEndian<Offset32>,
1809 pub delta_glyph_id: BigEndian<Int24>,
1810}
1811
1812#[allow(clippy::absurd_extreme_comparisons)]
1813const _: () =
1814 assert!(std::mem::size_of::<SingleSubstFormat3FixedHeader>() <= SingleSubstFormat3::MIN_SIZE);
1815
1816#[derive(Clone)]
1818pub struct SingleSubstFormat3<'a> {
1819 data: TableDataRef<'a, SingleSubstFormat3FixedHeader>,
1820}
1821
1822#[allow(clippy::needless_lifetimes)]
1823impl<'a> SingleSubstFormat3<'a> {
1824 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Int24::RAW_BYTE_LEN);
1825 basic_table_impls!(impl_the_methods);
1826
1827 pub fn subst_format(&self) -> u16 {
1829 self.data.header().subst_format.get()
1830 }
1831
1832 pub fn coverage_offset(&self) -> Offset32 {
1835 self.data.header().coverage_offset.get()
1836 }
1837
1838 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1840 let data = self.offset_data();
1841 self.coverage_offset().resolve(data)
1842 }
1843
1844 pub fn delta_glyph_id(&self) -> Int24 {
1846 self.data.header().delta_glyph_id.get()
1847 }
1848
1849 pub fn subst_format_byte_range(&self) -> Range<usize> {
1850 let start = 0;
1851 let end = start + u16::RAW_BYTE_LEN;
1852 start..end
1853 }
1854
1855 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
1856 let start = self.subst_format_byte_range().end;
1857 let end = start + Offset32::RAW_BYTE_LEN;
1858 start..end
1859 }
1860
1861 pub fn delta_glyph_id_byte_range(&self) -> Range<usize> {
1862 let start = self.coverage_offset_byte_range().end;
1863 let end = start + Int24::RAW_BYTE_LEN;
1864 start..end
1865 }
1866}
1867
1868impl Format<u16> for SingleSubstFormat4<'_> {
1869 const FORMAT: u16 = 4;
1870}
1871
1872impl<'a> MinByteRange<'a> for SingleSubstFormat4<'a> {
1873 fn min_byte_range(&self) -> Range<usize> {
1874 0..self.substitute_glyph_ids_byte_range().end
1875 }
1876 fn min_table_bytes(&self) -> &'a [u8] {
1877 let range = self.min_byte_range();
1878 self.offset_data().as_bytes().get(range).unwrap_or_default()
1879 }
1880}
1881
1882impl ReadArgs for SingleSubstFormat4<'_> {
1883 type Args = ();
1884}
1885
1886impl<'a> FontRead<'a> for SingleSubstFormat4<'a> {
1887 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1888 #[allow(clippy::absurd_extreme_comparisons)]
1889 if data.len() < Self::MIN_SIZE {
1890 return Err(ReadError::OutOfBounds);
1891 }
1892 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1893 return Err(ReadError::OutOfBounds);
1894 };
1895 Ok(Self { data })
1896 }
1897}
1898
1899#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1901#[repr(C, packed)]
1902#[doc(hidden)]
1903pub struct SingleSubstFormat4FixedHeader {
1904 pub subst_format: BigEndian<u16>,
1905 pub coverage_offset: BigEndian<Offset32>,
1906 pub glyph_count: BigEndian<Uint24>,
1907}
1908
1909#[allow(clippy::absurd_extreme_comparisons)]
1910const _: () =
1911 assert!(std::mem::size_of::<SingleSubstFormat4FixedHeader>() <= SingleSubstFormat4::MIN_SIZE);
1912
1913#[derive(Clone)]
1915pub struct SingleSubstFormat4<'a> {
1916 data: TableDataRef<'a, SingleSubstFormat4FixedHeader>,
1917}
1918
1919#[allow(clippy::needless_lifetimes)]
1920impl<'a> SingleSubstFormat4<'a> {
1921 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
1922 basic_table_impls!(impl_the_methods);
1923
1924 pub fn subst_format(&self) -> u16 {
1926 self.data.header().subst_format.get()
1927 }
1928
1929 pub fn coverage_offset(&self) -> Offset32 {
1932 self.data.header().coverage_offset.get()
1933 }
1934
1935 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1937 let data = self.offset_data();
1938 self.coverage_offset().resolve(data)
1939 }
1940
1941 pub fn glyph_count(&self) -> Uint24 {
1943 self.data.header().glyph_count.get()
1944 }
1945
1946 pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId24>] {
1948 let range = self.substitute_glyph_ids_byte_range();
1949 self.offset_data()
1950 .read_array(range)
1951 .ok()
1952 .unwrap_or_default()
1953 }
1954
1955 pub fn subst_format_byte_range(&self) -> Range<usize> {
1956 let start = 0;
1957 let end = start + u16::RAW_BYTE_LEN;
1958 start..end
1959 }
1960
1961 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
1962 let start = self.subst_format_byte_range().end;
1963 let end = start + Offset32::RAW_BYTE_LEN;
1964 start..end
1965 }
1966
1967 pub fn glyph_count_byte_range(&self) -> Range<usize> {
1968 let start = self.coverage_offset_byte_range().end;
1969 let end = start + Uint24::RAW_BYTE_LEN;
1970 start..end
1971 }
1972
1973 pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> {
1974 let glyph_count = self.glyph_count();
1975 let start = self.glyph_count_byte_range().end;
1976 let end =
1977 start + (transforms::to_usize(glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN);
1978 start..end
1979 }
1980}
1981
1982impl Format<u16> for MultipleSubstFormat2<'_> {
1983 const FORMAT: u16 = 2;
1984}
1985
1986impl<'a> MinByteRange<'a> for MultipleSubstFormat2<'a> {
1987 fn min_byte_range(&self) -> Range<usize> {
1988 0..self.sequence_offsets_byte_range().end
1989 }
1990 fn min_table_bytes(&self) -> &'a [u8] {
1991 let range = self.min_byte_range();
1992 self.offset_data().as_bytes().get(range).unwrap_or_default()
1993 }
1994}
1995
1996impl ReadArgs for MultipleSubstFormat2<'_> {
1997 type Args = ();
1998}
1999
2000impl<'a> FontRead<'a> for MultipleSubstFormat2<'a> {
2001 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2002 #[allow(clippy::absurd_extreme_comparisons)]
2003 if data.len() < Self::MIN_SIZE {
2004 return Err(ReadError::OutOfBounds);
2005 }
2006 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2007 return Err(ReadError::OutOfBounds);
2008 };
2009 Ok(Self { data })
2010 }
2011}
2012
2013#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2015#[repr(C, packed)]
2016#[doc(hidden)]
2017pub struct MultipleSubstFormat2FixedHeader {
2018 pub subst_format: BigEndian<u16>,
2019 pub coverage_offset: BigEndian<Offset32>,
2020 pub sequence_count: BigEndian<Uint24>,
2021}
2022
2023#[allow(clippy::absurd_extreme_comparisons)]
2024const _: () = assert!(
2025 std::mem::size_of::<MultipleSubstFormat2FixedHeader>() <= MultipleSubstFormat2::MIN_SIZE
2026);
2027
2028#[derive(Clone)]
2030pub struct MultipleSubstFormat2<'a> {
2031 data: TableDataRef<'a, MultipleSubstFormat2FixedHeader>,
2032}
2033
2034#[allow(clippy::needless_lifetimes)]
2035impl<'a> MultipleSubstFormat2<'a> {
2036 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
2037 basic_table_impls!(impl_the_methods);
2038
2039 pub fn subst_format(&self) -> u16 {
2041 self.data.header().subst_format.get()
2042 }
2043
2044 pub fn coverage_offset(&self) -> Offset32 {
2047 self.data.header().coverage_offset.get()
2048 }
2049
2050 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
2052 let data = self.offset_data();
2053 self.coverage_offset().resolve(data)
2054 }
2055
2056 pub fn sequence_count(&self) -> Uint24 {
2058 self.data.header().sequence_count.get()
2059 }
2060
2061 pub fn sequence_offsets(&self) -> &'a [BigEndian<Offset24>] {
2064 let range = self.sequence_offsets_byte_range();
2065 self.offset_data()
2066 .read_array(range)
2067 .ok()
2068 .unwrap_or_default()
2069 }
2070
2071 pub fn sequences(&self) -> ArrayOfOffsets<'a, Sequence2<'a>, Offset24> {
2073 let data = self.offset_data();
2074 let offsets = self.sequence_offsets();
2075 ArrayOfOffsets::new(offsets, data, ())
2076 }
2077
2078 pub fn subst_format_byte_range(&self) -> Range<usize> {
2079 let start = 0;
2080 let end = start + u16::RAW_BYTE_LEN;
2081 start..end
2082 }
2083
2084 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
2085 let start = self.subst_format_byte_range().end;
2086 let end = start + Offset32::RAW_BYTE_LEN;
2087 start..end
2088 }
2089
2090 pub fn sequence_count_byte_range(&self) -> Range<usize> {
2091 let start = self.coverage_offset_byte_range().end;
2092 let end = start + Uint24::RAW_BYTE_LEN;
2093 start..end
2094 }
2095
2096 pub fn sequence_offsets_byte_range(&self) -> Range<usize> {
2097 let sequence_count = self.sequence_count();
2098 let start = self.sequence_count_byte_range().end;
2099 let end =
2100 start + (transforms::to_usize(sequence_count)).saturating_mul(Offset24::RAW_BYTE_LEN);
2101 start..end
2102 }
2103}
2104
2105impl Format<u16> for AlternateSubstFormat2<'_> {
2106 const FORMAT: u16 = 2;
2107}
2108
2109impl<'a> MinByteRange<'a> for AlternateSubstFormat2<'a> {
2110 fn min_byte_range(&self) -> Range<usize> {
2111 0..self.alternate_set_offsets_byte_range().end
2112 }
2113 fn min_table_bytes(&self) -> &'a [u8] {
2114 let range = self.min_byte_range();
2115 self.offset_data().as_bytes().get(range).unwrap_or_default()
2116 }
2117}
2118
2119impl ReadArgs for AlternateSubstFormat2<'_> {
2120 type Args = ();
2121}
2122
2123impl<'a> FontRead<'a> for AlternateSubstFormat2<'a> {
2124 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2125 #[allow(clippy::absurd_extreme_comparisons)]
2126 if data.len() < Self::MIN_SIZE {
2127 return Err(ReadError::OutOfBounds);
2128 }
2129 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2130 return Err(ReadError::OutOfBounds);
2131 };
2132 Ok(Self { data })
2133 }
2134}
2135
2136#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2138#[repr(C, packed)]
2139#[doc(hidden)]
2140pub struct AlternateSubstFormat2FixedHeader {
2141 pub subst_format: BigEndian<u16>,
2142 pub coverage_offset: BigEndian<Offset32>,
2143 pub alternate_set_count: BigEndian<Uint24>,
2144}
2145
2146#[allow(clippy::absurd_extreme_comparisons)]
2147const _: () = assert!(
2148 std::mem::size_of::<AlternateSubstFormat2FixedHeader>() <= AlternateSubstFormat2::MIN_SIZE
2149);
2150
2151#[derive(Clone)]
2153pub struct AlternateSubstFormat2<'a> {
2154 data: TableDataRef<'a, AlternateSubstFormat2FixedHeader>,
2155}
2156
2157#[allow(clippy::needless_lifetimes)]
2158impl<'a> AlternateSubstFormat2<'a> {
2159 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
2160 basic_table_impls!(impl_the_methods);
2161
2162 pub fn subst_format(&self) -> u16 {
2164 self.data.header().subst_format.get()
2165 }
2166
2167 pub fn coverage_offset(&self) -> Offset32 {
2170 self.data.header().coverage_offset.get()
2171 }
2172
2173 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
2175 let data = self.offset_data();
2176 self.coverage_offset().resolve(data)
2177 }
2178
2179 pub fn alternate_set_count(&self) -> Uint24 {
2181 self.data.header().alternate_set_count.get()
2182 }
2183
2184 pub fn alternate_set_offsets(&self) -> &'a [BigEndian<Offset24>] {
2187 let range = self.alternate_set_offsets_byte_range();
2188 self.offset_data()
2189 .read_array(range)
2190 .ok()
2191 .unwrap_or_default()
2192 }
2193
2194 pub fn alternate_sets(&self) -> ArrayOfOffsets<'a, AlternateSet2<'a>, Offset24> {
2196 let data = self.offset_data();
2197 let offsets = self.alternate_set_offsets();
2198 ArrayOfOffsets::new(offsets, data, ())
2199 }
2200
2201 pub fn subst_format_byte_range(&self) -> Range<usize> {
2202 let start = 0;
2203 let end = start + u16::RAW_BYTE_LEN;
2204 start..end
2205 }
2206
2207 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
2208 let start = self.subst_format_byte_range().end;
2209 let end = start + Offset32::RAW_BYTE_LEN;
2210 start..end
2211 }
2212
2213 pub fn alternate_set_count_byte_range(&self) -> Range<usize> {
2214 let start = self.coverage_offset_byte_range().end;
2215 let end = start + Uint24::RAW_BYTE_LEN;
2216 start..end
2217 }
2218
2219 pub fn alternate_set_offsets_byte_range(&self) -> Range<usize> {
2220 let alternate_set_count = self.alternate_set_count();
2221 let start = self.alternate_set_count_byte_range().end;
2222 let end = start
2223 + (transforms::to_usize(alternate_set_count)).saturating_mul(Offset24::RAW_BYTE_LEN);
2224 start..end
2225 }
2226}
2227
2228impl Format<u16> for LigatureSubstFormat2<'_> {
2229 const FORMAT: u16 = 2;
2230}
2231
2232impl<'a> MinByteRange<'a> for LigatureSubstFormat2<'a> {
2233 fn min_byte_range(&self) -> Range<usize> {
2234 0..self.ligature_set_offsets_byte_range().end
2235 }
2236 fn min_table_bytes(&self) -> &'a [u8] {
2237 let range = self.min_byte_range();
2238 self.offset_data().as_bytes().get(range).unwrap_or_default()
2239 }
2240}
2241
2242impl ReadArgs for LigatureSubstFormat2<'_> {
2243 type Args = ();
2244}
2245
2246impl<'a> FontRead<'a> for LigatureSubstFormat2<'a> {
2247 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2248 #[allow(clippy::absurd_extreme_comparisons)]
2249 if data.len() < Self::MIN_SIZE {
2250 return Err(ReadError::OutOfBounds);
2251 }
2252 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2253 return Err(ReadError::OutOfBounds);
2254 };
2255 Ok(Self { data })
2256 }
2257}
2258
2259#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2261#[repr(C, packed)]
2262#[doc(hidden)]
2263pub struct LigatureSubstFormat2FixedHeader {
2264 pub subst_format: BigEndian<u16>,
2265 pub coverage_offset: BigEndian<Offset32>,
2266 pub ligature_set_count: BigEndian<Uint24>,
2267}
2268
2269#[allow(clippy::absurd_extreme_comparisons)]
2270const _: () = assert!(
2271 std::mem::size_of::<LigatureSubstFormat2FixedHeader>() <= LigatureSubstFormat2::MIN_SIZE
2272);
2273
2274#[derive(Clone)]
2276pub struct LigatureSubstFormat2<'a> {
2277 data: TableDataRef<'a, LigatureSubstFormat2FixedHeader>,
2278}
2279
2280#[allow(clippy::needless_lifetimes)]
2281impl<'a> LigatureSubstFormat2<'a> {
2282 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
2283 basic_table_impls!(impl_the_methods);
2284
2285 pub fn subst_format(&self) -> u16 {
2287 self.data.header().subst_format.get()
2288 }
2289
2290 pub fn coverage_offset(&self) -> Offset32 {
2293 self.data.header().coverage_offset.get()
2294 }
2295
2296 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
2298 let data = self.offset_data();
2299 self.coverage_offset().resolve(data)
2300 }
2301
2302 pub fn ligature_set_count(&self) -> Uint24 {
2304 self.data.header().ligature_set_count.get()
2305 }
2306
2307 pub fn ligature_set_offsets(&self) -> &'a [BigEndian<Offset24>] {
2310 let range = self.ligature_set_offsets_byte_range();
2311 self.offset_data()
2312 .read_array(range)
2313 .ok()
2314 .unwrap_or_default()
2315 }
2316
2317 pub fn ligature_sets(&self) -> ArrayOfOffsets<'a, LigatureSet2<'a>, Offset24> {
2319 let data = self.offset_data();
2320 let offsets = self.ligature_set_offsets();
2321 ArrayOfOffsets::new(offsets, data, ())
2322 }
2323
2324 pub fn subst_format_byte_range(&self) -> Range<usize> {
2325 let start = 0;
2326 let end = start + u16::RAW_BYTE_LEN;
2327 start..end
2328 }
2329
2330 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
2331 let start = self.subst_format_byte_range().end;
2332 let end = start + Offset32::RAW_BYTE_LEN;
2333 start..end
2334 }
2335
2336 pub fn ligature_set_count_byte_range(&self) -> Range<usize> {
2337 let start = self.coverage_offset_byte_range().end;
2338 let end = start + Uint24::RAW_BYTE_LEN;
2339 start..end
2340 }
2341
2342 pub fn ligature_set_offsets_byte_range(&self) -> Range<usize> {
2343 let ligature_set_count = self.ligature_set_count();
2344 let start = self.ligature_set_count_byte_range().end;
2345 let end = start
2346 + (transforms::to_usize(ligature_set_count)).saturating_mul(Offset24::RAW_BYTE_LEN);
2347 start..end
2348 }
2349}
2350
2351impl Format<u16> for ReverseChainSingleSubstFormat2<'_> {
2352 const FORMAT: u16 = 2;
2353}
2354
2355impl<'a> MinByteRange<'a> for ReverseChainSingleSubstFormat2<'a> {
2356 fn min_byte_range(&self) -> Range<usize> {
2357 0..self.substitute_glyph_ids_byte_range().end
2358 }
2359 fn min_table_bytes(&self) -> &'a [u8] {
2360 let range = self.min_byte_range();
2361 self.offset_data().as_bytes().get(range).unwrap_or_default()
2362 }
2363}
2364
2365impl ReadArgs for ReverseChainSingleSubstFormat2<'_> {
2366 type Args = ();
2367}
2368
2369impl<'a> FontRead<'a> for ReverseChainSingleSubstFormat2<'a> {
2370 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2371 #[allow(clippy::absurd_extreme_comparisons)]
2372 if data.len() < Self::MIN_SIZE {
2373 return Err(ReadError::OutOfBounds);
2374 }
2375 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2376 return Err(ReadError::OutOfBounds);
2377 };
2378 Ok(Self { data })
2379 }
2380}
2381
2382#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2384#[repr(C, packed)]
2385#[doc(hidden)]
2386pub struct ReverseChainSingleSubstFormat2FixedHeader {
2387 pub subst_format: BigEndian<u16>,
2388 pub coverage_offset: BigEndian<Offset32>,
2389 pub backtrack_glyph_count: BigEndian<u16>,
2390}
2391
2392#[allow(clippy::absurd_extreme_comparisons)]
2393const _: () = assert!(
2394 std::mem::size_of::<ReverseChainSingleSubstFormat2FixedHeader>()
2395 <= ReverseChainSingleSubstFormat2::MIN_SIZE
2396);
2397
2398#[derive(Clone)]
2400pub struct ReverseChainSingleSubstFormat2<'a> {
2401 data: TableDataRef<'a, ReverseChainSingleSubstFormat2FixedHeader>,
2402}
2403
2404#[allow(clippy::needless_lifetimes)]
2405impl<'a> ReverseChainSingleSubstFormat2<'a> {
2406 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
2407 + Offset32::RAW_BYTE_LEN
2408 + u16::RAW_BYTE_LEN
2409 + u16::RAW_BYTE_LEN
2410 + Uint24::RAW_BYTE_LEN);
2411 basic_table_impls!(impl_the_methods);
2412
2413 pub fn subst_format(&self) -> u16 {
2415 self.data.header().subst_format.get()
2416 }
2417
2418 pub fn coverage_offset(&self) -> Offset32 {
2421 self.data.header().coverage_offset.get()
2422 }
2423
2424 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
2426 let data = self.offset_data();
2427 self.coverage_offset().resolve(data)
2428 }
2429
2430 pub fn backtrack_glyph_count(&self) -> u16 {
2432 self.data.header().backtrack_glyph_count.get()
2433 }
2434
2435 pub fn backtrack_coverage_offsets(&self) -> &'a [BigEndian<Offset24>] {
2438 let range = self.backtrack_coverage_offsets_byte_range();
2439 self.offset_data()
2440 .read_array(range)
2441 .ok()
2442 .unwrap_or_default()
2443 }
2444
2445 pub fn backtrack_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset24> {
2447 let data = self.offset_data();
2448 let offsets = self.backtrack_coverage_offsets();
2449 ArrayOfOffsets::new(offsets, data, ())
2450 }
2451
2452 pub fn lookahead_glyph_count(&self) -> u16 {
2454 let range = self.lookahead_glyph_count_byte_range();
2455 self.offset_data()
2456 .read_at(range.start)
2457 .ok()
2458 .unwrap_or_default()
2459 }
2460
2461 pub fn lookahead_coverage_offsets(&self) -> &'a [BigEndian<Offset24>] {
2464 let range = self.lookahead_coverage_offsets_byte_range();
2465 self.offset_data()
2466 .read_array(range)
2467 .ok()
2468 .unwrap_or_default()
2469 }
2470
2471 pub fn lookahead_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset24> {
2473 let data = self.offset_data();
2474 let offsets = self.lookahead_coverage_offsets();
2475 ArrayOfOffsets::new(offsets, data, ())
2476 }
2477
2478 pub fn glyph_count(&self) -> Uint24 {
2480 let range = self.glyph_count_byte_range();
2481 self.offset_data()
2482 .read_at(range.start)
2483 .ok()
2484 .unwrap_or_default()
2485 }
2486
2487 pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId24>] {
2489 let range = self.substitute_glyph_ids_byte_range();
2490 self.offset_data()
2491 .read_array(range)
2492 .ok()
2493 .unwrap_or_default()
2494 }
2495
2496 pub fn subst_format_byte_range(&self) -> Range<usize> {
2497 let start = 0;
2498 let end = start + u16::RAW_BYTE_LEN;
2499 start..end
2500 }
2501
2502 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
2503 let start = self.subst_format_byte_range().end;
2504 let end = start + Offset32::RAW_BYTE_LEN;
2505 start..end
2506 }
2507
2508 pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> {
2509 let start = self.coverage_offset_byte_range().end;
2510 let end = start + u16::RAW_BYTE_LEN;
2511 start..end
2512 }
2513
2514 pub fn backtrack_coverage_offsets_byte_range(&self) -> Range<usize> {
2515 let backtrack_glyph_count = self.backtrack_glyph_count();
2516 let start = self.backtrack_glyph_count_byte_range().end;
2517 let end = start
2518 + (transforms::to_usize(backtrack_glyph_count)).saturating_mul(Offset24::RAW_BYTE_LEN);
2519 start..end
2520 }
2521
2522 pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> {
2523 let start = self.backtrack_coverage_offsets_byte_range().end;
2524 let end = start + u16::RAW_BYTE_LEN;
2525 start..end
2526 }
2527
2528 pub fn lookahead_coverage_offsets_byte_range(&self) -> Range<usize> {
2529 let lookahead_glyph_count = self.lookahead_glyph_count();
2530 let start = self.lookahead_glyph_count_byte_range().end;
2531 let end = start
2532 + (transforms::to_usize(lookahead_glyph_count)).saturating_mul(Offset24::RAW_BYTE_LEN);
2533 start..end
2534 }
2535
2536 pub fn glyph_count_byte_range(&self) -> Range<usize> {
2537 let start = self.lookahead_coverage_offsets_byte_range().end;
2538 let end = start + Uint24::RAW_BYTE_LEN;
2539 start..end
2540 }
2541
2542 pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> {
2543 let glyph_count = self.glyph_count();
2544 let start = self.glyph_count_byte_range().end;
2545 let end =
2546 start + (transforms::to_usize(glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN);
2547 start..end
2548 }
2549}
2550
2551impl<'a> MinByteRange<'a> for Sequence2<'a> {
2552 fn min_byte_range(&self) -> Range<usize> {
2553 0..self.substitute_glyph_ids_byte_range().end
2554 }
2555 fn min_table_bytes(&self) -> &'a [u8] {
2556 let range = self.min_byte_range();
2557 self.offset_data().as_bytes().get(range).unwrap_or_default()
2558 }
2559}
2560
2561impl ReadArgs for Sequence2<'_> {
2562 type Args = ();
2563}
2564
2565impl<'a> FontRead<'a> for Sequence2<'a> {
2566 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2567 #[allow(clippy::absurd_extreme_comparisons)]
2568 if data.len() < Self::MIN_SIZE {
2569 return Err(ReadError::OutOfBounds);
2570 }
2571 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2572 return Err(ReadError::OutOfBounds);
2573 };
2574 Ok(Self { data })
2575 }
2576}
2577
2578#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2580#[repr(C, packed)]
2581#[doc(hidden)]
2582pub struct Sequence2FixedHeader {
2583 pub glyph_count: BigEndian<u16>,
2584}
2585
2586#[allow(clippy::absurd_extreme_comparisons)]
2587const _: () = assert!(std::mem::size_of::<Sequence2FixedHeader>() <= Sequence2::MIN_SIZE);
2588
2589#[derive(Clone)]
2591pub struct Sequence2<'a> {
2592 data: TableDataRef<'a, Sequence2FixedHeader>,
2593}
2594
2595#[allow(clippy::needless_lifetimes)]
2596impl<'a> Sequence2<'a> {
2597 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
2598 basic_table_impls!(impl_the_methods);
2599
2600 pub fn glyph_count(&self) -> u16 {
2603 self.data.header().glyph_count.get()
2604 }
2605
2606 pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId24>] {
2608 let range = self.substitute_glyph_ids_byte_range();
2609 self.offset_data()
2610 .read_array(range)
2611 .ok()
2612 .unwrap_or_default()
2613 }
2614
2615 pub fn glyph_count_byte_range(&self) -> Range<usize> {
2616 let start = 0;
2617 let end = start + u16::RAW_BYTE_LEN;
2618 start..end
2619 }
2620
2621 pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> {
2622 let glyph_count = self.glyph_count();
2623 let start = self.glyph_count_byte_range().end;
2624 let end =
2625 start + (transforms::to_usize(glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN);
2626 start..end
2627 }
2628}
2629
2630const _: () = assert!(FontData::default_data_long_enough(Sequence2::MIN_SIZE));
2631
2632impl Default for Sequence2<'_> {
2633 fn default() -> Self {
2634 Self {
2635 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2636 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2637 }
2638 }
2639}
2640
2641impl<'a> MinByteRange<'a> for AlternateSet2<'a> {
2642 fn min_byte_range(&self) -> Range<usize> {
2643 0..self.alternate_glyph_ids_byte_range().end
2644 }
2645 fn min_table_bytes(&self) -> &'a [u8] {
2646 let range = self.min_byte_range();
2647 self.offset_data().as_bytes().get(range).unwrap_or_default()
2648 }
2649}
2650
2651impl ReadArgs for AlternateSet2<'_> {
2652 type Args = ();
2653}
2654
2655impl<'a> FontRead<'a> for AlternateSet2<'a> {
2656 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2657 #[allow(clippy::absurd_extreme_comparisons)]
2658 if data.len() < Self::MIN_SIZE {
2659 return Err(ReadError::OutOfBounds);
2660 }
2661 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2662 return Err(ReadError::OutOfBounds);
2663 };
2664 Ok(Self { data })
2665 }
2666}
2667
2668#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2670#[repr(C, packed)]
2671#[doc(hidden)]
2672pub struct AlternateSet2FixedHeader {
2673 pub glyph_count: BigEndian<u16>,
2674}
2675
2676#[allow(clippy::absurd_extreme_comparisons)]
2677const _: () = assert!(std::mem::size_of::<AlternateSet2FixedHeader>() <= AlternateSet2::MIN_SIZE);
2678
2679#[derive(Clone)]
2681pub struct AlternateSet2<'a> {
2682 data: TableDataRef<'a, AlternateSet2FixedHeader>,
2683}
2684
2685#[allow(clippy::needless_lifetimes)]
2686impl<'a> AlternateSet2<'a> {
2687 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
2688 basic_table_impls!(impl_the_methods);
2689
2690 pub fn glyph_count(&self) -> u16 {
2692 self.data.header().glyph_count.get()
2693 }
2694
2695 pub fn alternate_glyph_ids(&self) -> &'a [BigEndian<GlyphId24>] {
2697 let range = self.alternate_glyph_ids_byte_range();
2698 self.offset_data()
2699 .read_array(range)
2700 .ok()
2701 .unwrap_or_default()
2702 }
2703
2704 pub fn glyph_count_byte_range(&self) -> Range<usize> {
2705 let start = 0;
2706 let end = start + u16::RAW_BYTE_LEN;
2707 start..end
2708 }
2709
2710 pub fn alternate_glyph_ids_byte_range(&self) -> Range<usize> {
2711 let glyph_count = self.glyph_count();
2712 let start = self.glyph_count_byte_range().end;
2713 let end =
2714 start + (transforms::to_usize(glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN);
2715 start..end
2716 }
2717}
2718
2719const _: () = assert!(FontData::default_data_long_enough(AlternateSet2::MIN_SIZE));
2720
2721impl Default for AlternateSet2<'_> {
2722 fn default() -> Self {
2723 Self {
2724 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2725 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2726 }
2727 }
2728}
2729
2730impl<'a> MinByteRange<'a> for LigatureSet2<'a> {
2731 fn min_byte_range(&self) -> Range<usize> {
2732 0..self.ligature_offsets_byte_range().end
2733 }
2734 fn min_table_bytes(&self) -> &'a [u8] {
2735 let range = self.min_byte_range();
2736 self.offset_data().as_bytes().get(range).unwrap_or_default()
2737 }
2738}
2739
2740impl ReadArgs for LigatureSet2<'_> {
2741 type Args = ();
2742}
2743
2744impl<'a> FontRead<'a> for LigatureSet2<'a> {
2745 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2746 #[allow(clippy::absurd_extreme_comparisons)]
2747 if data.len() < Self::MIN_SIZE {
2748 return Err(ReadError::OutOfBounds);
2749 }
2750 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2751 return Err(ReadError::OutOfBounds);
2752 };
2753 Ok(Self { data })
2754 }
2755}
2756
2757#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2759#[repr(C, packed)]
2760#[doc(hidden)]
2761pub struct LigatureSet2FixedHeader {
2762 pub ligature_count: BigEndian<u16>,
2763}
2764
2765#[allow(clippy::absurd_extreme_comparisons)]
2766const _: () = assert!(std::mem::size_of::<LigatureSet2FixedHeader>() <= LigatureSet2::MIN_SIZE);
2767
2768#[derive(Clone)]
2770pub struct LigatureSet2<'a> {
2771 data: TableDataRef<'a, LigatureSet2FixedHeader>,
2772}
2773
2774#[allow(clippy::needless_lifetimes)]
2775impl<'a> LigatureSet2<'a> {
2776 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
2777 basic_table_impls!(impl_the_methods);
2778
2779 pub fn ligature_count(&self) -> u16 {
2781 self.data.header().ligature_count.get()
2782 }
2783
2784 pub fn ligature_offsets(&self) -> &'a [BigEndian<Offset24>] {
2787 let range = self.ligature_offsets_byte_range();
2788 self.offset_data()
2789 .read_array(range)
2790 .ok()
2791 .unwrap_or_default()
2792 }
2793
2794 pub fn ligatures(&self) -> ArrayOfOffsets<'a, Ligature2<'a>, Offset24> {
2796 let data = self.offset_data();
2797 let offsets = self.ligature_offsets();
2798 ArrayOfOffsets::new(offsets, data, ())
2799 }
2800
2801 pub fn ligature_count_byte_range(&self) -> Range<usize> {
2802 let start = 0;
2803 let end = start + u16::RAW_BYTE_LEN;
2804 start..end
2805 }
2806
2807 pub fn ligature_offsets_byte_range(&self) -> Range<usize> {
2808 let ligature_count = self.ligature_count();
2809 let start = self.ligature_count_byte_range().end;
2810 let end =
2811 start + (transforms::to_usize(ligature_count)).saturating_mul(Offset24::RAW_BYTE_LEN);
2812 start..end
2813 }
2814}
2815
2816const _: () = assert!(FontData::default_data_long_enough(LigatureSet2::MIN_SIZE));
2817
2818impl Default for LigatureSet2<'_> {
2819 fn default() -> Self {
2820 Self {
2821 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2822 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2823 }
2824 }
2825}
2826
2827impl<'a> MinByteRange<'a> for Ligature2<'a> {
2828 fn min_byte_range(&self) -> Range<usize> {
2829 0..self.component_glyph_ids_byte_range().end
2830 }
2831 fn min_table_bytes(&self) -> &'a [u8] {
2832 let range = self.min_byte_range();
2833 self.offset_data().as_bytes().get(range).unwrap_or_default()
2834 }
2835}
2836
2837impl ReadArgs for Ligature2<'_> {
2838 type Args = ();
2839}
2840
2841impl<'a> FontRead<'a> for Ligature2<'a> {
2842 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2843 #[allow(clippy::absurd_extreme_comparisons)]
2844 if data.len() < Self::MIN_SIZE {
2845 return Err(ReadError::OutOfBounds);
2846 }
2847 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2848 return Err(ReadError::OutOfBounds);
2849 };
2850 Ok(Self { data })
2851 }
2852}
2853
2854#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2856#[repr(C, packed)]
2857#[doc(hidden)]
2858pub struct Ligature2FixedHeader {
2859 pub ligature_glyph: BigEndian<GlyphId24>,
2860 pub component_count: BigEndian<u16>,
2861}
2862
2863#[allow(clippy::absurd_extreme_comparisons)]
2864const _: () = assert!(std::mem::size_of::<Ligature2FixedHeader>() <= Ligature2::MIN_SIZE);
2865
2866#[derive(Clone)]
2868pub struct Ligature2<'a> {
2869 data: TableDataRef<'a, Ligature2FixedHeader>,
2870}
2871
2872#[allow(clippy::needless_lifetimes)]
2873impl<'a> Ligature2<'a> {
2874 pub const MIN_SIZE: usize = (GlyphId24::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2875 basic_table_impls!(impl_the_methods);
2876
2877 pub fn ligature_glyph(&self) -> GlyphId24 {
2879 self.data.header().ligature_glyph.get()
2880 }
2881
2882 pub fn component_count(&self) -> u16 {
2884 self.data.header().component_count.get()
2885 }
2886
2887 pub fn component_glyph_ids(&self) -> &'a [BigEndian<GlyphId24>] {
2890 let range = self.component_glyph_ids_byte_range();
2891 self.offset_data()
2892 .read_array(range)
2893 .ok()
2894 .unwrap_or_default()
2895 }
2896
2897 pub fn ligature_glyph_byte_range(&self) -> Range<usize> {
2898 let start = 0;
2899 let end = start + GlyphId24::RAW_BYTE_LEN;
2900 start..end
2901 }
2902
2903 pub fn component_count_byte_range(&self) -> Range<usize> {
2904 let start = self.ligature_glyph_byte_range().end;
2905 let end = start + u16::RAW_BYTE_LEN;
2906 start..end
2907 }
2908
2909 pub fn component_glyph_ids_byte_range(&self) -> Range<usize> {
2910 let component_count = self.component_count();
2911 let start = self.component_count_byte_range().end;
2912 let end = start
2913 + (transforms::subtract(component_count, 1_usize))
2914 .saturating_mul(GlyphId24::RAW_BYTE_LEN);
2915 start..end
2916 }
2917}
2918
2919const _: () = assert!(FontData::default_data_long_enough(Ligature2::MIN_SIZE));
2920
2921impl Default for Ligature2<'_> {
2922 fn default() -> Self {
2923 Self {
2924 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2925 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2926 }
2927 }
2928}
2929
2930#[derive(Clone)]
2932pub enum MultipleSubst<'a> {
2933 Format1(MultipleSubstFormat1<'a>),
2934 Format2(MultipleSubstFormat2<'a>),
2935}
2936
2937impl Default for MultipleSubst<'_> {
2938 fn default() -> Self {
2939 Self::Format1(Default::default())
2940 }
2941}
2942
2943impl<'a> MultipleSubst<'a> {
2944 pub fn offset_data(&self) -> FontData<'a> {
2946 match self {
2947 Self::Format1(item) => item.offset_data(),
2948 Self::Format2(item) => item.offset_data(),
2949 }
2950 }
2951
2952 pub fn subst_format(&self) -> u16 {
2954 match self {
2955 Self::Format1(item) => item.subst_format(),
2956 Self::Format2(item) => item.subst_format(),
2957 }
2958 }
2959}
2960
2961impl ReadArgs for MultipleSubst<'_> {
2962 type Args = ();
2963}
2964
2965impl<'a> FontRead<'a> for MultipleSubst<'a> {
2966 #[inline]
2967 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2968 let format: u16 = data.read_at(0usize)?;
2969 match format {
2970 MultipleSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
2971 MultipleSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
2972 other => Err(ReadError::InvalidFormat(other.into())),
2973 }
2974 }
2975}
2976
2977impl<'a> MinByteRange<'a> for MultipleSubst<'a> {
2978 fn min_byte_range(&self) -> Range<usize> {
2979 match self {
2980 Self::Format1(item) => item.min_byte_range(),
2981 Self::Format2(item) => item.min_byte_range(),
2982 }
2983 }
2984 fn min_table_bytes(&self) -> &'a [u8] {
2985 match self {
2986 Self::Format1(item) => item.min_table_bytes(),
2987 Self::Format2(item) => item.min_table_bytes(),
2988 }
2989 }
2990}
2991
2992#[derive(Clone)]
2994pub enum AlternateSubst<'a> {
2995 Format1(AlternateSubstFormat1<'a>),
2996 Format2(AlternateSubstFormat2<'a>),
2997}
2998
2999impl Default for AlternateSubst<'_> {
3000 fn default() -> Self {
3001 Self::Format1(Default::default())
3002 }
3003}
3004
3005impl<'a> AlternateSubst<'a> {
3006 pub fn offset_data(&self) -> FontData<'a> {
3008 match self {
3009 Self::Format1(item) => item.offset_data(),
3010 Self::Format2(item) => item.offset_data(),
3011 }
3012 }
3013
3014 pub fn subst_format(&self) -> u16 {
3016 match self {
3017 Self::Format1(item) => item.subst_format(),
3018 Self::Format2(item) => item.subst_format(),
3019 }
3020 }
3021}
3022
3023impl ReadArgs for AlternateSubst<'_> {
3024 type Args = ();
3025}
3026
3027impl<'a> FontRead<'a> for AlternateSubst<'a> {
3028 #[inline]
3029 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3030 let format: u16 = data.read_at(0usize)?;
3031 match format {
3032 AlternateSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
3033 AlternateSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
3034 other => Err(ReadError::InvalidFormat(other.into())),
3035 }
3036 }
3037}
3038
3039impl<'a> MinByteRange<'a> for AlternateSubst<'a> {
3040 fn min_byte_range(&self) -> Range<usize> {
3041 match self {
3042 Self::Format1(item) => item.min_byte_range(),
3043 Self::Format2(item) => item.min_byte_range(),
3044 }
3045 }
3046 fn min_table_bytes(&self) -> &'a [u8] {
3047 match self {
3048 Self::Format1(item) => item.min_table_bytes(),
3049 Self::Format2(item) => item.min_table_bytes(),
3050 }
3051 }
3052}
3053
3054#[derive(Clone)]
3056pub enum LigatureSubst<'a> {
3057 Format1(LigatureSubstFormat1<'a>),
3058 Format2(LigatureSubstFormat2<'a>),
3059}
3060
3061impl Default for LigatureSubst<'_> {
3062 fn default() -> Self {
3063 Self::Format1(Default::default())
3064 }
3065}
3066
3067impl<'a> LigatureSubst<'a> {
3068 pub fn offset_data(&self) -> FontData<'a> {
3070 match self {
3071 Self::Format1(item) => item.offset_data(),
3072 Self::Format2(item) => item.offset_data(),
3073 }
3074 }
3075
3076 pub fn subst_format(&self) -> u16 {
3078 match self {
3079 Self::Format1(item) => item.subst_format(),
3080 Self::Format2(item) => item.subst_format(),
3081 }
3082 }
3083}
3084
3085impl ReadArgs for LigatureSubst<'_> {
3086 type Args = ();
3087}
3088
3089impl<'a> FontRead<'a> for LigatureSubst<'a> {
3090 #[inline]
3091 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3092 let format: u16 = data.read_at(0usize)?;
3093 match format {
3094 LigatureSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
3095 LigatureSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
3096 other => Err(ReadError::InvalidFormat(other.into())),
3097 }
3098 }
3099}
3100
3101impl<'a> MinByteRange<'a> for LigatureSubst<'a> {
3102 fn min_byte_range(&self) -> Range<usize> {
3103 match self {
3104 Self::Format1(item) => item.min_byte_range(),
3105 Self::Format2(item) => item.min_byte_range(),
3106 }
3107 }
3108 fn min_table_bytes(&self) -> &'a [u8] {
3109 match self {
3110 Self::Format1(item) => item.min_table_bytes(),
3111 Self::Format2(item) => item.min_table_bytes(),
3112 }
3113 }
3114}
3115
3116#[derive(Clone)]
3118pub enum ReverseChainSingleSubst<'a> {
3119 Format1(ReverseChainSingleSubstFormat1<'a>),
3120 Format2(ReverseChainSingleSubstFormat2<'a>),
3121}
3122
3123impl Default for ReverseChainSingleSubst<'_> {
3124 fn default() -> Self {
3125 Self::Format1(Default::default())
3126 }
3127}
3128
3129impl<'a> ReverseChainSingleSubst<'a> {
3130 pub fn offset_data(&self) -> FontData<'a> {
3132 match self {
3133 Self::Format1(item) => item.offset_data(),
3134 Self::Format2(item) => item.offset_data(),
3135 }
3136 }
3137
3138 pub fn subst_format(&self) -> u16 {
3140 match self {
3141 Self::Format1(item) => item.subst_format(),
3142 Self::Format2(item) => item.subst_format(),
3143 }
3144 }
3145
3146 pub fn backtrack_glyph_count(&self) -> u16 {
3148 match self {
3149 Self::Format1(item) => item.backtrack_glyph_count(),
3150 Self::Format2(item) => item.backtrack_glyph_count(),
3151 }
3152 }
3153
3154 pub fn lookahead_glyph_count(&self) -> u16 {
3156 match self {
3157 Self::Format1(item) => item.lookahead_glyph_count(),
3158 Self::Format2(item) => item.lookahead_glyph_count(),
3159 }
3160 }
3161}
3162
3163impl ReadArgs for ReverseChainSingleSubst<'_> {
3164 type Args = ();
3165}
3166
3167impl<'a> FontRead<'a> for ReverseChainSingleSubst<'a> {
3168 #[inline]
3169 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3170 let format: u16 = data.read_at(0usize)?;
3171 match format {
3172 ReverseChainSingleSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
3173 ReverseChainSingleSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
3174 other => Err(ReadError::InvalidFormat(other.into())),
3175 }
3176 }
3177}
3178
3179impl<'a> MinByteRange<'a> for ReverseChainSingleSubst<'a> {
3180 fn min_byte_range(&self) -> Range<usize> {
3181 match self {
3182 Self::Format1(item) => item.min_byte_range(),
3183 Self::Format2(item) => item.min_byte_range(),
3184 }
3185 }
3186 fn min_table_bytes(&self) -> &'a [u8] {
3187 match self {
3188 Self::Format1(item) => item.min_table_bytes(),
3189 Self::Format2(item) => item.min_table_bytes(),
3190 }
3191 }
3192}