Coverage Report

Created: 2026-10-24 07:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.46.0/generated/generated_head.rs
Line
Count
Source
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)]
6
use 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)]
12
pub struct MacStyle {
13
    bits: u16,
14
}
15
16
impl 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
39
impl MacStyle {
40
    ///  Returns an empty set of flags.
41
    #[inline]
42
0
    pub const fn empty() -> Self {
43
0
        Self { bits: 0 }
44
0
    }
45
46
    /// Returns the set containing all flags.
47
    #[inline]
48
0
    pub const fn all() -> Self {
49
0
        Self {
50
0
            bits: Self::BOLD.bits
51
0
                | Self::ITALIC.bits
52
0
                | Self::UNDERLINE.bits
53
0
                | Self::OUTLINE.bits
54
0
                | Self::SHADOW.bits
55
0
                | Self::CONDENSED.bits
56
0
                | Self::EXTENDED.bits,
57
0
        }
58
0
    }
59
60
    /// Returns the raw value of the flags currently stored.
61
    #[inline]
62
0
    pub const fn bits(&self) -> u16 {
63
0
        self.bits
64
0
    }
65
66
    /// Convert from underlying bit representation, unless that
67
    /// representation contains bits that do not correspond to a flag.
68
    #[inline]
69
0
    pub const fn from_bits(bits: u16) -> Option<Self> {
70
0
        if (bits & !Self::all().bits()) == 0 {
71
0
            Some(Self { bits })
72
        } else {
73
0
            None
74
        }
75
0
    }
76
77
    /// Convert from underlying bit representation, dropping any bits
78
    /// that do not correspond to flags.
79
    #[inline]
80
0
    pub const fn from_bits_truncate(bits: u16) -> Self {
81
0
        Self {
82
0
            bits: bits & Self::all().bits,
83
0
        }
84
0
    }
85
86
    /// Returns `true` if no flags are currently stored.
87
    #[inline]
88
0
    pub const fn is_empty(&self) -> bool {
89
0
        self.bits() == Self::empty().bits()
90
0
    }
91
92
    /// Returns `true` if there are flags common to both `self` and `other`.
93
    #[inline]
94
0
    pub const fn intersects(&self, other: Self) -> bool {
95
0
        !(Self {
96
0
            bits: self.bits & other.bits,
97
0
        })
98
0
        .is_empty()
99
0
    }
100
101
    /// Returns `true` if all of the flags in `other` are contained within `self`.
102
    #[inline]
103
0
    pub const fn contains(&self, other: Self) -> bool {
104
0
        (self.bits & other.bits) == other.bits
105
0
    }
106
107
    /// Inserts the specified flags in-place.
108
    #[inline]
109
0
    pub fn insert(&mut self, other: Self) {
110
0
        self.bits |= other.bits;
111
0
    }
112
113
    /// Removes the specified flags in-place.
114
    #[inline]
115
0
    pub fn remove(&mut self, other: Self) {
116
0
        self.bits &= !other.bits;
117
0
    }
118
119
    /// Toggles the specified flags in-place.
120
    #[inline]
121
0
    pub fn toggle(&mut self, other: Self) {
122
0
        self.bits ^= other.bits;
123
0
    }
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
0
    pub const fn intersection(self, other: Self) -> Self {
138
0
        Self {
139
0
            bits: self.bits & other.bits,
140
0
        }
141
0
    }
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
0
    pub const fn union(self, other: Self) -> Self {
156
0
        Self {
157
0
            bits: self.bits | other.bits,
158
0
        }
159
0
    }
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
0
    pub const fn difference(self, other: Self) -> Self {
176
0
        Self {
177
0
            bits: self.bits & !other.bits,
178
0
        }
179
0
    }
180
}
181
182
impl std::ops::BitOr for MacStyle {
183
    type Output = Self;
184
185
    /// Returns the union of the two sets of flags.
186
    #[inline]
187
0
    fn bitor(self, other: MacStyle) -> Self {
188
0
        Self {
189
0
            bits: self.bits | other.bits,
190
0
        }
191
0
    }
192
}
193
194
impl std::ops::BitOrAssign for MacStyle {
195
    /// Adds the set of flags.
196
    #[inline]
197
0
    fn bitor_assign(&mut self, other: Self) {
198
0
        self.bits |= other.bits;
199
0
    }
200
}
201
202
impl 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
0
    fn bitxor(self, other: Self) -> Self {
208
0
        Self {
209
0
            bits: self.bits ^ other.bits,
210
0
        }
211
0
    }
212
}
213
214
impl std::ops::BitXorAssign for MacStyle {
215
    /// Toggles the set of flags.
216
    #[inline]
217
0
    fn bitxor_assign(&mut self, other: Self) {
218
0
        self.bits ^= other.bits;
219
0
    }
220
}
221
222
impl std::ops::BitAnd for MacStyle {
223
    type Output = Self;
224
225
    /// Returns the intersection between the two sets of flags.
226
    #[inline]
227
0
    fn bitand(self, other: Self) -> Self {
228
0
        Self {
229
0
            bits: self.bits & other.bits,
230
0
        }
231
0
    }
232
}
233
234
impl std::ops::BitAndAssign for MacStyle {
235
    /// Disables all flags disabled in the set.
236
    #[inline]
237
0
    fn bitand_assign(&mut self, other: Self) {
238
0
        self.bits &= other.bits;
239
0
    }
240
}
241
242
impl std::ops::Sub for MacStyle {
243
    type Output = Self;
244
245
    /// Returns the set difference of the two sets of flags.
246
    #[inline]
247
0
    fn sub(self, other: Self) -> Self {
248
0
        Self {
249
0
            bits: self.bits & !other.bits,
250
0
        }
251
0
    }
252
}
253
254
impl std::ops::SubAssign for MacStyle {
255
    /// Disables all flags enabled in the set.
256
    #[inline]
257
0
    fn sub_assign(&mut self, other: Self) {
258
0
        self.bits &= !other.bits;
259
0
    }
260
}
261
262
impl std::ops::Not for MacStyle {
263
    type Output = Self;
264
265
    /// Returns the complement of this set of flags.
266
    #[inline]
267
0
    fn not(self) -> Self {
268
0
        Self { bits: !self.bits } & Self::all()
269
0
    }
270
}
271
272
impl std::fmt::Debug for MacStyle {
273
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
274
0
        let members: &[(&str, Self)] = &[
275
0
            ("BOLD", Self::BOLD),
276
0
            ("ITALIC", Self::ITALIC),
277
0
            ("UNDERLINE", Self::UNDERLINE),
278
0
            ("OUTLINE", Self::OUTLINE),
279
0
            ("SHADOW", Self::SHADOW),
280
0
            ("CONDENSED", Self::CONDENSED),
281
0
            ("EXTENDED", Self::EXTENDED),
282
0
        ];
283
0
        let mut first = true;
284
0
        for (name, value) in members {
285
0
            if self.contains(*value) {
286
0
                if !first {
287
0
                    f.write_str(" | ")?;
288
0
                }
289
0
                first = false;
290
0
                f.write_str(name)?;
291
0
            }
292
        }
293
0
        if first {
294
0
            f.write_str("(empty)")?;
295
0
        }
296
0
        Ok(())
297
0
    }
298
}
299
300
impl std::fmt::Binary for MacStyle {
301
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
302
0
        std::fmt::Binary::fmt(&self.bits, f)
303
0
    }
304
}
305
306
impl std::fmt::Octal for MacStyle {
307
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
308
0
        std::fmt::Octal::fmt(&self.bits, f)
309
0
    }
310
}
311
312
impl std::fmt::LowerHex for MacStyle {
313
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
314
0
        std::fmt::LowerHex::fmt(&self.bits, f)
315
0
    }
316
}
317
318
impl std::fmt::UpperHex for MacStyle {
319
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
320
0
        std::fmt::UpperHex::fmt(&self.bits, f)
321
0
    }
322
}
323
324
impl font_types::Scalar for MacStyle {
325
    type Raw = <u16 as font_types::Scalar>::Raw;
326
0
    fn to_raw(self) -> Self::Raw {
327
0
        self.bits().to_raw()
328
0
    }
329
0
    fn from_raw(raw: Self::Raw) -> Self {
330
0
        let t = <u16>::from_raw(raw);
331
0
        Self::from_bits_truncate(t)
332
0
    }
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)]
339
pub struct Flags {
340
    bits: u16,
341
}
342
343
impl 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
372
impl Flags {
373
    ///  Returns an empty set of flags.
374
    #[inline]
375
0
    pub const fn empty() -> Self {
376
0
        Self { bits: 0 }
377
0
    }
378
379
    /// Returns the set containing all flags.
380
    #[inline]
381
0
    pub const fn all() -> Self {
382
0
        Self {
383
0
            bits: Self::BASELINE_AT_Y_0.bits
384
0
                | Self::LSB_AT_X_0.bits
385
0
                | Self::INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE.bits
386
0
                | Self::FORCE_INTEGER_PPEM.bits
387
0
                | Self::INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH.bits
388
0
                | Self::LOSSLESS_TRANSFORMED_FONT_DATA.bits
389
0
                | Self::CONVERTED_FONT.bits
390
0
                | Self::OPTIMIZED_FOR_CLEARTYPE.bits
391
0
                | Self::LAST_RESORT_FONT.bits,
392
0
        }
393
0
    }
394
395
    /// Returns the raw value of the flags currently stored.
396
    #[inline]
397
0
    pub const fn bits(&self) -> u16 {
398
0
        self.bits
399
0
    }
400
401
    /// Convert from underlying bit representation, unless that
402
    /// representation contains bits that do not correspond to a flag.
403
    #[inline]
404
0
    pub const fn from_bits(bits: u16) -> Option<Self> {
405
0
        if (bits & !Self::all().bits()) == 0 {
406
0
            Some(Self { bits })
407
        } else {
408
0
            None
409
        }
410
0
    }
411
412
    /// Convert from underlying bit representation, dropping any bits
413
    /// that do not correspond to flags.
414
    #[inline]
415
0
    pub const fn from_bits_truncate(bits: u16) -> Self {
416
0
        Self {
417
0
            bits: bits & Self::all().bits,
418
0
        }
419
0
    }
420
421
    /// Returns `true` if no flags are currently stored.
422
    #[inline]
423
0
    pub const fn is_empty(&self) -> bool {
424
0
        self.bits() == Self::empty().bits()
425
0
    }
426
427
    /// Returns `true` if there are flags common to both `self` and `other`.
428
    #[inline]
429
0
    pub const fn intersects(&self, other: Self) -> bool {
430
0
        !(Self {
431
0
            bits: self.bits & other.bits,
432
0
        })
433
0
        .is_empty()
434
0
    }
435
436
    /// Returns `true` if all of the flags in `other` are contained within `self`.
437
    #[inline]
438
0
    pub const fn contains(&self, other: Self) -> bool {
439
0
        (self.bits & other.bits) == other.bits
440
0
    }
441
442
    /// Inserts the specified flags in-place.
443
    #[inline]
444
0
    pub fn insert(&mut self, other: Self) {
445
0
        self.bits |= other.bits;
446
0
    }
447
448
    /// Removes the specified flags in-place.
449
    #[inline]
450
0
    pub fn remove(&mut self, other: Self) {
451
0
        self.bits &= !other.bits;
452
0
    }
453
454
    /// Toggles the specified flags in-place.
455
    #[inline]
456
0
    pub fn toggle(&mut self, other: Self) {
457
0
        self.bits ^= other.bits;
458
0
    }
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
0
    pub const fn intersection(self, other: Self) -> Self {
473
0
        Self {
474
0
            bits: self.bits & other.bits,
475
0
        }
476
0
    }
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
0
    pub const fn union(self, other: Self) -> Self {
491
0
        Self {
492
0
            bits: self.bits | other.bits,
493
0
        }
494
0
    }
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
0
    pub const fn difference(self, other: Self) -> Self {
511
0
        Self {
512
0
            bits: self.bits & !other.bits,
513
0
        }
514
0
    }
515
}
516
517
impl std::ops::BitOr for Flags {
518
    type Output = Self;
519
520
    /// Returns the union of the two sets of flags.
521
    #[inline]
522
0
    fn bitor(self, other: Flags) -> Self {
523
0
        Self {
524
0
            bits: self.bits | other.bits,
525
0
        }
526
0
    }
527
}
528
529
impl std::ops::BitOrAssign for Flags {
530
    /// Adds the set of flags.
531
    #[inline]
532
0
    fn bitor_assign(&mut self, other: Self) {
533
0
        self.bits |= other.bits;
534
0
    }
535
}
536
537
impl 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
0
    fn bitxor(self, other: Self) -> Self {
543
0
        Self {
544
0
            bits: self.bits ^ other.bits,
545
0
        }
546
0
    }
547
}
548
549
impl std::ops::BitXorAssign for Flags {
550
    /// Toggles the set of flags.
551
    #[inline]
552
0
    fn bitxor_assign(&mut self, other: Self) {
553
0
        self.bits ^= other.bits;
554
0
    }
555
}
556
557
impl std::ops::BitAnd for Flags {
558
    type Output = Self;
559
560
    /// Returns the intersection between the two sets of flags.
561
    #[inline]
562
0
    fn bitand(self, other: Self) -> Self {
563
0
        Self {
564
0
            bits: self.bits & other.bits,
565
0
        }
566
0
    }
567
}
568
569
impl std::ops::BitAndAssign for Flags {
570
    /// Disables all flags disabled in the set.
571
    #[inline]
572
0
    fn bitand_assign(&mut self, other: Self) {
573
0
        self.bits &= other.bits;
574
0
    }
575
}
576
577
impl std::ops::Sub for Flags {
578
    type Output = Self;
579
580
    /// Returns the set difference of the two sets of flags.
581
    #[inline]
582
0
    fn sub(self, other: Self) -> Self {
583
0
        Self {
584
0
            bits: self.bits & !other.bits,
585
0
        }
586
0
    }
587
}
588
589
impl std::ops::SubAssign for Flags {
590
    /// Disables all flags enabled in the set.
591
    #[inline]
592
0
    fn sub_assign(&mut self, other: Self) {
593
0
        self.bits &= !other.bits;
594
0
    }
595
}
596
597
impl std::ops::Not for Flags {
598
    type Output = Self;
599
600
    /// Returns the complement of this set of flags.
601
    #[inline]
602
0
    fn not(self) -> Self {
603
0
        Self { bits: !self.bits } & Self::all()
604
0
    }
605
}
606
607
impl std::fmt::Debug for Flags {
608
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
609
0
        let members: &[(&str, Self)] = &[
610
0
            ("BASELINE_AT_Y_0", Self::BASELINE_AT_Y_0),
611
0
            ("LSB_AT_X_0", Self::LSB_AT_X_0),
612
0
            (
613
0
                "INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE",
614
0
                Self::INSTRUCTIONS_MAY_DEPEND_ON_POINT_SIZE,
615
0
            ),
616
0
            ("FORCE_INTEGER_PPEM", Self::FORCE_INTEGER_PPEM),
617
0
            (
618
0
                "INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH",
619
0
                Self::INSTRUCTIONS_MAY_ALTER_ADVANCE_WIDTH,
620
0
            ),
621
0
            (
622
0
                "LOSSLESS_TRANSFORMED_FONT_DATA",
623
0
                Self::LOSSLESS_TRANSFORMED_FONT_DATA,
624
0
            ),
625
0
            ("CONVERTED_FONT", Self::CONVERTED_FONT),
626
0
            ("OPTIMIZED_FOR_CLEARTYPE", Self::OPTIMIZED_FOR_CLEARTYPE),
627
0
            ("LAST_RESORT_FONT", Self::LAST_RESORT_FONT),
628
0
        ];
629
0
        let mut first = true;
630
0
        for (name, value) in members {
631
0
            if self.contains(*value) {
632
0
                if !first {
633
0
                    f.write_str(" | ")?;
634
0
                }
635
0
                first = false;
636
0
                f.write_str(name)?;
637
0
            }
638
        }
639
0
        if first {
640
0
            f.write_str("(empty)")?;
641
0
        }
642
0
        Ok(())
643
0
    }
644
}
645
646
impl std::fmt::Binary for Flags {
647
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
648
0
        std::fmt::Binary::fmt(&self.bits, f)
649
0
    }
650
}
651
652
impl std::fmt::Octal for Flags {
653
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
654
0
        std::fmt::Octal::fmt(&self.bits, f)
655
0
    }
656
}
657
658
impl std::fmt::LowerHex for Flags {
659
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
660
0
        std::fmt::LowerHex::fmt(&self.bits, f)
661
0
    }
662
}
663
664
impl std::fmt::UpperHex for Flags {
665
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
666
0
        std::fmt::UpperHex::fmt(&self.bits, f)
667
0
    }
668
}
669
670
impl font_types::Scalar for Flags {
671
    type Raw = <u16 as font_types::Scalar>::Raw;
672
0
    fn to_raw(self) -> Self::Raw {
673
0
        self.bits().to_raw()
674
0
    }
675
0
    fn from_raw(raw: Self::Raw) -> Self {
676
0
        let t = <u16>::from_raw(raw);
677
0
        Self::from_bits_truncate(t)
678
0
    }
679
}
680
681
impl<'a> MinByteRange<'a> for Head<'a> {
682
0
    fn min_byte_range(&self) -> Range<usize> {
683
0
        0..self.glyph_data_format_byte_range().end
684
0
    }
685
0
    fn min_table_bytes(&self) -> &'a [u8] {
686
0
        let range = self.min_byte_range();
687
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
688
0
    }
689
}
690
691
impl TopLevelTable for Head<'_> {
692
    /// `head`
693
    const TAG: Tag = Tag::new(b"head");
694
}
695
696
impl ReadArgs for Head<'_> {
697
    type Args = ();
698
}
699
700
impl<'a> FontRead<'a> for Head<'a> {
701
5.62k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
702
        #[allow(clippy::absurd_extreme_comparisons)]
703
5.62k
        if data.len() < Self::MIN_SIZE {
704
13
            return Err(ReadError::OutOfBounds);
705
5.61k
        }
706
5.61k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
707
0
            return Err(ReadError::OutOfBounds);
708
        };
709
5.61k
        Ok(Self { data })
710
5.62k
    }
711
}
712
713
/// The fields at the start of the table, which are read directly.
714
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
715
#[repr(C, packed)]
716
#[doc(hidden)]
717
pub struct HeadFixedHeader {
718
    pub version: BigEndian<MajorMinor>,
719
    pub font_revision: BigEndian<Fixed>,
720
    pub checksum_adjustment: BigEndian<u32>,
721
    pub magic_number: BigEndian<u32>,
722
    pub flags: BigEndian<Flags>,
723
    pub units_per_em: BigEndian<u16>,
724
    pub created: BigEndian<LongDateTime>,
725
    pub modified: BigEndian<LongDateTime>,
726
    pub x_min: BigEndian<i16>,
727
    pub y_min: BigEndian<i16>,
728
    pub x_max: BigEndian<i16>,
729
    pub y_max: BigEndian<i16>,
730
    pub mac_style: BigEndian<MacStyle>,
731
    pub lowest_rec_ppem: BigEndian<u16>,
732
    pub font_direction_hint: BigEndian<i16>,
733
    pub index_to_loc_format: BigEndian<i16>,
734
    pub glyph_data_format: BigEndian<i16>,
735
}
736
737
#[allow(clippy::absurd_extreme_comparisons)]
738
const _: () = assert!(std::mem::size_of::<HeadFixedHeader>() <= Head::MIN_SIZE);
739
740
/// The [head](https://docs.microsoft.com/en-us/typography/opentype/spec/head)
741
/// (font header) table.
742
#[derive(Clone)]
743
pub struct Head<'a> {
744
    data: TableDataRef<'a, HeadFixedHeader>,
745
}
746
747
#[allow(clippy::needless_lifetimes)]
748
impl<'a> Head<'a> {
749
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
750
        + Fixed::RAW_BYTE_LEN
751
        + u32::RAW_BYTE_LEN
752
        + u32::RAW_BYTE_LEN
753
        + Flags::RAW_BYTE_LEN
754
        + u16::RAW_BYTE_LEN
755
        + LongDateTime::RAW_BYTE_LEN
756
        + LongDateTime::RAW_BYTE_LEN
757
        + i16::RAW_BYTE_LEN
758
        + i16::RAW_BYTE_LEN
759
        + i16::RAW_BYTE_LEN
760
        + i16::RAW_BYTE_LEN
761
        + MacStyle::RAW_BYTE_LEN
762
        + u16::RAW_BYTE_LEN
763
        + i16::RAW_BYTE_LEN
764
        + i16::RAW_BYTE_LEN
765
        + i16::RAW_BYTE_LEN);
766
    basic_table_impls!(impl_the_methods);
767
768
    /// Version number of the font header table, set to (1, 0)
769
0
    pub fn version(&self) -> MajorMinor {
770
0
        self.data.header().version.get()
771
0
    }
772
773
    /// Set by font manufacturer.
774
0
    pub fn font_revision(&self) -> Fixed {
775
0
        self.data.header().font_revision.get()
776
0
    }
777
778
    /// To compute: set it to 0, sum the entire font as uint32, then
779
    /// store 0xB1B0AFBA - sum. If the font is used as a component in a
780
    /// font collection file, the value of this field will be
781
    /// invalidated by changes to the file structure and font table
782
    /// directory, and must be ignored.
783
0
    pub fn checksum_adjustment(&self) -> u32 {
784
0
        self.data.header().checksum_adjustment.get()
785
0
    }
786
787
    /// Set to 0x5F0F3CF5.
788
0
    pub fn magic_number(&self) -> u32 {
789
0
        self.data.header().magic_number.get()
790
0
    }
791
792
    /// See the flags enum.
793
0
    pub fn flags(&self) -> Flags {
794
0
        self.data.header().flags.get()
795
0
    }
796
797
    /// Set to a value from 16 to 16384. Any value in this range is
798
    /// valid. In fonts that have TrueType outlines, a power of 2 is
799
    /// recommended as this allows performance optimizations in some
800
    /// rasterizers.
801
3.81k
    pub fn units_per_em(&self) -> u16 {
802
3.81k
        self.data.header().units_per_em.get()
803
3.81k
    }
804
805
    /// Number of seconds since 12:00 midnight that started January 1st
806
    /// 1904 in GMT/UTC time zone.
807
0
    pub fn created(&self) -> LongDateTime {
808
0
        self.data.header().created.get()
809
0
    }
810
811
    /// Number of seconds since 12:00 midnight that started January 1st
812
    /// 1904 in GMT/UTC time zone.
813
0
    pub fn modified(&self) -> LongDateTime {
814
0
        self.data.header().modified.get()
815
0
    }
816
817
    /// Minimum x coordinate across all glyph bounding boxes.
818
3.69k
    pub fn x_min(&self) -> i16 {
819
3.69k
        self.data.header().x_min.get()
820
3.69k
    }
821
822
    /// Minimum y coordinate across all glyph bounding boxes.
823
3.69k
    pub fn y_min(&self) -> i16 {
824
3.69k
        self.data.header().y_min.get()
825
3.69k
    }
826
827
    /// Maximum x coordinate across all glyph bounding boxes.
828
3.69k
    pub fn x_max(&self) -> i16 {
829
3.69k
        self.data.header().x_max.get()
830
3.69k
    }
831
832
    /// Maximum y coordinate across all glyph bounding boxes.
833
3.69k
    pub fn y_max(&self) -> i16 {
834
3.69k
        self.data.header().y_max.get()
835
3.69k
    }
836
837
    /// Bits identifying the font's style; see [MacStyle]
838
0
    pub fn mac_style(&self) -> MacStyle {
839
0
        self.data.header().mac_style.get()
840
0
    }
841
842
    /// Smallest readable size in pixels.
843
0
    pub fn lowest_rec_ppem(&self) -> u16 {
844
0
        self.data.header().lowest_rec_ppem.get()
845
0
    }
846
847
    /// Deprecated (Set to 2).
848
0
    pub fn font_direction_hint(&self) -> i16 {
849
0
        self.data.header().font_direction_hint.get()
850
0
    }
851
852
    /// 0 for short offsets (Offset16), 1 for long (Offset32).
853
1.79k
    pub fn index_to_loc_format(&self) -> i16 {
854
1.79k
        self.data.header().index_to_loc_format.get()
855
1.79k
    }
856
857
    /// 0 for current format.
858
0
    pub fn glyph_data_format(&self) -> i16 {
859
0
        self.data.header().glyph_data_format.get()
860
0
    }
861
862
0
    pub fn version_byte_range(&self) -> Range<usize> {
863
0
        let start = 0;
864
0
        let end = start + MajorMinor::RAW_BYTE_LEN;
865
0
        start..end
866
0
    }
867
868
0
    pub fn font_revision_byte_range(&self) -> Range<usize> {
869
0
        let start = self.version_byte_range().end;
870
0
        let end = start + Fixed::RAW_BYTE_LEN;
871
0
        start..end
872
0
    }
873
874
0
    pub fn checksum_adjustment_byte_range(&self) -> Range<usize> {
875
0
        let start = self.font_revision_byte_range().end;
876
0
        let end = start + u32::RAW_BYTE_LEN;
877
0
        start..end
878
0
    }
879
880
0
    pub fn magic_number_byte_range(&self) -> Range<usize> {
881
0
        let start = self.checksum_adjustment_byte_range().end;
882
0
        let end = start + u32::RAW_BYTE_LEN;
883
0
        start..end
884
0
    }
885
886
0
    pub fn flags_byte_range(&self) -> Range<usize> {
887
0
        let start = self.magic_number_byte_range().end;
888
0
        let end = start + Flags::RAW_BYTE_LEN;
889
0
        start..end
890
0
    }
891
892
0
    pub fn units_per_em_byte_range(&self) -> Range<usize> {
893
0
        let start = self.flags_byte_range().end;
894
0
        let end = start + u16::RAW_BYTE_LEN;
895
0
        start..end
896
0
    }
897
898
0
    pub fn created_byte_range(&self) -> Range<usize> {
899
0
        let start = self.units_per_em_byte_range().end;
900
0
        let end = start + LongDateTime::RAW_BYTE_LEN;
901
0
        start..end
902
0
    }
903
904
0
    pub fn modified_byte_range(&self) -> Range<usize> {
905
0
        let start = self.created_byte_range().end;
906
0
        let end = start + LongDateTime::RAW_BYTE_LEN;
907
0
        start..end
908
0
    }
909
910
0
    pub fn x_min_byte_range(&self) -> Range<usize> {
911
0
        let start = self.modified_byte_range().end;
912
0
        let end = start + i16::RAW_BYTE_LEN;
913
0
        start..end
914
0
    }
915
916
0
    pub fn y_min_byte_range(&self) -> Range<usize> {
917
0
        let start = self.x_min_byte_range().end;
918
0
        let end = start + i16::RAW_BYTE_LEN;
919
0
        start..end
920
0
    }
921
922
0
    pub fn x_max_byte_range(&self) -> Range<usize> {
923
0
        let start = self.y_min_byte_range().end;
924
0
        let end = start + i16::RAW_BYTE_LEN;
925
0
        start..end
926
0
    }
927
928
0
    pub fn y_max_byte_range(&self) -> Range<usize> {
929
0
        let start = self.x_max_byte_range().end;
930
0
        let end = start + i16::RAW_BYTE_LEN;
931
0
        start..end
932
0
    }
933
934
0
    pub fn mac_style_byte_range(&self) -> Range<usize> {
935
0
        let start = self.y_max_byte_range().end;
936
0
        let end = start + MacStyle::RAW_BYTE_LEN;
937
0
        start..end
938
0
    }
939
940
0
    pub fn lowest_rec_ppem_byte_range(&self) -> Range<usize> {
941
0
        let start = self.mac_style_byte_range().end;
942
0
        let end = start + u16::RAW_BYTE_LEN;
943
0
        start..end
944
0
    }
945
946
0
    pub fn font_direction_hint_byte_range(&self) -> Range<usize> {
947
0
        let start = self.lowest_rec_ppem_byte_range().end;
948
0
        let end = start + i16::RAW_BYTE_LEN;
949
0
        start..end
950
0
    }
951
952
0
    pub fn index_to_loc_format_byte_range(&self) -> Range<usize> {
953
0
        let start = self.font_direction_hint_byte_range().end;
954
0
        let end = start + i16::RAW_BYTE_LEN;
955
0
        start..end
956
0
    }
957
958
0
    pub fn glyph_data_format_byte_range(&self) -> Range<usize> {
959
0
        let start = self.index_to_loc_format_byte_range().end;
960
0
        let end = start + i16::RAW_BYTE_LEN;
961
0
        start..end
962
0
    }
963
}
964
965
const _: () = assert!(FontData::default_data_long_enough(Head::MIN_SIZE));
966
967
impl Default for Head<'_> {
968
0
    fn default() -> Self {
969
        Self {
970
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
971
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
972
        }
973
0
    }
974
}