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_gasp.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
impl<'a> MinByteRange<'a> for Gasp<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.gasp_ranges_byte_range().end
11
0
    }
12
0
    fn min_table_bytes(&self) -> &'a [u8] {
13
0
        let range = self.min_byte_range();
14
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
15
0
    }
16
}
17
18
impl TopLevelTable for Gasp<'_> {
19
    /// `gasp`
20
    const TAG: Tag = Tag::new(b"gasp");
21
}
22
23
impl ReadArgs for Gasp<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Gasp<'a> {
28
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
0
        if data.len() < Self::MIN_SIZE {
31
0
            return Err(ReadError::OutOfBounds);
32
0
        }
33
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
0
        Ok(Self { data })
37
0
    }
38
}
39
40
/// The fields at the start of the table, which are read directly.
41
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42
#[repr(C, packed)]
43
#[doc(hidden)]
44
pub struct GaspFixedHeader {
45
    pub version: BigEndian<u16>,
46
    pub num_ranges: BigEndian<u16>,
47
}
48
49
#[allow(clippy::absurd_extreme_comparisons)]
50
const _: () = assert!(std::mem::size_of::<GaspFixedHeader>() <= Gasp::MIN_SIZE);
51
52
/// [gasp](https://learn.microsoft.com/en-us/typography/opentype/spec/gasp#gasp-table-formats)
53
#[derive(Clone)]
54
pub struct Gasp<'a> {
55
    data: TableDataRef<'a, GaspFixedHeader>,
56
}
57
58
#[allow(clippy::needless_lifetimes)]
59
impl<'a> Gasp<'a> {
60
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
61
    basic_table_impls!(impl_the_methods);
62
63
    /// Version number (set to 1)
64
0
    pub fn version(&self) -> u16 {
65
0
        self.data.header().version.get()
66
0
    }
67
68
    /// Number of records to follow
69
0
    pub fn num_ranges(&self) -> u16 {
70
0
        self.data.header().num_ranges.get()
71
0
    }
72
73
    /// Sorted by ppem
74
0
    pub fn gasp_ranges(&self) -> &'a [GaspRange] {
75
0
        let range = self.gasp_ranges_byte_range();
76
0
        self.offset_data()
77
0
            .read_array(range)
78
0
            .ok()
79
0
            .unwrap_or_default()
80
0
    }
81
82
0
    pub fn version_byte_range(&self) -> Range<usize> {
83
0
        let start = 0;
84
0
        let end = start + u16::RAW_BYTE_LEN;
85
0
        start..end
86
0
    }
87
88
0
    pub fn num_ranges_byte_range(&self) -> Range<usize> {
89
0
        let start = self.version_byte_range().end;
90
0
        let end = start + u16::RAW_BYTE_LEN;
91
0
        start..end
92
0
    }
93
94
0
    pub fn gasp_ranges_byte_range(&self) -> Range<usize> {
95
0
        let num_ranges = self.num_ranges();
96
0
        let start = self.num_ranges_byte_range().end;
97
0
        let end =
98
0
            start + (transforms::to_usize(num_ranges)).saturating_mul(GaspRange::RAW_BYTE_LEN);
99
0
        start..end
100
0
    }
101
}
102
103
const _: () = assert!(FontData::default_data_long_enough(Gasp::MIN_SIZE));
104
105
impl Default for Gasp<'_> {
106
0
    fn default() -> Self {
107
        Self {
108
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
109
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
110
        }
111
0
    }
112
}
113
114
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
115
#[repr(C)]
116
#[repr(packed)]
117
pub struct GaspRange {
118
    /// Upper limit of range, in PPEM
119
    pub range_max_ppem: BigEndian<u16>,
120
    /// Flags describing desired rasterizer behavior.
121
    pub range_gasp_behavior: BigEndian<GaspRangeBehavior>,
122
}
123
124
impl GaspRange {
125
    /// Upper limit of range, in PPEM
126
0
    pub fn range_max_ppem(&self) -> u16 {
127
0
        self.range_max_ppem.get()
128
0
    }
129
130
    /// Flags describing desired rasterizer behavior.
131
0
    pub fn range_gasp_behavior(&self) -> GaspRangeBehavior {
132
0
        self.range_gasp_behavior.get()
133
0
    }
134
}
135
136
impl FixedSize for GaspRange {
137
    const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + GaspRangeBehavior::RAW_BYTE_LEN;
138
}
139
140
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
141
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
142
#[repr(transparent)]
143
pub struct GaspRangeBehavior {
144
    bits: u16,
145
}
146
147
impl GaspRangeBehavior {
148
    /// Use gridfitting
149
    pub const GASP_GRIDFIT: Self = Self { bits: 0x0001 };
150
151
    /// Use grayscale rendering
152
    pub const GASP_DOGRAY: Self = Self { bits: 0x0002 };
153
154
    /// Use gridfitting with ClearType symmetric smoothing Only
155
    /// supported in version 1 'gasp'
156
    pub const GASP_SYMMETRIC_GRIDFIT: Self = Self { bits: 0x0004 };
157
158
    /// Use smoothing along multiple axes with ClearType® Only
159
    /// supported in version 1 'gasp'
160
    pub const GASP_SYMMETRIC_SMOOTHING: Self = Self { bits: 0x0008 };
161
}
162
163
impl GaspRangeBehavior {
164
    ///  Returns an empty set of flags.
165
    #[inline]
166
0
    pub const fn empty() -> Self {
167
0
        Self { bits: 0 }
168
0
    }
169
170
    /// Returns the set containing all flags.
171
    #[inline]
172
0
    pub const fn all() -> Self {
173
0
        Self {
174
0
            bits: Self::GASP_GRIDFIT.bits
175
0
                | Self::GASP_DOGRAY.bits
176
0
                | Self::GASP_SYMMETRIC_GRIDFIT.bits
177
0
                | Self::GASP_SYMMETRIC_SMOOTHING.bits,
178
0
        }
179
0
    }
180
181
    /// Returns the raw value of the flags currently stored.
182
    #[inline]
183
0
    pub const fn bits(&self) -> u16 {
184
0
        self.bits
185
0
    }
186
187
    /// Convert from underlying bit representation, unless that
188
    /// representation contains bits that do not correspond to a flag.
189
    #[inline]
190
0
    pub const fn from_bits(bits: u16) -> Option<Self> {
191
0
        if (bits & !Self::all().bits()) == 0 {
192
0
            Some(Self { bits })
193
        } else {
194
0
            None
195
        }
196
0
    }
197
198
    /// Convert from underlying bit representation, dropping any bits
199
    /// that do not correspond to flags.
200
    #[inline]
201
0
    pub const fn from_bits_truncate(bits: u16) -> Self {
202
0
        Self {
203
0
            bits: bits & Self::all().bits,
204
0
        }
205
0
    }
206
207
    /// Returns `true` if no flags are currently stored.
208
    #[inline]
209
0
    pub const fn is_empty(&self) -> bool {
210
0
        self.bits() == Self::empty().bits()
211
0
    }
212
213
    /// Returns `true` if there are flags common to both `self` and `other`.
214
    #[inline]
215
0
    pub const fn intersects(&self, other: Self) -> bool {
216
0
        !(Self {
217
0
            bits: self.bits & other.bits,
218
0
        })
219
0
        .is_empty()
220
0
    }
221
222
    /// Returns `true` if all of the flags in `other` are contained within `self`.
223
    #[inline]
224
0
    pub const fn contains(&self, other: Self) -> bool {
225
0
        (self.bits & other.bits) == other.bits
226
0
    }
227
228
    /// Inserts the specified flags in-place.
229
    #[inline]
230
0
    pub fn insert(&mut self, other: Self) {
231
0
        self.bits |= other.bits;
232
0
    }
233
234
    /// Removes the specified flags in-place.
235
    #[inline]
236
0
    pub fn remove(&mut self, other: Self) {
237
0
        self.bits &= !other.bits;
238
0
    }
239
240
    /// Toggles the specified flags in-place.
241
    #[inline]
242
0
    pub fn toggle(&mut self, other: Self) {
243
0
        self.bits ^= other.bits;
244
0
    }
245
246
    /// Returns the intersection between the flags in `self` and
247
    /// `other`.
248
    ///
249
    /// Specifically, the returned set contains only the flags which are
250
    /// present in *both* `self` *and* `other`.
251
    ///
252
    /// This is equivalent to using the `&` operator (e.g.
253
    /// [`ops::BitAnd`]), as in `flags & other`.
254
    ///
255
    /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
256
    #[inline]
257
    #[must_use]
258
0
    pub const fn intersection(self, other: Self) -> Self {
259
0
        Self {
260
0
            bits: self.bits & other.bits,
261
0
        }
262
0
    }
263
264
    /// Returns the union of between the flags in `self` and `other`.
265
    ///
266
    /// Specifically, the returned set contains all flags which are
267
    /// present in *either* `self` *or* `other`, including any which are
268
    /// present in both.
269
    ///
270
    /// This is equivalent to using the `|` operator (e.g.
271
    /// [`ops::BitOr`]), as in `flags | other`.
272
    ///
273
    /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
274
    #[inline]
275
    #[must_use]
276
0
    pub const fn union(self, other: Self) -> Self {
277
0
        Self {
278
0
            bits: self.bits | other.bits,
279
0
        }
280
0
    }
281
282
    /// Returns the difference between the flags in `self` and `other`.
283
    ///
284
    /// Specifically, the returned set contains all flags present in
285
    /// `self`, except for the ones present in `other`.
286
    ///
287
    /// It is also conceptually equivalent to the "bit-clear" operation:
288
    /// `flags & !other` (and this syntax is also supported).
289
    ///
290
    /// This is equivalent to using the `-` operator (e.g.
291
    /// [`ops::Sub`]), as in `flags - other`.
292
    ///
293
    /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
294
    #[inline]
295
    #[must_use]
296
0
    pub const fn difference(self, other: Self) -> Self {
297
0
        Self {
298
0
            bits: self.bits & !other.bits,
299
0
        }
300
0
    }
301
}
302
303
impl std::ops::BitOr for GaspRangeBehavior {
304
    type Output = Self;
305
306
    /// Returns the union of the two sets of flags.
307
    #[inline]
308
0
    fn bitor(self, other: GaspRangeBehavior) -> Self {
309
0
        Self {
310
0
            bits: self.bits | other.bits,
311
0
        }
312
0
    }
313
}
314
315
impl std::ops::BitOrAssign for GaspRangeBehavior {
316
    /// Adds the set of flags.
317
    #[inline]
318
0
    fn bitor_assign(&mut self, other: Self) {
319
0
        self.bits |= other.bits;
320
0
    }
321
}
322
323
impl std::ops::BitXor for GaspRangeBehavior {
324
    type Output = Self;
325
326
    /// Returns the left flags, but with all the right flags toggled.
327
    #[inline]
328
0
    fn bitxor(self, other: Self) -> Self {
329
0
        Self {
330
0
            bits: self.bits ^ other.bits,
331
0
        }
332
0
    }
333
}
334
335
impl std::ops::BitXorAssign for GaspRangeBehavior {
336
    /// Toggles the set of flags.
337
    #[inline]
338
0
    fn bitxor_assign(&mut self, other: Self) {
339
0
        self.bits ^= other.bits;
340
0
    }
341
}
342
343
impl std::ops::BitAnd for GaspRangeBehavior {
344
    type Output = Self;
345
346
    /// Returns the intersection between the two sets of flags.
347
    #[inline]
348
0
    fn bitand(self, other: Self) -> Self {
349
0
        Self {
350
0
            bits: self.bits & other.bits,
351
0
        }
352
0
    }
353
}
354
355
impl std::ops::BitAndAssign for GaspRangeBehavior {
356
    /// Disables all flags disabled in the set.
357
    #[inline]
358
0
    fn bitand_assign(&mut self, other: Self) {
359
0
        self.bits &= other.bits;
360
0
    }
361
}
362
363
impl std::ops::Sub for GaspRangeBehavior {
364
    type Output = Self;
365
366
    /// Returns the set difference of the two sets of flags.
367
    #[inline]
368
0
    fn sub(self, other: Self) -> Self {
369
0
        Self {
370
0
            bits: self.bits & !other.bits,
371
0
        }
372
0
    }
373
}
374
375
impl std::ops::SubAssign for GaspRangeBehavior {
376
    /// Disables all flags enabled in the set.
377
    #[inline]
378
0
    fn sub_assign(&mut self, other: Self) {
379
0
        self.bits &= !other.bits;
380
0
    }
381
}
382
383
impl std::ops::Not for GaspRangeBehavior {
384
    type Output = Self;
385
386
    /// Returns the complement of this set of flags.
387
    #[inline]
388
0
    fn not(self) -> Self {
389
0
        Self { bits: !self.bits } & Self::all()
390
0
    }
391
}
392
393
impl std::fmt::Debug for GaspRangeBehavior {
394
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
395
0
        let members: &[(&str, Self)] = &[
396
0
            ("GASP_GRIDFIT", Self::GASP_GRIDFIT),
397
0
            ("GASP_DOGRAY", Self::GASP_DOGRAY),
398
0
            ("GASP_SYMMETRIC_GRIDFIT", Self::GASP_SYMMETRIC_GRIDFIT),
399
0
            ("GASP_SYMMETRIC_SMOOTHING", Self::GASP_SYMMETRIC_SMOOTHING),
400
0
        ];
401
0
        let mut first = true;
402
0
        for (name, value) in members {
403
0
            if self.contains(*value) {
404
0
                if !first {
405
0
                    f.write_str(" | ")?;
406
0
                }
407
0
                first = false;
408
0
                f.write_str(name)?;
409
0
            }
410
        }
411
0
        if first {
412
0
            f.write_str("(empty)")?;
413
0
        }
414
0
        Ok(())
415
0
    }
416
}
417
418
impl std::fmt::Binary for GaspRangeBehavior {
419
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
420
0
        std::fmt::Binary::fmt(&self.bits, f)
421
0
    }
422
}
423
424
impl std::fmt::Octal for GaspRangeBehavior {
425
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
426
0
        std::fmt::Octal::fmt(&self.bits, f)
427
0
    }
428
}
429
430
impl std::fmt::LowerHex for GaspRangeBehavior {
431
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
432
0
        std::fmt::LowerHex::fmt(&self.bits, f)
433
0
    }
434
}
435
436
impl std::fmt::UpperHex for GaspRangeBehavior {
437
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
438
0
        std::fmt::UpperHex::fmt(&self.bits, f)
439
0
    }
440
}
441
442
impl font_types::Scalar for GaspRangeBehavior {
443
    type Raw = <u16 as font_types::Scalar>::Raw;
444
0
    fn to_raw(self) -> Self::Raw {
445
0
        self.bits().to_raw()
446
0
    }
447
0
    fn from_raw(raw: Self::Raw) -> Self {
448
0
        let t = <u16>::from_raw(raw);
449
0
        Self::from_bits_truncate(t)
450
0
    }
451
}