Skip to main content

read_fonts/generated/
generated_head.rs

1// THIS FILE IS AUTOGENERATED.
2// Any changes to this file will be overwritten.
3// For more information about how codegen works, see font-codegen/README.md
4
5#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8/// The `macStyle` field for the head table.
9#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11#[repr(transparent)]
12pub struct MacStyle {
13    bits: u16,
14}
15
16impl MacStyle {
17    /// Bit 0: Bold (if set to 1)
18    pub const BOLD: Self = Self { bits: 0x0001 };
19
20    /// Bit 1: Italic (if set to 1)
21    pub const ITALIC: Self = Self { bits: 0x0002 };
22
23    /// Bit 2: Underline (if set to 1)
24    pub const UNDERLINE: Self = Self { bits: 0x0004 };
25
26    /// Bit 3: Outline (if set to 1)
27    pub const OUTLINE: Self = Self { bits: 0x0008 };
28
29    /// Bit 4: Shadow (if set to 1)
30    pub const SHADOW: Self = Self { bits: 0x0010 };
31
32    /// Bit 5: Condensed (if set to 1)
33    pub const CONDENSED: Self = Self { bits: 0x0020 };
34
35    /// Bit 6: Extended (if set to 1)
36    pub const EXTENDED: Self = Self { bits: 0x0040 };
37}
38
39impl MacStyle {
40    ///  Returns an empty set of flags.
41    #[inline]
42    pub const fn empty() -> Self {
43        Self { bits: 0 }
44    }
45
46    /// Returns the set containing all flags.
47    #[inline]
48    pub const fn all() -> Self {
49        Self {
50            bits: Self::BOLD.bits
51                | Self::ITALIC.bits
52                | Self::UNDERLINE.bits
53                | Self::OUTLINE.bits
54                | Self::SHADOW.bits
55                | Self::CONDENSED.bits
56                | Self::EXTENDED.bits,
57        }
58    }
59
60    /// Returns the raw value of the flags currently stored.
61    #[inline]
62    pub const fn bits(&self) -> u16 {
63        self.bits
64    }
65
66    /// Convert from underlying bit representation, unless that
67    /// representation contains bits that do not correspond to a flag.
68    #[inline]
69    pub const fn from_bits(bits: u16) -> Option<Self> {
70        if (bits & !Self::all().bits()) == 0 {
71            Some(Self { bits })
72        } else {
73            None
74        }
75    }
76
77    /// Convert from underlying bit representation, dropping any bits
78    /// that do not correspond to flags.
79    #[inline]
80    pub const fn from_bits_truncate(bits: u16) -> Self {
81        Self {
82            bits: bits & Self::all().bits,
83        }
84    }
85
86    /// Returns `true` if no flags are currently stored.
87    #[inline]
88    pub const fn is_empty(&self) -> bool {
89        self.bits() == Self::empty().bits()
90    }
91
92    /// Returns `true` if there are flags common to both `self` and `other`.
93    #[inline]
94    pub const fn intersects(&self, other: Self) -> bool {
95        !(Self {
96            bits: self.bits & other.bits,
97        })
98        .is_empty()
99    }
100
101    /// Returns `true` if all of the flags in `other` are contained within `self`.
102    #[inline]
103    pub const fn contains(&self, other: Self) -> bool {
104        (self.bits & other.bits) == other.bits
105    }
106
107    /// Inserts the specified flags in-place.
108    #[inline]
109    pub fn insert(&mut self, other: Self) {
110        self.bits |= other.bits;
111    }
112
113    /// Removes the specified flags in-place.
114    #[inline]
115    pub fn remove(&mut self, other: Self) {
116        self.bits &= !other.bits;
117    }
118
119    /// Toggles the specified flags in-place.
120    #[inline]
121    pub fn toggle(&mut self, other: Self) {
122        self.bits ^= other.bits;
123    }
124
125    /// Returns the intersection between the flags in `self` and
126    /// `other`.
127    ///
128    /// Specifically, the returned set contains only the flags which are
129    /// present in *both* `self` *and* `other`.
130    ///
131    /// This is equivalent to using the `&` operator (e.g.
132    /// [`ops::BitAnd`]), as in `flags & other`.
133    ///
134    /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
135    #[inline]
136    #[must_use]
137    pub const fn intersection(self, other: Self) -> Self {
138        Self {
139            bits: self.bits & other.bits,
140        }
141    }
142
143    /// Returns the union of between the flags in `self` and `other`.
144    ///
145    /// Specifically, the returned set contains all flags which are
146    /// present in *either* `self` *or* `other`, including any which are
147    /// present in both.
148    ///
149    /// This is equivalent to using the `|` operator (e.g.
150    /// [`ops::BitOr`]), as in `flags | other`.
151    ///
152    /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
153    #[inline]
154    #[must_use]
155    pub const fn union(self, other: Self) -> Self {
156        Self {
157            bits: self.bits | other.bits,
158        }
159    }
160
161    /// Returns the difference between the flags in `self` and `other`.
162    ///
163    /// Specifically, the returned set contains all flags present in
164    /// `self`, except for the ones present in `other`.
165    ///
166    /// It is also conceptually equivalent to the "bit-clear" operation:
167    /// `flags & !other` (and this syntax is also supported).
168    ///
169    /// This is equivalent to using the `-` operator (e.g.
170    /// [`ops::Sub`]), as in `flags - other`.
171    ///
172    /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
173    #[inline]
174    #[must_use]
175    pub const fn difference(self, other: Self) -> Self {
176        Self {
177            bits: self.bits & !other.bits,
178        }
179    }
180}
181
182impl std::ops::BitOr for MacStyle {
183    type Output = Self;
184
185    /// Returns the union of the two sets of flags.
186    #[inline]
187    fn bitor(self, other: MacStyle) -> Self {
188        Self {
189            bits: self.bits | other.bits,
190        }
191    }
192}
193
194impl std::ops::BitOrAssign for MacStyle {
195    /// Adds the set of flags.
196    #[inline]
197    fn bitor_assign(&mut self, other: Self) {
198        self.bits |= other.bits;
199    }
200}
201
202impl std::ops::BitXor for MacStyle {
203    type Output = Self;
204
205    /// Returns the left flags, but with all the right flags toggled.
206    #[inline]
207    fn bitxor(self, other: Self) -> Self {
208        Self {
209            bits: self.bits ^ other.bits,
210        }
211    }
212}
213
214impl std::ops::BitXorAssign for MacStyle {
215    /// Toggles the set of flags.
216    #[inline]
217    fn bitxor_assign(&mut self, other: Self) {
218        self.bits ^= other.bits;
219    }
220}
221
222impl std::ops::BitAnd for MacStyle {
223    type Output = Self;
224
225    /// Returns the intersection between the two sets of flags.
226    #[inline]
227    fn bitand(self, other: Self) -> Self {
228        Self {
229            bits: self.bits & other.bits,
230        }
231    }
232}
233
234impl std::ops::BitAndAssign for MacStyle {
235    /// Disables all flags disabled in the set.
236    #[inline]
237    fn bitand_assign(&mut self, other: Self) {
238        self.bits &= other.bits;
239    }
240}
241
242impl std::ops::Sub for MacStyle {
243    type Output = Self;
244
245    /// Returns the set difference of the two sets of flags.
246    #[inline]
247    fn sub(self, other: Self) -> Self {
248        Self {
249            bits: self.bits & !other.bits,
250        }
251    }
252}
253
254impl std::ops::SubAssign for MacStyle {
255    /// Disables all flags enabled in the set.
256    #[inline]
257    fn sub_assign(&mut self, other: Self) {
258        self.bits &= !other.bits;
259    }
260}
261
262impl std::ops::Not for MacStyle {
263    type Output = Self;
264
265    /// Returns the complement of this set of flags.
266    #[inline]
267    fn not(self) -> Self {
268        Self { bits: !self.bits } & Self::all()
269    }
270}
271
272impl std::fmt::Debug for MacStyle {
273    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
274        let members: &[(&str, Self)] = &[
275            ("BOLD", Self::BOLD),
276            ("ITALIC", Self::ITALIC),
277            ("UNDERLINE", Self::UNDERLINE),
278            ("OUTLINE", Self::OUTLINE),
279            ("SHADOW", Self::SHADOW),
280            ("CONDENSED", Self::CONDENSED),
281            ("EXTENDED", Self::EXTENDED),
282        ];
283        let mut first = true;
284        for (name, value) in members {
285            if self.contains(*value) {
286                if !first {
287                    f.write_str(" | ")?;
288                }
289                first = false;
290                f.write_str(name)?;
291            }
292        }
293        if first {
294            f.write_str("(empty)")?;
295        }
296        Ok(())
297    }
298}
299
300impl std::fmt::Binary for MacStyle {
301    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
302        std::fmt::Binary::fmt(&self.bits, f)
303    }
304}
305
306impl std::fmt::Octal for MacStyle {
307    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
308        std::fmt::Octal::fmt(&self.bits, f)
309    }
310}
311
312impl std::fmt::LowerHex for MacStyle {
313    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
314        std::fmt::LowerHex::fmt(&self.bits, f)
315    }
316}
317
318impl std::fmt::UpperHex for MacStyle {
319    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
320        std::fmt::UpperHex::fmt(&self.bits, f)
321    }
322}
323
324impl font_types::Scalar for MacStyle {
325    type Raw = <u16 as font_types::Scalar>::Raw;
326    fn to_raw(self) -> Self::Raw {
327        self.bits().to_raw()
328    }
329    fn from_raw(raw: Self::Raw) -> Self {
330        let t = <u16>::from_raw(raw);
331        Self::from_bits_truncate(t)
332    }
333}
334
335/// The `flags` field for the head table.
336#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
337#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
338#[repr(transparent)]
339pub struct Flags {
340    bits: u16,
341}
342
343impl Flags {
344    /// Bit 0: Baseline for font at y=0.
345    pub const BASELINE_AT_Y_0: Self = Self { bits: 0x0001 };
346
347    /// Bit 1: Left sidebearing point at x=0 (relevant only for TrueType rasterizers).
348    pub const LSB_AT_X_0: Self = Self { bits: 0x0002 };
349
350    /// Bit 2: Instructions may depend on point size.
351    pub const INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE: Self = Self { bits: 0x0004 };
352
353    /// Bit 3: Force ppem to integer values for all internal scaler math; may use fractional ppem sizes if this bit is clear. It is strongly recommended that this be set in hinted fonts.
354    pub const FORCE_INTEGER_PPEM: Self = Self { bits: 0x0008 };
355
356    /// Bit 4: Instructions may alter advance width (the advance widths might not scale linearly).
357    pub const INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH: Self = Self { bits: 0x0010 };
358
359    /// Bit 11: Font data is “lossless” as a result of having been subjected to optimizing transformation and/or compression (such as compression mechanisms defined by ISO/IEC 14496-18, MicroType® Express, WOFF 2.0, or similar) where the original font functionality and features are retained but the binary compatibility between input and output font files is not guaranteed. As a result of the applied transform, the DSIG table may also be invalidated.
360    pub const LOSSLESS_TRANSFORMED_FONT_DATA: Self = Self { bits: 0x0800 };
361
362    /// Bit 12: Font converted (produce compatible metrics).
363    pub const CONVERTED_FONT: Self = Self { bits: 0x1000 };
364
365    /// Bit 13: Font optimized for ClearType. Note, fonts that rely on embedded bitmaps (EBDT) for rendering should not be considered optimized for ClearType, and therefore should keep this bit cleared.
366    pub const OPTIMIZED_FOR_CLEARTYPE: Self = Self { bits: 0x2000 };
367
368    /// Bit 14: Last Resort font. If set, indicates that the glyphs encoded in the 'cmap' subtables are simply generic symbolic representations of code point ranges and do not truly represent support for those code points. If unset, indicates that the glyphs encoded in the 'cmap' subtables represent proper support for those code points.
369    pub const LAST_RESORT_FONT: Self = Self { bits: 0x4000 };
370}
371
372impl Flags {
373    ///  Returns an empty set of flags.
374    #[inline]
375    pub const fn empty() -> Self {
376        Self { bits: 0 }
377    }
378
379    /// Returns the set containing all flags.
380    #[inline]
381    pub const fn all() -> Self {
382        Self {
383            bits: Self::BASELINE_AT_Y_0.bits
384                | Self::LSB_AT_X_0.bits
385                | Self::INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE.bits
386                | Self::FORCE_INTEGER_PPEM.bits
387                | Self::INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH.bits
388                | Self::LOSSLESS_TRANSFORMED_FONT_DATA.bits
389                | Self::CONVERTED_FONT.bits
390                | Self::OPTIMIZED_FOR_CLEARTYPE.bits
391                | Self::LAST_RESORT_FONT.bits,
392        }
393    }
394
395    /// Returns the raw value of the flags currently stored.
396    #[inline]
397    pub const fn bits(&self) -> u16 {
398        self.bits
399    }
400
401    /// Convert from underlying bit representation, unless that
402    /// representation contains bits that do not correspond to a flag.
403    #[inline]
404    pub const fn from_bits(bits: u16) -> Option<Self> {
405        if (bits & !Self::all().bits()) == 0 {
406            Some(Self { bits })
407        } else {
408            None
409        }
410    }
411
412    /// Convert from underlying bit representation, dropping any bits
413    /// that do not correspond to flags.
414    #[inline]
415    pub const fn from_bits_truncate(bits: u16) -> Self {
416        Self {
417            bits: bits & Self::all().bits,
418        }
419    }
420
421    /// Returns `true` if no flags are currently stored.
422    #[inline]
423    pub const fn is_empty(&self) -> bool {
424        self.bits() == Self::empty().bits()
425    }
426
427    /// Returns `true` if there are flags common to both `self` and `other`.
428    #[inline]
429    pub const fn intersects(&self, other: Self) -> bool {
430        !(Self {
431            bits: self.bits & other.bits,
432        })
433        .is_empty()
434    }
435
436    /// Returns `true` if all of the flags in `other` are contained within `self`.
437    #[inline]
438    pub const fn contains(&self, other: Self) -> bool {
439        (self.bits & other.bits) == other.bits
440    }
441
442    /// Inserts the specified flags in-place.
443    #[inline]
444    pub fn insert(&mut self, other: Self) {
445        self.bits |= other.bits;
446    }
447
448    /// Removes the specified flags in-place.
449    #[inline]
450    pub fn remove(&mut self, other: Self) {
451        self.bits &= !other.bits;
452    }
453
454    /// Toggles the specified flags in-place.
455    #[inline]
456    pub fn toggle(&mut self, other: Self) {
457        self.bits ^= other.bits;
458    }
459
460    /// Returns the intersection between the flags in `self` and
461    /// `other`.
462    ///
463    /// Specifically, the returned set contains only the flags which are
464    /// present in *both* `self` *and* `other`.
465    ///
466    /// This is equivalent to using the `&` operator (e.g.
467    /// [`ops::BitAnd`]), as in `flags & other`.
468    ///
469    /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
470    #[inline]
471    #[must_use]
472    pub const fn intersection(self, other: Self) -> Self {
473        Self {
474            bits: self.bits & other.bits,
475        }
476    }
477
478    /// Returns the union of between the flags in `self` and `other`.
479    ///
480    /// Specifically, the returned set contains all flags which are
481    /// present in *either* `self` *or* `other`, including any which are
482    /// present in both.
483    ///
484    /// This is equivalent to using the `|` operator (e.g.
485    /// [`ops::BitOr`]), as in `flags | other`.
486    ///
487    /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
488    #[inline]
489    #[must_use]
490    pub const fn union(self, other: Self) -> Self {
491        Self {
492            bits: self.bits | other.bits,
493        }
494    }
495
496    /// Returns the difference between the flags in `self` and `other`.
497    ///
498    /// Specifically, the returned set contains all flags present in
499    /// `self`, except for the ones present in `other`.
500    ///
501    /// It is also conceptually equivalent to the "bit-clear" operation:
502    /// `flags & !other` (and this syntax is also supported).
503    ///
504    /// This is equivalent to using the `-` operator (e.g.
505    /// [`ops::Sub`]), as in `flags - other`.
506    ///
507    /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
508    #[inline]
509    #[must_use]
510    pub const fn difference(self, other: Self) -> Self {
511        Self {
512            bits: self.bits & !other.bits,
513        }
514    }
515}
516
517impl std::ops::BitOr for Flags {
518    type Output = Self;
519
520    /// Returns the union of the two sets of flags.
521    #[inline]
522    fn bitor(self, other: Flags) -> Self {
523        Self {
524            bits: self.bits | other.bits,
525        }
526    }
527}
528
529impl std::ops::BitOrAssign for Flags {
530    /// Adds the set of flags.
531    #[inline]
532    fn bitor_assign(&mut self, other: Self) {
533        self.bits |= other.bits;
534    }
535}
536
537impl std::ops::BitXor for Flags {
538    type Output = Self;
539
540    /// Returns the left flags, but with all the right flags toggled.
541    #[inline]
542    fn bitxor(self, other: Self) -> Self {
543        Self {
544            bits: self.bits ^ other.bits,
545        }
546    }
547}
548
549impl std::ops::BitXorAssign for Flags {
550    /// Toggles the set of flags.
551    #[inline]
552    fn bitxor_assign(&mut self, other: Self) {
553        self.bits ^= other.bits;
554    }
555}
556
557impl std::ops::BitAnd for Flags {
558    type Output = Self;
559
560    /// Returns the intersection between the two sets of flags.
561    #[inline]
562    fn bitand(self, other: Self) -> Self {
563        Self {
564            bits: self.bits & other.bits,
565        }
566    }
567}
568
569impl std::ops::BitAndAssign for Flags {
570    /// Disables all flags disabled in the set.
571    #[inline]
572    fn bitand_assign(&mut self, other: Self) {
573        self.bits &= other.bits;
574    }
575}
576
577impl std::ops::Sub for Flags {
578    type Output = Self;
579
580    /// Returns the set difference of the two sets of flags.
581    #[inline]
582    fn sub(self, other: Self) -> Self {
583        Self {
584            bits: self.bits & !other.bits,
585        }
586    }
587}
588
589impl std::ops::SubAssign for Flags {
590    /// Disables all flags enabled in the set.
591    #[inline]
592    fn sub_assign(&mut self, other: Self) {
593        self.bits &= !other.bits;
594    }
595}
596
597impl std::ops::Not for Flags {
598    type Output = Self;
599
600    /// Returns the complement of this set of flags.
601    #[inline]
602    fn not(self) -> Self {
603        Self { bits: !self.bits } & Self::all()
604    }
605}
606
607impl std::fmt::Debug for Flags {
608    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
609        let members: &[(&str, Self)] = &[
610            ("BASELINE_AT_Y_0", Self::BASELINE_AT_Y_0),
611            ("LSB_AT_X_0", Self::LSB_AT_X_0),
612            (
613                "INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE",
614                Self::INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE,
615            ),
616            ("FORCE_INTEGER_PPEM", Self::FORCE_INTEGER_PPEM),
617            (
618                "INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH",
619                Self::INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH,
620            ),
621            (
622                "LOSSLESS_TRANSFORMED_FONT_DATA",
623                Self::LOSSLESS_TRANSFORMED_FONT_DATA,
624            ),
625            ("CONVERTED_FONT", Self::CONVERTED_FONT),
626            ("OPTIMIZED_FOR_CLEARTYPE", Self::OPTIMIZED_FOR_CLEARTYPE),
627            ("LAST_RESORT_FONT", Self::LAST_RESORT_FONT),
628        ];
629        let mut first = true;
630        for (name, value) in members {
631            if self.contains(*value) {
632                if !first {
633                    f.write_str(" | ")?;
634                }
635                first = false;
636                f.write_str(name)?;
637            }
638        }
639        if first {
640            f.write_str("(empty)")?;
641        }
642        Ok(())
643    }
644}
645
646impl std::fmt::Binary for Flags {
647    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
648        std::fmt::Binary::fmt(&self.bits, f)
649    }
650}
651
652impl std::fmt::Octal for Flags {
653    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
654        std::fmt::Octal::fmt(&self.bits, f)
655    }
656}
657
658impl std::fmt::LowerHex for Flags {
659    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
660        std::fmt::LowerHex::fmt(&self.bits, f)
661    }
662}
663
664impl std::fmt::UpperHex for Flags {
665    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
666        std::fmt::UpperHex::fmt(&self.bits, f)
667    }
668}
669
670impl font_types::Scalar for Flags {
671    type Raw = <u16 as font_types::Scalar>::Raw;
672    fn to_raw(self) -> Self::Raw {
673        self.bits().to_raw()
674    }
675    fn from_raw(raw: Self::Raw) -> Self {
676        let t = <u16>::from_raw(raw);
677        Self::from_bits_truncate(t)
678    }
679}
680
681impl<'a> MinByteRange<'a> for Head<'a> {
682    fn min_byte_range(&self) -> Range<usize> {
683        0..self.glyph_data_format_byte_range().end
684    }
685    fn min_table_bytes(&self) -> &'a [u8] {
686        let range = self.min_byte_range();
687        self.data.as_bytes().get(range).unwrap_or_default()
688    }
689}
690
691impl TopLevelTable for Head<'_> {
692    /// `head`
693    const TAG: Tag = Tag::new(b"head");
694}
695
696impl ReadArgs for Head<'_> {
697    type Args = ();
698}
699
700impl<'a> FontRead<'a> for Head<'a> {
701    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
702        #[allow(clippy::absurd_extreme_comparisons)]
703        if data.len() < Self::MIN_SIZE {
704            return Err(ReadError::OutOfBounds);
705        }
706        Ok(Self { data })
707    }
708}
709
710/// The [head](https://docs.microsoft.com/en-us/typography/opentype/spec/head)
711/// (font header) table.
712#[derive(Clone)]
713pub struct Head<'a> {
714    data: FontData<'a>,
715}
716
717#[allow(clippy::needless_lifetimes)]
718impl<'a> Head<'a> {
719    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
720        + Fixed::RAW_BYTE_LEN
721        + u32::RAW_BYTE_LEN
722        + u32::RAW_BYTE_LEN
723        + Flags::RAW_BYTE_LEN
724        + u16::RAW_BYTE_LEN
725        + LongDateTime::RAW_BYTE_LEN
726        + LongDateTime::RAW_BYTE_LEN
727        + i16::RAW_BYTE_LEN
728        + i16::RAW_BYTE_LEN
729        + i16::RAW_BYTE_LEN
730        + i16::RAW_BYTE_LEN
731        + MacStyle::RAW_BYTE_LEN
732        + u16::RAW_BYTE_LEN
733        + i16::RAW_BYTE_LEN
734        + i16::RAW_BYTE_LEN
735        + i16::RAW_BYTE_LEN);
736    basic_table_impls!(impl_the_methods);
737
738    /// Version number of the font header table, set to (1, 0)
739    pub fn version(&self) -> MajorMinor {
740        let range = self.version_byte_range();
741        self.data.read_at(range.start).ok().unwrap()
742    }
743
744    /// Set by font manufacturer.
745    pub fn font_revision(&self) -> Fixed {
746        let range = self.font_revision_byte_range();
747        self.data.read_at(range.start).ok().unwrap()
748    }
749
750    /// To compute: set it to 0, sum the entire font as uint32, then
751    /// store 0xB1B0AFBA - sum. If the font is used as a component in a
752    /// font collection file, the value of this field will be
753    /// invalidated by changes to the file structure and font table
754    /// directory, and must be ignored.
755    pub fn checksum_adjustment(&self) -> u32 {
756        let range = self.checksum_adjustment_byte_range();
757        self.data.read_at(range.start).ok().unwrap()
758    }
759
760    /// Set to 0x5F0F3CF5.
761    pub fn magic_number(&self) -> u32 {
762        let range = self.magic_number_byte_range();
763        self.data.read_at(range.start).ok().unwrap()
764    }
765
766    /// See the flags enum.
767    pub fn flags(&self) -> Flags {
768        let range = self.flags_byte_range();
769        self.data.read_at(range.start).ok().unwrap()
770    }
771
772    /// Set to a value from 16 to 16384. Any value in this range is
773    /// valid. In fonts that have TrueType outlines, a power of 2 is
774    /// recommended as this allows performance optimizations in some
775    /// rasterizers.
776    pub fn units_per_em(&self) -> u16 {
777        let range = self.units_per_em_byte_range();
778        self.data.read_at(range.start).ok().unwrap()
779    }
780
781    /// Number of seconds since 12:00 midnight that started January 1st
782    /// 1904 in GMT/UTC time zone.
783    pub fn created(&self) -> LongDateTime {
784        let range = self.created_byte_range();
785        self.data.read_at(range.start).ok().unwrap()
786    }
787
788    /// Number of seconds since 12:00 midnight that started January 1st
789    /// 1904 in GMT/UTC time zone.
790    pub fn modified(&self) -> LongDateTime {
791        let range = self.modified_byte_range();
792        self.data.read_at(range.start).ok().unwrap()
793    }
794
795    /// Minimum x coordinate across all glyph bounding boxes.
796    pub fn x_min(&self) -> i16 {
797        let range = self.x_min_byte_range();
798        self.data.read_at(range.start).ok().unwrap()
799    }
800
801    /// Minimum y coordinate across all glyph bounding boxes.
802    pub fn y_min(&self) -> i16 {
803        let range = self.y_min_byte_range();
804        self.data.read_at(range.start).ok().unwrap()
805    }
806
807    /// Maximum x coordinate across all glyph bounding boxes.
808    pub fn x_max(&self) -> i16 {
809        let range = self.x_max_byte_range();
810        self.data.read_at(range.start).ok().unwrap()
811    }
812
813    /// Maximum y coordinate across all glyph bounding boxes.
814    pub fn y_max(&self) -> i16 {
815        let range = self.y_max_byte_range();
816        self.data.read_at(range.start).ok().unwrap()
817    }
818
819    /// Bits identifying the font's style; see [MacStyle]
820    pub fn mac_style(&self) -> MacStyle {
821        let range = self.mac_style_byte_range();
822        self.data.read_at(range.start).ok().unwrap()
823    }
824
825    /// Smallest readable size in pixels.
826    pub fn lowest_rec_ppem(&self) -> u16 {
827        let range = self.lowest_rec_ppem_byte_range();
828        self.data.read_at(range.start).ok().unwrap()
829    }
830
831    /// Deprecated (Set to 2).
832    pub fn font_direction_hint(&self) -> i16 {
833        let range = self.font_direction_hint_byte_range();
834        self.data.read_at(range.start).ok().unwrap()
835    }
836
837    /// 0 for short offsets (Offset16), 1 for long (Offset32).
838    pub fn index_to_loc_format(&self) -> i16 {
839        let range = self.index_to_loc_format_byte_range();
840        self.data.read_at(range.start).ok().unwrap()
841    }
842
843    /// 0 for current format.
844    pub fn glyph_data_format(&self) -> i16 {
845        let range = self.glyph_data_format_byte_range();
846        self.data.read_at(range.start).ok().unwrap()
847    }
848
849    pub fn version_byte_range(&self) -> Range<usize> {
850        let start = 0;
851        let end = start + MajorMinor::RAW_BYTE_LEN;
852        start..end
853    }
854
855    pub fn font_revision_byte_range(&self) -> Range<usize> {
856        let start = self.version_byte_range().end;
857        let end = start + Fixed::RAW_BYTE_LEN;
858        start..end
859    }
860
861    pub fn checksum_adjustment_byte_range(&self) -> Range<usize> {
862        let start = self.font_revision_byte_range().end;
863        let end = start + u32::RAW_BYTE_LEN;
864        start..end
865    }
866
867    pub fn magic_number_byte_range(&self) -> Range<usize> {
868        let start = self.checksum_adjustment_byte_range().end;
869        let end = start + u32::RAW_BYTE_LEN;
870        start..end
871    }
872
873    pub fn flags_byte_range(&self) -> Range<usize> {
874        let start = self.magic_number_byte_range().end;
875        let end = start + Flags::RAW_BYTE_LEN;
876        start..end
877    }
878
879    pub fn units_per_em_byte_range(&self) -> Range<usize> {
880        let start = self.flags_byte_range().end;
881        let end = start + u16::RAW_BYTE_LEN;
882        start..end
883    }
884
885    pub fn created_byte_range(&self) -> Range<usize> {
886        let start = self.units_per_em_byte_range().end;
887        let end = start + LongDateTime::RAW_BYTE_LEN;
888        start..end
889    }
890
891    pub fn modified_byte_range(&self) -> Range<usize> {
892        let start = self.created_byte_range().end;
893        let end = start + LongDateTime::RAW_BYTE_LEN;
894        start..end
895    }
896
897    pub fn x_min_byte_range(&self) -> Range<usize> {
898        let start = self.modified_byte_range().end;
899        let end = start + i16::RAW_BYTE_LEN;
900        start..end
901    }
902
903    pub fn y_min_byte_range(&self) -> Range<usize> {
904        let start = self.x_min_byte_range().end;
905        let end = start + i16::RAW_BYTE_LEN;
906        start..end
907    }
908
909    pub fn x_max_byte_range(&self) -> Range<usize> {
910        let start = self.y_min_byte_range().end;
911        let end = start + i16::RAW_BYTE_LEN;
912        start..end
913    }
914
915    pub fn y_max_byte_range(&self) -> Range<usize> {
916        let start = self.x_max_byte_range().end;
917        let end = start + i16::RAW_BYTE_LEN;
918        start..end
919    }
920
921    pub fn mac_style_byte_range(&self) -> Range<usize> {
922        let start = self.y_max_byte_range().end;
923        let end = start + MacStyle::RAW_BYTE_LEN;
924        start..end
925    }
926
927    pub fn lowest_rec_ppem_byte_range(&self) -> Range<usize> {
928        let start = self.mac_style_byte_range().end;
929        let end = start + u16::RAW_BYTE_LEN;
930        start..end
931    }
932
933    pub fn font_direction_hint_byte_range(&self) -> Range<usize> {
934        let start = self.lowest_rec_ppem_byte_range().end;
935        let end = start + i16::RAW_BYTE_LEN;
936        start..end
937    }
938
939    pub fn index_to_loc_format_byte_range(&self) -> Range<usize> {
940        let start = self.font_direction_hint_byte_range().end;
941        let end = start + i16::RAW_BYTE_LEN;
942        start..end
943    }
944
945    pub fn glyph_data_format_byte_range(&self) -> Range<usize> {
946        let start = self.index_to_loc_format_byte_range().end;
947        let end = start + i16::RAW_BYTE_LEN;
948        start..end
949    }
950}
951
952const _: () = assert!(FontData::default_data_long_enough(Head::MIN_SIZE));
953
954impl Default for Head<'_> {
955    fn default() -> Self {
956        Self {
957            data: FontData::default_table_data(),
958        }
959    }
960}