1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Cmap<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self.encoding_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 TopLevelTable for Cmap<'_> {
19 const TAG: Tag = Tag::new(b"cmap");
21}
22
23impl ReadArgs for Cmap<'_> {
24 type Args = ();
25}
26
27impl<'a> FontRead<'a> for Cmap<'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 CmapFixedHeader {
45 pub version: BigEndian<u16>,
46 pub num_tables: BigEndian<u16>,
47}
48
49#[allow(clippy::absurd_extreme_comparisons)]
50const _: () = assert!(std::mem::size_of::<CmapFixedHeader>() <= Cmap::MIN_SIZE);
51
52#[derive(Clone)]
54pub struct Cmap<'a> {
55 data: TableDataRef<'a, CmapFixedHeader>,
56}
57
58#[allow(clippy::needless_lifetimes)]
59impl<'a> Cmap<'a> {
60 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
61 basic_table_impls!(impl_the_methods);
62
63 pub fn version(&self) -> u16 {
65 self.data.header().version.get()
66 }
67
68 pub fn num_tables(&self) -> u16 {
70 self.data.header().num_tables.get()
71 }
72
73 pub fn encoding_records(&self) -> &'a [EncodingRecord] {
74 let range = self.encoding_records_byte_range();
75 self.offset_data()
76 .read_array(range)
77 .ok()
78 .unwrap_or_default()
79 }
80
81 pub fn version_byte_range(&self) -> Range<usize> {
82 let start = 0usize;
83 let end = start.saturating_add(u16::RAW_BYTE_LEN);
84 start..end
85 }
86
87 pub fn num_tables_byte_range(&self) -> Range<usize> {
88 let start = self.version_byte_range().end;
89 let end = start.saturating_add(u16::RAW_BYTE_LEN);
90 start..end
91 }
92
93 pub fn encoding_records_byte_range(&self) -> Range<usize> {
94 let num_tables = self.num_tables();
95 let start = self.num_tables_byte_range().end;
96 let end = start.saturating_add(
97 (transforms::to_usize(num_tables)).saturating_mul(EncodingRecord::RAW_BYTE_LEN),
98 );
99 start..end
100 }
101}
102
103const _: () = assert!(FontData::default_data_long_enough(Cmap::MIN_SIZE));
104
105impl Default for Cmap<'_> {
106 fn default() -> Self {
107 Self {
108 data: TableDataRef::new(FontData::default_table_data().as_bytes())
109 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
110 }
111 }
112}
113
114impl<'a> MinByteRange<'a> for Dmap<'a> {
115 fn min_byte_range(&self) -> Range<usize> {
116 0..self.encoding_records_byte_range().end
117 }
118 fn min_table_bytes(&self) -> &'a [u8] {
119 let range = self.min_byte_range();
120 self.offset_data().as_bytes().get(range).unwrap_or_default()
121 }
122}
123
124impl TopLevelTable for Dmap<'_> {
125 const TAG: Tag = Tag::new(b"DMAP");
127}
128
129impl ReadArgs for Dmap<'_> {
130 type Args = ();
131}
132
133impl<'a> FontRead<'a> for Dmap<'a> {
134 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
135 #[allow(clippy::absurd_extreme_comparisons)]
136 if data.len() < Self::MIN_SIZE {
137 return Err(ReadError::OutOfBounds);
138 }
139 let Some(data) = TableDataRef::new(data.as_bytes()) else {
140 return Err(ReadError::OutOfBounds);
141 };
142 Ok(Self { data })
143 }
144}
145
146#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
148#[repr(C, packed)]
149#[doc(hidden)]
150pub struct DmapFixedHeader {
151 pub version: BigEndian<u16>,
152 pub num_tables: BigEndian<u16>,
153}
154
155#[allow(clippy::absurd_extreme_comparisons)]
156const _: () = assert!(std::mem::size_of::<DmapFixedHeader>() <= Dmap::MIN_SIZE);
157
158#[derive(Clone)]
160pub struct Dmap<'a> {
161 data: TableDataRef<'a, DmapFixedHeader>,
162}
163
164#[allow(clippy::needless_lifetimes)]
165impl<'a> Dmap<'a> {
166 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
167 basic_table_impls!(impl_the_methods);
168
169 pub fn version(&self) -> u16 {
171 self.data.header().version.get()
172 }
173
174 pub fn num_tables(&self) -> u16 {
176 self.data.header().num_tables.get()
177 }
178
179 pub fn encoding_records(&self) -> &'a [EncodingRecord] {
180 let range = self.encoding_records_byte_range();
181 self.offset_data()
182 .read_array(range)
183 .ok()
184 .unwrap_or_default()
185 }
186
187 pub fn version_byte_range(&self) -> Range<usize> {
188 let start = 0usize;
189 let end = start.saturating_add(u16::RAW_BYTE_LEN);
190 start..end
191 }
192
193 pub fn num_tables_byte_range(&self) -> Range<usize> {
194 let start = self.version_byte_range().end;
195 let end = start.saturating_add(u16::RAW_BYTE_LEN);
196 start..end
197 }
198
199 pub fn encoding_records_byte_range(&self) -> Range<usize> {
200 let num_tables = self.num_tables();
201 let start = self.num_tables_byte_range().end;
202 let end = start.saturating_add(
203 (transforms::to_usize(num_tables)).saturating_mul(EncodingRecord::RAW_BYTE_LEN),
204 );
205 start..end
206 }
207}
208
209const _: () = assert!(FontData::default_data_long_enough(Dmap::MIN_SIZE));
210
211impl Default for Dmap<'_> {
212 fn default() -> Self {
213 Self {
214 data: TableDataRef::new(FontData::default_table_data().as_bytes())
215 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
216 }
217 }
218}
219
220#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
222#[repr(C)]
223#[repr(packed)]
224pub struct EncodingRecord {
225 pub platform_id: BigEndian<PlatformId>,
227 pub encoding_id: BigEndian<u16>,
229 pub subtable_offset: BigEndian<Offset32>,
232}
233
234impl EncodingRecord {
235 pub fn platform_id(&self) -> PlatformId {
237 self.platform_id.get()
238 }
239
240 pub fn encoding_id(&self) -> u16 {
242 self.encoding_id.get()
243 }
244
245 pub fn subtable_offset(&self) -> Offset32 {
248 self.subtable_offset.get()
249 }
250
251 pub fn subtable<'a>(&self, data: FontData<'a>) -> Result<CmapSubtable<'a>, ReadError> {
257 self.subtable_offset().resolve(data)
258 }
259}
260
261impl FixedSize for EncodingRecord {
262 const RAW_BYTE_LEN: usize =
263 PlatformId::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
264}
265
266#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
268#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
269#[repr(u16)]
270#[allow(clippy::manual_non_exhaustive)]
271pub enum PlatformId {
272 #[default]
273 Unicode = 0,
274 Macintosh = 1,
275 ISO = 2,
276 Windows = 3,
277 Custom = 4,
278 #[doc(hidden)]
279 Unknown,
281}
282
283impl PlatformId {
284 pub fn new(raw: u16) -> Self {
288 match raw {
289 0 => Self::Unicode,
290 1 => Self::Macintosh,
291 2 => Self::ISO,
292 3 => Self::Windows,
293 4 => Self::Custom,
294 _ => Self::Unknown,
295 }
296 }
297}
298
299impl font_types::Scalar for PlatformId {
300 type Raw = <u16 as font_types::Scalar>::Raw;
301 fn to_raw(self) -> Self::Raw {
302 (self as u16).to_raw()
303 }
304 fn from_raw(raw: Self::Raw) -> Self {
305 let t = <u16>::from_raw(raw);
306 Self::new(t)
307 }
308}
309
310#[derive(Clone)]
312pub enum CmapSubtable<'a> {
313 Format0(Cmap0<'a>),
314 Format2(Cmap2<'a>),
315 Format4(Cmap4<'a>),
316 Format6(Cmap6<'a>),
317 Format8(Cmap8<'a>),
318 Format10(Cmap10<'a>),
319 Format12(Cmap12<'a>),
320 Format13(Cmap13<'a>),
321 Format14(Cmap14<'a>),
322 Format15(Cmap15<'a>),
323}
324
325impl Default for CmapSubtable<'_> {
326 fn default() -> Self {
327 Self::Format0(Default::default())
328 }
329}
330
331impl<'a> CmapSubtable<'a> {
332 pub fn offset_data(&self) -> FontData<'a> {
334 match self {
335 Self::Format0(item) => item.offset_data(),
336 Self::Format2(item) => item.offset_data(),
337 Self::Format4(item) => item.offset_data(),
338 Self::Format6(item) => item.offset_data(),
339 Self::Format8(item) => item.offset_data(),
340 Self::Format10(item) => item.offset_data(),
341 Self::Format12(item) => item.offset_data(),
342 Self::Format13(item) => item.offset_data(),
343 Self::Format14(item) => item.offset_data(),
344 Self::Format15(item) => item.offset_data(),
345 }
346 }
347
348 pub fn format(&self) -> u16 {
350 match self {
351 Self::Format0(item) => item.format(),
352 Self::Format2(item) => item.format(),
353 Self::Format4(item) => item.format(),
354 Self::Format6(item) => item.format(),
355 Self::Format8(item) => item.format(),
356 Self::Format10(item) => item.format(),
357 Self::Format12(item) => item.format(),
358 Self::Format13(item) => item.format(),
359 Self::Format14(item) => item.format(),
360 Self::Format15(item) => item.format(),
361 }
362 }
363}
364
365impl ReadArgs for CmapSubtable<'_> {
366 type Args = ();
367}
368
369impl<'a> FontRead<'a> for CmapSubtable<'a> {
370 #[inline]
371 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
372 let format: u16 = data.read_at(0usize)?;
373 match format {
374 Cmap0::FORMAT => Ok(Self::Format0(FontRead::read(data)?)),
375 Cmap2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
376 Cmap4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
377 Cmap6::FORMAT => Ok(Self::Format6(FontRead::read(data)?)),
378 Cmap8::FORMAT => Ok(Self::Format8(FontRead::read(data)?)),
379 Cmap10::FORMAT => Ok(Self::Format10(FontRead::read(data)?)),
380 Cmap12::FORMAT => Ok(Self::Format12(FontRead::read(data)?)),
381 Cmap13::FORMAT => Ok(Self::Format13(FontRead::read(data)?)),
382 Cmap14::FORMAT => Ok(Self::Format14(FontRead::read(data)?)),
383 Cmap15::FORMAT => Ok(Self::Format15(FontRead::read(data)?)),
384 other => Err(ReadError::InvalidFormat(other.into())),
385 }
386 }
387}
388
389impl<'a> MinByteRange<'a> for CmapSubtable<'a> {
390 fn min_byte_range(&self) -> Range<usize> {
391 match self {
392 Self::Format0(item) => item.min_byte_range(),
393 Self::Format2(item) => item.min_byte_range(),
394 Self::Format4(item) => item.min_byte_range(),
395 Self::Format6(item) => item.min_byte_range(),
396 Self::Format8(item) => item.min_byte_range(),
397 Self::Format10(item) => item.min_byte_range(),
398 Self::Format12(item) => item.min_byte_range(),
399 Self::Format13(item) => item.min_byte_range(),
400 Self::Format14(item) => item.min_byte_range(),
401 Self::Format15(item) => item.min_byte_range(),
402 }
403 }
404 fn min_table_bytes(&self) -> &'a [u8] {
405 match self {
406 Self::Format0(item) => item.min_table_bytes(),
407 Self::Format2(item) => item.min_table_bytes(),
408 Self::Format4(item) => item.min_table_bytes(),
409 Self::Format6(item) => item.min_table_bytes(),
410 Self::Format8(item) => item.min_table_bytes(),
411 Self::Format10(item) => item.min_table_bytes(),
412 Self::Format12(item) => item.min_table_bytes(),
413 Self::Format13(item) => item.min_table_bytes(),
414 Self::Format14(item) => item.min_table_bytes(),
415 Self::Format15(item) => item.min_table_bytes(),
416 }
417 }
418}
419
420impl Format<u16> for Cmap0<'_> {
421 const FORMAT: u16 = 0;
422}
423
424impl<'a> MinByteRange<'a> for Cmap0<'a> {
425 fn min_byte_range(&self) -> Range<usize> {
426 0..self.glyph_id_array_byte_range().end
427 }
428 fn min_table_bytes(&self) -> &'a [u8] {
429 let range = self.min_byte_range();
430 self.offset_data().as_bytes().get(range).unwrap_or_default()
431 }
432}
433
434impl ReadArgs for Cmap0<'_> {
435 type Args = ();
436}
437
438impl<'a> FontRead<'a> for Cmap0<'a> {
439 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
440 #[allow(clippy::absurd_extreme_comparisons)]
441 if data.len() < Self::MIN_SIZE {
442 return Err(ReadError::OutOfBounds);
443 }
444 let Some(data) = TableDataRef::new(data.as_bytes()) else {
445 return Err(ReadError::OutOfBounds);
446 };
447 Ok(Self { data })
448 }
449}
450
451#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
453#[repr(C, packed)]
454#[doc(hidden)]
455pub struct Cmap0FixedHeader {
456 pub format: BigEndian<u16>,
457 pub length: BigEndian<u16>,
458 pub language: BigEndian<u16>,
459}
460
461#[allow(clippy::absurd_extreme_comparisons)]
462const _: () = assert!(std::mem::size_of::<Cmap0FixedHeader>() <= Cmap0::MIN_SIZE);
463
464#[derive(Clone)]
466pub struct Cmap0<'a> {
467 data: TableDataRef<'a, Cmap0FixedHeader>,
468}
469
470#[allow(clippy::needless_lifetimes)]
471impl<'a> Cmap0<'a> {
472 pub const MIN_SIZE: usize =
473 (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u8::RAW_BYTE_LEN * 256_usize);
474 basic_table_impls!(impl_the_methods);
475
476 pub fn format(&self) -> u16 {
478 self.data.header().format.get()
479 }
480
481 pub fn length(&self) -> u16 {
483 self.data.header().length.get()
484 }
485
486 pub fn language(&self) -> u16 {
489 self.data.header().language.get()
490 }
491
492 pub fn glyph_id_array(&self) -> &'a [u8] {
494 let range = self.glyph_id_array_byte_range();
495 self.offset_data()
496 .read_array(range)
497 .ok()
498 .unwrap_or_default()
499 }
500
501 pub fn format_byte_range(&self) -> Range<usize> {
502 let start = 0usize;
503 let end = start.saturating_add(u16::RAW_BYTE_LEN);
504 start..end
505 }
506
507 pub fn length_byte_range(&self) -> Range<usize> {
508 let start = self.format_byte_range().end;
509 let end = start.saturating_add(u16::RAW_BYTE_LEN);
510 start..end
511 }
512
513 pub fn language_byte_range(&self) -> Range<usize> {
514 let start = self.length_byte_range().end;
515 let end = start.saturating_add(u16::RAW_BYTE_LEN);
516 start..end
517 }
518
519 pub fn glyph_id_array_byte_range(&self) -> Range<usize> {
520 let start = self.language_byte_range().end;
521 let end = start.saturating_add((256_usize).saturating_mul(u8::RAW_BYTE_LEN));
522 start..end
523 }
524}
525
526const _: () = assert!(FontData::default_data_long_enough(Cmap0::MIN_SIZE));
527
528impl Default for Cmap0<'_> {
529 fn default() -> Self {
530 Self {
531 data: TableDataRef::new(FontData::default_table_data().as_bytes())
532 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
533 }
534 }
535}
536
537impl Format<u16> for Cmap2<'_> {
538 const FORMAT: u16 = 2;
539}
540
541impl<'a> MinByteRange<'a> for Cmap2<'a> {
542 fn min_byte_range(&self) -> Range<usize> {
543 0..self.sub_header_keys_byte_range().end
544 }
545 fn min_table_bytes(&self) -> &'a [u8] {
546 let range = self.min_byte_range();
547 self.offset_data().as_bytes().get(range).unwrap_or_default()
548 }
549}
550
551impl ReadArgs for Cmap2<'_> {
552 type Args = ();
553}
554
555impl<'a> FontRead<'a> for Cmap2<'a> {
556 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
557 #[allow(clippy::absurd_extreme_comparisons)]
558 if data.len() < Self::MIN_SIZE {
559 return Err(ReadError::OutOfBounds);
560 }
561 let Some(data) = TableDataRef::new(data.as_bytes()) else {
562 return Err(ReadError::OutOfBounds);
563 };
564 Ok(Self { data })
565 }
566}
567
568#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
570#[repr(C, packed)]
571#[doc(hidden)]
572pub struct Cmap2FixedHeader {
573 pub format: BigEndian<u16>,
574 pub length: BigEndian<u16>,
575 pub language: BigEndian<u16>,
576}
577
578#[allow(clippy::absurd_extreme_comparisons)]
579const _: () = assert!(std::mem::size_of::<Cmap2FixedHeader>() <= Cmap2::MIN_SIZE);
580
581#[derive(Clone)]
583pub struct Cmap2<'a> {
584 data: TableDataRef<'a, Cmap2FixedHeader>,
585}
586
587#[allow(clippy::needless_lifetimes)]
588impl<'a> Cmap2<'a> {
589 pub const MIN_SIZE: usize =
590 (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN * 256_usize);
591 basic_table_impls!(impl_the_methods);
592
593 pub fn format(&self) -> u16 {
595 self.data.header().format.get()
596 }
597
598 pub fn length(&self) -> u16 {
600 self.data.header().length.get()
601 }
602
603 pub fn language(&self) -> u16 {
606 self.data.header().language.get()
607 }
608
609 pub fn sub_header_keys(&self) -> &'a [BigEndian<u16>] {
612 let range = self.sub_header_keys_byte_range();
613 self.offset_data()
614 .read_array(range)
615 .ok()
616 .unwrap_or_default()
617 }
618
619 pub fn format_byte_range(&self) -> Range<usize> {
620 let start = 0usize;
621 let end = start.saturating_add(u16::RAW_BYTE_LEN);
622 start..end
623 }
624
625 pub fn length_byte_range(&self) -> Range<usize> {
626 let start = self.format_byte_range().end;
627 let end = start.saturating_add(u16::RAW_BYTE_LEN);
628 start..end
629 }
630
631 pub fn language_byte_range(&self) -> Range<usize> {
632 let start = self.length_byte_range().end;
633 let end = start.saturating_add(u16::RAW_BYTE_LEN);
634 start..end
635 }
636
637 pub fn sub_header_keys_byte_range(&self) -> Range<usize> {
638 let start = self.language_byte_range().end;
639 let end = start.saturating_add((256_usize).saturating_mul(u16::RAW_BYTE_LEN));
640 start..end
641 }
642}
643
644#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
646#[repr(C)]
647#[repr(packed)]
648pub struct SubHeader {
649 pub first_code: BigEndian<u16>,
651 pub entry_count: BigEndian<u16>,
653 pub id_delta: BigEndian<i16>,
655 pub id_range_offset: BigEndian<u16>,
657}
658
659impl SubHeader {
660 pub fn first_code(&self) -> u16 {
662 self.first_code.get()
663 }
664
665 pub fn entry_count(&self) -> u16 {
667 self.entry_count.get()
668 }
669
670 pub fn id_delta(&self) -> i16 {
672 self.id_delta.get()
673 }
674
675 pub fn id_range_offset(&self) -> u16 {
677 self.id_range_offset.get()
678 }
679}
680
681impl FixedSize for SubHeader {
682 const RAW_BYTE_LEN: usize =
683 u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
684}
685
686impl Format<u16> for Cmap4<'_> {
687 const FORMAT: u16 = 4;
688}
689
690impl<'a> MinByteRange<'a> for Cmap4<'a> {
691 fn min_byte_range(&self) -> Range<usize> {
692 0..self.glyph_id_array_byte_range().end
693 }
694 fn min_table_bytes(&self) -> &'a [u8] {
695 let range = self.min_byte_range();
696 self.offset_data().as_bytes().get(range).unwrap_or_default()
697 }
698}
699
700impl ReadArgs for Cmap4<'_> {
701 type Args = ();
702}
703
704impl<'a> FontRead<'a> for Cmap4<'a> {
705 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
706 #[allow(clippy::absurd_extreme_comparisons)]
707 if data.len() < Self::MIN_SIZE {
708 return Err(ReadError::OutOfBounds);
709 }
710 let Some(data) = TableDataRef::new(data.as_bytes()) else {
711 return Err(ReadError::OutOfBounds);
712 };
713 Ok(Self { data })
714 }
715}
716
717#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
719#[repr(C, packed)]
720#[doc(hidden)]
721pub struct Cmap4FixedHeader {
722 pub format: BigEndian<u16>,
723 pub length: BigEndian<u16>,
724 pub language: BigEndian<u16>,
725 pub seg_count_x2: BigEndian<u16>,
726 pub search_range: BigEndian<u16>,
727 pub entry_selector: BigEndian<u16>,
728 pub range_shift: BigEndian<u16>,
729}
730
731#[allow(clippy::absurd_extreme_comparisons)]
732const _: () = assert!(std::mem::size_of::<Cmap4FixedHeader>() <= Cmap4::MIN_SIZE);
733
734#[derive(Clone)]
736pub struct Cmap4<'a> {
737 data: TableDataRef<'a, Cmap4FixedHeader>,
738}
739
740#[allow(clippy::needless_lifetimes)]
741impl<'a> Cmap4<'a> {
742 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
743 + u16::RAW_BYTE_LEN
744 + u16::RAW_BYTE_LEN
745 + u16::RAW_BYTE_LEN
746 + u16::RAW_BYTE_LEN
747 + u16::RAW_BYTE_LEN
748 + u16::RAW_BYTE_LEN
749 + u16::RAW_BYTE_LEN);
750 basic_table_impls!(impl_the_methods);
751
752 pub fn format(&self) -> u16 {
754 self.data.header().format.get()
755 }
756
757 pub fn length(&self) -> u16 {
759 self.data.header().length.get()
760 }
761
762 pub fn language(&self) -> u16 {
765 self.data.header().language.get()
766 }
767
768 pub fn seg_count_x2(&self) -> u16 {
770 self.data.header().seg_count_x2.get()
771 }
772
773 pub fn search_range(&self) -> u16 {
777 self.data.header().search_range.get()
778 }
779
780 pub fn entry_selector(&self) -> u16 {
783 self.data.header().entry_selector.get()
784 }
785
786 pub fn range_shift(&self) -> u16 {
789 self.data.header().range_shift.get()
790 }
791
792 pub fn end_code(&self) -> &'a [BigEndian<u16>] {
794 let range = self.end_code_byte_range();
795 self.offset_data()
796 .read_array(range)
797 .ok()
798 .unwrap_or_default()
799 }
800
801 pub fn start_code(&self) -> &'a [BigEndian<u16>] {
803 let range = self.start_code_byte_range();
804 self.offset_data()
805 .read_array(range)
806 .ok()
807 .unwrap_or_default()
808 }
809
810 pub fn id_delta(&self) -> &'a [BigEndian<i16>] {
812 let range = self.id_delta_byte_range();
813 self.offset_data()
814 .read_array(range)
815 .ok()
816 .unwrap_or_default()
817 }
818
819 pub fn id_range_offsets(&self) -> &'a [BigEndian<u16>] {
821 let range = self.id_range_offsets_byte_range();
822 self.offset_data()
823 .read_array(range)
824 .ok()
825 .unwrap_or_default()
826 }
827
828 pub fn glyph_id_array(&self) -> &'a [BigEndian<u16>] {
830 let range = self.glyph_id_array_byte_range();
831 self.offset_data()
832 .read_array(range)
833 .ok()
834 .unwrap_or_default()
835 }
836
837 pub fn format_byte_range(&self) -> Range<usize> {
838 let start = 0usize;
839 let end = start.saturating_add(u16::RAW_BYTE_LEN);
840 start..end
841 }
842
843 pub fn length_byte_range(&self) -> Range<usize> {
844 let start = self.format_byte_range().end;
845 let end = start.saturating_add(u16::RAW_BYTE_LEN);
846 start..end
847 }
848
849 pub fn language_byte_range(&self) -> Range<usize> {
850 let start = self.length_byte_range().end;
851 let end = start.saturating_add(u16::RAW_BYTE_LEN);
852 start..end
853 }
854
855 pub fn seg_count_x2_byte_range(&self) -> Range<usize> {
856 let start = self.language_byte_range().end;
857 let end = start.saturating_add(u16::RAW_BYTE_LEN);
858 start..end
859 }
860
861 pub fn search_range_byte_range(&self) -> Range<usize> {
862 let start = self.seg_count_x2_byte_range().end;
863 let end = start.saturating_add(u16::RAW_BYTE_LEN);
864 start..end
865 }
866
867 pub fn entry_selector_byte_range(&self) -> Range<usize> {
868 let start = self.search_range_byte_range().end;
869 let end = start.saturating_add(u16::RAW_BYTE_LEN);
870 start..end
871 }
872
873 pub fn range_shift_byte_range(&self) -> Range<usize> {
874 let start = self.entry_selector_byte_range().end;
875 let end = start.saturating_add(u16::RAW_BYTE_LEN);
876 start..end
877 }
878
879 pub fn end_code_byte_range(&self) -> Range<usize> {
880 let seg_count_x2 = self.seg_count_x2();
881 let start = self.range_shift_byte_range().end;
882 let end = start
883 .saturating_add((transforms::half(seg_count_x2)).saturating_mul(u16::RAW_BYTE_LEN));
884 start..end
885 }
886
887 pub fn reserved_pad_byte_range(&self) -> Range<usize> {
888 let start = self.end_code_byte_range().end;
889 let end = start.saturating_add(u16::RAW_BYTE_LEN);
890 start..end
891 }
892
893 pub fn start_code_byte_range(&self) -> Range<usize> {
894 let seg_count_x2 = self.seg_count_x2();
895 let start = self.reserved_pad_byte_range().end;
896 let end = start
897 .saturating_add((transforms::half(seg_count_x2)).saturating_mul(u16::RAW_BYTE_LEN));
898 start..end
899 }
900
901 pub fn id_delta_byte_range(&self) -> Range<usize> {
902 let seg_count_x2 = self.seg_count_x2();
903 let start = self.start_code_byte_range().end;
904 let end = start
905 .saturating_add((transforms::half(seg_count_x2)).saturating_mul(i16::RAW_BYTE_LEN));
906 start..end
907 }
908
909 pub fn id_range_offsets_byte_range(&self) -> Range<usize> {
910 let seg_count_x2 = self.seg_count_x2();
911 let start = self.id_delta_byte_range().end;
912 let end = start
913 .saturating_add((transforms::half(seg_count_x2)).saturating_mul(u16::RAW_BYTE_LEN));
914 start..end
915 }
916
917 pub fn glyph_id_array_byte_range(&self) -> Range<usize> {
918 let start = self.id_range_offsets_byte_range().end;
919 let end = start.saturating_add(
920 self.offset_data().len().saturating_sub(start) / u16::RAW_BYTE_LEN * u16::RAW_BYTE_LEN,
921 );
922 start..end
923 }
924}
925
926impl Format<u16> for Cmap6<'_> {
927 const FORMAT: u16 = 6;
928}
929
930impl<'a> MinByteRange<'a> for Cmap6<'a> {
931 fn min_byte_range(&self) -> Range<usize> {
932 0..self.glyph_id_array_byte_range().end
933 }
934 fn min_table_bytes(&self) -> &'a [u8] {
935 let range = self.min_byte_range();
936 self.offset_data().as_bytes().get(range).unwrap_or_default()
937 }
938}
939
940impl ReadArgs for Cmap6<'_> {
941 type Args = ();
942}
943
944impl<'a> FontRead<'a> for Cmap6<'a> {
945 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
946 #[allow(clippy::absurd_extreme_comparisons)]
947 if data.len() < Self::MIN_SIZE {
948 return Err(ReadError::OutOfBounds);
949 }
950 let Some(data) = TableDataRef::new(data.as_bytes()) else {
951 return Err(ReadError::OutOfBounds);
952 };
953 Ok(Self { data })
954 }
955}
956
957#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
959#[repr(C, packed)]
960#[doc(hidden)]
961pub struct Cmap6FixedHeader {
962 pub format: BigEndian<u16>,
963 pub length: BigEndian<u16>,
964 pub language: BigEndian<u16>,
965 pub first_code: BigEndian<u16>,
966 pub entry_count: BigEndian<u16>,
967}
968
969#[allow(clippy::absurd_extreme_comparisons)]
970const _: () = assert!(std::mem::size_of::<Cmap6FixedHeader>() <= Cmap6::MIN_SIZE);
971
972#[derive(Clone)]
974pub struct Cmap6<'a> {
975 data: TableDataRef<'a, Cmap6FixedHeader>,
976}
977
978#[allow(clippy::needless_lifetimes)]
979impl<'a> Cmap6<'a> {
980 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
981 + u16::RAW_BYTE_LEN
982 + u16::RAW_BYTE_LEN
983 + u16::RAW_BYTE_LEN
984 + u16::RAW_BYTE_LEN);
985 basic_table_impls!(impl_the_methods);
986
987 pub fn format(&self) -> u16 {
989 self.data.header().format.get()
990 }
991
992 pub fn length(&self) -> u16 {
994 self.data.header().length.get()
995 }
996
997 pub fn language(&self) -> u16 {
1000 self.data.header().language.get()
1001 }
1002
1003 pub fn first_code(&self) -> u16 {
1005 self.data.header().first_code.get()
1006 }
1007
1008 pub fn entry_count(&self) -> u16 {
1010 self.data.header().entry_count.get()
1011 }
1012
1013 pub fn glyph_id_array(&self) -> &'a [BigEndian<u16>] {
1015 let range = self.glyph_id_array_byte_range();
1016 self.offset_data()
1017 .read_array(range)
1018 .ok()
1019 .unwrap_or_default()
1020 }
1021
1022 pub fn format_byte_range(&self) -> Range<usize> {
1023 let start = 0usize;
1024 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1025 start..end
1026 }
1027
1028 pub fn length_byte_range(&self) -> Range<usize> {
1029 let start = self.format_byte_range().end;
1030 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1031 start..end
1032 }
1033
1034 pub fn language_byte_range(&self) -> Range<usize> {
1035 let start = self.length_byte_range().end;
1036 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1037 start..end
1038 }
1039
1040 pub fn first_code_byte_range(&self) -> Range<usize> {
1041 let start = self.language_byte_range().end;
1042 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1043 start..end
1044 }
1045
1046 pub fn entry_count_byte_range(&self) -> Range<usize> {
1047 let start = self.first_code_byte_range().end;
1048 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1049 start..end
1050 }
1051
1052 pub fn glyph_id_array_byte_range(&self) -> Range<usize> {
1053 let entry_count = self.entry_count();
1054 let start = self.entry_count_byte_range().end;
1055 let end = start
1056 .saturating_add((transforms::to_usize(entry_count)).saturating_mul(u16::RAW_BYTE_LEN));
1057 start..end
1058 }
1059}
1060
1061impl Format<u16> for Cmap8<'_> {
1062 const FORMAT: u16 = 8;
1063}
1064
1065impl<'a> MinByteRange<'a> for Cmap8<'a> {
1066 fn min_byte_range(&self) -> Range<usize> {
1067 0..self.groups_byte_range().end
1068 }
1069 fn min_table_bytes(&self) -> &'a [u8] {
1070 let range = self.min_byte_range();
1071 self.offset_data().as_bytes().get(range).unwrap_or_default()
1072 }
1073}
1074
1075impl ReadArgs for Cmap8<'_> {
1076 type Args = ();
1077}
1078
1079impl<'a> FontRead<'a> for Cmap8<'a> {
1080 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1081 #[allow(clippy::absurd_extreme_comparisons)]
1082 if data.len() < Self::MIN_SIZE {
1083 return Err(ReadError::OutOfBounds);
1084 }
1085 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1086 return Err(ReadError::OutOfBounds);
1087 };
1088 Ok(Self { data })
1089 }
1090}
1091
1092#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1094#[repr(C, packed)]
1095#[doc(hidden)]
1096pub struct Cmap8FixedHeader {
1097 pub format: BigEndian<u16>,
1098 pub reserved: BigEndian<u16>,
1099 pub length: BigEndian<u32>,
1100 pub language: BigEndian<u32>,
1101}
1102
1103#[allow(clippy::absurd_extreme_comparisons)]
1104const _: () = assert!(std::mem::size_of::<Cmap8FixedHeader>() <= Cmap8::MIN_SIZE);
1105
1106#[derive(Clone)]
1108pub struct Cmap8<'a> {
1109 data: TableDataRef<'a, Cmap8FixedHeader>,
1110}
1111
1112#[allow(clippy::needless_lifetimes)]
1113impl<'a> Cmap8<'a> {
1114 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
1115 + u16::RAW_BYTE_LEN
1116 + u32::RAW_BYTE_LEN
1117 + u32::RAW_BYTE_LEN
1118 + u8::RAW_BYTE_LEN * 8192_usize
1119 + u32::RAW_BYTE_LEN);
1120 basic_table_impls!(impl_the_methods);
1121
1122 pub fn format(&self) -> u16 {
1124 self.data.header().format.get()
1125 }
1126
1127 pub fn length(&self) -> u32 {
1129 self.data.header().length.get()
1130 }
1131
1132 pub fn language(&self) -> u32 {
1135 self.data.header().language.get()
1136 }
1137
1138 pub fn is32(&self) -> &'a [u8] {
1142 let range = self.is32_byte_range();
1143 self.offset_data()
1144 .read_array(range)
1145 .ok()
1146 .unwrap_or_default()
1147 }
1148
1149 pub fn num_groups(&self) -> u32 {
1151 let range = self.num_groups_byte_range();
1152 self.offset_data()
1153 .read_at(range.start)
1154 .ok()
1155 .unwrap_or_default()
1156 }
1157
1158 pub fn groups(&self) -> &'a [SequentialMapGroup] {
1160 let range = self.groups_byte_range();
1161 self.offset_data()
1162 .read_array(range)
1163 .ok()
1164 .unwrap_or_default()
1165 }
1166
1167 pub fn format_byte_range(&self) -> Range<usize> {
1168 let start = 0usize;
1169 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1170 start..end
1171 }
1172
1173 pub fn reserved_byte_range(&self) -> Range<usize> {
1174 let start = self.format_byte_range().end;
1175 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1176 start..end
1177 }
1178
1179 pub fn length_byte_range(&self) -> Range<usize> {
1180 let start = self.reserved_byte_range().end;
1181 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1182 start..end
1183 }
1184
1185 pub fn language_byte_range(&self) -> Range<usize> {
1186 let start = self.length_byte_range().end;
1187 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1188 start..end
1189 }
1190
1191 pub fn is32_byte_range(&self) -> Range<usize> {
1192 let start = self.language_byte_range().end;
1193 let end = start.saturating_add((8192_usize).saturating_mul(u8::RAW_BYTE_LEN));
1194 start..end
1195 }
1196
1197 pub fn num_groups_byte_range(&self) -> Range<usize> {
1198 let start = self.is32_byte_range().end;
1199 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1200 start..end
1201 }
1202
1203 pub fn groups_byte_range(&self) -> Range<usize> {
1204 let num_groups = self.num_groups();
1205 let start = self.num_groups_byte_range().end;
1206 let end = start.saturating_add(
1207 (transforms::to_usize(num_groups)).saturating_mul(SequentialMapGroup::RAW_BYTE_LEN),
1208 );
1209 start..end
1210 }
1211}
1212
1213#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1215#[repr(C)]
1216#[repr(packed)]
1217pub struct SequentialMapGroup {
1218 pub start_char_code: BigEndian<u32>,
1223 pub end_char_code: BigEndian<u32>,
1226 pub start_glyph_id: BigEndian<u32>,
1228}
1229
1230impl SequentialMapGroup {
1231 pub fn start_char_code(&self) -> u32 {
1236 self.start_char_code.get()
1237 }
1238
1239 pub fn end_char_code(&self) -> u32 {
1242 self.end_char_code.get()
1243 }
1244
1245 pub fn start_glyph_id(&self) -> u32 {
1247 self.start_glyph_id.get()
1248 }
1249}
1250
1251impl FixedSize for SequentialMapGroup {
1252 const RAW_BYTE_LEN: usize = u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN;
1253}
1254
1255impl Format<u16> for Cmap10<'_> {
1256 const FORMAT: u16 = 10;
1257}
1258
1259impl<'a> MinByteRange<'a> for Cmap10<'a> {
1260 fn min_byte_range(&self) -> Range<usize> {
1261 0..self.glyph_id_array_byte_range().end
1262 }
1263 fn min_table_bytes(&self) -> &'a [u8] {
1264 let range = self.min_byte_range();
1265 self.offset_data().as_bytes().get(range).unwrap_or_default()
1266 }
1267}
1268
1269impl ReadArgs for Cmap10<'_> {
1270 type Args = ();
1271}
1272
1273impl<'a> FontRead<'a> for Cmap10<'a> {
1274 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1275 #[allow(clippy::absurd_extreme_comparisons)]
1276 if data.len() < Self::MIN_SIZE {
1277 return Err(ReadError::OutOfBounds);
1278 }
1279 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1280 return Err(ReadError::OutOfBounds);
1281 };
1282 Ok(Self { data })
1283 }
1284}
1285
1286#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1288#[repr(C, packed)]
1289#[doc(hidden)]
1290pub struct Cmap10FixedHeader {
1291 pub format: BigEndian<u16>,
1292 pub reserved: BigEndian<u16>,
1293 pub length: BigEndian<u32>,
1294 pub language: BigEndian<u32>,
1295 pub start_char_code: BigEndian<u32>,
1296 pub num_chars: BigEndian<u32>,
1297}
1298
1299#[allow(clippy::absurd_extreme_comparisons)]
1300const _: () = assert!(std::mem::size_of::<Cmap10FixedHeader>() <= Cmap10::MIN_SIZE);
1301
1302#[derive(Clone)]
1304pub struct Cmap10<'a> {
1305 data: TableDataRef<'a, Cmap10FixedHeader>,
1306}
1307
1308#[allow(clippy::needless_lifetimes)]
1309impl<'a> Cmap10<'a> {
1310 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
1311 + u16::RAW_BYTE_LEN
1312 + u32::RAW_BYTE_LEN
1313 + u32::RAW_BYTE_LEN
1314 + u32::RAW_BYTE_LEN
1315 + u32::RAW_BYTE_LEN);
1316 basic_table_impls!(impl_the_methods);
1317
1318 pub fn format(&self) -> u16 {
1320 self.data.header().format.get()
1321 }
1322
1323 pub fn length(&self) -> u32 {
1325 self.data.header().length.get()
1326 }
1327
1328 pub fn language(&self) -> u32 {
1331 self.data.header().language.get()
1332 }
1333
1334 pub fn start_char_code(&self) -> u32 {
1336 self.data.header().start_char_code.get()
1337 }
1338
1339 pub fn num_chars(&self) -> u32 {
1341 self.data.header().num_chars.get()
1342 }
1343
1344 pub fn glyph_id_array(&self) -> &'a [BigEndian<u16>] {
1346 let range = self.glyph_id_array_byte_range();
1347 self.offset_data()
1348 .read_array(range)
1349 .ok()
1350 .unwrap_or_default()
1351 }
1352
1353 pub fn format_byte_range(&self) -> Range<usize> {
1354 let start = 0usize;
1355 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1356 start..end
1357 }
1358
1359 pub fn reserved_byte_range(&self) -> Range<usize> {
1360 let start = self.format_byte_range().end;
1361 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1362 start..end
1363 }
1364
1365 pub fn length_byte_range(&self) -> Range<usize> {
1366 let start = self.reserved_byte_range().end;
1367 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1368 start..end
1369 }
1370
1371 pub fn language_byte_range(&self) -> Range<usize> {
1372 let start = self.length_byte_range().end;
1373 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1374 start..end
1375 }
1376
1377 pub fn start_char_code_byte_range(&self) -> Range<usize> {
1378 let start = self.language_byte_range().end;
1379 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1380 start..end
1381 }
1382
1383 pub fn num_chars_byte_range(&self) -> Range<usize> {
1384 let start = self.start_char_code_byte_range().end;
1385 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1386 start..end
1387 }
1388
1389 pub fn glyph_id_array_byte_range(&self) -> Range<usize> {
1390 let num_chars = self.num_chars();
1391 let start = self.num_chars_byte_range().end;
1392 let end = start
1393 .saturating_add((transforms::to_usize(num_chars)).saturating_mul(u16::RAW_BYTE_LEN));
1394 start..end
1395 }
1396}
1397
1398impl Format<u16> for Cmap12<'_> {
1399 const FORMAT: u16 = 12;
1400}
1401
1402impl<'a> MinByteRange<'a> for Cmap12<'a> {
1403 fn min_byte_range(&self) -> Range<usize> {
1404 0..self.groups_byte_range().end
1405 }
1406 fn min_table_bytes(&self) -> &'a [u8] {
1407 let range = self.min_byte_range();
1408 self.offset_data().as_bytes().get(range).unwrap_or_default()
1409 }
1410}
1411
1412impl ReadArgs for Cmap12<'_> {
1413 type Args = ();
1414}
1415
1416impl<'a> FontRead<'a> for Cmap12<'a> {
1417 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1418 #[allow(clippy::absurd_extreme_comparisons)]
1419 if data.len() < Self::MIN_SIZE {
1420 return Err(ReadError::OutOfBounds);
1421 }
1422 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1423 return Err(ReadError::OutOfBounds);
1424 };
1425 Ok(Self { data })
1426 }
1427}
1428
1429#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1431#[repr(C, packed)]
1432#[doc(hidden)]
1433pub struct Cmap12FixedHeader {
1434 pub format: BigEndian<u16>,
1435 pub reserved: BigEndian<u16>,
1436 pub length: BigEndian<u32>,
1437 pub language: BigEndian<u32>,
1438 pub num_groups: BigEndian<u32>,
1439}
1440
1441#[allow(clippy::absurd_extreme_comparisons)]
1442const _: () = assert!(std::mem::size_of::<Cmap12FixedHeader>() <= Cmap12::MIN_SIZE);
1443
1444#[derive(Clone)]
1446pub struct Cmap12<'a> {
1447 data: TableDataRef<'a, Cmap12FixedHeader>,
1448}
1449
1450#[allow(clippy::needless_lifetimes)]
1451impl<'a> Cmap12<'a> {
1452 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
1453 + u16::RAW_BYTE_LEN
1454 + u32::RAW_BYTE_LEN
1455 + u32::RAW_BYTE_LEN
1456 + u32::RAW_BYTE_LEN);
1457 basic_table_impls!(impl_the_methods);
1458
1459 pub fn format(&self) -> u16 {
1461 self.data.header().format.get()
1462 }
1463
1464 pub fn length(&self) -> u32 {
1466 self.data.header().length.get()
1467 }
1468
1469 pub fn language(&self) -> u32 {
1472 self.data.header().language.get()
1473 }
1474
1475 pub fn num_groups(&self) -> u32 {
1477 self.data.header().num_groups.get()
1478 }
1479
1480 pub fn groups(&self) -> &'a [SequentialMapGroup] {
1482 let range = self.groups_byte_range();
1483 self.offset_data()
1484 .read_array(range)
1485 .ok()
1486 .unwrap_or_default()
1487 }
1488
1489 pub fn format_byte_range(&self) -> Range<usize> {
1490 let start = 0usize;
1491 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1492 start..end
1493 }
1494
1495 pub fn reserved_byte_range(&self) -> Range<usize> {
1496 let start = self.format_byte_range().end;
1497 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1498 start..end
1499 }
1500
1501 pub fn length_byte_range(&self) -> Range<usize> {
1502 let start = self.reserved_byte_range().end;
1503 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1504 start..end
1505 }
1506
1507 pub fn language_byte_range(&self) -> Range<usize> {
1508 let start = self.length_byte_range().end;
1509 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1510 start..end
1511 }
1512
1513 pub fn num_groups_byte_range(&self) -> Range<usize> {
1514 let start = self.language_byte_range().end;
1515 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1516 start..end
1517 }
1518
1519 pub fn groups_byte_range(&self) -> Range<usize> {
1520 let num_groups = self.num_groups();
1521 let start = self.num_groups_byte_range().end;
1522 let end = start.saturating_add(
1523 (transforms::to_usize(num_groups)).saturating_mul(SequentialMapGroup::RAW_BYTE_LEN),
1524 );
1525 start..end
1526 }
1527}
1528
1529impl Format<u16> for Cmap13<'_> {
1530 const FORMAT: u16 = 13;
1531}
1532
1533impl<'a> MinByteRange<'a> for Cmap13<'a> {
1534 fn min_byte_range(&self) -> Range<usize> {
1535 0..self.groups_byte_range().end
1536 }
1537 fn min_table_bytes(&self) -> &'a [u8] {
1538 let range = self.min_byte_range();
1539 self.offset_data().as_bytes().get(range).unwrap_or_default()
1540 }
1541}
1542
1543impl ReadArgs for Cmap13<'_> {
1544 type Args = ();
1545}
1546
1547impl<'a> FontRead<'a> for Cmap13<'a> {
1548 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1549 #[allow(clippy::absurd_extreme_comparisons)]
1550 if data.len() < Self::MIN_SIZE {
1551 return Err(ReadError::OutOfBounds);
1552 }
1553 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1554 return Err(ReadError::OutOfBounds);
1555 };
1556 Ok(Self { data })
1557 }
1558}
1559
1560#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1562#[repr(C, packed)]
1563#[doc(hidden)]
1564pub struct Cmap13FixedHeader {
1565 pub format: BigEndian<u16>,
1566 pub reserved: BigEndian<u16>,
1567 pub length: BigEndian<u32>,
1568 pub language: BigEndian<u32>,
1569 pub num_groups: BigEndian<u32>,
1570}
1571
1572#[allow(clippy::absurd_extreme_comparisons)]
1573const _: () = assert!(std::mem::size_of::<Cmap13FixedHeader>() <= Cmap13::MIN_SIZE);
1574
1575#[derive(Clone)]
1577pub struct Cmap13<'a> {
1578 data: TableDataRef<'a, Cmap13FixedHeader>,
1579}
1580
1581#[allow(clippy::needless_lifetimes)]
1582impl<'a> Cmap13<'a> {
1583 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
1584 + u16::RAW_BYTE_LEN
1585 + u32::RAW_BYTE_LEN
1586 + u32::RAW_BYTE_LEN
1587 + u32::RAW_BYTE_LEN);
1588 basic_table_impls!(impl_the_methods);
1589
1590 pub fn format(&self) -> u16 {
1592 self.data.header().format.get()
1593 }
1594
1595 pub fn length(&self) -> u32 {
1597 self.data.header().length.get()
1598 }
1599
1600 pub fn language(&self) -> u32 {
1603 self.data.header().language.get()
1604 }
1605
1606 pub fn num_groups(&self) -> u32 {
1608 self.data.header().num_groups.get()
1609 }
1610
1611 pub fn groups(&self) -> &'a [ConstantMapGroup] {
1613 let range = self.groups_byte_range();
1614 self.offset_data()
1615 .read_array(range)
1616 .ok()
1617 .unwrap_or_default()
1618 }
1619
1620 pub fn format_byte_range(&self) -> Range<usize> {
1621 let start = 0usize;
1622 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1623 start..end
1624 }
1625
1626 pub fn reserved_byte_range(&self) -> Range<usize> {
1627 let start = self.format_byte_range().end;
1628 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1629 start..end
1630 }
1631
1632 pub fn length_byte_range(&self) -> Range<usize> {
1633 let start = self.reserved_byte_range().end;
1634 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1635 start..end
1636 }
1637
1638 pub fn language_byte_range(&self) -> Range<usize> {
1639 let start = self.length_byte_range().end;
1640 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1641 start..end
1642 }
1643
1644 pub fn num_groups_byte_range(&self) -> Range<usize> {
1645 let start = self.language_byte_range().end;
1646 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1647 start..end
1648 }
1649
1650 pub fn groups_byte_range(&self) -> Range<usize> {
1651 let num_groups = self.num_groups();
1652 let start = self.num_groups_byte_range().end;
1653 let end = start.saturating_add(
1654 (transforms::to_usize(num_groups)).saturating_mul(ConstantMapGroup::RAW_BYTE_LEN),
1655 );
1656 start..end
1657 }
1658}
1659
1660#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1662#[repr(C)]
1663#[repr(packed)]
1664pub struct ConstantMapGroup {
1665 pub start_char_code: BigEndian<u32>,
1667 pub end_char_code: BigEndian<u32>,
1669 pub glyph_id: BigEndian<u32>,
1672}
1673
1674impl ConstantMapGroup {
1675 pub fn start_char_code(&self) -> u32 {
1677 self.start_char_code.get()
1678 }
1679
1680 pub fn end_char_code(&self) -> u32 {
1682 self.end_char_code.get()
1683 }
1684
1685 pub fn glyph_id(&self) -> u32 {
1688 self.glyph_id.get()
1689 }
1690}
1691
1692impl FixedSize for ConstantMapGroup {
1693 const RAW_BYTE_LEN: usize = u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN;
1694}
1695
1696impl Format<u16> for Cmap14<'_> {
1697 const FORMAT: u16 = 14;
1698}
1699
1700impl<'a> MinByteRange<'a> for Cmap14<'a> {
1701 fn min_byte_range(&self) -> Range<usize> {
1702 0..self.var_selector_byte_range().end
1703 }
1704 fn min_table_bytes(&self) -> &'a [u8] {
1705 let range = self.min_byte_range();
1706 self.offset_data().as_bytes().get(range).unwrap_or_default()
1707 }
1708}
1709
1710impl ReadArgs for Cmap14<'_> {
1711 type Args = ();
1712}
1713
1714impl<'a> FontRead<'a> for Cmap14<'a> {
1715 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1716 #[allow(clippy::absurd_extreme_comparisons)]
1717 if data.len() < Self::MIN_SIZE {
1718 return Err(ReadError::OutOfBounds);
1719 }
1720 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1721 return Err(ReadError::OutOfBounds);
1722 };
1723 Ok(Self { data })
1724 }
1725}
1726
1727#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1729#[repr(C, packed)]
1730#[doc(hidden)]
1731pub struct Cmap14FixedHeader {
1732 pub format: BigEndian<u16>,
1733 pub length: BigEndian<u32>,
1734 pub num_var_selector_records: BigEndian<u32>,
1735}
1736
1737#[allow(clippy::absurd_extreme_comparisons)]
1738const _: () = assert!(std::mem::size_of::<Cmap14FixedHeader>() <= Cmap14::MIN_SIZE);
1739
1740#[derive(Clone)]
1742pub struct Cmap14<'a> {
1743 data: TableDataRef<'a, Cmap14FixedHeader>,
1744}
1745
1746#[allow(clippy::needless_lifetimes)]
1747impl<'a> Cmap14<'a> {
1748 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
1749 basic_table_impls!(impl_the_methods);
1750
1751 pub fn format(&self) -> u16 {
1753 self.data.header().format.get()
1754 }
1755
1756 pub fn length(&self) -> u32 {
1758 self.data.header().length.get()
1759 }
1760
1761 pub fn num_var_selector_records(&self) -> u32 {
1763 self.data.header().num_var_selector_records.get()
1764 }
1765
1766 pub fn var_selector(&self) -> &'a [VariationSelector] {
1768 let range = self.var_selector_byte_range();
1769 self.offset_data()
1770 .read_array(range)
1771 .ok()
1772 .unwrap_or_default()
1773 }
1774
1775 pub fn format_byte_range(&self) -> Range<usize> {
1776 let start = 0usize;
1777 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1778 start..end
1779 }
1780
1781 pub fn length_byte_range(&self) -> Range<usize> {
1782 let start = self.format_byte_range().end;
1783 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1784 start..end
1785 }
1786
1787 pub fn num_var_selector_records_byte_range(&self) -> Range<usize> {
1788 let start = self.length_byte_range().end;
1789 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1790 start..end
1791 }
1792
1793 pub fn var_selector_byte_range(&self) -> Range<usize> {
1794 let num_var_selector_records = self.num_var_selector_records();
1795 let start = self.num_var_selector_records_byte_range().end;
1796 let end = start.saturating_add(
1797 (transforms::to_usize(num_var_selector_records))
1798 .saturating_mul(VariationSelector::RAW_BYTE_LEN),
1799 );
1800 start..end
1801 }
1802}
1803
1804impl Format<u16> for Cmap15<'_> {
1805 const FORMAT: u16 = 15;
1806}
1807
1808impl<'a> MinByteRange<'a> for Cmap15<'a> {
1809 fn min_byte_range(&self) -> Range<usize> {
1810 0..self.var_selector_byte_range().end
1811 }
1812 fn min_table_bytes(&self) -> &'a [u8] {
1813 let range = self.min_byte_range();
1814 self.offset_data().as_bytes().get(range).unwrap_or_default()
1815 }
1816}
1817
1818impl ReadArgs for Cmap15<'_> {
1819 type Args = ();
1820}
1821
1822impl<'a> FontRead<'a> for Cmap15<'a> {
1823 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1824 #[allow(clippy::absurd_extreme_comparisons)]
1825 if data.len() < Self::MIN_SIZE {
1826 return Err(ReadError::OutOfBounds);
1827 }
1828 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1829 return Err(ReadError::OutOfBounds);
1830 };
1831 Ok(Self { data })
1832 }
1833}
1834
1835#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1837#[repr(C, packed)]
1838#[doc(hidden)]
1839pub struct Cmap15FixedHeader {
1840 pub format: BigEndian<u16>,
1841 pub length: BigEndian<u32>,
1842 pub num_var_selector_records: BigEndian<u32>,
1843}
1844
1845#[allow(clippy::absurd_extreme_comparisons)]
1846const _: () = assert!(std::mem::size_of::<Cmap15FixedHeader>() <= Cmap15::MIN_SIZE);
1847
1848#[derive(Clone)]
1850pub struct Cmap15<'a> {
1851 data: TableDataRef<'a, Cmap15FixedHeader>,
1852}
1853
1854#[allow(clippy::needless_lifetimes)]
1855impl<'a> Cmap15<'a> {
1856 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
1857 basic_table_impls!(impl_the_methods);
1858
1859 pub fn format(&self) -> u16 {
1861 self.data.header().format.get()
1862 }
1863
1864 pub fn length(&self) -> u32 {
1866 self.data.header().length.get()
1867 }
1868
1869 pub fn num_var_selector_records(&self) -> u32 {
1871 self.data.header().num_var_selector_records.get()
1872 }
1873
1874 pub fn var_selector(&self) -> &'a [VariationSelector15] {
1875 let range = self.var_selector_byte_range();
1876 self.offset_data()
1877 .read_array(range)
1878 .ok()
1879 .unwrap_or_default()
1880 }
1881
1882 pub fn format_byte_range(&self) -> Range<usize> {
1883 let start = 0usize;
1884 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1885 start..end
1886 }
1887
1888 pub fn length_byte_range(&self) -> Range<usize> {
1889 let start = self.format_byte_range().end;
1890 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1891 start..end
1892 }
1893
1894 pub fn num_var_selector_records_byte_range(&self) -> Range<usize> {
1895 let start = self.length_byte_range().end;
1896 let end = start.saturating_add(u32::RAW_BYTE_LEN);
1897 start..end
1898 }
1899
1900 pub fn var_selector_byte_range(&self) -> Range<usize> {
1901 let num_var_selector_records = self.num_var_selector_records();
1902 let start = self.num_var_selector_records_byte_range().end;
1903 let end = start.saturating_add(
1904 (transforms::to_usize(num_var_selector_records))
1905 .saturating_mul(VariationSelector15::RAW_BYTE_LEN),
1906 );
1907 start..end
1908 }
1909}
1910
1911#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
1913#[repr(C)]
1914#[repr(packed)]
1915pub struct VariationSelector15 {
1916 pub var_selector: BigEndian<Uint24>,
1917 pub default_uvs_offset: BigEndian<Nullable<Offset32>>,
1918 pub non_default_uvs_offset: BigEndian<Nullable<Offset32>>,
1919}
1920
1921impl VariationSelector15 {
1922 pub fn var_selector(&self) -> Uint24 {
1923 self.var_selector.get()
1924 }
1925
1926 pub fn default_uvs_offset(&self) -> Nullable<Offset32> {
1927 self.default_uvs_offset.get()
1928 }
1929
1930 pub fn default_uvs<'a>(&self, data: FontData<'a>) -> Option<Result<DefaultUvs<'a>, ReadError>> {
1934 self.default_uvs_offset().resolve(data)
1935 }
1936
1937 pub fn non_default_uvs_offset(&self) -> Nullable<Offset32> {
1938 self.non_default_uvs_offset.get()
1939 }
1940
1941 pub fn non_default_uvs<'a>(
1945 &self,
1946 data: FontData<'a>,
1947 ) -> Option<Result<NonDefaultUvs24<'a>, ReadError>> {
1948 self.non_default_uvs_offset().resolve(data)
1949 }
1950}
1951
1952impl FixedSize for VariationSelector15 {
1953 const RAW_BYTE_LEN: usize =
1954 Uint24::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
1955}
1956
1957#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
1959#[repr(C)]
1960#[repr(packed)]
1961pub struct VariationSelector {
1962 pub var_selector: BigEndian<Uint24>,
1964 pub default_uvs_offset: BigEndian<Nullable<Offset32>>,
1967 pub non_default_uvs_offset: BigEndian<Nullable<Offset32>>,
1970}
1971
1972impl VariationSelector {
1973 pub fn var_selector(&self) -> Uint24 {
1975 self.var_selector.get()
1976 }
1977
1978 pub fn default_uvs_offset(&self) -> Nullable<Offset32> {
1981 self.default_uvs_offset.get()
1982 }
1983
1984 pub fn default_uvs<'a>(&self, data: FontData<'a>) -> Option<Result<DefaultUvs<'a>, ReadError>> {
1990 self.default_uvs_offset().resolve(data)
1991 }
1992
1993 pub fn non_default_uvs_offset(&self) -> Nullable<Offset32> {
1996 self.non_default_uvs_offset.get()
1997 }
1998
1999 pub fn non_default_uvs<'a>(
2005 &self,
2006 data: FontData<'a>,
2007 ) -> Option<Result<NonDefaultUvs<'a>, ReadError>> {
2008 self.non_default_uvs_offset().resolve(data)
2009 }
2010}
2011
2012impl FixedSize for VariationSelector {
2013 const RAW_BYTE_LEN: usize =
2014 Uint24::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
2015}
2016
2017impl<'a> MinByteRange<'a> for DefaultUvs<'a> {
2018 fn min_byte_range(&self) -> Range<usize> {
2019 0..self.ranges_byte_range().end
2020 }
2021 fn min_table_bytes(&self) -> &'a [u8] {
2022 let range = self.min_byte_range();
2023 self.offset_data().as_bytes().get(range).unwrap_or_default()
2024 }
2025}
2026
2027impl ReadArgs for DefaultUvs<'_> {
2028 type Args = ();
2029}
2030
2031impl<'a> FontRead<'a> for DefaultUvs<'a> {
2032 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2033 #[allow(clippy::absurd_extreme_comparisons)]
2034 if data.len() < Self::MIN_SIZE {
2035 return Err(ReadError::OutOfBounds);
2036 }
2037 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2038 return Err(ReadError::OutOfBounds);
2039 };
2040 Ok(Self { data })
2041 }
2042}
2043
2044#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2046#[repr(C, packed)]
2047#[doc(hidden)]
2048pub struct DefaultUvsFixedHeader {
2049 pub num_unicode_value_ranges: BigEndian<u32>,
2050}
2051
2052#[allow(clippy::absurd_extreme_comparisons)]
2053const _: () = assert!(std::mem::size_of::<DefaultUvsFixedHeader>() <= DefaultUvs::MIN_SIZE);
2054
2055#[derive(Clone)]
2057pub struct DefaultUvs<'a> {
2058 data: TableDataRef<'a, DefaultUvsFixedHeader>,
2059}
2060
2061#[allow(clippy::needless_lifetimes)]
2062impl<'a> DefaultUvs<'a> {
2063 pub const MIN_SIZE: usize = u32::RAW_BYTE_LEN;
2064 basic_table_impls!(impl_the_methods);
2065
2066 pub fn num_unicode_value_ranges(&self) -> u32 {
2068 self.data.header().num_unicode_value_ranges.get()
2069 }
2070
2071 pub fn ranges(&self) -> &'a [UnicodeRange] {
2073 let range = self.ranges_byte_range();
2074 self.offset_data()
2075 .read_array(range)
2076 .ok()
2077 .unwrap_or_default()
2078 }
2079
2080 pub fn num_unicode_value_ranges_byte_range(&self) -> Range<usize> {
2081 let start = 0usize;
2082 let end = start.saturating_add(u32::RAW_BYTE_LEN);
2083 start..end
2084 }
2085
2086 pub fn ranges_byte_range(&self) -> Range<usize> {
2087 let num_unicode_value_ranges = self.num_unicode_value_ranges();
2088 let start = self.num_unicode_value_ranges_byte_range().end;
2089 let end = start.saturating_add(
2090 (transforms::to_usize(num_unicode_value_ranges))
2091 .saturating_mul(UnicodeRange::RAW_BYTE_LEN),
2092 );
2093 start..end
2094 }
2095}
2096
2097const _: () = assert!(FontData::default_data_long_enough(DefaultUvs::MIN_SIZE));
2098
2099impl Default for DefaultUvs<'_> {
2100 fn default() -> Self {
2101 Self {
2102 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2103 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2104 }
2105 }
2106}
2107
2108impl<'a> MinByteRange<'a> for NonDefaultUvs<'a> {
2109 fn min_byte_range(&self) -> Range<usize> {
2110 0..self.uvs_mapping_byte_range().end
2111 }
2112 fn min_table_bytes(&self) -> &'a [u8] {
2113 let range = self.min_byte_range();
2114 self.offset_data().as_bytes().get(range).unwrap_or_default()
2115 }
2116}
2117
2118impl ReadArgs for NonDefaultUvs<'_> {
2119 type Args = ();
2120}
2121
2122impl<'a> FontRead<'a> for NonDefaultUvs<'a> {
2123 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2124 #[allow(clippy::absurd_extreme_comparisons)]
2125 if data.len() < Self::MIN_SIZE {
2126 return Err(ReadError::OutOfBounds);
2127 }
2128 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2129 return Err(ReadError::OutOfBounds);
2130 };
2131 Ok(Self { data })
2132 }
2133}
2134
2135#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2137#[repr(C, packed)]
2138#[doc(hidden)]
2139pub struct NonDefaultUvsFixedHeader {
2140 pub num_uvs_mappings: BigEndian<u32>,
2141}
2142
2143#[allow(clippy::absurd_extreme_comparisons)]
2144const _: () = assert!(std::mem::size_of::<NonDefaultUvsFixedHeader>() <= NonDefaultUvs::MIN_SIZE);
2145
2146#[derive(Clone)]
2148pub struct NonDefaultUvs<'a> {
2149 data: TableDataRef<'a, NonDefaultUvsFixedHeader>,
2150}
2151
2152#[allow(clippy::needless_lifetimes)]
2153impl<'a> NonDefaultUvs<'a> {
2154 pub const MIN_SIZE: usize = u32::RAW_BYTE_LEN;
2155 basic_table_impls!(impl_the_methods);
2156
2157 pub fn num_uvs_mappings(&self) -> u32 {
2158 self.data.header().num_uvs_mappings.get()
2159 }
2160
2161 pub fn uvs_mapping(&self) -> &'a [UvsMapping] {
2162 let range = self.uvs_mapping_byte_range();
2163 self.offset_data()
2164 .read_array(range)
2165 .ok()
2166 .unwrap_or_default()
2167 }
2168
2169 pub fn num_uvs_mappings_byte_range(&self) -> Range<usize> {
2170 let start = 0usize;
2171 let end = start.saturating_add(u32::RAW_BYTE_LEN);
2172 start..end
2173 }
2174
2175 pub fn uvs_mapping_byte_range(&self) -> Range<usize> {
2176 let num_uvs_mappings = self.num_uvs_mappings();
2177 let start = self.num_uvs_mappings_byte_range().end;
2178 let end = start.saturating_add(
2179 (transforms::to_usize(num_uvs_mappings)).saturating_mul(UvsMapping::RAW_BYTE_LEN),
2180 );
2181 start..end
2182 }
2183}
2184
2185const _: () = assert!(FontData::default_data_long_enough(NonDefaultUvs::MIN_SIZE));
2186
2187impl Default for NonDefaultUvs<'_> {
2188 fn default() -> Self {
2189 Self {
2190 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2191 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2192 }
2193 }
2194}
2195
2196impl<'a> MinByteRange<'a> for NonDefaultUvs24<'a> {
2197 fn min_byte_range(&self) -> Range<usize> {
2198 0..self.uvs_mapping_byte_range().end
2199 }
2200 fn min_table_bytes(&self) -> &'a [u8] {
2201 let range = self.min_byte_range();
2202 self.offset_data().as_bytes().get(range).unwrap_or_default()
2203 }
2204}
2205
2206impl ReadArgs for NonDefaultUvs24<'_> {
2207 type Args = ();
2208}
2209
2210impl<'a> FontRead<'a> for NonDefaultUvs24<'a> {
2211 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2212 #[allow(clippy::absurd_extreme_comparisons)]
2213 if data.len() < Self::MIN_SIZE {
2214 return Err(ReadError::OutOfBounds);
2215 }
2216 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2217 return Err(ReadError::OutOfBounds);
2218 };
2219 Ok(Self { data })
2220 }
2221}
2222
2223#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2225#[repr(C, packed)]
2226#[doc(hidden)]
2227pub struct NonDefaultUvs24FixedHeader {
2228 pub num_uvs_mappings: BigEndian<u32>,
2229}
2230
2231#[allow(clippy::absurd_extreme_comparisons)]
2232const _: () =
2233 assert!(std::mem::size_of::<NonDefaultUvs24FixedHeader>() <= NonDefaultUvs24::MIN_SIZE);
2234
2235#[derive(Clone)]
2237pub struct NonDefaultUvs24<'a> {
2238 data: TableDataRef<'a, NonDefaultUvs24FixedHeader>,
2239}
2240
2241#[allow(clippy::needless_lifetimes)]
2242impl<'a> NonDefaultUvs24<'a> {
2243 pub const MIN_SIZE: usize = u32::RAW_BYTE_LEN;
2244 basic_table_impls!(impl_the_methods);
2245
2246 pub fn num_uvs_mappings(&self) -> u32 {
2247 self.data.header().num_uvs_mappings.get()
2248 }
2249
2250 pub fn uvs_mapping(&self) -> &'a [UvsMapping24] {
2251 let range = self.uvs_mapping_byte_range();
2252 self.offset_data()
2253 .read_array(range)
2254 .ok()
2255 .unwrap_or_default()
2256 }
2257
2258 pub fn num_uvs_mappings_byte_range(&self) -> Range<usize> {
2259 let start = 0usize;
2260 let end = start.saturating_add(u32::RAW_BYTE_LEN);
2261 start..end
2262 }
2263
2264 pub fn uvs_mapping_byte_range(&self) -> Range<usize> {
2265 let num_uvs_mappings = self.num_uvs_mappings();
2266 let start = self.num_uvs_mappings_byte_range().end;
2267 let end = start.saturating_add(
2268 (transforms::to_usize(num_uvs_mappings)).saturating_mul(UvsMapping24::RAW_BYTE_LEN),
2269 );
2270 start..end
2271 }
2272}
2273
2274const _: () = assert!(FontData::default_data_long_enough(
2275 NonDefaultUvs24::MIN_SIZE
2276));
2277
2278impl Default for NonDefaultUvs24<'_> {
2279 fn default() -> Self {
2280 Self {
2281 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2282 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2283 }
2284 }
2285}
2286
2287#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
2289#[repr(C)]
2290#[repr(packed)]
2291pub struct UvsMapping24 {
2292 pub unicode_value: BigEndian<Uint24>,
2293 pub glyph_id: BigEndian<Uint24>,
2294}
2295
2296impl UvsMapping24 {
2297 pub fn unicode_value(&self) -> Uint24 {
2298 self.unicode_value.get()
2299 }
2300
2301 pub fn glyph_id(&self) -> Uint24 {
2302 self.glyph_id.get()
2303 }
2304}
2305
2306impl FixedSize for UvsMapping24 {
2307 const RAW_BYTE_LEN: usize = Uint24::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN;
2308}
2309
2310#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
2312#[repr(C)]
2313#[repr(packed)]
2314pub struct UvsMapping {
2315 pub unicode_value: BigEndian<Uint24>,
2317 pub glyph_id: BigEndian<u16>,
2319}
2320
2321impl UvsMapping {
2322 pub fn unicode_value(&self) -> Uint24 {
2324 self.unicode_value.get()
2325 }
2326
2327 pub fn glyph_id(&self) -> u16 {
2329 self.glyph_id.get()
2330 }
2331}
2332
2333impl FixedSize for UvsMapping {
2334 const RAW_BYTE_LEN: usize = Uint24::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
2335}
2336
2337#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
2339#[repr(C)]
2340#[repr(packed)]
2341pub struct UnicodeRange {
2342 pub start_unicode_value: BigEndian<Uint24>,
2344 pub additional_count: u8,
2346}
2347
2348impl UnicodeRange {
2349 pub fn start_unicode_value(&self) -> Uint24 {
2351 self.start_unicode_value.get()
2352 }
2353
2354 pub fn additional_count(&self) -> u8 {
2356 self.additional_count
2357 }
2358}
2359
2360impl FixedSize for UnicodeRange {
2361 const RAW_BYTE_LEN: usize = Uint24::RAW_BYTE_LEN + u8::RAW_BYTE_LEN;
2362}