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.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 Ok(Self { data })
34 }
35}
36
37#[derive(Clone)]
39pub struct Gasp<'a> {
40 data: FontData<'a>,
41}
42
43#[allow(clippy::needless_lifetimes)]
44impl<'a> Gasp<'a> {
45 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
46 basic_table_impls!(impl_the_methods);
47
48 pub fn version(&self) -> u16 {
50 let range = self.version_byte_range();
51 self.data.read_at(range.start).ok().unwrap()
52 }
53
54 pub fn num_ranges(&self) -> u16 {
56 let range = self.num_ranges_byte_range();
57 self.data.read_at(range.start).ok().unwrap()
58 }
59
60 pub fn gasp_ranges(&self) -> &'a [GaspRange] {
62 let range = self.gasp_ranges_byte_range();
63 self.data.read_array(range).ok().unwrap_or_default()
64 }
65
66 pub fn version_byte_range(&self) -> Range<usize> {
67 let start = 0;
68 let end = start + u16::RAW_BYTE_LEN;
69 start..end
70 }
71
72 pub fn num_ranges_byte_range(&self) -> Range<usize> {
73 let start = self.version_byte_range().end;
74 let end = start + u16::RAW_BYTE_LEN;
75 start..end
76 }
77
78 pub fn gasp_ranges_byte_range(&self) -> Range<usize> {
79 let num_ranges = self.num_ranges();
80 let start = self.num_ranges_byte_range().end;
81 let end =
82 start + (transforms::to_usize(num_ranges)).saturating_mul(GaspRange::RAW_BYTE_LEN);
83 start..end
84 }
85}
86
87const _: () = assert!(FontData::default_data_long_enough(Gasp::MIN_SIZE));
88
89impl Default for Gasp<'_> {
90 fn default() -> Self {
91 Self {
92 data: FontData::default_table_data(),
93 }
94 }
95}
96
97#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
98#[repr(C)]
99#[repr(packed)]
100pub struct GaspRange {
101 pub range_max_ppem: BigEndian<u16>,
103 pub range_gasp_behavior: BigEndian<GaspRangeBehavior>,
105}
106
107impl GaspRange {
108 pub fn range_max_ppem(&self) -> u16 {
110 self.range_max_ppem.get()
111 }
112
113 pub fn range_gasp_behavior(&self) -> GaspRangeBehavior {
115 self.range_gasp_behavior.get()
116 }
117}
118
119impl FixedSize for GaspRange {
120 const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + GaspRangeBehavior::RAW_BYTE_LEN;
121}
122
123#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
124#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
125#[repr(transparent)]
126pub struct GaspRangeBehavior {
127 bits: u16,
128}
129
130impl GaspRangeBehavior {
131 pub const GASP_GRIDFIT: Self = Self { bits: 0x0001 };
133
134 pub const GASP_DOGRAY: Self = Self { bits: 0x0002 };
136
137 pub const GASP_SYMMETRIC_GRIDFIT: Self = Self { bits: 0x0004 };
140
141 pub const GASP_SYMMETRIC_SMOOTHING: Self = Self { bits: 0x0008 };
144}
145
146impl GaspRangeBehavior {
147 #[inline]
149 pub const fn empty() -> Self {
150 Self { bits: 0 }
151 }
152
153 #[inline]
155 pub const fn all() -> Self {
156 Self {
157 bits: Self::GASP_GRIDFIT.bits
158 | Self::GASP_DOGRAY.bits
159 | Self::GASP_SYMMETRIC_GRIDFIT.bits
160 | Self::GASP_SYMMETRIC_SMOOTHING.bits,
161 }
162 }
163
164 #[inline]
166 pub const fn bits(&self) -> u16 {
167 self.bits
168 }
169
170 #[inline]
173 pub const fn from_bits(bits: u16) -> Option<Self> {
174 if (bits & !Self::all().bits()) == 0 {
175 Some(Self { bits })
176 } else {
177 None
178 }
179 }
180
181 #[inline]
184 pub const fn from_bits_truncate(bits: u16) -> Self {
185 Self {
186 bits: bits & Self::all().bits,
187 }
188 }
189
190 #[inline]
192 pub const fn is_empty(&self) -> bool {
193 self.bits() == Self::empty().bits()
194 }
195
196 #[inline]
198 pub const fn intersects(&self, other: Self) -> bool {
199 !(Self {
200 bits: self.bits & other.bits,
201 })
202 .is_empty()
203 }
204
205 #[inline]
207 pub const fn contains(&self, other: Self) -> bool {
208 (self.bits & other.bits) == other.bits
209 }
210
211 #[inline]
213 pub fn insert(&mut self, other: Self) {
214 self.bits |= other.bits;
215 }
216
217 #[inline]
219 pub fn remove(&mut self, other: Self) {
220 self.bits &= !other.bits;
221 }
222
223 #[inline]
225 pub fn toggle(&mut self, other: Self) {
226 self.bits ^= other.bits;
227 }
228
229 #[inline]
240 #[must_use]
241 pub const fn intersection(self, other: Self) -> Self {
242 Self {
243 bits: self.bits & other.bits,
244 }
245 }
246
247 #[inline]
258 #[must_use]
259 pub const fn union(self, other: Self) -> Self {
260 Self {
261 bits: self.bits | other.bits,
262 }
263 }
264
265 #[inline]
278 #[must_use]
279 pub const fn difference(self, other: Self) -> Self {
280 Self {
281 bits: self.bits & !other.bits,
282 }
283 }
284}
285
286impl std::ops::BitOr for GaspRangeBehavior {
287 type Output = Self;
288
289 #[inline]
291 fn bitor(self, other: GaspRangeBehavior) -> Self {
292 Self {
293 bits: self.bits | other.bits,
294 }
295 }
296}
297
298impl std::ops::BitOrAssign for GaspRangeBehavior {
299 #[inline]
301 fn bitor_assign(&mut self, other: Self) {
302 self.bits |= other.bits;
303 }
304}
305
306impl std::ops::BitXor for GaspRangeBehavior {
307 type Output = Self;
308
309 #[inline]
311 fn bitxor(self, other: Self) -> Self {
312 Self {
313 bits: self.bits ^ other.bits,
314 }
315 }
316}
317
318impl std::ops::BitXorAssign for GaspRangeBehavior {
319 #[inline]
321 fn bitxor_assign(&mut self, other: Self) {
322 self.bits ^= other.bits;
323 }
324}
325
326impl std::ops::BitAnd for GaspRangeBehavior {
327 type Output = Self;
328
329 #[inline]
331 fn bitand(self, other: Self) -> Self {
332 Self {
333 bits: self.bits & other.bits,
334 }
335 }
336}
337
338impl std::ops::BitAndAssign for GaspRangeBehavior {
339 #[inline]
341 fn bitand_assign(&mut self, other: Self) {
342 self.bits &= other.bits;
343 }
344}
345
346impl std::ops::Sub for GaspRangeBehavior {
347 type Output = Self;
348
349 #[inline]
351 fn sub(self, other: Self) -> Self {
352 Self {
353 bits: self.bits & !other.bits,
354 }
355 }
356}
357
358impl std::ops::SubAssign for GaspRangeBehavior {
359 #[inline]
361 fn sub_assign(&mut self, other: Self) {
362 self.bits &= !other.bits;
363 }
364}
365
366impl std::ops::Not for GaspRangeBehavior {
367 type Output = Self;
368
369 #[inline]
371 fn not(self) -> Self {
372 Self { bits: !self.bits } & Self::all()
373 }
374}
375
376impl std::fmt::Debug for GaspRangeBehavior {
377 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
378 let members: &[(&str, Self)] = &[
379 ("GASP_GRIDFIT", Self::GASP_GRIDFIT),
380 ("GASP_DOGRAY", Self::GASP_DOGRAY),
381 ("GASP_SYMMETRIC_GRIDFIT", Self::GASP_SYMMETRIC_GRIDFIT),
382 ("GASP_SYMMETRIC_SMOOTHING", Self::GASP_SYMMETRIC_SMOOTHING),
383 ];
384 let mut first = true;
385 for (name, value) in members {
386 if self.contains(*value) {
387 if !first {
388 f.write_str(" | ")?;
389 }
390 first = false;
391 f.write_str(name)?;
392 }
393 }
394 if first {
395 f.write_str("(empty)")?;
396 }
397 Ok(())
398 }
399}
400
401impl std::fmt::Binary for GaspRangeBehavior {
402 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
403 std::fmt::Binary::fmt(&self.bits, f)
404 }
405}
406
407impl std::fmt::Octal for GaspRangeBehavior {
408 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
409 std::fmt::Octal::fmt(&self.bits, f)
410 }
411}
412
413impl std::fmt::LowerHex for GaspRangeBehavior {
414 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
415 std::fmt::LowerHex::fmt(&self.bits, f)
416 }
417}
418
419impl std::fmt::UpperHex for GaspRangeBehavior {
420 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
421 std::fmt::UpperHex::fmt(&self.bits, f)
422 }
423}
424
425impl font_types::Scalar for GaspRangeBehavior {
426 type Raw = <u16 as font_types::Scalar>::Raw;
427 fn to_raw(self) -> Self::Raw {
428 self.bits().to_raw()
429 }
430 fn from_raw(raw: Self::Raw) -> Self {
431 let t = <u16>::from_raw(raw);
432 Self::from_bits_truncate(t)
433 }
434}