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#[cfg(feature = "experimental_traverse")]
336impl<'a> From<MacStyle> for FieldType<'a> {
337    fn from(src: MacStyle) -> FieldType<'a> {
338        src.bits().into()
339    }
340}
341
342/// The `flags` field for the head table.
343#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
344#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
345#[repr(transparent)]
346pub struct Flags {
347    bits: u16,
348}
349
350impl Flags {
351    /// Bit 0: Baseline for font at y=0.
352    pub const BASELINE_AT_Y_0: Self = Self { bits: 0x0001 };
353
354    /// Bit 1: Left sidebearing point at x=0 (relevant only for TrueType rasterizers).
355    pub const LSB_AT_X_0: Self = Self { bits: 0x0002 };
356
357    /// Bit 2: Instructions may depend on point size.
358    pub const INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE: Self = Self { bits: 0x0004 };
359
360    /// 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.
361    pub const FORCE_INTEGER_PPEM: Self = Self { bits: 0x0008 };
362
363    /// Bit 4: Instructions may alter advance width (the advance widths might not scale linearly).
364    pub const INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH: Self = Self { bits: 0x0010 };
365
366    /// 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.
367    pub const LOSSLESS_TRANSFORMED_FONT_DATA: Self = Self { bits: 0x0800 };
368
369    /// Bit 12: Font converted (produce compatible metrics).
370    pub const CONVERTED_FONT: Self = Self { bits: 0x1000 };
371
372    /// 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.
373    pub const OPTIMIZED_FOR_CLEARTYPE: Self = Self { bits: 0x2000 };
374
375    /// 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.
376    pub const LAST_RESORT_FONT: Self = Self { bits: 0x4000 };
377}
378
379impl Flags {
380    ///  Returns an empty set of flags.
381    #[inline]
382    pub const fn empty() -> Self {
383        Self { bits: 0 }
384    }
385
386    /// Returns the set containing all flags.
387    #[inline]
388    pub const fn all() -> Self {
389        Self {
390            bits: Self::BASELINE_AT_Y_0.bits
391                | Self::LSB_AT_X_0.bits
392                | Self::INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE.bits
393                | Self::FORCE_INTEGER_PPEM.bits
394                | Self::INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH.bits
395                | Self::LOSSLESS_TRANSFORMED_FONT_DATA.bits
396                | Self::CONVERTED_FONT.bits
397                | Self::OPTIMIZED_FOR_CLEARTYPE.bits
398                | Self::LAST_RESORT_FONT.bits,
399        }
400    }
401
402    /// Returns the raw value of the flags currently stored.
403    #[inline]
404    pub const fn bits(&self) -> u16 {
405        self.bits
406    }
407
408    /// Convert from underlying bit representation, unless that
409    /// representation contains bits that do not correspond to a flag.
410    #[inline]
411    pub const fn from_bits(bits: u16) -> Option<Self> {
412        if (bits & !Self::all().bits()) == 0 {
413            Some(Self { bits })
414        } else {
415            None
416        }
417    }
418
419    /// Convert from underlying bit representation, dropping any bits
420    /// that do not correspond to flags.
421    #[inline]
422    pub const fn from_bits_truncate(bits: u16) -> Self {
423        Self {
424            bits: bits & Self::all().bits,
425        }
426    }
427
428    /// Returns `true` if no flags are currently stored.
429    #[inline]
430    pub const fn is_empty(&self) -> bool {
431        self.bits() == Self::empty().bits()
432    }
433
434    /// Returns `true` if there are flags common to both `self` and `other`.
435    #[inline]
436    pub const fn intersects(&self, other: Self) -> bool {
437        !(Self {
438            bits: self.bits & other.bits,
439        })
440        .is_empty()
441    }
442
443    /// Returns `true` if all of the flags in `other` are contained within `self`.
444    #[inline]
445    pub const fn contains(&self, other: Self) -> bool {
446        (self.bits & other.bits) == other.bits
447    }
448
449    /// Inserts the specified flags in-place.
450    #[inline]
451    pub fn insert(&mut self, other: Self) {
452        self.bits |= other.bits;
453    }
454
455    /// Removes the specified flags in-place.
456    #[inline]
457    pub fn remove(&mut self, other: Self) {
458        self.bits &= !other.bits;
459    }
460
461    /// Toggles the specified flags in-place.
462    #[inline]
463    pub fn toggle(&mut self, other: Self) {
464        self.bits ^= other.bits;
465    }
466
467    /// Returns the intersection between the flags in `self` and
468    /// `other`.
469    ///
470    /// Specifically, the returned set contains only the flags which are
471    /// present in *both* `self` *and* `other`.
472    ///
473    /// This is equivalent to using the `&` operator (e.g.
474    /// [`ops::BitAnd`]), as in `flags & other`.
475    ///
476    /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
477    #[inline]
478    #[must_use]
479    pub const fn intersection(self, other: Self) -> Self {
480        Self {
481            bits: self.bits & other.bits,
482        }
483    }
484
485    /// Returns the union of between the flags in `self` and `other`.
486    ///
487    /// Specifically, the returned set contains all flags which are
488    /// present in *either* `self` *or* `other`, including any which are
489    /// present in both.
490    ///
491    /// This is equivalent to using the `|` operator (e.g.
492    /// [`ops::BitOr`]), as in `flags | other`.
493    ///
494    /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
495    #[inline]
496    #[must_use]
497    pub const fn union(self, other: Self) -> Self {
498        Self {
499            bits: self.bits | other.bits,
500        }
501    }
502
503    /// Returns the difference between the flags in `self` and `other`.
504    ///
505    /// Specifically, the returned set contains all flags present in
506    /// `self`, except for the ones present in `other`.
507    ///
508    /// It is also conceptually equivalent to the "bit-clear" operation:
509    /// `flags & !other` (and this syntax is also supported).
510    ///
511    /// This is equivalent to using the `-` operator (e.g.
512    /// [`ops::Sub`]), as in `flags - other`.
513    ///
514    /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
515    #[inline]
516    #[must_use]
517    pub const fn difference(self, other: Self) -> Self {
518        Self {
519            bits: self.bits & !other.bits,
520        }
521    }
522}
523
524impl std::ops::BitOr for Flags {
525    type Output = Self;
526
527    /// Returns the union of the two sets of flags.
528    #[inline]
529    fn bitor(self, other: Flags) -> Self {
530        Self {
531            bits: self.bits | other.bits,
532        }
533    }
534}
535
536impl std::ops::BitOrAssign for Flags {
537    /// Adds the set of flags.
538    #[inline]
539    fn bitor_assign(&mut self, other: Self) {
540        self.bits |= other.bits;
541    }
542}
543
544impl std::ops::BitXor for Flags {
545    type Output = Self;
546
547    /// Returns the left flags, but with all the right flags toggled.
548    #[inline]
549    fn bitxor(self, other: Self) -> Self {
550        Self {
551            bits: self.bits ^ other.bits,
552        }
553    }
554}
555
556impl std::ops::BitXorAssign for Flags {
557    /// Toggles the set of flags.
558    #[inline]
559    fn bitxor_assign(&mut self, other: Self) {
560        self.bits ^= other.bits;
561    }
562}
563
564impl std::ops::BitAnd for Flags {
565    type Output = Self;
566
567    /// Returns the intersection between the two sets of flags.
568    #[inline]
569    fn bitand(self, other: Self) -> Self {
570        Self {
571            bits: self.bits & other.bits,
572        }
573    }
574}
575
576impl std::ops::BitAndAssign for Flags {
577    /// Disables all flags disabled in the set.
578    #[inline]
579    fn bitand_assign(&mut self, other: Self) {
580        self.bits &= other.bits;
581    }
582}
583
584impl std::ops::Sub for Flags {
585    type Output = Self;
586
587    /// Returns the set difference of the two sets of flags.
588    #[inline]
589    fn sub(self, other: Self) -> Self {
590        Self {
591            bits: self.bits & !other.bits,
592        }
593    }
594}
595
596impl std::ops::SubAssign for Flags {
597    /// Disables all flags enabled in the set.
598    #[inline]
599    fn sub_assign(&mut self, other: Self) {
600        self.bits &= !other.bits;
601    }
602}
603
604impl std::ops::Not for Flags {
605    type Output = Self;
606
607    /// Returns the complement of this set of flags.
608    #[inline]
609    fn not(self) -> Self {
610        Self { bits: !self.bits } & Self::all()
611    }
612}
613
614impl std::fmt::Debug for Flags {
615    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
616        let members: &[(&str, Self)] = &[
617            ("BASELINE_AT_Y_0", Self::BASELINE_AT_Y_0),
618            ("LSB_AT_X_0", Self::LSB_AT_X_0),
619            (
620                "INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE",
621                Self::INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE,
622            ),
623            ("FORCE_INTEGER_PPEM", Self::FORCE_INTEGER_PPEM),
624            (
625                "INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH",
626                Self::INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH,
627            ),
628            (
629                "LOSSLESS_TRANSFORMED_FONT_DATA",
630                Self::LOSSLESS_TRANSFORMED_FONT_DATA,
631            ),
632            ("CONVERTED_FONT", Self::CONVERTED_FONT),
633            ("OPTIMIZED_FOR_CLEARTYPE", Self::OPTIMIZED_FOR_CLEARTYPE),
634            ("LAST_RESORT_FONT", Self::LAST_RESORT_FONT),
635        ];
636        let mut first = true;
637        for (name, value) in members {
638            if self.contains(*value) {
639                if !first {
640                    f.write_str(" | ")?;
641                }
642                first = false;
643                f.write_str(name)?;
644            }
645        }
646        if first {
647            f.write_str("(empty)")?;
648        }
649        Ok(())
650    }
651}
652
653impl std::fmt::Binary for Flags {
654    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
655        std::fmt::Binary::fmt(&self.bits, f)
656    }
657}
658
659impl std::fmt::Octal for Flags {
660    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
661        std::fmt::Octal::fmt(&self.bits, f)
662    }
663}
664
665impl std::fmt::LowerHex for Flags {
666    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
667        std::fmt::LowerHex::fmt(&self.bits, f)
668    }
669}
670
671impl std::fmt::UpperHex for Flags {
672    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
673        std::fmt::UpperHex::fmt(&self.bits, f)
674    }
675}
676
677impl font_types::Scalar for Flags {
678    type Raw = <u16 as font_types::Scalar>::Raw;
679    fn to_raw(self) -> Self::Raw {
680        self.bits().to_raw()
681    }
682    fn from_raw(raw: Self::Raw) -> Self {
683        let t = <u16>::from_raw(raw);
684        Self::from_bits_truncate(t)
685    }
686}
687
688#[cfg(feature = "experimental_traverse")]
689impl<'a> From<Flags> for FieldType<'a> {
690    fn from(src: Flags) -> FieldType<'a> {
691        src.bits().into()
692    }
693}
694
695impl<'a> MinByteRange<'a> for Head<'a> {
696    fn min_byte_range(&self) -> Range<usize> {
697        0..self.glyph_data_format_byte_range().end
698    }
699    fn min_table_bytes(&self) -> &'a [u8] {
700        let range = self.min_byte_range();
701        self.data.as_bytes().get(range).unwrap_or_default()
702    }
703}
704
705impl TopLevelTable for Head<'_> {
706    /// `head`
707    const TAG: Tag = Tag::new(b"head");
708}
709
710impl ReadArgs for Head<'_> {
711    type Args = ();
712}
713
714impl<'a> FontRead<'a> for Head<'a> {
715    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
716        #[allow(clippy::absurd_extreme_comparisons)]
717        if data.len() < Self::MIN_SIZE {
718            return Err(ReadError::OutOfBounds);
719        }
720        Ok(Self { data })
721    }
722}
723
724/// The [head](https://docs.microsoft.com/en-us/typography/opentype/spec/head)
725/// (font header) table.
726#[derive(Clone)]
727pub struct Head<'a> {
728    data: FontData<'a>,
729}
730
731#[allow(clippy::needless_lifetimes)]
732impl<'a> Head<'a> {
733    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
734        + Fixed::RAW_BYTE_LEN
735        + u32::RAW_BYTE_LEN
736        + u32::RAW_BYTE_LEN
737        + Flags::RAW_BYTE_LEN
738        + u16::RAW_BYTE_LEN
739        + LongDateTime::RAW_BYTE_LEN
740        + LongDateTime::RAW_BYTE_LEN
741        + i16::RAW_BYTE_LEN
742        + i16::RAW_BYTE_LEN
743        + i16::RAW_BYTE_LEN
744        + i16::RAW_BYTE_LEN
745        + MacStyle::RAW_BYTE_LEN
746        + u16::RAW_BYTE_LEN
747        + i16::RAW_BYTE_LEN
748        + i16::RAW_BYTE_LEN
749        + i16::RAW_BYTE_LEN);
750    basic_table_impls!(impl_the_methods);
751
752    /// Version number of the font header table, set to (1, 0)
753    pub fn version(&self) -> MajorMinor {
754        let range = self.version_byte_range();
755        self.data.read_at(range.start).ok().unwrap()
756    }
757
758    /// Set by font manufacturer.
759    pub fn font_revision(&self) -> Fixed {
760        let range = self.font_revision_byte_range();
761        self.data.read_at(range.start).ok().unwrap()
762    }
763
764    /// To compute: set it to 0, sum the entire font as uint32, then
765    /// store 0xB1B0AFBA - sum. If the font is used as a component in a
766    /// font collection file, the value of this field will be
767    /// invalidated by changes to the file structure and font table
768    /// directory, and must be ignored.
769    pub fn checksum_adjustment(&self) -> u32 {
770        let range = self.checksum_adjustment_byte_range();
771        self.data.read_at(range.start).ok().unwrap()
772    }
773
774    /// Set to 0x5F0F3CF5.
775    pub fn magic_number(&self) -> u32 {
776        let range = self.magic_number_byte_range();
777        self.data.read_at(range.start).ok().unwrap()
778    }
779
780    /// See the flags enum.
781    pub fn flags(&self) -> Flags {
782        let range = self.flags_byte_range();
783        self.data.read_at(range.start).ok().unwrap()
784    }
785
786    /// Set to a value from 16 to 16384. Any value in this range is
787    /// valid. In fonts that have TrueType outlines, a power of 2 is
788    /// recommended as this allows performance optimizations in some
789    /// rasterizers.
790    pub fn units_per_em(&self) -> u16 {
791        let range = self.units_per_em_byte_range();
792        self.data.read_at(range.start).ok().unwrap()
793    }
794
795    /// Number of seconds since 12:00 midnight that started January 1st
796    /// 1904 in GMT/UTC time zone.
797    pub fn created(&self) -> LongDateTime {
798        let range = self.created_byte_range();
799        self.data.read_at(range.start).ok().unwrap()
800    }
801
802    /// Number of seconds since 12:00 midnight that started January 1st
803    /// 1904 in GMT/UTC time zone.
804    pub fn modified(&self) -> LongDateTime {
805        let range = self.modified_byte_range();
806        self.data.read_at(range.start).ok().unwrap()
807    }
808
809    /// Minimum x coordinate across all glyph bounding boxes.
810    pub fn x_min(&self) -> i16 {
811        let range = self.x_min_byte_range();
812        self.data.read_at(range.start).ok().unwrap()
813    }
814
815    /// Minimum y coordinate across all glyph bounding boxes.
816    pub fn y_min(&self) -> i16 {
817        let range = self.y_min_byte_range();
818        self.data.read_at(range.start).ok().unwrap()
819    }
820
821    /// Maximum x coordinate across all glyph bounding boxes.
822    pub fn x_max(&self) -> i16 {
823        let range = self.x_max_byte_range();
824        self.data.read_at(range.start).ok().unwrap()
825    }
826
827    /// Maximum y coordinate across all glyph bounding boxes.
828    pub fn y_max(&self) -> i16 {
829        let range = self.y_max_byte_range();
830        self.data.read_at(range.start).ok().unwrap()
831    }
832
833    /// Bits identifying the font's style; see [MacStyle]
834    pub fn mac_style(&self) -> MacStyle {
835        let range = self.mac_style_byte_range();
836        self.data.read_at(range.start).ok().unwrap()
837    }
838
839    /// Smallest readable size in pixels.
840    pub fn lowest_rec_ppem(&self) -> u16 {
841        let range = self.lowest_rec_ppem_byte_range();
842        self.data.read_at(range.start).ok().unwrap()
843    }
844
845    /// Deprecated (Set to 2).
846    pub fn font_direction_hint(&self) -> i16 {
847        let range = self.font_direction_hint_byte_range();
848        self.data.read_at(range.start).ok().unwrap()
849    }
850
851    /// 0 for short offsets (Offset16), 1 for long (Offset32).
852    pub fn index_to_loc_format(&self) -> i16 {
853        let range = self.index_to_loc_format_byte_range();
854        self.data.read_at(range.start).ok().unwrap()
855    }
856
857    /// 0 for current format.
858    pub fn glyph_data_format(&self) -> i16 {
859        let range = self.glyph_data_format_byte_range();
860        self.data.read_at(range.start).ok().unwrap()
861    }
862
863    pub fn version_byte_range(&self) -> Range<usize> {
864        let start = 0;
865        let end = start + MajorMinor::RAW_BYTE_LEN;
866        start..end
867    }
868
869    pub fn font_revision_byte_range(&self) -> Range<usize> {
870        let start = self.version_byte_range().end;
871        let end = start + Fixed::RAW_BYTE_LEN;
872        start..end
873    }
874
875    pub fn checksum_adjustment_byte_range(&self) -> Range<usize> {
876        let start = self.font_revision_byte_range().end;
877        let end = start + u32::RAW_BYTE_LEN;
878        start..end
879    }
880
881    pub fn magic_number_byte_range(&self) -> Range<usize> {
882        let start = self.checksum_adjustment_byte_range().end;
883        let end = start + u32::RAW_BYTE_LEN;
884        start..end
885    }
886
887    pub fn flags_byte_range(&self) -> Range<usize> {
888        let start = self.magic_number_byte_range().end;
889        let end = start + Flags::RAW_BYTE_LEN;
890        start..end
891    }
892
893    pub fn units_per_em_byte_range(&self) -> Range<usize> {
894        let start = self.flags_byte_range().end;
895        let end = start + u16::RAW_BYTE_LEN;
896        start..end
897    }
898
899    pub fn created_byte_range(&self) -> Range<usize> {
900        let start = self.units_per_em_byte_range().end;
901        let end = start + LongDateTime::RAW_BYTE_LEN;
902        start..end
903    }
904
905    pub fn modified_byte_range(&self) -> Range<usize> {
906        let start = self.created_byte_range().end;
907        let end = start + LongDateTime::RAW_BYTE_LEN;
908        start..end
909    }
910
911    pub fn x_min_byte_range(&self) -> Range<usize> {
912        let start = self.modified_byte_range().end;
913        let end = start + i16::RAW_BYTE_LEN;
914        start..end
915    }
916
917    pub fn y_min_byte_range(&self) -> Range<usize> {
918        let start = self.x_min_byte_range().end;
919        let end = start + i16::RAW_BYTE_LEN;
920        start..end
921    }
922
923    pub fn x_max_byte_range(&self) -> Range<usize> {
924        let start = self.y_min_byte_range().end;
925        let end = start + i16::RAW_BYTE_LEN;
926        start..end
927    }
928
929    pub fn y_max_byte_range(&self) -> Range<usize> {
930        let start = self.x_max_byte_range().end;
931        let end = start + i16::RAW_BYTE_LEN;
932        start..end
933    }
934
935    pub fn mac_style_byte_range(&self) -> Range<usize> {
936        let start = self.y_max_byte_range().end;
937        let end = start + MacStyle::RAW_BYTE_LEN;
938        start..end
939    }
940
941    pub fn lowest_rec_ppem_byte_range(&self) -> Range<usize> {
942        let start = self.mac_style_byte_range().end;
943        let end = start + u16::RAW_BYTE_LEN;
944        start..end
945    }
946
947    pub fn font_direction_hint_byte_range(&self) -> Range<usize> {
948        let start = self.lowest_rec_ppem_byte_range().end;
949        let end = start + i16::RAW_BYTE_LEN;
950        start..end
951    }
952
953    pub fn index_to_loc_format_byte_range(&self) -> Range<usize> {
954        let start = self.font_direction_hint_byte_range().end;
955        let end = start + i16::RAW_BYTE_LEN;
956        start..end
957    }
958
959    pub fn glyph_data_format_byte_range(&self) -> Range<usize> {
960        let start = self.index_to_loc_format_byte_range().end;
961        let end = start + i16::RAW_BYTE_LEN;
962        start..end
963    }
964}
965
966const _: () = assert!(FontData::default_data_long_enough(Head::MIN_SIZE));
967
968impl Default for Head<'_> {
969    fn default() -> Self {
970        Self {
971            data: FontData::default_table_data(),
972        }
973    }
974}
975
976#[cfg(feature = "experimental_traverse")]
977impl<'a> SomeTable<'a> for Head<'a> {
978    fn type_name(&self) -> &str {
979        "Head"
980    }
981    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
982        match idx {
983            0usize => Some(Field::new("version", self.version())),
984            1usize => Some(Field::new("font_revision", self.font_revision())),
985            2usize => Some(Field::new(
986                "checksum_adjustment",
987                self.checksum_adjustment(),
988            )),
989            3usize => Some(Field::new("magic_number", self.magic_number())),
990            4usize => Some(Field::new("flags", self.flags())),
991            5usize => Some(Field::new("units_per_em", self.units_per_em())),
992            6usize => Some(Field::new("created", self.created())),
993            7usize => Some(Field::new("modified", self.modified())),
994            8usize => Some(Field::new("x_min", self.x_min())),
995            9usize => Some(Field::new("y_min", self.y_min())),
996            10usize => Some(Field::new("x_max", self.x_max())),
997            11usize => Some(Field::new("y_max", self.y_max())),
998            12usize => Some(Field::new("mac_style", self.mac_style())),
999            13usize => Some(Field::new("lowest_rec_ppem", self.lowest_rec_ppem())),
1000            14usize => Some(Field::new(
1001                "font_direction_hint",
1002                self.font_direction_hint(),
1003            )),
1004            15usize => Some(Field::new(
1005                "index_to_loc_format",
1006                self.index_to_loc_format(),
1007            )),
1008            16usize => Some(Field::new("glyph_data_format", self.glyph_data_format())),
1009            _ => None,
1010        }
1011    }
1012}
1013
1014#[cfg(feature = "experimental_traverse")]
1015#[allow(clippy::needless_lifetimes)]
1016impl<'a> std::fmt::Debug for Head<'a> {
1017    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1018        (self as &dyn SomeTable<'a>).fmt(f)
1019    }
1020}