read_fonts/generated/
generated_gasp.rs1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Gasp<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self.gasp_ranges_byte_range().end
11 }
12 fn min_table_bytes(&self) -> &'a [u8] {
13 let range = self.min_byte_range();
14 self.offset_data().as_bytes().get(range).unwrap_or_default()
15 }
16}
17
18impl TopLevelTable for Gasp<'_> {
19 const TAG: Tag = Tag::new(b"gasp");
21}
22
23impl ReadArgs for Gasp<'_> {
24 type Args = ();
25}
26
27impl<'a> FontRead<'a> for Gasp<'a> {
28 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29 #[allow(clippy::absurd_extreme_comparisons)]
30 if data.len() < Self::MIN_SIZE {
31 return Err(ReadError::OutOfBounds);
32 }
33 let Some(data) = TableDataRef::new(data.as_bytes()) else {
34 return Err(ReadError::OutOfBounds);
35 };
36 Ok(Self { data })
37 }
38}
39
40#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42#[repr(C, packed)]
43#[doc(hidden)]
44pub struct GaspFixedHeader {
45 pub version: BigEndian<u16>,
46 pub num_ranges: BigEndian<u16>,
47}
48
49#[allow(clippy::absurd_extreme_comparisons)]
50const _: () = assert!(std::mem::size_of::<GaspFixedHeader>() <= Gasp::MIN_SIZE);
51
52#[derive(Clone)]
54pub struct Gasp<'a> {
55 data: TableDataRef<'a, GaspFixedHeader>,
56}
57
58#[allow(clippy::needless_lifetimes)]
59impl<'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 pub fn version(&self) -> u16 {
65 self.data.header().version.get()
66 }
67
68 pub fn num_ranges(&self) -> u16 {
70 self.data.header().num_ranges.get()
71 }
72
73 pub fn gasp_ranges(&self) -> &'a [GaspRange] {
75 let range = self.gasp_ranges_byte_range();
76 self.offset_data()
77 .read_array(range)
78 .ok()
79 .unwrap_or_default()
80 }
81
82 pub fn version_byte_range(&self) -> Range<usize> {
83 let start = 0;
84 let end = start + u16::RAW_BYTE_LEN;
85 start..end
86 }
87
88 pub fn num_ranges_byte_range(&self) -> Range<usize> {
89 let start = self.version_byte_range().end;
90 let end = start + u16::RAW_BYTE_LEN;
91 start..end
92 }
93
94 pub fn gasp_ranges_byte_range(&self) -> Range<usize> {
95 let num_ranges = self.num_ranges();
96 let start = self.num_ranges_byte_range().end;
97 let end =
98 start + (transforms::to_usize(num_ranges)).saturating_mul(GaspRange::RAW_BYTE_LEN);
99 start..end
100 }
101}
102
103const _: () = assert!(FontData::default_data_long_enough(Gasp::MIN_SIZE));
104
105impl Default for Gasp<'_> {
106 fn default() -> Self {
107 Self {
108 data: TableDataRef::new(FontData::default_table_data().as_bytes())
109 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
110 }
111 }
112}
113
114#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
115#[repr(C)]
116#[repr(packed)]
117pub struct GaspRange {
118 pub range_max_ppem: BigEndian<u16>,
120 pub range_gasp_behavior: BigEndian<GaspRangeBehavior>,
122}
123
124impl GaspRange {
125 pub fn range_max_ppem(&self) -> u16 {
127 self.range_max_ppem.get()
128 }
129
130 pub fn range_gasp_behavior(&self) -> GaspRangeBehavior {
132 self.range_gasp_behavior.get()
133 }
134}
135
136impl 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)]
143pub struct GaspRangeBehavior {
144 bits: u16,
145}
146
147impl GaspRangeBehavior {
148 pub const GASP_GRIDFIT: Self = Self { bits: 0x0001 };
150
151 pub const GASP_DOGRAY: Self = Self { bits: 0x0002 };
153
154 pub const GASP_SYMMETRIC_GRIDFIT: Self = Self { bits: 0x0004 };
157
158 pub const GASP_SYMMETRIC_SMOOTHING: Self = Self { bits: 0x0008 };
161}
162
163impl GaspRangeBehavior {
164 #[inline]
166 pub const fn empty() -> Self {
167 Self { bits: 0 }
168 }
169
170 #[inline]
172 pub const fn all() -> Self {
173 Self {
174 bits: Self::GASP_GRIDFIT.bits
175 | Self::GASP_DOGRAY.bits
176 | Self::GASP_SYMMETRIC_GRIDFIT.bits
177 | Self::GASP_SYMMETRIC_SMOOTHING.bits,
178 }
179 }
180
181 #[inline]
183 pub const fn bits(&self) -> u16 {
184 self.bits
185 }
186
187 #[inline]
190 pub const fn from_bits(bits: u16) -> Option<Self> {
191 if (bits & !Self::all().bits()) == 0 {
192 Some(Self { bits })
193 } else {
194 None
195 }
196 }
197
198 #[inline]
201 pub const fn from_bits_truncate(bits: u16) -> Self {
202 Self {
203 bits: bits & Self::all().bits,
204 }
205 }
206
207 #[inline]
209 pub const fn is_empty(&self) -> bool {
210 self.bits() == Self::empty().bits()
211 }
212
213 #[inline]
215 pub const fn intersects(&self, other: Self) -> bool {
216 !(Self {
217 bits: self.bits & other.bits,
218 })
219 .is_empty()
220 }
221
222 #[inline]
224 pub const fn contains(&self, other: Self) -> bool {
225 (self.bits & other.bits) == other.bits
226 }
227
228 #[inline]
230 pub fn insert(&mut self, other: Self) {
231 self.bits |= other.bits;
232 }
233
234 #[inline]
236 pub fn remove(&mut self, other: Self) {
237 self.bits &= !other.bits;
238 }
239
240 #[inline]
242 pub fn toggle(&mut self, other: Self) {
243 self.bits ^= other.bits;
244 }
245
246 #[inline]
257 #[must_use]
258 pub const fn intersection(self, other: Self) -> Self {
259 Self {
260 bits: self.bits & other.bits,
261 }
262 }
263
264 #[inline]
275 #[must_use]
276 pub const fn union(self, other: Self) -> Self {
277 Self {
278 bits: self.bits | other.bits,
279 }
280 }
281
282 #[inline]
295 #[must_use]
296 pub const fn difference(self, other: Self) -> Self {
297 Self {
298 bits: self.bits & !other.bits,
299 }
300 }
301}
302
303impl std::ops::BitOr for GaspRangeBehavior {
304 type Output = Self;
305
306 #[inline]
308 fn bitor(self, other: GaspRangeBehavior) -> Self {
309 Self {
310 bits: self.bits | other.bits,
311 }
312 }
313}
314
315impl std::ops::BitOrAssign for GaspRangeBehavior {
316 #[inline]
318 fn bitor_assign(&mut self, other: Self) {
319 self.bits |= other.bits;
320 }
321}
322
323impl std::ops::BitXor for GaspRangeBehavior {
324 type Output = Self;
325
326 #[inline]
328 fn bitxor(self, other: Self) -> Self {
329 Self {
330 bits: self.bits ^ other.bits,
331 }
332 }
333}
334
335impl std::ops::BitXorAssign for GaspRangeBehavior {
336 #[inline]
338 fn bitxor_assign(&mut self, other: Self) {
339 self.bits ^= other.bits;
340 }
341}
342
343impl std::ops::BitAnd for GaspRangeBehavior {
344 type Output = Self;
345
346 #[inline]
348 fn bitand(self, other: Self) -> Self {
349 Self {
350 bits: self.bits & other.bits,
351 }
352 }
353}
354
355impl std::ops::BitAndAssign for GaspRangeBehavior {
356 #[inline]
358 fn bitand_assign(&mut self, other: Self) {
359 self.bits &= other.bits;
360 }
361}
362
363impl std::ops::Sub for GaspRangeBehavior {
364 type Output = Self;
365
366 #[inline]
368 fn sub(self, other: Self) -> Self {
369 Self {
370 bits: self.bits & !other.bits,
371 }
372 }
373}
374
375impl std::ops::SubAssign for GaspRangeBehavior {
376 #[inline]
378 fn sub_assign(&mut self, other: Self) {
379 self.bits &= !other.bits;
380 }
381}
382
383impl std::ops::Not for GaspRangeBehavior {
384 type Output = Self;
385
386 #[inline]
388 fn not(self) -> Self {
389 Self { bits: !self.bits } & Self::all()
390 }
391}
392
393impl std::fmt::Debug for GaspRangeBehavior {
394 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
395 let members: &[(&str, Self)] = &[
396 ("GASP_GRIDFIT", Self::GASP_GRIDFIT),
397 ("GASP_DOGRAY", Self::GASP_DOGRAY),
398 ("GASP_SYMMETRIC_GRIDFIT", Self::GASP_SYMMETRIC_GRIDFIT),
399 ("GASP_SYMMETRIC_SMOOTHING", Self::GASP_SYMMETRIC_SMOOTHING),
400 ];
401 let mut first = true;
402 for (name, value) in members {
403 if self.contains(*value) {
404 if !first {
405 f.write_str(" | ")?;
406 }
407 first = false;
408 f.write_str(name)?;
409 }
410 }
411 if first {
412 f.write_str("(empty)")?;
413 }
414 Ok(())
415 }
416}
417
418impl std::fmt::Binary for GaspRangeBehavior {
419 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
420 std::fmt::Binary::fmt(&self.bits, f)
421 }
422}
423
424impl std::fmt::Octal for GaspRangeBehavior {
425 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
426 std::fmt::Octal::fmt(&self.bits, f)
427 }
428}
429
430impl std::fmt::LowerHex for GaspRangeBehavior {
431 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
432 std::fmt::LowerHex::fmt(&self.bits, f)
433 }
434}
435
436impl std::fmt::UpperHex for GaspRangeBehavior {
437 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
438 std::fmt::UpperHex::fmt(&self.bits, f)
439 }
440}
441
442impl font_types::Scalar for GaspRangeBehavior {
443 type Raw = <u16 as font_types::Scalar>::Raw;
444 fn to_raw(self) -> Self::Raw {
445 self.bits().to_raw()
446 }
447 fn from_raw(raw: Self::Raw) -> Self {
448 let t = <u16>::from_raw(raw);
449 Self::from_bits_truncate(t)
450 }
451}