/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.47.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 = 0usize; |
84 | 0 | let end = start.saturating_add(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.saturating_add(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 = start.saturating_add( |
98 | 0 | (transforms::to_usize(num_ranges)).saturating_mul(GaspRange::RAW_BYTE_LEN), |
99 | | ); |
100 | 0 | start..end |
101 | 0 | } |
102 | | } |
103 | | |
104 | | const _: () = assert!(FontData::default_data_long_enough(Gasp::MIN_SIZE)); |
105 | | |
106 | | impl Default for Gasp<'_> { |
107 | 0 | fn default() -> Self { |
108 | | Self { |
109 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
110 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
111 | | } |
112 | 0 | } |
113 | | } |
114 | | |
115 | | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)] |
116 | | #[repr(C)] |
117 | | #[repr(packed)] |
118 | | pub struct GaspRange { |
119 | | /// Upper limit of range, in PPEM |
120 | | pub range_max_ppem: BigEndian<u16>, |
121 | | /// Flags describing desired rasterizer behavior. |
122 | | pub range_gasp_behavior: BigEndian<GaspRangeBehavior>, |
123 | | } |
124 | | |
125 | | impl GaspRange { |
126 | | /// Upper limit of range, in PPEM |
127 | 0 | pub fn range_max_ppem(&self) -> u16 { |
128 | 0 | self.range_max_ppem.get() |
129 | 0 | } |
130 | | |
131 | | /// Flags describing desired rasterizer behavior. |
132 | 0 | pub fn range_gasp_behavior(&self) -> GaspRangeBehavior { |
133 | 0 | self.range_gasp_behavior.get() |
134 | 0 | } |
135 | | } |
136 | | |
137 | | impl FixedSize for GaspRange { |
138 | | const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + GaspRangeBehavior::RAW_BYTE_LEN; |
139 | | } |
140 | | |
141 | | #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)] |
142 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
143 | | #[repr(transparent)] |
144 | | pub struct GaspRangeBehavior { |
145 | | bits: u16, |
146 | | } |
147 | | |
148 | | impl GaspRangeBehavior { |
149 | | /// Use gridfitting |
150 | | pub const GASP_GRIDFIT: Self = Self { bits: 0x0001 }; |
151 | | |
152 | | /// Use grayscale rendering |
153 | | pub const GASP_DOGRAY: Self = Self { bits: 0x0002 }; |
154 | | |
155 | | /// Use gridfitting with ClearType symmetric smoothing Only |
156 | | /// supported in version 1 'gasp' |
157 | | pub const GASP_SYMMETRIC_GRIDFIT: Self = Self { bits: 0x0004 }; |
158 | | |
159 | | /// Use smoothing along multiple axes with ClearType® Only |
160 | | /// supported in version 1 'gasp' |
161 | | pub const GASP_SYMMETRIC_SMOOTHING: Self = Self { bits: 0x0008 }; |
162 | | } |
163 | | |
164 | | impl GaspRangeBehavior { |
165 | | /// Returns an empty set of flags. |
166 | | #[inline] |
167 | 0 | pub const fn empty() -> Self { |
168 | 0 | Self { bits: 0 } |
169 | 0 | } |
170 | | |
171 | | /// Returns the set containing all flags. |
172 | | #[inline] |
173 | 0 | pub const fn all() -> Self { |
174 | 0 | Self { |
175 | 0 | bits: Self::GASP_GRIDFIT.bits |
176 | 0 | | Self::GASP_DOGRAY.bits |
177 | 0 | | Self::GASP_SYMMETRIC_GRIDFIT.bits |
178 | 0 | | Self::GASP_SYMMETRIC_SMOOTHING.bits, |
179 | 0 | } |
180 | 0 | } |
181 | | |
182 | | /// Returns the raw value of the flags currently stored. |
183 | | #[inline] |
184 | 0 | pub const fn bits(&self) -> u16 { |
185 | 0 | self.bits |
186 | 0 | } |
187 | | |
188 | | /// Convert from underlying bit representation, unless that |
189 | | /// representation contains bits that do not correspond to a flag. |
190 | | #[inline] |
191 | 0 | pub const fn from_bits(bits: u16) -> Option<Self> { |
192 | 0 | if (bits & !Self::all().bits()) == 0 { |
193 | 0 | Some(Self { bits }) |
194 | | } else { |
195 | 0 | None |
196 | | } |
197 | 0 | } |
198 | | |
199 | | /// Convert from underlying bit representation, dropping any bits |
200 | | /// that do not correspond to flags. |
201 | | #[inline] |
202 | 0 | pub const fn from_bits_truncate(bits: u16) -> Self { |
203 | 0 | Self { |
204 | 0 | bits: bits & Self::all().bits, |
205 | 0 | } |
206 | 0 | } |
207 | | |
208 | | /// Returns `true` if no flags are currently stored. |
209 | | #[inline] |
210 | 0 | pub const fn is_empty(&self) -> bool { |
211 | 0 | self.bits() == Self::empty().bits() |
212 | 0 | } |
213 | | |
214 | | /// Returns `true` if there are flags common to both `self` and `other`. |
215 | | #[inline] |
216 | 0 | pub const fn intersects(&self, other: Self) -> bool { |
217 | 0 | !(Self { |
218 | 0 | bits: self.bits & other.bits, |
219 | 0 | }) |
220 | 0 | .is_empty() |
221 | 0 | } |
222 | | |
223 | | /// Returns `true` if all of the flags in `other` are contained within `self`. |
224 | | #[inline] |
225 | 0 | pub const fn contains(&self, other: Self) -> bool { |
226 | 0 | (self.bits & other.bits) == other.bits |
227 | 0 | } |
228 | | |
229 | | /// Inserts the specified flags in-place. |
230 | | #[inline] |
231 | 0 | pub fn insert(&mut self, other: Self) { |
232 | 0 | self.bits |= other.bits; |
233 | 0 | } |
234 | | |
235 | | /// Removes the specified flags in-place. |
236 | | #[inline] |
237 | 0 | pub fn remove(&mut self, other: Self) { |
238 | 0 | self.bits &= !other.bits; |
239 | 0 | } |
240 | | |
241 | | /// Toggles the specified flags in-place. |
242 | | #[inline] |
243 | 0 | pub fn toggle(&mut self, other: Self) { |
244 | 0 | self.bits ^= other.bits; |
245 | 0 | } |
246 | | |
247 | | /// Returns the intersection between the flags in `self` and |
248 | | /// `other`. |
249 | | /// |
250 | | /// Specifically, the returned set contains only the flags which are |
251 | | /// present in *both* `self` *and* `other`. |
252 | | /// |
253 | | /// This is equivalent to using the `&` operator (e.g. |
254 | | /// [`ops::BitAnd`]), as in `flags & other`. |
255 | | /// |
256 | | /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html |
257 | | #[inline] |
258 | | #[must_use] |
259 | 0 | pub const fn intersection(self, other: Self) -> Self { |
260 | 0 | Self { |
261 | 0 | bits: self.bits & other.bits, |
262 | 0 | } |
263 | 0 | } |
264 | | |
265 | | /// Returns the union of between the flags in `self` and `other`. |
266 | | /// |
267 | | /// Specifically, the returned set contains all flags which are |
268 | | /// present in *either* `self` *or* `other`, including any which are |
269 | | /// present in both. |
270 | | /// |
271 | | /// This is equivalent to using the `|` operator (e.g. |
272 | | /// [`ops::BitOr`]), as in `flags | other`. |
273 | | /// |
274 | | /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html |
275 | | #[inline] |
276 | | #[must_use] |
277 | 0 | pub const fn union(self, other: Self) -> Self { |
278 | 0 | Self { |
279 | 0 | bits: self.bits | other.bits, |
280 | 0 | } |
281 | 0 | } |
282 | | |
283 | | /// Returns the difference between the flags in `self` and `other`. |
284 | | /// |
285 | | /// Specifically, the returned set contains all flags present in |
286 | | /// `self`, except for the ones present in `other`. |
287 | | /// |
288 | | /// It is also conceptually equivalent to the "bit-clear" operation: |
289 | | /// `flags & !other` (and this syntax is also supported). |
290 | | /// |
291 | | /// This is equivalent to using the `-` operator (e.g. |
292 | | /// [`ops::Sub`]), as in `flags - other`. |
293 | | /// |
294 | | /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html |
295 | | #[inline] |
296 | | #[must_use] |
297 | 0 | pub const fn difference(self, other: Self) -> Self { |
298 | 0 | Self { |
299 | 0 | bits: self.bits & !other.bits, |
300 | 0 | } |
301 | 0 | } |
302 | | } |
303 | | |
304 | | impl std::ops::BitOr for GaspRangeBehavior { |
305 | | type Output = Self; |
306 | | |
307 | | /// Returns the union of the two sets of flags. |
308 | | #[inline] |
309 | 0 | fn bitor(self, other: GaspRangeBehavior) -> Self { |
310 | 0 | Self { |
311 | 0 | bits: self.bits | other.bits, |
312 | 0 | } |
313 | 0 | } |
314 | | } |
315 | | |
316 | | impl std::ops::BitOrAssign for GaspRangeBehavior { |
317 | | /// Adds the set of flags. |
318 | | #[inline] |
319 | 0 | fn bitor_assign(&mut self, other: Self) { |
320 | 0 | self.bits |= other.bits; |
321 | 0 | } |
322 | | } |
323 | | |
324 | | impl std::ops::BitXor for GaspRangeBehavior { |
325 | | type Output = Self; |
326 | | |
327 | | /// Returns the left flags, but with all the right flags toggled. |
328 | | #[inline] |
329 | 0 | fn bitxor(self, other: Self) -> Self { |
330 | 0 | Self { |
331 | 0 | bits: self.bits ^ other.bits, |
332 | 0 | } |
333 | 0 | } |
334 | | } |
335 | | |
336 | | impl std::ops::BitXorAssign for GaspRangeBehavior { |
337 | | /// Toggles the set of flags. |
338 | | #[inline] |
339 | 0 | fn bitxor_assign(&mut self, other: Self) { |
340 | 0 | self.bits ^= other.bits; |
341 | 0 | } |
342 | | } |
343 | | |
344 | | impl std::ops::BitAnd for GaspRangeBehavior { |
345 | | type Output = Self; |
346 | | |
347 | | /// Returns the intersection between the two sets of flags. |
348 | | #[inline] |
349 | 0 | fn bitand(self, other: Self) -> Self { |
350 | 0 | Self { |
351 | 0 | bits: self.bits & other.bits, |
352 | 0 | } |
353 | 0 | } |
354 | | } |
355 | | |
356 | | impl std::ops::BitAndAssign for GaspRangeBehavior { |
357 | | /// Disables all flags disabled in the set. |
358 | | #[inline] |
359 | 0 | fn bitand_assign(&mut self, other: Self) { |
360 | 0 | self.bits &= other.bits; |
361 | 0 | } |
362 | | } |
363 | | |
364 | | impl std::ops::Sub for GaspRangeBehavior { |
365 | | type Output = Self; |
366 | | |
367 | | /// Returns the set difference of the two sets of flags. |
368 | | #[inline] |
369 | 0 | fn sub(self, other: Self) -> Self { |
370 | 0 | Self { |
371 | 0 | bits: self.bits & !other.bits, |
372 | 0 | } |
373 | 0 | } |
374 | | } |
375 | | |
376 | | impl std::ops::SubAssign for GaspRangeBehavior { |
377 | | /// Disables all flags enabled in the set. |
378 | | #[inline] |
379 | 0 | fn sub_assign(&mut self, other: Self) { |
380 | 0 | self.bits &= !other.bits; |
381 | 0 | } |
382 | | } |
383 | | |
384 | | impl std::ops::Not for GaspRangeBehavior { |
385 | | type Output = Self; |
386 | | |
387 | | /// Returns the complement of this set of flags. |
388 | | #[inline] |
389 | 0 | fn not(self) -> Self { |
390 | 0 | Self { bits: !self.bits } & Self::all() |
391 | 0 | } |
392 | | } |
393 | | |
394 | | impl std::fmt::Debug for GaspRangeBehavior { |
395 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
396 | 0 | let members: &[(&str, Self)] = &[ |
397 | 0 | ("GASP_GRIDFIT", Self::GASP_GRIDFIT), |
398 | 0 | ("GASP_DOGRAY", Self::GASP_DOGRAY), |
399 | 0 | ("GASP_SYMMETRIC_GRIDFIT", Self::GASP_SYMMETRIC_GRIDFIT), |
400 | 0 | ("GASP_SYMMETRIC_SMOOTHING", Self::GASP_SYMMETRIC_SMOOTHING), |
401 | 0 | ]; |
402 | 0 | let mut first = true; |
403 | 0 | for (name, value) in members { |
404 | 0 | if self.contains(*value) { |
405 | 0 | if !first { |
406 | 0 | f.write_str(" | ")?; |
407 | 0 | } |
408 | 0 | first = false; |
409 | 0 | f.write_str(name)?; |
410 | 0 | } |
411 | | } |
412 | 0 | if first { |
413 | 0 | f.write_str("(empty)")?; |
414 | 0 | } |
415 | 0 | Ok(()) |
416 | 0 | } |
417 | | } |
418 | | |
419 | | impl std::fmt::Binary for GaspRangeBehavior { |
420 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
421 | 0 | std::fmt::Binary::fmt(&self.bits, f) |
422 | 0 | } |
423 | | } |
424 | | |
425 | | impl std::fmt::Octal for GaspRangeBehavior { |
426 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
427 | 0 | std::fmt::Octal::fmt(&self.bits, f) |
428 | 0 | } |
429 | | } |
430 | | |
431 | | impl std::fmt::LowerHex for GaspRangeBehavior { |
432 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
433 | 0 | std::fmt::LowerHex::fmt(&self.bits, f) |
434 | 0 | } |
435 | | } |
436 | | |
437 | | impl std::fmt::UpperHex for GaspRangeBehavior { |
438 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
439 | 0 | std::fmt::UpperHex::fmt(&self.bits, f) |
440 | 0 | } |
441 | | } |
442 | | |
443 | | impl font_types::Scalar for GaspRangeBehavior { |
444 | | type Raw = <u16 as font_types::Scalar>::Raw; |
445 | 0 | fn to_raw(self) -> Self::Raw { |
446 | 0 | self.bits().to_raw() |
447 | 0 | } |
448 | 0 | fn from_raw(raw: Self::Raw) -> Self { |
449 | 0 | let t = <u16>::from_raw(raw); |
450 | 0 | Self::from_bits_truncate(t) |
451 | 0 | } |
452 | | } |