/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.47.0/generated/generated_gpos.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 Gpos<'a> { |
9 | 0 | fn min_byte_range(&self) -> Range<usize> { |
10 | 0 | 0..self.lookup_list_offset_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 Gpos<'_> { |
19 | | /// `GPOS` |
20 | | const TAG: Tag = Tag::new(b"GPOS"); |
21 | | } |
22 | | |
23 | | impl ReadArgs for Gpos<'_> { |
24 | | type Args = (); |
25 | | } |
26 | | |
27 | | impl<'a> FontRead<'a> for Gpos<'a> { |
28 | 112k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
29 | | #[allow(clippy::absurd_extreme_comparisons)] |
30 | 112k | if data.len() < Self::MIN_SIZE { |
31 | 13 | return Err(ReadError::OutOfBounds); |
32 | 112k | } |
33 | 112k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
34 | 0 | return Err(ReadError::OutOfBounds); |
35 | | }; |
36 | 112k | Ok(Self { data }) |
37 | 112k | } |
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 GposFixedHeader { |
45 | | pub version: BigEndian<MajorMinor>, |
46 | | pub script_list_offset: BigEndian<Nullable<Offset16>>, |
47 | | pub feature_list_offset: BigEndian<Nullable<Offset16>>, |
48 | | pub lookup_list_offset: BigEndian<Nullable<Offset16>>, |
49 | | } |
50 | | |
51 | | #[allow(clippy::absurd_extreme_comparisons)] |
52 | | const _: () = assert!(std::mem::size_of::<GposFixedHeader>() <= Gpos::MIN_SIZE); |
53 | | |
54 | | /// [Class Definition Table Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table-format-1) |
55 | | /// [GPOS Version 1.0](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#gpos-header) |
56 | | #[derive(Clone)] |
57 | | pub struct Gpos<'a> { |
58 | | data: TableDataRef<'a, GposFixedHeader>, |
59 | | } |
60 | | |
61 | | #[allow(clippy::needless_lifetimes)] |
62 | | impl<'a> Gpos<'a> { |
63 | | pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN |
64 | | + Offset16::RAW_BYTE_LEN |
65 | | + Offset16::RAW_BYTE_LEN |
66 | | + Offset16::RAW_BYTE_LEN); |
67 | | basic_table_impls!(impl_the_methods); |
68 | | |
69 | | /// The major and minor version of the GPOS table, as a tuple (u16, u16) |
70 | 866k | pub fn version(&self) -> MajorMinor { |
71 | 866k | self.data.header().version.get() |
72 | 866k | } |
73 | | |
74 | | /// Offset to ScriptList table, from beginning of GPOS table |
75 | 50.0k | pub fn script_list_offset(&self) -> Nullable<Offset16> { |
76 | 50.0k | self.data.header().script_list_offset.get() |
77 | 50.0k | } |
78 | | |
79 | | /// Offset to FeatureList table, from beginning of GPOS table |
80 | 36.8k | pub fn feature_list_offset(&self) -> Nullable<Offset16> { |
81 | 36.8k | self.data.header().feature_list_offset.get() |
82 | 36.8k | } |
83 | | |
84 | | /// Offset to LookupList table, from beginning of GPOS table |
85 | 112k | pub fn lookup_list_offset(&self) -> Nullable<Offset16> { |
86 | 112k | self.data.header().lookup_list_offset.get() |
87 | 112k | } |
88 | | |
89 | 6.97k | pub fn feature_variations_offset(&self) -> Option<Nullable<Offset32>> { |
90 | 6.97k | let range = self.feature_variations_offset_byte_range(); |
91 | 6.97k | (!range.is_empty()) |
92 | 6.97k | .then(|| self.offset_data().read_at(range.start).ok()) |
93 | 6.97k | .flatten() |
94 | 6.97k | } |
95 | | |
96 | | /// Attempt to resolve [`feature_variations_offset`][Self::feature_variations_offset]. |
97 | 6.97k | pub fn feature_variations(&self) -> Option<Result<FeatureVariations<'a>, ReadError>> { |
98 | 6.97k | let data = self.offset_data(); |
99 | 6.97k | self.feature_variations_offset().map(|x| x.resolve(data))? |
100 | 6.97k | } |
101 | | |
102 | | /// 32-bit offset to ScriptList, taking precedence when nonzero. |
103 | 50.0k | pub fn script_list2_offset(&self) -> Option<Nullable<Offset32>> { |
104 | 50.0k | let range = self.script_list2_offset_byte_range(); |
105 | 50.0k | (!range.is_empty()) |
106 | 50.0k | .then(|| self.offset_data().read_at(range.start).ok()) |
107 | 50.0k | .flatten() |
108 | 50.0k | } |
109 | | |
110 | | /// Attempt to resolve [`script_list2_offset`][Self::script_list2_offset]. |
111 | 0 | pub fn script_list2(&self) -> Option<Result<ScriptList<'a>, ReadError>> { |
112 | 0 | let data = self.offset_data(); |
113 | 0 | self.script_list2_offset().map(|x| x.resolve(data))? |
114 | 0 | } |
115 | | |
116 | | /// 32-bit offset to FeatureList, taking precedence when nonzero. |
117 | 36.8k | pub fn feature_list2_offset(&self) -> Option<Nullable<Offset32>> { |
118 | 36.8k | let range = self.feature_list2_offset_byte_range(); |
119 | 36.8k | (!range.is_empty()) |
120 | 36.8k | .then(|| self.offset_data().read_at(range.start).ok()) |
121 | 36.8k | .flatten() |
122 | 36.8k | } |
123 | | |
124 | | /// Attempt to resolve [`feature_list2_offset`][Self::feature_list2_offset]. |
125 | 0 | pub fn feature_list2(&self) -> Option<Result<FeatureList<'a>, ReadError>> { |
126 | 0 | let data = self.offset_data(); |
127 | 0 | self.feature_list2_offset().map(|x| x.resolve(data))? |
128 | 0 | } |
129 | | |
130 | | /// 32-bit offset to LookupList2, taking precedence when nonzero. |
131 | 112k | pub fn lookup_list2_offset(&self) -> Option<Nullable<Offset32>> { |
132 | 112k | let range = self.lookup_list2_offset_byte_range(); |
133 | 112k | (!range.is_empty()) |
134 | 112k | .then(|| self.offset_data().read_at(range.start).ok()) |
135 | 112k | .flatten() |
136 | 112k | } |
137 | | |
138 | | /// Attempt to resolve [`lookup_list2_offset`][Self::lookup_list2_offset]. |
139 | 0 | pub fn lookup_list2(&self) -> Option<Result<PositionLookupList2<'a>, ReadError>> { |
140 | 0 | let data = self.offset_data(); |
141 | 0 | self.lookup_list2_offset().map(|x| x.resolve(data))? |
142 | 0 | } |
143 | | |
144 | 206k | pub fn version_byte_range(&self) -> Range<usize> { |
145 | 206k | let start = 0usize; |
146 | 206k | let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN); |
147 | 206k | start..end |
148 | 206k | } |
149 | | |
150 | 206k | pub fn script_list_offset_byte_range(&self) -> Range<usize> { |
151 | 206k | let start = self.version_byte_range().end; |
152 | 206k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
153 | 206k | start..end |
154 | 206k | } |
155 | | |
156 | 206k | pub fn feature_list_offset_byte_range(&self) -> Range<usize> { |
157 | 206k | let start = self.script_list_offset_byte_range().end; |
158 | 206k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
159 | 206k | start..end |
160 | 206k | } |
161 | | |
162 | 206k | pub fn lookup_list_offset_byte_range(&self) -> Range<usize> { |
163 | 206k | let start = self.feature_list_offset_byte_range().end; |
164 | 206k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
165 | 206k | start..end |
166 | 206k | } |
167 | | |
168 | 206k | pub fn feature_variations_offset_byte_range(&self) -> Range<usize> { |
169 | 206k | let start = self.lookup_list_offset_byte_range().end; |
170 | 206k | let end = if self.version().compatible((1u16, 1u16)) { |
171 | 1.92k | start.saturating_add(Offset32::RAW_BYTE_LEN) |
172 | | } else { |
173 | 204k | start |
174 | | }; |
175 | 206k | start..end |
176 | 206k | } |
177 | | |
178 | 199k | pub fn script_list2_offset_byte_range(&self) -> Range<usize> { |
179 | 199k | let start = self.feature_variations_offset_byte_range().end; |
180 | 199k | let end = if self.version().compatible((1u16, 2u16)) { |
181 | 1.15k | start.saturating_add(Offset32::RAW_BYTE_LEN) |
182 | | } else { |
183 | 198k | start |
184 | | }; |
185 | 199k | start..end |
186 | 199k | } |
187 | | |
188 | 149k | pub fn feature_list2_offset_byte_range(&self) -> Range<usize> { |
189 | 149k | let start = self.script_list2_offset_byte_range().end; |
190 | 149k | let end = if self.version().compatible((1u16, 2u16)) { |
191 | 627 | start.saturating_add(Offset32::RAW_BYTE_LEN) |
192 | | } else { |
193 | 148k | start |
194 | | }; |
195 | 149k | start..end |
196 | 149k | } |
197 | | |
198 | 112k | pub fn lookup_list2_offset_byte_range(&self) -> Range<usize> { |
199 | 112k | let start = self.feature_list2_offset_byte_range().end; |
200 | 112k | let end = if self.version().compatible((1u16, 2u16)) { |
201 | 562 | start.saturating_add(Offset32::RAW_BYTE_LEN) |
202 | | } else { |
203 | 111k | start |
204 | | }; |
205 | 112k | start..end |
206 | 112k | } |
207 | | } |
208 | | |
209 | | const _: () = assert!(FontData::default_data_long_enough(Gpos::MIN_SIZE)); |
210 | | |
211 | | impl Default for Gpos<'_> { |
212 | 0 | fn default() -> Self { |
213 | | Self { |
214 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
215 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
216 | | } |
217 | 0 | } |
218 | | } |
219 | | |
220 | | /// A [GPOS Lookup](https://learn.microsoft.com/en-us/typography/opentype/spec/gpos#gsubLookupTypeEnum) subtable. |
221 | | pub enum PositionLookup<'a> { |
222 | | Single(Lookup<'a, SinglePos<'a>>), |
223 | | Pair(Lookup<'a, PairPos<'a>>), |
224 | | Cursive(Lookup<'a, CursivePos<'a>>), |
225 | | MarkToBase(Lookup<'a, MarkBasePos<'a>>), |
226 | | MarkToLig(Lookup<'a, MarkLigPos<'a>>), |
227 | | MarkToMark(Lookup<'a, MarkMarkPos<'a>>), |
228 | | Contextual(Lookup<'a, PositionSequenceContext<'a>>), |
229 | | ChainContextual(Lookup<'a, PositionChainContext<'a>>), |
230 | | Extension(Lookup<'a, ExtensionSubtable<'a>>), |
231 | | } |
232 | | |
233 | | impl Default for PositionLookup<'_> { |
234 | 0 | fn default() -> Self { |
235 | 0 | Self::Single(Default::default()) |
236 | 0 | } |
237 | | } |
238 | | |
239 | | impl ReadArgs for PositionLookup<'_> { |
240 | | type Args = (); |
241 | | } |
242 | | |
243 | | impl<'a> FontRead<'a> for PositionLookup<'a> { |
244 | 0 | fn read_with_args(bytes: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
245 | 0 | let discriminant = Lookup::read_discriminant(bytes)?; |
246 | 0 | match discriminant { |
247 | 0 | 1 => Ok(PositionLookup::Single(FontRead::read(bytes)?)), |
248 | 0 | 2 => Ok(PositionLookup::Pair(FontRead::read(bytes)?)), |
249 | 0 | 3 => Ok(PositionLookup::Cursive(FontRead::read(bytes)?)), |
250 | 0 | 4 => Ok(PositionLookup::MarkToBase(FontRead::read(bytes)?)), |
251 | 0 | 5 => Ok(PositionLookup::MarkToLig(FontRead::read(bytes)?)), |
252 | 0 | 6 => Ok(PositionLookup::MarkToMark(FontRead::read(bytes)?)), |
253 | 0 | 7 => Ok(PositionLookup::Contextual(FontRead::read(bytes)?)), |
254 | 0 | 8 => Ok(PositionLookup::ChainContextual(FontRead::read(bytes)?)), |
255 | 0 | 9 => Ok(PositionLookup::Extension(FontRead::read(bytes)?)), |
256 | 0 | other => Err(ReadError::InvalidFormat(other.into())), |
257 | | } |
258 | 0 | } |
259 | | } |
260 | | |
261 | | impl<'a> PositionLookup<'a> { |
262 | | #[allow(dead_code)] |
263 | | /// Return the inner table, removing the specific generics. |
264 | | /// |
265 | | /// This lets us return a single concrete type we can call methods on. |
266 | 0 | pub(crate) fn of_unit_type(&self) -> Lookup<'a, ()> { |
267 | 0 | match self { |
268 | 0 | PositionLookup::Single(inner) => inner.of_unit_type(), |
269 | 0 | PositionLookup::Pair(inner) => inner.of_unit_type(), |
270 | 0 | PositionLookup::Cursive(inner) => inner.of_unit_type(), |
271 | 0 | PositionLookup::MarkToBase(inner) => inner.of_unit_type(), |
272 | 0 | PositionLookup::MarkToLig(inner) => inner.of_unit_type(), |
273 | 0 | PositionLookup::MarkToMark(inner) => inner.of_unit_type(), |
274 | 0 | PositionLookup::Contextual(inner) => inner.of_unit_type(), |
275 | 0 | PositionLookup::ChainContextual(inner) => inner.of_unit_type(), |
276 | 0 | PositionLookup::Extension(inner) => inner.of_unit_type(), |
277 | | } |
278 | 0 | } |
279 | | } |
280 | | |
281 | | /// See [ValueRecord] |
282 | | #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)] |
283 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
284 | | #[repr(transparent)] |
285 | | pub struct ValueFormat { |
286 | | bits: u16, |
287 | | } |
288 | | |
289 | | impl ValueFormat { |
290 | | /// Includes horizontal adjustment for placement |
291 | | pub const X_PLACEMENT: Self = Self { bits: 0x0001 }; |
292 | | |
293 | | /// Includes vertical adjustment for placement |
294 | | pub const Y_PLACEMENT: Self = Self { bits: 0x0002 }; |
295 | | |
296 | | /// Includes horizontal adjustment for advance |
297 | | pub const X_ADVANCE: Self = Self { bits: 0x0004 }; |
298 | | |
299 | | /// Includes vertical adjustment for advance |
300 | | pub const Y_ADVANCE: Self = Self { bits: 0x0008 }; |
301 | | |
302 | | /// Includes Device table (non-variable font) / VariationIndex |
303 | | /// table (variable font) for horizontal placement |
304 | | pub const X_PLACEMENT_DEVICE: Self = Self { bits: 0x0010 }; |
305 | | |
306 | | /// Includes Device table (non-variable font) / VariationIndex |
307 | | /// table (variable font) for vertical placement |
308 | | pub const Y_PLACEMENT_DEVICE: Self = Self { bits: 0x0020 }; |
309 | | |
310 | | /// Includes Device table (non-variable font) / VariationIndex |
311 | | /// table (variable font) for horizontal advance |
312 | | pub const X_ADVANCE_DEVICE: Self = Self { bits: 0x0040 }; |
313 | | |
314 | | /// Includes Device table (non-variable font) / VariationIndex |
315 | | /// table (variable font) for vertical advance |
316 | | pub const Y_ADVANCE_DEVICE: Self = Self { bits: 0x0080 }; |
317 | | } |
318 | | |
319 | | impl ValueFormat { |
320 | | /// Returns an empty set of flags. |
321 | | #[inline] |
322 | 2.81M | pub const fn empty() -> Self { |
323 | 2.81M | Self { bits: 0 } |
324 | 2.81M | } <read_fonts::tables::gpos::ValueFormat>::empty Line | Count | Source | 322 | 2.81M | pub const fn empty() -> Self { | 323 | 2.81M | Self { bits: 0 } | 324 | 2.81M | } |
Unexecuted instantiation: <read_fonts::tables::gpos::ValueFormat>::empty |
325 | | |
326 | | /// Returns the set containing all flags. |
327 | | #[inline] |
328 | 1.42M | pub const fn all() -> Self { |
329 | 1.42M | Self { |
330 | 1.42M | bits: Self::X_PLACEMENT.bits |
331 | 1.42M | | Self::Y_PLACEMENT.bits |
332 | 1.42M | | Self::X_ADVANCE.bits |
333 | 1.42M | | Self::Y_ADVANCE.bits |
334 | 1.42M | | Self::X_PLACEMENT_DEVICE.bits |
335 | 1.42M | | Self::Y_PLACEMENT_DEVICE.bits |
336 | 1.42M | | Self::X_ADVANCE_DEVICE.bits |
337 | 1.42M | | Self::Y_ADVANCE_DEVICE.bits, |
338 | 1.42M | } |
339 | 1.42M | } |
340 | | |
341 | | /// Returns the raw value of the flags currently stored. |
342 | | #[inline] |
343 | 16.5M | pub const fn bits(&self) -> u16 { |
344 | 16.5M | self.bits |
345 | 16.5M | } <read_fonts::tables::gpos::ValueFormat>::bits Line | Count | Source | 343 | 15.6M | pub const fn bits(&self) -> u16 { | 344 | 15.6M | self.bits | 345 | 15.6M | } |
<read_fonts::tables::gpos::ValueFormat>::bits Line | Count | Source | 343 | 882k | pub const fn bits(&self) -> u16 { | 344 | 882k | self.bits | 345 | 882k | } |
|
346 | | |
347 | | /// Convert from underlying bit representation, unless that |
348 | | /// representation contains bits that do not correspond to a flag. |
349 | | #[inline] |
350 | 0 | pub const fn from_bits(bits: u16) -> Option<Self> { |
351 | 0 | if (bits & !Self::all().bits()) == 0 { |
352 | 0 | Some(Self { bits }) |
353 | | } else { |
354 | 0 | None |
355 | | } |
356 | 0 | } |
357 | | |
358 | | /// Convert from underlying bit representation, dropping any bits |
359 | | /// that do not correspond to flags. |
360 | | #[inline] |
361 | 1.42M | pub const fn from_bits_truncate(bits: u16) -> Self { |
362 | 1.42M | Self { |
363 | 1.42M | bits: bits & Self::all().bits, |
364 | 1.42M | } |
365 | 1.42M | } |
366 | | |
367 | | /// Returns `true` if no flags are currently stored. |
368 | | #[inline] |
369 | 2.81M | pub const fn is_empty(&self) -> bool { |
370 | 2.81M | self.bits() == Self::empty().bits() |
371 | 2.81M | } <read_fonts::tables::gpos::ValueFormat>::is_empty Line | Count | Source | 369 | 2.81M | pub const fn is_empty(&self) -> bool { | 370 | 2.81M | self.bits() == Self::empty().bits() | 371 | 2.81M | } |
Unexecuted instantiation: <read_fonts::tables::gpos::ValueFormat>::is_empty |
372 | | |
373 | | /// Returns `true` if there are flags common to both `self` and `other`. |
374 | | #[inline] |
375 | 1.37M | pub const fn intersects(&self, other: Self) -> bool { |
376 | 1.37M | !(Self { |
377 | 1.37M | bits: self.bits & other.bits, |
378 | 1.37M | }) |
379 | 1.37M | .is_empty() |
380 | 1.37M | } <read_fonts::tables::gpos::ValueFormat>::intersects Line | Count | Source | 375 | 1.37M | pub const fn intersects(&self, other: Self) -> bool { | 376 | 1.37M | !(Self { | 377 | 1.37M | bits: self.bits & other.bits, | 378 | 1.37M | }) | 379 | 1.37M | .is_empty() | 380 | 1.37M | } |
Unexecuted instantiation: <read_fonts::tables::gpos::ValueFormat>::intersects |
381 | | |
382 | | /// Returns `true` if all of the flags in `other` are contained within `self`. |
383 | | #[inline] |
384 | 5.48M | pub const fn contains(&self, other: Self) -> bool { |
385 | 5.48M | (self.bits & other.bits) == other.bits |
386 | 5.48M | } <read_fonts::tables::gpos::ValueFormat>::contains Line | Count | Source | 384 | 5.48M | pub const fn contains(&self, other: Self) -> bool { | 385 | 5.48M | (self.bits & other.bits) == other.bits | 386 | 5.48M | } |
Unexecuted instantiation: <read_fonts::tables::gpos::ValueFormat>::contains |
387 | | |
388 | | /// Inserts the specified flags in-place. |
389 | | #[inline] |
390 | 0 | pub fn insert(&mut self, other: Self) { |
391 | 0 | self.bits |= other.bits; |
392 | 0 | } |
393 | | |
394 | | /// Removes the specified flags in-place. |
395 | | #[inline] |
396 | 0 | pub fn remove(&mut self, other: Self) { |
397 | 0 | self.bits &= !other.bits; |
398 | 0 | } |
399 | | |
400 | | /// Toggles the specified flags in-place. |
401 | | #[inline] |
402 | 0 | pub fn toggle(&mut self, other: Self) { |
403 | 0 | self.bits ^= other.bits; |
404 | 0 | } |
405 | | |
406 | | /// Returns the intersection between the flags in `self` and |
407 | | /// `other`. |
408 | | /// |
409 | | /// Specifically, the returned set contains only the flags which are |
410 | | /// present in *both* `self` *and* `other`. |
411 | | /// |
412 | | /// This is equivalent to using the `&` operator (e.g. |
413 | | /// [`ops::BitAnd`]), as in `flags & other`. |
414 | | /// |
415 | | /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html |
416 | | #[inline] |
417 | | #[must_use] |
418 | 0 | pub const fn intersection(self, other: Self) -> Self { |
419 | 0 | Self { |
420 | 0 | bits: self.bits & other.bits, |
421 | 0 | } |
422 | 0 | } |
423 | | |
424 | | /// Returns the union of between the flags in `self` and `other`. |
425 | | /// |
426 | | /// Specifically, the returned set contains all flags which are |
427 | | /// present in *either* `self` *or* `other`, including any which are |
428 | | /// present in both. |
429 | | /// |
430 | | /// This is equivalent to using the `|` operator (e.g. |
431 | | /// [`ops::BitOr`]), as in `flags | other`. |
432 | | /// |
433 | | /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html |
434 | | #[inline] |
435 | | #[must_use] |
436 | 0 | pub const fn union(self, other: Self) -> Self { |
437 | 0 | Self { |
438 | 0 | bits: self.bits | other.bits, |
439 | 0 | } |
440 | 0 | } |
441 | | |
442 | | /// Returns the difference between the flags in `self` and `other`. |
443 | | /// |
444 | | /// Specifically, the returned set contains all flags present in |
445 | | /// `self`, except for the ones present in `other`. |
446 | | /// |
447 | | /// It is also conceptually equivalent to the "bit-clear" operation: |
448 | | /// `flags & !other` (and this syntax is also supported). |
449 | | /// |
450 | | /// This is equivalent to using the `-` operator (e.g. |
451 | | /// [`ops::Sub`]), as in `flags - other`. |
452 | | /// |
453 | | /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html |
454 | | #[inline] |
455 | | #[must_use] |
456 | 0 | pub const fn difference(self, other: Self) -> Self { |
457 | 0 | Self { |
458 | 0 | bits: self.bits & !other.bits, |
459 | 0 | } |
460 | 0 | } |
461 | | } |
462 | | |
463 | | impl std::ops::BitOr for ValueFormat { |
464 | | type Output = Self; |
465 | | |
466 | | /// Returns the union of the two sets of flags. |
467 | | #[inline] |
468 | 0 | fn bitor(self, other: ValueFormat) -> Self { |
469 | 0 | Self { |
470 | 0 | bits: self.bits | other.bits, |
471 | 0 | } |
472 | 0 | } |
473 | | } |
474 | | |
475 | | impl std::ops::BitOrAssign for ValueFormat { |
476 | | /// Adds the set of flags. |
477 | | #[inline] |
478 | 0 | fn bitor_assign(&mut self, other: Self) { |
479 | 0 | self.bits |= other.bits; |
480 | 0 | } |
481 | | } |
482 | | |
483 | | impl std::ops::BitXor for ValueFormat { |
484 | | type Output = Self; |
485 | | |
486 | | /// Returns the left flags, but with all the right flags toggled. |
487 | | #[inline] |
488 | 0 | fn bitxor(self, other: Self) -> Self { |
489 | 0 | Self { |
490 | 0 | bits: self.bits ^ other.bits, |
491 | 0 | } |
492 | 0 | } |
493 | | } |
494 | | |
495 | | impl std::ops::BitXorAssign for ValueFormat { |
496 | | /// Toggles the set of flags. |
497 | | #[inline] |
498 | 0 | fn bitxor_assign(&mut self, other: Self) { |
499 | 0 | self.bits ^= other.bits; |
500 | 0 | } |
501 | | } |
502 | | |
503 | | impl std::ops::BitAnd for ValueFormat { |
504 | | type Output = Self; |
505 | | |
506 | | /// Returns the intersection between the two sets of flags. |
507 | | #[inline] |
508 | 0 | fn bitand(self, other: Self) -> Self { |
509 | 0 | Self { |
510 | 0 | bits: self.bits & other.bits, |
511 | 0 | } |
512 | 0 | } |
513 | | } |
514 | | |
515 | | impl std::ops::BitAndAssign for ValueFormat { |
516 | | /// Disables all flags disabled in the set. |
517 | | #[inline] |
518 | 0 | fn bitand_assign(&mut self, other: Self) { |
519 | 0 | self.bits &= other.bits; |
520 | 0 | } |
521 | | } |
522 | | |
523 | | impl std::ops::Sub for ValueFormat { |
524 | | type Output = Self; |
525 | | |
526 | | /// Returns the set difference of the two sets of flags. |
527 | | #[inline] |
528 | 0 | fn sub(self, other: Self) -> Self { |
529 | 0 | Self { |
530 | 0 | bits: self.bits & !other.bits, |
531 | 0 | } |
532 | 0 | } |
533 | | } |
534 | | |
535 | | impl std::ops::SubAssign for ValueFormat { |
536 | | /// Disables all flags enabled in the set. |
537 | | #[inline] |
538 | 0 | fn sub_assign(&mut self, other: Self) { |
539 | 0 | self.bits &= !other.bits; |
540 | 0 | } |
541 | | } |
542 | | |
543 | | impl std::ops::Not for ValueFormat { |
544 | | type Output = Self; |
545 | | |
546 | | /// Returns the complement of this set of flags. |
547 | | #[inline] |
548 | 0 | fn not(self) -> Self { |
549 | 0 | Self { bits: !self.bits } & Self::all() |
550 | 0 | } |
551 | | } |
552 | | |
553 | | impl std::fmt::Debug for ValueFormat { |
554 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
555 | 0 | let members: &[(&str, Self)] = &[ |
556 | 0 | ("X_PLACEMENT", Self::X_PLACEMENT), |
557 | 0 | ("Y_PLACEMENT", Self::Y_PLACEMENT), |
558 | 0 | ("X_ADVANCE", Self::X_ADVANCE), |
559 | 0 | ("Y_ADVANCE", Self::Y_ADVANCE), |
560 | 0 | ("X_PLACEMENT_DEVICE", Self::X_PLACEMENT_DEVICE), |
561 | 0 | ("Y_PLACEMENT_DEVICE", Self::Y_PLACEMENT_DEVICE), |
562 | 0 | ("X_ADVANCE_DEVICE", Self::X_ADVANCE_DEVICE), |
563 | 0 | ("Y_ADVANCE_DEVICE", Self::Y_ADVANCE_DEVICE), |
564 | 0 | ]; |
565 | 0 | let mut first = true; |
566 | 0 | for (name, value) in members { |
567 | 0 | if self.contains(*value) { |
568 | 0 | if !first { |
569 | 0 | f.write_str(" | ")?; |
570 | 0 | } |
571 | 0 | first = false; |
572 | 0 | f.write_str(name)?; |
573 | 0 | } |
574 | | } |
575 | 0 | if first { |
576 | 0 | f.write_str("(empty)")?; |
577 | 0 | } |
578 | 0 | Ok(()) |
579 | 0 | } |
580 | | } |
581 | | |
582 | | impl std::fmt::Binary for ValueFormat { |
583 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
584 | 0 | std::fmt::Binary::fmt(&self.bits, f) |
585 | 0 | } |
586 | | } |
587 | | |
588 | | impl std::fmt::Octal for ValueFormat { |
589 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
590 | 0 | std::fmt::Octal::fmt(&self.bits, f) |
591 | 0 | } |
592 | | } |
593 | | |
594 | | impl std::fmt::LowerHex for ValueFormat { |
595 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
596 | 0 | std::fmt::LowerHex::fmt(&self.bits, f) |
597 | 0 | } |
598 | | } |
599 | | |
600 | | impl std::fmt::UpperHex for ValueFormat { |
601 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
602 | 0 | std::fmt::UpperHex::fmt(&self.bits, f) |
603 | 0 | } |
604 | | } |
605 | | |
606 | | impl font_types::Scalar for ValueFormat { |
607 | | type Raw = <u16 as font_types::Scalar>::Raw; |
608 | 0 | fn to_raw(self) -> Self::Raw { |
609 | 0 | self.bits().to_raw() |
610 | 0 | } |
611 | 1.42M | fn from_raw(raw: Self::Raw) -> Self { |
612 | 1.42M | let t = <u16>::from_raw(raw); |
613 | 1.42M | Self::from_bits_truncate(t) |
614 | 1.42M | } |
615 | | } |
616 | | |
617 | | /// [Anchor Tables](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#anchor-tables) |
618 | | /// position one glyph with respect to another. |
619 | | #[derive(Clone)] |
620 | | pub enum AnchorTable<'a> { |
621 | | Format1(AnchorFormat1<'a>), |
622 | | Format2(AnchorFormat2<'a>), |
623 | | Format3(AnchorFormat3<'a>), |
624 | | } |
625 | | |
626 | | impl Default for AnchorTable<'_> { |
627 | 0 | fn default() -> Self { |
628 | 0 | Self::Format1(Default::default()) |
629 | 0 | } |
630 | | } |
631 | | |
632 | | impl<'a> AnchorTable<'a> { |
633 | | ///Return the `FontData` used to resolve offsets for this table. |
634 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
635 | 0 | match self { |
636 | 0 | Self::Format1(item) => item.offset_data(), |
637 | 0 | Self::Format2(item) => item.offset_data(), |
638 | 0 | Self::Format3(item) => item.offset_data(), |
639 | | } |
640 | 0 | } |
641 | | |
642 | | /// Format identifier, = 1 |
643 | 0 | pub fn anchor_format(&self) -> u16 { |
644 | 0 | match self { |
645 | 0 | Self::Format1(item) => item.anchor_format(), |
646 | 0 | Self::Format2(item) => item.anchor_format(), |
647 | 0 | Self::Format3(item) => item.anchor_format(), |
648 | | } |
649 | 0 | } |
650 | | |
651 | | /// Horizontal value, in design units |
652 | 938k | pub fn x_coordinate(&self) -> i16 { |
653 | 938k | match self { |
654 | 17.4k | Self::Format1(item) => item.x_coordinate(), |
655 | 919k | Self::Format2(item) => item.x_coordinate(), |
656 | 2.09k | Self::Format3(item) => item.x_coordinate(), |
657 | | } |
658 | 938k | } |
659 | | |
660 | | /// Vertical value, in design units |
661 | 938k | pub fn y_coordinate(&self) -> i16 { |
662 | 938k | match self { |
663 | 17.4k | Self::Format1(item) => item.y_coordinate(), |
664 | 919k | Self::Format2(item) => item.y_coordinate(), |
665 | 2.09k | Self::Format3(item) => item.y_coordinate(), |
666 | | } |
667 | 938k | } |
668 | | } |
669 | | |
670 | | impl ReadArgs for AnchorTable<'_> { |
671 | | type Args = (); |
672 | | } |
673 | | |
674 | | impl<'a> FontRead<'a> for AnchorTable<'a> { |
675 | | #[inline] |
676 | 2.10M | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
677 | 2.10M | let format: u16 = data.read_at(0usize)?; |
678 | 2.10M | match format { |
679 | 77.2k | AnchorFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
680 | 1.25M | AnchorFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
681 | 9.05k | AnchorFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)), |
682 | 763k | other => Err(ReadError::InvalidFormat(other.into())), |
683 | | } |
684 | 2.10M | } <read_fonts::tables::gpos::AnchorTable as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 676 | 2.10M | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 677 | 2.10M | let format: u16 = data.read_at(0usize)?; | 678 | 2.10M | match format { | 679 | 77.2k | AnchorFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 680 | 1.25M | AnchorFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 681 | 9.05k | AnchorFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)), | 682 | 763k | other => Err(ReadError::InvalidFormat(other.into())), | 683 | | } | 684 | 2.10M | } |
Unexecuted instantiation: <read_fonts::tables::gpos::AnchorTable as read_fonts::read::FontRead>::read_with_args |
685 | | } |
686 | | |
687 | | impl<'a> MinByteRange<'a> for AnchorTable<'a> { |
688 | 0 | fn min_byte_range(&self) -> Range<usize> { |
689 | 0 | match self { |
690 | 0 | Self::Format1(item) => item.min_byte_range(), |
691 | 0 | Self::Format2(item) => item.min_byte_range(), |
692 | 0 | Self::Format3(item) => item.min_byte_range(), |
693 | | } |
694 | 0 | } |
695 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
696 | 0 | match self { |
697 | 0 | Self::Format1(item) => item.min_table_bytes(), |
698 | 0 | Self::Format2(item) => item.min_table_bytes(), |
699 | 0 | Self::Format3(item) => item.min_table_bytes(), |
700 | | } |
701 | 0 | } |
702 | | } |
703 | | |
704 | | impl Format<u16> for AnchorFormat1<'_> { |
705 | | const FORMAT: u16 = 1; |
706 | | } |
707 | | |
708 | | impl<'a> MinByteRange<'a> for AnchorFormat1<'a> { |
709 | 0 | fn min_byte_range(&self) -> Range<usize> { |
710 | 0 | 0..self.y_coordinate_byte_range().end |
711 | 0 | } |
712 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
713 | 0 | let range = self.min_byte_range(); |
714 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
715 | 0 | } |
716 | | } |
717 | | |
718 | | impl ReadArgs for AnchorFormat1<'_> { |
719 | | type Args = (); |
720 | | } |
721 | | |
722 | | impl<'a> FontRead<'a> for AnchorFormat1<'a> { |
723 | 77.2k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
724 | | #[allow(clippy::absurd_extreme_comparisons)] |
725 | 77.2k | if data.len() < Self::MIN_SIZE { |
726 | 2.27k | return Err(ReadError::OutOfBounds); |
727 | 74.9k | } |
728 | 74.9k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
729 | 0 | return Err(ReadError::OutOfBounds); |
730 | | }; |
731 | 74.9k | Ok(Self { data }) |
732 | 77.2k | } |
733 | | } |
734 | | |
735 | | /// The fields at the start of the table, which are read directly. |
736 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
737 | | #[repr(C, packed)] |
738 | | #[doc(hidden)] |
739 | | pub struct AnchorFormat1FixedHeader { |
740 | | pub anchor_format: BigEndian<u16>, |
741 | | pub x_coordinate: BigEndian<i16>, |
742 | | pub y_coordinate: BigEndian<i16>, |
743 | | } |
744 | | |
745 | | #[allow(clippy::absurd_extreme_comparisons)] |
746 | | const _: () = assert!(std::mem::size_of::<AnchorFormat1FixedHeader>() <= AnchorFormat1::MIN_SIZE); |
747 | | |
748 | | /// [Anchor Table Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#anchor-table-format-1-design-units): Design Units |
749 | | #[derive(Clone)] |
750 | | pub struct AnchorFormat1<'a> { |
751 | | data: TableDataRef<'a, AnchorFormat1FixedHeader>, |
752 | | } |
753 | | |
754 | | #[allow(clippy::needless_lifetimes)] |
755 | | impl<'a> AnchorFormat1<'a> { |
756 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN); |
757 | | basic_table_impls!(impl_the_methods); |
758 | | |
759 | | /// Format identifier, = 1 |
760 | 0 | pub fn anchor_format(&self) -> u16 { |
761 | 0 | self.data.header().anchor_format.get() |
762 | 0 | } |
763 | | |
764 | | /// Horizontal value, in design units |
765 | 17.4k | pub fn x_coordinate(&self) -> i16 { |
766 | 17.4k | self.data.header().x_coordinate.get() |
767 | 17.4k | } |
768 | | |
769 | | /// Vertical value, in design units |
770 | 17.4k | pub fn y_coordinate(&self) -> i16 { |
771 | 17.4k | self.data.header().y_coordinate.get() |
772 | 17.4k | } |
773 | | |
774 | 0 | pub fn anchor_format_byte_range(&self) -> Range<usize> { |
775 | 0 | let start = 0usize; |
776 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
777 | 0 | start..end |
778 | 0 | } |
779 | | |
780 | 0 | pub fn x_coordinate_byte_range(&self) -> Range<usize> { |
781 | 0 | let start = self.anchor_format_byte_range().end; |
782 | 0 | let end = start.saturating_add(i16::RAW_BYTE_LEN); |
783 | 0 | start..end |
784 | 0 | } |
785 | | |
786 | 0 | pub fn y_coordinate_byte_range(&self) -> Range<usize> { |
787 | 0 | let start = self.x_coordinate_byte_range().end; |
788 | 0 | let end = start.saturating_add(i16::RAW_BYTE_LEN); |
789 | 0 | start..end |
790 | 0 | } |
791 | | } |
792 | | |
793 | | const _: () = assert!(FontData::default_data_long_enough(AnchorFormat1::MIN_SIZE)); |
794 | | |
795 | | impl Default for AnchorFormat1<'_> { |
796 | 0 | fn default() -> Self { |
797 | | Self { |
798 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
799 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
800 | | } |
801 | 0 | } |
802 | | } |
803 | | |
804 | | impl Format<u16> for AnchorFormat2<'_> { |
805 | | const FORMAT: u16 = 2; |
806 | | } |
807 | | |
808 | | impl<'a> MinByteRange<'a> for AnchorFormat2<'a> { |
809 | 0 | fn min_byte_range(&self) -> Range<usize> { |
810 | 0 | 0..self.anchor_point_byte_range().end |
811 | 0 | } |
812 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
813 | 0 | let range = self.min_byte_range(); |
814 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
815 | 0 | } |
816 | | } |
817 | | |
818 | | impl ReadArgs for AnchorFormat2<'_> { |
819 | | type Args = (); |
820 | | } |
821 | | |
822 | | impl<'a> FontRead<'a> for AnchorFormat2<'a> { |
823 | 1.25M | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
824 | | #[allow(clippy::absurd_extreme_comparisons)] |
825 | 1.25M | if data.len() < Self::MIN_SIZE { |
826 | 9.43k | return Err(ReadError::OutOfBounds); |
827 | 1.24M | } |
828 | 1.24M | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
829 | 0 | return Err(ReadError::OutOfBounds); |
830 | | }; |
831 | 1.24M | Ok(Self { data }) |
832 | 1.25M | } |
833 | | } |
834 | | |
835 | | /// The fields at the start of the table, which are read directly. |
836 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
837 | | #[repr(C, packed)] |
838 | | #[doc(hidden)] |
839 | | pub struct AnchorFormat2FixedHeader { |
840 | | pub anchor_format: BigEndian<u16>, |
841 | | pub x_coordinate: BigEndian<i16>, |
842 | | pub y_coordinate: BigEndian<i16>, |
843 | | pub anchor_point: BigEndian<u16>, |
844 | | } |
845 | | |
846 | | #[allow(clippy::absurd_extreme_comparisons)] |
847 | | const _: () = assert!(std::mem::size_of::<AnchorFormat2FixedHeader>() <= AnchorFormat2::MIN_SIZE); |
848 | | |
849 | | /// [Anchor Table Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#anchor-table-format-2-design-units-plus-contour-point): Design Units Plus Contour Point |
850 | | #[derive(Clone)] |
851 | | pub struct AnchorFormat2<'a> { |
852 | | data: TableDataRef<'a, AnchorFormat2FixedHeader>, |
853 | | } |
854 | | |
855 | | #[allow(clippy::needless_lifetimes)] |
856 | | impl<'a> AnchorFormat2<'a> { |
857 | | pub const MIN_SIZE: usize = |
858 | | (u16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN); |
859 | | basic_table_impls!(impl_the_methods); |
860 | | |
861 | | /// Format identifier, = 2 |
862 | 0 | pub fn anchor_format(&self) -> u16 { |
863 | 0 | self.data.header().anchor_format.get() |
864 | 0 | } |
865 | | |
866 | | /// Horizontal value, in design units |
867 | 919k | pub fn x_coordinate(&self) -> i16 { |
868 | 919k | self.data.header().x_coordinate.get() |
869 | 919k | } |
870 | | |
871 | | /// Vertical value, in design units |
872 | 919k | pub fn y_coordinate(&self) -> i16 { |
873 | 919k | self.data.header().y_coordinate.get() |
874 | 919k | } |
875 | | |
876 | | /// Index to glyph contour point |
877 | 0 | pub fn anchor_point(&self) -> u16 { |
878 | 0 | self.data.header().anchor_point.get() |
879 | 0 | } |
880 | | |
881 | 0 | pub fn anchor_format_byte_range(&self) -> Range<usize> { |
882 | 0 | let start = 0usize; |
883 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
884 | 0 | start..end |
885 | 0 | } |
886 | | |
887 | 0 | pub fn x_coordinate_byte_range(&self) -> Range<usize> { |
888 | 0 | let start = self.anchor_format_byte_range().end; |
889 | 0 | let end = start.saturating_add(i16::RAW_BYTE_LEN); |
890 | 0 | start..end |
891 | 0 | } |
892 | | |
893 | 0 | pub fn y_coordinate_byte_range(&self) -> Range<usize> { |
894 | 0 | let start = self.x_coordinate_byte_range().end; |
895 | 0 | let end = start.saturating_add(i16::RAW_BYTE_LEN); |
896 | 0 | start..end |
897 | 0 | } |
898 | | |
899 | 0 | pub fn anchor_point_byte_range(&self) -> Range<usize> { |
900 | 0 | let start = self.y_coordinate_byte_range().end; |
901 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
902 | 0 | start..end |
903 | 0 | } |
904 | | } |
905 | | |
906 | | impl Format<u16> for AnchorFormat3<'_> { |
907 | | const FORMAT: u16 = 3; |
908 | | } |
909 | | |
910 | | impl<'a> MinByteRange<'a> for AnchorFormat3<'a> { |
911 | 0 | fn min_byte_range(&self) -> Range<usize> { |
912 | 0 | 0..self.y_device_offset_byte_range().end |
913 | 0 | } |
914 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
915 | 0 | let range = self.min_byte_range(); |
916 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
917 | 0 | } |
918 | | } |
919 | | |
920 | | impl ReadArgs for AnchorFormat3<'_> { |
921 | | type Args = (); |
922 | | } |
923 | | |
924 | | impl<'a> FontRead<'a> for AnchorFormat3<'a> { |
925 | 9.05k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
926 | | #[allow(clippy::absurd_extreme_comparisons)] |
927 | 9.05k | if data.len() < Self::MIN_SIZE { |
928 | 2.07k | return Err(ReadError::OutOfBounds); |
929 | 6.98k | } |
930 | 6.98k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
931 | 0 | return Err(ReadError::OutOfBounds); |
932 | | }; |
933 | 6.98k | Ok(Self { data }) |
934 | 9.05k | } |
935 | | } |
936 | | |
937 | | /// The fields at the start of the table, which are read directly. |
938 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
939 | | #[repr(C, packed)] |
940 | | #[doc(hidden)] |
941 | | pub struct AnchorFormat3FixedHeader { |
942 | | pub anchor_format: BigEndian<u16>, |
943 | | pub x_coordinate: BigEndian<i16>, |
944 | | pub y_coordinate: BigEndian<i16>, |
945 | | pub x_device_offset: BigEndian<Nullable<Offset16>>, |
946 | | pub y_device_offset: BigEndian<Nullable<Offset16>>, |
947 | | } |
948 | | |
949 | | #[allow(clippy::absurd_extreme_comparisons)] |
950 | | const _: () = assert!(std::mem::size_of::<AnchorFormat3FixedHeader>() <= AnchorFormat3::MIN_SIZE); |
951 | | |
952 | | /// [Anchor Table Format 3](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#anchor-table-format-3-design-units-plus-device-or-variationindex-tables): Design Units Plus Device or VariationIndex Tables |
953 | | #[derive(Clone)] |
954 | | pub struct AnchorFormat3<'a> { |
955 | | data: TableDataRef<'a, AnchorFormat3FixedHeader>, |
956 | | } |
957 | | |
958 | | #[allow(clippy::needless_lifetimes)] |
959 | | impl<'a> AnchorFormat3<'a> { |
960 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
961 | | + i16::RAW_BYTE_LEN |
962 | | + i16::RAW_BYTE_LEN |
963 | | + Offset16::RAW_BYTE_LEN |
964 | | + Offset16::RAW_BYTE_LEN); |
965 | | basic_table_impls!(impl_the_methods); |
966 | | |
967 | | /// Format identifier, = 3 |
968 | 0 | pub fn anchor_format(&self) -> u16 { |
969 | 0 | self.data.header().anchor_format.get() |
970 | 0 | } |
971 | | |
972 | | /// Horizontal value, in design units |
973 | 2.09k | pub fn x_coordinate(&self) -> i16 { |
974 | 2.09k | self.data.header().x_coordinate.get() |
975 | 2.09k | } |
976 | | |
977 | | /// Vertical value, in design units |
978 | 2.09k | pub fn y_coordinate(&self) -> i16 { |
979 | 2.09k | self.data.header().y_coordinate.get() |
980 | 2.09k | } |
981 | | |
982 | | /// Offset to Device table (non-variable font) / VariationIndex |
983 | | /// table (variable font) for X coordinate, from beginning of |
984 | | /// Anchor table (may be NULL) |
985 | 0 | pub fn x_device_offset(&self) -> Nullable<Offset16> { |
986 | 0 | self.data.header().x_device_offset.get() |
987 | 0 | } |
988 | | |
989 | | /// Attempt to resolve [`x_device_offset`][Self::x_device_offset]. |
990 | 0 | pub fn x_device(&self) -> Option<Result<DeviceOrVariationIndex<'a>, ReadError>> { |
991 | 0 | let data = self.offset_data(); |
992 | 0 | self.x_device_offset().resolve(data) |
993 | 0 | } |
994 | | |
995 | | /// Offset to Device table (non-variable font) / VariationIndex |
996 | | /// table (variable font) for Y coordinate, from beginning of |
997 | | /// Anchor table (may be NULL) |
998 | 0 | pub fn y_device_offset(&self) -> Nullable<Offset16> { |
999 | 0 | self.data.header().y_device_offset.get() |
1000 | 0 | } |
1001 | | |
1002 | | /// Attempt to resolve [`y_device_offset`][Self::y_device_offset]. |
1003 | 0 | pub fn y_device(&self) -> Option<Result<DeviceOrVariationIndex<'a>, ReadError>> { |
1004 | 0 | let data = self.offset_data(); |
1005 | 0 | self.y_device_offset().resolve(data) |
1006 | 0 | } |
1007 | | |
1008 | 0 | pub fn anchor_format_byte_range(&self) -> Range<usize> { |
1009 | 0 | let start = 0usize; |
1010 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1011 | 0 | start..end |
1012 | 0 | } |
1013 | | |
1014 | 0 | pub fn x_coordinate_byte_range(&self) -> Range<usize> { |
1015 | 0 | let start = self.anchor_format_byte_range().end; |
1016 | 0 | let end = start.saturating_add(i16::RAW_BYTE_LEN); |
1017 | 0 | start..end |
1018 | 0 | } |
1019 | | |
1020 | 0 | pub fn y_coordinate_byte_range(&self) -> Range<usize> { |
1021 | 0 | let start = self.x_coordinate_byte_range().end; |
1022 | 0 | let end = start.saturating_add(i16::RAW_BYTE_LEN); |
1023 | 0 | start..end |
1024 | 0 | } |
1025 | | |
1026 | 0 | pub fn x_device_offset_byte_range(&self) -> Range<usize> { |
1027 | 0 | let start = self.y_coordinate_byte_range().end; |
1028 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
1029 | 0 | start..end |
1030 | 0 | } |
1031 | | |
1032 | 0 | pub fn y_device_offset_byte_range(&self) -> Range<usize> { |
1033 | 0 | let start = self.x_device_offset_byte_range().end; |
1034 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
1035 | 0 | start..end |
1036 | 0 | } |
1037 | | } |
1038 | | |
1039 | | impl<'a> MinByteRange<'a> for MarkArray<'a> { |
1040 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1041 | 0 | 0..self.mark_records_byte_range().end |
1042 | 0 | } |
1043 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1044 | 0 | let range = self.min_byte_range(); |
1045 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1046 | 0 | } |
1047 | | } |
1048 | | |
1049 | | impl ReadArgs for MarkArray<'_> { |
1050 | | type Args = (); |
1051 | | } |
1052 | | |
1053 | | impl<'a> FontRead<'a> for MarkArray<'a> { |
1054 | 11.6k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1055 | | #[allow(clippy::absurd_extreme_comparisons)] |
1056 | 11.6k | if data.len() < Self::MIN_SIZE { |
1057 | 215 | return Err(ReadError::OutOfBounds); |
1058 | 11.4k | } |
1059 | 11.4k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1060 | 0 | return Err(ReadError::OutOfBounds); |
1061 | | }; |
1062 | 11.4k | Ok(Self { data }) |
1063 | 11.6k | } |
1064 | | } |
1065 | | |
1066 | | /// The fields at the start of the table, which are read directly. |
1067 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1068 | | #[repr(C, packed)] |
1069 | | #[doc(hidden)] |
1070 | | pub struct MarkArrayFixedHeader { |
1071 | | pub mark_count: BigEndian<u16>, |
1072 | | } |
1073 | | |
1074 | | #[allow(clippy::absurd_extreme_comparisons)] |
1075 | | const _: () = assert!(std::mem::size_of::<MarkArrayFixedHeader>() <= MarkArray::MIN_SIZE); |
1076 | | |
1077 | | /// [Mark Array Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#mark-array-table) |
1078 | | #[derive(Clone)] |
1079 | | pub struct MarkArray<'a> { |
1080 | | data: TableDataRef<'a, MarkArrayFixedHeader>, |
1081 | | } |
1082 | | |
1083 | | #[allow(clippy::needless_lifetimes)] |
1084 | | impl<'a> MarkArray<'a> { |
1085 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
1086 | | basic_table_impls!(impl_the_methods); |
1087 | | |
1088 | | /// Number of MarkRecords |
1089 | 11.4k | pub fn mark_count(&self) -> u16 { |
1090 | 11.4k | self.data.header().mark_count.get() |
1091 | 11.4k | } |
1092 | | |
1093 | | /// Array of MarkRecords, ordered by corresponding glyphs in the |
1094 | | /// associated mark Coverage table. |
1095 | 0 | pub fn mark_records(&self) -> &'a [MarkRecord] { |
1096 | 0 | let range = self.mark_records_byte_range(); |
1097 | 0 | self.offset_data() |
1098 | 0 | .read_array(range) |
1099 | 0 | .ok() |
1100 | 0 | .unwrap_or_default() |
1101 | 0 | } |
1102 | | |
1103 | 0 | pub fn mark_count_byte_range(&self) -> Range<usize> { |
1104 | 0 | let start = 0usize; |
1105 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1106 | 0 | start..end |
1107 | 0 | } |
1108 | | |
1109 | 0 | pub fn mark_records_byte_range(&self) -> Range<usize> { |
1110 | 0 | let mark_count = self.mark_count(); |
1111 | 0 | let start = self.mark_count_byte_range().end; |
1112 | 0 | let end = start.saturating_add( |
1113 | 0 | (transforms::to_usize(mark_count)).saturating_mul(MarkRecord::RAW_BYTE_LEN), |
1114 | | ); |
1115 | 0 | start..end |
1116 | 0 | } |
1117 | | } |
1118 | | |
1119 | | const _: () = assert!(FontData::default_data_long_enough(MarkArray::MIN_SIZE)); |
1120 | | |
1121 | | impl Default for MarkArray<'_> { |
1122 | 0 | fn default() -> Self { |
1123 | | Self { |
1124 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
1125 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
1126 | | } |
1127 | 0 | } |
1128 | | } |
1129 | | |
1130 | | /// Part of [MarkArray] |
1131 | | #[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)] |
1132 | | #[repr(C)] |
1133 | | #[repr(packed)] |
1134 | | pub struct MarkRecord { |
1135 | | /// Class defined for the associated mark. |
1136 | | pub mark_class: BigEndian<u16>, |
1137 | | /// Offset to Anchor table, from beginning of MarkArray table. |
1138 | | pub mark_anchor_offset: BigEndian<Offset16>, |
1139 | | } |
1140 | | |
1141 | | impl MarkRecord { |
1142 | | /// Class defined for the associated mark. |
1143 | 0 | pub fn mark_class(&self) -> u16 { |
1144 | 0 | self.mark_class.get() |
1145 | 0 | } |
1146 | | |
1147 | | /// Offset to Anchor table, from beginning of MarkArray table. |
1148 | 0 | pub fn mark_anchor_offset(&self) -> Offset16 { |
1149 | 0 | self.mark_anchor_offset.get() |
1150 | 0 | } |
1151 | | |
1152 | | /// Offset to Anchor table, from beginning of MarkArray table. |
1153 | | /// |
1154 | | /// The `data` argument should be retrieved from the parent table |
1155 | | /// By calling its `offset_data` method. |
1156 | 0 | pub fn mark_anchor<'a>(&self, data: FontData<'a>) -> Result<AnchorTable<'a>, ReadError> { |
1157 | 0 | self.mark_anchor_offset().resolve(data) |
1158 | 0 | } |
1159 | | } |
1160 | | |
1161 | | impl FixedSize for MarkRecord { |
1162 | | const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN; |
1163 | | } |
1164 | | |
1165 | | /// [Lookup Type 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-1-single-adjustment-positioning-subtable): Single Adjustment Positioning Subtable |
1166 | | #[derive(Clone)] |
1167 | | pub enum SinglePos<'a> { |
1168 | | Format1(SinglePosFormat1<'a>), |
1169 | | Format2(SinglePosFormat2<'a>), |
1170 | | Format3(SinglePosFormat3<'a>), |
1171 | | Format4(SinglePosFormat4<'a>), |
1172 | | } |
1173 | | |
1174 | | impl Default for SinglePos<'_> { |
1175 | 0 | fn default() -> Self { |
1176 | 0 | Self::Format1(Default::default()) |
1177 | 0 | } |
1178 | | } |
1179 | | |
1180 | | impl<'a> SinglePos<'a> { |
1181 | | ///Return the `FontData` used to resolve offsets for this table. |
1182 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
1183 | 0 | match self { |
1184 | 0 | Self::Format1(item) => item.offset_data(), |
1185 | 0 | Self::Format2(item) => item.offset_data(), |
1186 | 0 | Self::Format3(item) => item.offset_data(), |
1187 | 0 | Self::Format4(item) => item.offset_data(), |
1188 | | } |
1189 | 0 | } |
1190 | | |
1191 | | /// Format identifier: format = 1 |
1192 | 0 | pub fn pos_format(&self) -> u16 { |
1193 | 0 | match self { |
1194 | 0 | Self::Format1(item) => item.pos_format(), |
1195 | 0 | Self::Format2(item) => item.pos_format(), |
1196 | 0 | Self::Format3(item) => item.pos_format(), |
1197 | 0 | Self::Format4(item) => item.pos_format(), |
1198 | | } |
1199 | 0 | } |
1200 | | |
1201 | | /// Defines the types of data in the ValueRecord. |
1202 | 0 | pub fn value_format(&self) -> ValueFormat { |
1203 | 0 | match self { |
1204 | 0 | Self::Format1(item) => item.value_format(), |
1205 | 0 | Self::Format2(item) => item.value_format(), |
1206 | 0 | Self::Format3(item) => item.value_format(), |
1207 | 0 | Self::Format4(item) => item.value_format(), |
1208 | | } |
1209 | 0 | } |
1210 | | } |
1211 | | |
1212 | | impl ReadArgs for SinglePos<'_> { |
1213 | | type Args = (); |
1214 | | } |
1215 | | |
1216 | | impl<'a> FontRead<'a> for SinglePos<'a> { |
1217 | | #[inline] |
1218 | 41.9k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1219 | 41.9k | let format: u16 = data.read_at(0usize)?; |
1220 | 41.6k | match format { |
1221 | 15.6k | SinglePosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
1222 | 1.81k | SinglePosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
1223 | 950 | SinglePosFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)), |
1224 | 1.12k | SinglePosFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)), |
1225 | 22.1k | other => Err(ReadError::InvalidFormat(other.into())), |
1226 | | } |
1227 | 41.9k | } <read_fonts::tables::gpos::SinglePos as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 1218 | 41.9k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 1219 | 41.9k | let format: u16 = data.read_at(0usize)?; | 1220 | 41.6k | match format { | 1221 | 15.6k | SinglePosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 1222 | 1.81k | SinglePosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 1223 | 950 | SinglePosFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)), | 1224 | 1.12k | SinglePosFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)), | 1225 | 22.1k | other => Err(ReadError::InvalidFormat(other.into())), | 1226 | | } | 1227 | 41.9k | } |
Unexecuted instantiation: <read_fonts::tables::gpos::SinglePos as read_fonts::read::FontRead>::read_with_args |
1228 | | } |
1229 | | |
1230 | | impl<'a> MinByteRange<'a> for SinglePos<'a> { |
1231 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1232 | 0 | match self { |
1233 | 0 | Self::Format1(item) => item.min_byte_range(), |
1234 | 0 | Self::Format2(item) => item.min_byte_range(), |
1235 | 0 | Self::Format3(item) => item.min_byte_range(), |
1236 | 0 | Self::Format4(item) => item.min_byte_range(), |
1237 | | } |
1238 | 0 | } |
1239 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1240 | 0 | match self { |
1241 | 0 | Self::Format1(item) => item.min_table_bytes(), |
1242 | 0 | Self::Format2(item) => item.min_table_bytes(), |
1243 | 0 | Self::Format3(item) => item.min_table_bytes(), |
1244 | 0 | Self::Format4(item) => item.min_table_bytes(), |
1245 | | } |
1246 | 0 | } |
1247 | | } |
1248 | | |
1249 | | impl Format<u16> for SinglePosFormat1<'_> { |
1250 | | const FORMAT: u16 = 1; |
1251 | | } |
1252 | | |
1253 | | impl<'a> MinByteRange<'a> for SinglePosFormat1<'a> { |
1254 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1255 | 0 | 0..self.value_record_byte_range().end |
1256 | 0 | } |
1257 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1258 | 0 | let range = self.min_byte_range(); |
1259 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1260 | 0 | } |
1261 | | } |
1262 | | |
1263 | | impl ReadArgs for SinglePosFormat1<'_> { |
1264 | | type Args = (); |
1265 | | } |
1266 | | |
1267 | | impl<'a> FontRead<'a> for SinglePosFormat1<'a> { |
1268 | 15.6k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1269 | | #[allow(clippy::absurd_extreme_comparisons)] |
1270 | 15.6k | if data.len() < Self::MIN_SIZE { |
1271 | 258 | return Err(ReadError::OutOfBounds); |
1272 | 15.3k | } |
1273 | 15.3k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1274 | 0 | return Err(ReadError::OutOfBounds); |
1275 | | }; |
1276 | 15.3k | Ok(Self { data }) |
1277 | 15.6k | } |
1278 | | } |
1279 | | |
1280 | | /// The fields at the start of the table, which are read directly. |
1281 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1282 | | #[repr(C, packed)] |
1283 | | #[doc(hidden)] |
1284 | | pub struct SinglePosFormat1FixedHeader { |
1285 | | pub pos_format: BigEndian<u16>, |
1286 | | pub coverage_offset: BigEndian<Offset16>, |
1287 | | pub value_format: BigEndian<ValueFormat>, |
1288 | | } |
1289 | | |
1290 | | #[allow(clippy::absurd_extreme_comparisons)] |
1291 | | const _: () = |
1292 | | assert!(std::mem::size_of::<SinglePosFormat1FixedHeader>() <= SinglePosFormat1::MIN_SIZE); |
1293 | | |
1294 | | /// [Single Adjustment Positioning Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#single-adjustment-positioning-format-1-single-positioning-value): Single Positioning Value |
1295 | | #[derive(Clone)] |
1296 | | pub struct SinglePosFormat1<'a> { |
1297 | | data: TableDataRef<'a, SinglePosFormat1FixedHeader>, |
1298 | | } |
1299 | | |
1300 | | #[allow(clippy::needless_lifetimes)] |
1301 | | impl<'a> SinglePosFormat1<'a> { |
1302 | | pub const MIN_SIZE: usize = |
1303 | | (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + ValueFormat::RAW_BYTE_LEN); |
1304 | | basic_table_impls!(impl_the_methods); |
1305 | | |
1306 | | /// Format identifier: format = 1 |
1307 | 0 | pub fn pos_format(&self) -> u16 { |
1308 | 0 | self.data.header().pos_format.get() |
1309 | 0 | } |
1310 | | |
1311 | | /// Offset to Coverage table, from beginning of SinglePos subtable. |
1312 | 15.3k | pub fn coverage_offset(&self) -> Offset16 { |
1313 | 15.3k | self.data.header().coverage_offset.get() |
1314 | 15.3k | } |
1315 | | |
1316 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
1317 | 15.3k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
1318 | 15.3k | let data = self.offset_data(); |
1319 | 15.3k | self.coverage_offset().resolve(data) |
1320 | 15.3k | } |
1321 | | |
1322 | | /// Defines the types of data in the ValueRecord. |
1323 | 30.6k | pub fn value_format(&self) -> ValueFormat { |
1324 | 30.6k | self.data.header().value_format.get() |
1325 | 30.6k | } |
1326 | | |
1327 | | /// Defines positioning value(s) — applied to all glyphs in the |
1328 | | /// Coverage table. |
1329 | 0 | pub fn value_record(&self) -> ValueRecord<'a> { |
1330 | 0 | let range = self.value_record_byte_range(); |
1331 | 0 | ValueRecord::read_at(self.offset_data(), range.start, self.value_format()) |
1332 | 0 | .unwrap_or_default() |
1333 | 0 | } |
1334 | | |
1335 | 15.3k | pub fn pos_format_byte_range(&self) -> Range<usize> { |
1336 | 15.3k | let start = 0usize; |
1337 | 15.3k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1338 | 15.3k | start..end |
1339 | 15.3k | } |
1340 | | |
1341 | 15.3k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
1342 | 15.3k | let start = self.pos_format_byte_range().end; |
1343 | 15.3k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
1344 | 15.3k | start..end |
1345 | 15.3k | } |
1346 | | |
1347 | 15.3k | pub fn value_format_byte_range(&self) -> Range<usize> { |
1348 | 15.3k | let start = self.coverage_offset_byte_range().end; |
1349 | 15.3k | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
1350 | 15.3k | start..end |
1351 | 15.3k | } |
1352 | | |
1353 | 15.3k | pub fn value_record_byte_range(&self) -> Range<usize> { |
1354 | 15.3k | let start = self.value_format_byte_range().end; |
1355 | 15.3k | let end = start.saturating_add( |
1356 | 15.3k | <ValueRecord as ComputeSize>::compute_size(self.value_format()).unwrap_or(0), |
1357 | | ); |
1358 | 15.3k | start..end |
1359 | 15.3k | } |
1360 | | } |
1361 | | |
1362 | | const _: () = assert!(FontData::default_data_long_enough( |
1363 | | SinglePosFormat1::MIN_SIZE |
1364 | | )); |
1365 | | |
1366 | | impl Default for SinglePosFormat1<'_> { |
1367 | 0 | fn default() -> Self { |
1368 | | Self { |
1369 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
1370 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
1371 | | } |
1372 | 0 | } |
1373 | | } |
1374 | | |
1375 | | impl Format<u16> for SinglePosFormat2<'_> { |
1376 | | const FORMAT: u16 = 2; |
1377 | | } |
1378 | | |
1379 | | impl<'a> MinByteRange<'a> for SinglePosFormat2<'a> { |
1380 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1381 | 0 | 0..self.value_records_byte_range().end |
1382 | 0 | } |
1383 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1384 | 0 | let range = self.min_byte_range(); |
1385 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1386 | 0 | } |
1387 | | } |
1388 | | |
1389 | | impl ReadArgs for SinglePosFormat2<'_> { |
1390 | | type Args = (); |
1391 | | } |
1392 | | |
1393 | | impl<'a> FontRead<'a> for SinglePosFormat2<'a> { |
1394 | 1.81k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1395 | | #[allow(clippy::absurd_extreme_comparisons)] |
1396 | 1.81k | if data.len() < Self::MIN_SIZE { |
1397 | 217 | return Err(ReadError::OutOfBounds); |
1398 | 1.59k | } |
1399 | 1.59k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1400 | 0 | return Err(ReadError::OutOfBounds); |
1401 | | }; |
1402 | 1.59k | Ok(Self { data }) |
1403 | 1.81k | } |
1404 | | } |
1405 | | |
1406 | | /// The fields at the start of the table, which are read directly. |
1407 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1408 | | #[repr(C, packed)] |
1409 | | #[doc(hidden)] |
1410 | | pub struct SinglePosFormat2FixedHeader { |
1411 | | pub pos_format: BigEndian<u16>, |
1412 | | pub coverage_offset: BigEndian<Offset16>, |
1413 | | pub value_format: BigEndian<ValueFormat>, |
1414 | | pub value_count: BigEndian<u16>, |
1415 | | } |
1416 | | |
1417 | | #[allow(clippy::absurd_extreme_comparisons)] |
1418 | | const _: () = |
1419 | | assert!(std::mem::size_of::<SinglePosFormat2FixedHeader>() <= SinglePosFormat2::MIN_SIZE); |
1420 | | |
1421 | | /// [Single Adjustment Positioning Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#single-adjustment-positioning-format-2-array-of-positioning-values): Array of Positioning Values |
1422 | | #[derive(Clone)] |
1423 | | pub struct SinglePosFormat2<'a> { |
1424 | | data: TableDataRef<'a, SinglePosFormat2FixedHeader>, |
1425 | | } |
1426 | | |
1427 | | #[allow(clippy::needless_lifetimes)] |
1428 | | impl<'a> SinglePosFormat2<'a> { |
1429 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
1430 | | + Offset16::RAW_BYTE_LEN |
1431 | | + ValueFormat::RAW_BYTE_LEN |
1432 | | + u16::RAW_BYTE_LEN); |
1433 | | basic_table_impls!(impl_the_methods); |
1434 | | |
1435 | | /// Format identifier: format = 2 |
1436 | 0 | pub fn pos_format(&self) -> u16 { |
1437 | 0 | self.data.header().pos_format.get() |
1438 | 0 | } |
1439 | | |
1440 | | /// Offset to Coverage table, from beginning of SinglePos subtable. |
1441 | 1.59k | pub fn coverage_offset(&self) -> Offset16 { |
1442 | 1.59k | self.data.header().coverage_offset.get() |
1443 | 1.59k | } |
1444 | | |
1445 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
1446 | 1.59k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
1447 | 1.59k | let data = self.offset_data(); |
1448 | 1.59k | self.coverage_offset().resolve(data) |
1449 | 1.59k | } |
1450 | | |
1451 | | /// Defines the types of data in the ValueRecords. |
1452 | 3.18k | pub fn value_format(&self) -> ValueFormat { |
1453 | 3.18k | self.data.header().value_format.get() |
1454 | 3.18k | } |
1455 | | |
1456 | | /// Number of ValueRecords — must equal glyphCount in the |
1457 | | /// Coverage table. |
1458 | 3.18k | pub fn value_count(&self) -> u16 { |
1459 | 3.18k | self.data.header().value_count.get() |
1460 | 3.18k | } |
1461 | | |
1462 | | /// Array of ValueRecords — positioning values applied to glyphs. |
1463 | 0 | pub fn value_records(&self) -> ComputedArray<'a, ValueRecord<'a>> { |
1464 | 0 | let range = self.value_records_byte_range(); |
1465 | 0 | ComputedArray::new(self.offset_data(), range, self.value_format()).unwrap_or_default() |
1466 | 0 | } |
1467 | | |
1468 | 1.59k | pub fn pos_format_byte_range(&self) -> Range<usize> { |
1469 | 1.59k | let start = 0usize; |
1470 | 1.59k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1471 | 1.59k | start..end |
1472 | 1.59k | } |
1473 | | |
1474 | 1.59k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
1475 | 1.59k | let start = self.pos_format_byte_range().end; |
1476 | 1.59k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
1477 | 1.59k | start..end |
1478 | 1.59k | } |
1479 | | |
1480 | 1.59k | pub fn value_format_byte_range(&self) -> Range<usize> { |
1481 | 1.59k | let start = self.coverage_offset_byte_range().end; |
1482 | 1.59k | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
1483 | 1.59k | start..end |
1484 | 1.59k | } |
1485 | | |
1486 | 1.59k | pub fn value_count_byte_range(&self) -> Range<usize> { |
1487 | 1.59k | let start = self.value_format_byte_range().end; |
1488 | 1.59k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1489 | 1.59k | start..end |
1490 | 1.59k | } |
1491 | | |
1492 | 1.59k | pub fn value_records_byte_range(&self) -> Range<usize> { |
1493 | 1.59k | let value_count = self.value_count(); |
1494 | 1.59k | let start = self.value_count_byte_range().end; |
1495 | 1.59k | let end = start.saturating_add((transforms::to_usize(value_count)).saturating_mul( |
1496 | 1.59k | <ValueRecord as ComputeSize>::compute_size(self.value_format()).unwrap_or(0), |
1497 | | )); |
1498 | 1.59k | start..end |
1499 | 1.59k | } |
1500 | | } |
1501 | | |
1502 | | /// [Lookup Type 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-1-single-adjustment-positioning-subtable): Single Adjustment Positioning Subtable |
1503 | | #[derive(Clone)] |
1504 | | pub enum PairPos<'a> { |
1505 | | Format1(PairPosFormat1<'a>), |
1506 | | Format2(PairPosFormat2<'a>), |
1507 | | Format3(PairPosFormat3<'a>), |
1508 | | Format4(PairPosFormat4<'a>), |
1509 | | } |
1510 | | |
1511 | | impl Default for PairPos<'_> { |
1512 | 0 | fn default() -> Self { |
1513 | 0 | Self::Format1(Default::default()) |
1514 | 0 | } |
1515 | | } |
1516 | | |
1517 | | impl<'a> PairPos<'a> { |
1518 | | ///Return the `FontData` used to resolve offsets for this table. |
1519 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
1520 | 0 | match self { |
1521 | 0 | Self::Format1(item) => item.offset_data(), |
1522 | 0 | Self::Format2(item) => item.offset_data(), |
1523 | 0 | Self::Format3(item) => item.offset_data(), |
1524 | 0 | Self::Format4(item) => item.offset_data(), |
1525 | | } |
1526 | 0 | } |
1527 | | |
1528 | | /// Format identifier: format = 1 |
1529 | 0 | pub fn pos_format(&self) -> u16 { |
1530 | 0 | match self { |
1531 | 0 | Self::Format1(item) => item.pos_format(), |
1532 | 0 | Self::Format2(item) => item.pos_format(), |
1533 | 0 | Self::Format3(item) => item.pos_format(), |
1534 | 0 | Self::Format4(item) => item.pos_format(), |
1535 | | } |
1536 | 0 | } |
1537 | | |
1538 | | /// Defines the types of data in valueRecord1 — for the first |
1539 | | /// glyph in the pair (may be zero). |
1540 | 0 | pub fn value_format1(&self) -> ValueFormat { |
1541 | 0 | match self { |
1542 | 0 | Self::Format1(item) => item.value_format1(), |
1543 | 0 | Self::Format2(item) => item.value_format1(), |
1544 | 0 | Self::Format3(item) => item.value_format1(), |
1545 | 0 | Self::Format4(item) => item.value_format1(), |
1546 | | } |
1547 | 0 | } |
1548 | | |
1549 | | /// Defines the types of data in valueRecord2 — for the second |
1550 | | /// glyph in the pair (may be zero). |
1551 | 0 | pub fn value_format2(&self) -> ValueFormat { |
1552 | 0 | match self { |
1553 | 0 | Self::Format1(item) => item.value_format2(), |
1554 | 0 | Self::Format2(item) => item.value_format2(), |
1555 | 0 | Self::Format3(item) => item.value_format2(), |
1556 | 0 | Self::Format4(item) => item.value_format2(), |
1557 | | } |
1558 | 0 | } |
1559 | | } |
1560 | | |
1561 | | impl ReadArgs for PairPos<'_> { |
1562 | | type Args = (); |
1563 | | } |
1564 | | |
1565 | | impl<'a> FontRead<'a> for PairPos<'a> { |
1566 | | #[inline] |
1567 | 611k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1568 | 611k | let format: u16 = data.read_at(0usize)?; |
1569 | 611k | match format { |
1570 | 21.6k | PairPosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
1571 | 210k | PairPosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
1572 | 6.18k | PairPosFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)), |
1573 | 6.30k | PairPosFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)), |
1574 | 366k | other => Err(ReadError::InvalidFormat(other.into())), |
1575 | | } |
1576 | 611k | } <read_fonts::tables::gpos::PairPos as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 1567 | 611k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 1568 | 611k | let format: u16 = data.read_at(0usize)?; | 1569 | 611k | match format { | 1570 | 21.6k | PairPosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 1571 | 210k | PairPosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 1572 | 6.18k | PairPosFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)), | 1573 | 6.30k | PairPosFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)), | 1574 | 366k | other => Err(ReadError::InvalidFormat(other.into())), | 1575 | | } | 1576 | 611k | } |
Unexecuted instantiation: <read_fonts::tables::gpos::PairPos as read_fonts::read::FontRead>::read_with_args |
1577 | | } |
1578 | | |
1579 | | impl<'a> MinByteRange<'a> for PairPos<'a> { |
1580 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1581 | 0 | match self { |
1582 | 0 | Self::Format1(item) => item.min_byte_range(), |
1583 | 0 | Self::Format2(item) => item.min_byte_range(), |
1584 | 0 | Self::Format3(item) => item.min_byte_range(), |
1585 | 0 | Self::Format4(item) => item.min_byte_range(), |
1586 | | } |
1587 | 0 | } |
1588 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1589 | 0 | match self { |
1590 | 0 | Self::Format1(item) => item.min_table_bytes(), |
1591 | 0 | Self::Format2(item) => item.min_table_bytes(), |
1592 | 0 | Self::Format3(item) => item.min_table_bytes(), |
1593 | 0 | Self::Format4(item) => item.min_table_bytes(), |
1594 | | } |
1595 | 0 | } |
1596 | | } |
1597 | | |
1598 | | impl Format<u16> for PairPosFormat1<'_> { |
1599 | | const FORMAT: u16 = 1; |
1600 | | } |
1601 | | |
1602 | | impl<'a> MinByteRange<'a> for PairPosFormat1<'a> { |
1603 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1604 | 0 | 0..self.pair_set_offsets_byte_range().end |
1605 | 0 | } |
1606 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1607 | 0 | let range = self.min_byte_range(); |
1608 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1609 | 0 | } |
1610 | | } |
1611 | | |
1612 | | impl ReadArgs for PairPosFormat1<'_> { |
1613 | | type Args = (); |
1614 | | } |
1615 | | |
1616 | | impl<'a> FontRead<'a> for PairPosFormat1<'a> { |
1617 | 21.6k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1618 | | #[allow(clippy::absurd_extreme_comparisons)] |
1619 | 21.6k | if data.len() < Self::MIN_SIZE { |
1620 | 457 | return Err(ReadError::OutOfBounds); |
1621 | 21.2k | } |
1622 | 21.2k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1623 | 0 | return Err(ReadError::OutOfBounds); |
1624 | | }; |
1625 | 21.2k | Ok(Self { data }) |
1626 | 21.6k | } |
1627 | | } |
1628 | | |
1629 | | /// The fields at the start of the table, which are read directly. |
1630 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1631 | | #[repr(C, packed)] |
1632 | | #[doc(hidden)] |
1633 | | pub struct PairPosFormat1FixedHeader { |
1634 | | pub pos_format: BigEndian<u16>, |
1635 | | pub coverage_offset: BigEndian<Offset16>, |
1636 | | pub value_format1: BigEndian<ValueFormat>, |
1637 | | pub value_format2: BigEndian<ValueFormat>, |
1638 | | pub pair_set_count: BigEndian<u16>, |
1639 | | } |
1640 | | |
1641 | | #[allow(clippy::absurd_extreme_comparisons)] |
1642 | | const _: () = assert!(std::mem::size_of::<PairPosFormat1FixedHeader>() <= PairPosFormat1::MIN_SIZE); |
1643 | | |
1644 | | /// [Pair Adjustment Positioning Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#pair-adjustment-positioning-format-1-adjustments-for-glyph-pairs): Adjustments for Glyph Pairs |
1645 | | #[derive(Clone)] |
1646 | | pub struct PairPosFormat1<'a> { |
1647 | | data: TableDataRef<'a, PairPosFormat1FixedHeader>, |
1648 | | } |
1649 | | |
1650 | | #[allow(clippy::needless_lifetimes)] |
1651 | | impl<'a> PairPosFormat1<'a> { |
1652 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
1653 | | + Offset16::RAW_BYTE_LEN |
1654 | | + ValueFormat::RAW_BYTE_LEN |
1655 | | + ValueFormat::RAW_BYTE_LEN |
1656 | | + u16::RAW_BYTE_LEN); |
1657 | | basic_table_impls!(impl_the_methods); |
1658 | | |
1659 | | /// Format identifier: format = 1 |
1660 | 0 | pub fn pos_format(&self) -> u16 { |
1661 | 0 | self.data.header().pos_format.get() |
1662 | 0 | } |
1663 | | |
1664 | | /// Offset to Coverage table, from beginning of PairPos subtable. |
1665 | 21.1k | pub fn coverage_offset(&self) -> Offset16 { |
1666 | 21.1k | self.data.header().coverage_offset.get() |
1667 | 21.1k | } |
1668 | | |
1669 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
1670 | 21.1k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
1671 | 21.1k | let data = self.offset_data(); |
1672 | 21.1k | self.coverage_offset().resolve(data) |
1673 | 21.1k | } |
1674 | | |
1675 | | /// Defines the types of data in valueRecord1 — for the first |
1676 | | /// glyph in the pair (may be zero). |
1677 | 42.4k | pub fn value_format1(&self) -> ValueFormat { |
1678 | 42.4k | self.data.header().value_format1.get() |
1679 | 42.4k | } |
1680 | | |
1681 | | /// Defines the types of data in valueRecord2 — for the second |
1682 | | /// glyph in the pair (may be zero). |
1683 | 42.4k | pub fn value_format2(&self) -> ValueFormat { |
1684 | 42.4k | self.data.header().value_format2.get() |
1685 | 42.4k | } |
1686 | | |
1687 | | /// Number of PairSet tables |
1688 | 21.2k | pub fn pair_set_count(&self) -> u16 { |
1689 | 21.2k | self.data.header().pair_set_count.get() |
1690 | 21.2k | } |
1691 | | |
1692 | | /// Array of offsets to PairSet tables. Offsets are from beginning |
1693 | | /// of PairPos subtable, ordered by Coverage Index. |
1694 | 0 | pub fn pair_set_offsets(&self) -> &'a [BigEndian<Offset16>] { |
1695 | 0 | let range = self.pair_set_offsets_byte_range(); |
1696 | 0 | self.offset_data() |
1697 | 0 | .read_array(range) |
1698 | 0 | .ok() |
1699 | 0 | .unwrap_or_default() |
1700 | 0 | } |
1701 | | |
1702 | | /// A dynamically resolving wrapper for [`pair_set_offsets`][Self::pair_set_offsets]. |
1703 | 0 | pub fn pair_sets(&self) -> ArrayOfOffsets<'a, PairSet<'a>, Offset16> { |
1704 | 0 | let data = self.offset_data(); |
1705 | 0 | let offsets = self.pair_set_offsets(); |
1706 | 0 | let args = (self.value_format1(), self.value_format2()); |
1707 | 0 | ArrayOfOffsets::new(offsets, data, args) |
1708 | 0 | } |
1709 | | |
1710 | 21.2k | pub fn pos_format_byte_range(&self) -> Range<usize> { |
1711 | 21.2k | let start = 0usize; |
1712 | 21.2k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1713 | 21.2k | start..end |
1714 | 21.2k | } |
1715 | | |
1716 | 21.2k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
1717 | 21.2k | let start = self.pos_format_byte_range().end; |
1718 | 21.2k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
1719 | 21.2k | start..end |
1720 | 21.2k | } |
1721 | | |
1722 | 21.2k | pub fn value_format1_byte_range(&self) -> Range<usize> { |
1723 | 21.2k | let start = self.coverage_offset_byte_range().end; |
1724 | 21.2k | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
1725 | 21.2k | start..end |
1726 | 21.2k | } |
1727 | | |
1728 | 21.2k | pub fn value_format2_byte_range(&self) -> Range<usize> { |
1729 | 21.2k | let start = self.value_format1_byte_range().end; |
1730 | 21.2k | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
1731 | 21.2k | start..end |
1732 | 21.2k | } |
1733 | | |
1734 | 21.2k | pub fn pair_set_count_byte_range(&self) -> Range<usize> { |
1735 | 21.2k | let start = self.value_format2_byte_range().end; |
1736 | 21.2k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1737 | 21.2k | start..end |
1738 | 21.2k | } |
1739 | | |
1740 | 21.2k | pub fn pair_set_offsets_byte_range(&self) -> Range<usize> { |
1741 | 21.2k | let pair_set_count = self.pair_set_count(); |
1742 | 21.2k | let start = self.pair_set_count_byte_range().end; |
1743 | 21.2k | let end = start.saturating_add( |
1744 | 21.2k | (transforms::to_usize(pair_set_count)).saturating_mul(Offset16::RAW_BYTE_LEN), |
1745 | | ); |
1746 | 21.2k | start..end |
1747 | 21.2k | } |
1748 | | } |
1749 | | |
1750 | | const _: () = assert!(FontData::default_data_long_enough(PairPosFormat1::MIN_SIZE)); |
1751 | | |
1752 | | impl Default for PairPosFormat1<'_> { |
1753 | 0 | fn default() -> Self { |
1754 | | Self { |
1755 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
1756 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
1757 | | } |
1758 | 0 | } |
1759 | | } |
1760 | | |
1761 | | impl<'a> MinByteRange<'a> for PairSet<'a> { |
1762 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1763 | 0 | 0..self.pair_value_records_byte_range().end |
1764 | 0 | } |
1765 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1766 | 0 | let range = self.min_byte_range(); |
1767 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1768 | 0 | } |
1769 | | } |
1770 | | |
1771 | | impl ReadArgs for PairSet<'_> { |
1772 | | type Args = (ValueFormat, ValueFormat); |
1773 | | } |
1774 | | |
1775 | | impl<'a> FontRead<'a> for PairSet<'a> { |
1776 | 0 | fn read_with_args( |
1777 | 0 | data: FontData<'a>, |
1778 | 0 | args: (ValueFormat, ValueFormat), |
1779 | 0 | ) -> Result<Self, ReadError> { |
1780 | 0 | let (value_format1, value_format2) = args; |
1781 | | |
1782 | | #[allow(clippy::absurd_extreme_comparisons)] |
1783 | 0 | if data.len() < Self::MIN_SIZE { |
1784 | 0 | return Err(ReadError::OutOfBounds); |
1785 | 0 | } |
1786 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1787 | 0 | return Err(ReadError::OutOfBounds); |
1788 | | }; |
1789 | 0 | Ok(Self { |
1790 | 0 | data, |
1791 | 0 | value_format1, |
1792 | 0 | value_format2, |
1793 | 0 | }) |
1794 | 0 | } |
1795 | | } |
1796 | | |
1797 | | impl<'a> PairSet<'a> { |
1798 | | /// A constructor that requires additional arguments. |
1799 | | /// |
1800 | | /// This type requires some external state in order to be |
1801 | | /// parsed. |
1802 | 0 | pub fn read( |
1803 | 0 | data: FontData<'a>, |
1804 | 0 | value_format1: ValueFormat, |
1805 | 0 | value_format2: ValueFormat, |
1806 | 0 | ) -> Result<Self, ReadError> { |
1807 | 0 | let args = (value_format1, value_format2); |
1808 | 0 | Self::read_with_args(data, args) |
1809 | 0 | } |
1810 | | } |
1811 | | |
1812 | | /// The fields at the start of the table, which are read directly. |
1813 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1814 | | #[repr(C, packed)] |
1815 | | #[doc(hidden)] |
1816 | | pub struct PairSetFixedHeader { |
1817 | | pub pair_value_count: BigEndian<u16>, |
1818 | | } |
1819 | | |
1820 | | #[allow(clippy::absurd_extreme_comparisons)] |
1821 | | const _: () = assert!(std::mem::size_of::<PairSetFixedHeader>() <= PairSet::MIN_SIZE); |
1822 | | |
1823 | | /// Part of [PairPosFormat1] |
1824 | | #[derive(Clone)] |
1825 | | pub struct PairSet<'a> { |
1826 | | data: TableDataRef<'a, PairSetFixedHeader>, |
1827 | | value_format1: ValueFormat, |
1828 | | value_format2: ValueFormat, |
1829 | | } |
1830 | | |
1831 | | #[allow(clippy::needless_lifetimes)] |
1832 | | impl<'a> PairSet<'a> { |
1833 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
1834 | | basic_table_impls!(impl_the_methods); |
1835 | | |
1836 | | /// Number of PairValueRecords |
1837 | 0 | pub fn pair_value_count(&self) -> u16 { |
1838 | 0 | self.data.header().pair_value_count.get() |
1839 | 0 | } |
1840 | | |
1841 | | /// Array of PairValueRecords, ordered by glyph ID of the second |
1842 | | /// glyph. |
1843 | 0 | pub fn pair_value_records(&self) -> ComputedArray<'a, PairValueRecord<'a>> { |
1844 | 0 | let range = self.pair_value_records_byte_range(); |
1845 | 0 | ComputedArray::new( |
1846 | 0 | self.offset_data(), |
1847 | 0 | range, |
1848 | 0 | (self.value_format1(), self.value_format2()), |
1849 | | ) |
1850 | 0 | .unwrap_or_default() |
1851 | 0 | } |
1852 | | |
1853 | 0 | pub(crate) fn value_format1(&self) -> ValueFormat { |
1854 | 0 | self.value_format1 |
1855 | 0 | } |
1856 | | |
1857 | 0 | pub(crate) fn value_format2(&self) -> ValueFormat { |
1858 | 0 | self.value_format2 |
1859 | 0 | } |
1860 | | |
1861 | 0 | pub fn pair_value_count_byte_range(&self) -> Range<usize> { |
1862 | 0 | let start = 0usize; |
1863 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1864 | 0 | start..end |
1865 | 0 | } |
1866 | | |
1867 | 0 | pub fn pair_value_records_byte_range(&self) -> Range<usize> { |
1868 | 0 | let pair_value_count = self.pair_value_count(); |
1869 | 0 | let start = self.pair_value_count_byte_range().end; |
1870 | 0 | let end = start.saturating_add( |
1871 | 0 | (transforms::to_usize(pair_value_count)).saturating_mul( |
1872 | 0 | <PairValueRecord as ComputeSize>::compute_size(( |
1873 | 0 | self.value_format1(), |
1874 | 0 | self.value_format2(), |
1875 | 0 | )) |
1876 | 0 | .unwrap_or(0), |
1877 | | ), |
1878 | | ); |
1879 | 0 | start..end |
1880 | 0 | } |
1881 | | } |
1882 | | |
1883 | | const _: () = assert!(FontData::default_data_long_enough(PairSet::MIN_SIZE)); |
1884 | | |
1885 | | impl Default for PairSet<'_> { |
1886 | 0 | fn default() -> Self { |
1887 | | Self { |
1888 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
1889 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
1890 | 0 | value_format1: Default::default(), |
1891 | 0 | value_format2: Default::default(), |
1892 | | } |
1893 | 0 | } |
1894 | | } |
1895 | | |
1896 | | /// Part of [PairSet] |
1897 | | #[derive(Clone, Debug)] |
1898 | | pub struct PairValueRecord<'a> { |
1899 | | /// Glyph ID of second glyph in the pair (first glyph is listed in |
1900 | | /// the Coverage table). |
1901 | | pub second_glyph: BigEndian<GlyphId16>, |
1902 | | /// Positioning data for the first glyph in the pair. |
1903 | | pub value_record1: ValueRecord<'a>, |
1904 | | /// Positioning data for the second glyph in the pair. |
1905 | | pub value_record2: ValueRecord<'a>, |
1906 | | } |
1907 | | |
1908 | | impl<'a> PairValueRecord<'a> { |
1909 | | /// Glyph ID of second glyph in the pair (first glyph is listed in |
1910 | | /// the Coverage table). |
1911 | 0 | pub fn second_glyph(&self) -> GlyphId16 { |
1912 | 0 | self.second_glyph.get() |
1913 | 0 | } |
1914 | | |
1915 | | /// Positioning data for the first glyph in the pair. |
1916 | 0 | pub fn value_record1(&self) -> &ValueRecord<'a> { |
1917 | 0 | &self.value_record1 |
1918 | 0 | } |
1919 | | |
1920 | | /// Positioning data for the second glyph in the pair. |
1921 | 0 | pub fn value_record2(&self) -> &ValueRecord<'a> { |
1922 | 0 | &self.value_record2 |
1923 | 0 | } |
1924 | | } |
1925 | | |
1926 | | impl ReadArgs for PairValueRecord<'_> { |
1927 | | type Args = (ValueFormat, ValueFormat); |
1928 | | } |
1929 | | |
1930 | | impl ComputeSize for PairValueRecord<'_> { |
1931 | | #[allow(clippy::needless_question_mark)] |
1932 | 0 | fn compute_size(args: (ValueFormat, ValueFormat)) -> Result<usize, ReadError> { |
1933 | 0 | let (value_format1, value_format2) = args; |
1934 | 0 | let mut result = 0usize; |
1935 | 0 | result = result |
1936 | 0 | .checked_add(GlyphId16::RAW_BYTE_LEN) |
1937 | 0 | .ok_or(ReadError::OutOfBounds)?; |
1938 | 0 | result = result |
1939 | 0 | .checked_add(<ValueRecord as ComputeSize>::compute_size(value_format1).unwrap_or(0)) |
1940 | 0 | .ok_or(ReadError::OutOfBounds)?; |
1941 | 0 | result = result |
1942 | 0 | .checked_add(<ValueRecord as ComputeSize>::compute_size(value_format2).unwrap_or(0)) |
1943 | 0 | .ok_or(ReadError::OutOfBounds)?; |
1944 | 0 | Ok(result) |
1945 | 0 | } |
1946 | | } |
1947 | | |
1948 | | impl<'a> FontReadAt<'a> for PairValueRecord<'a> { |
1949 | 0 | fn read_at( |
1950 | 0 | data: FontData<'a>, |
1951 | 0 | offset: usize, |
1952 | 0 | args: (ValueFormat, ValueFormat), |
1953 | 0 | ) -> Result<Self, ReadError> { |
1954 | 0 | let mut cursor = data.cursor(); |
1955 | 0 | cursor.advance_by(offset); |
1956 | 0 | let (value_format1, value_format2) = args; |
1957 | | Ok(Self { |
1958 | 0 | second_glyph: cursor.read_be()?, |
1959 | 0 | value_record1: cursor.read_at_with_args(value_format1)?, |
1960 | 0 | value_record2: cursor.read_at_with_args(value_format2)?, |
1961 | | }) |
1962 | 0 | } |
1963 | | } |
1964 | | |
1965 | | #[allow(clippy::needless_lifetimes)] |
1966 | | impl<'a> PairValueRecord<'a> { |
1967 | | /// A constructor that requires additional arguments. |
1968 | | /// |
1969 | | /// This type requires some external state in order to be |
1970 | | /// parsed. |
1971 | 0 | pub fn read( |
1972 | 0 | data: FontData<'a>, |
1973 | 0 | offset: usize, |
1974 | 0 | value_format1: ValueFormat, |
1975 | 0 | value_format2: ValueFormat, |
1976 | 0 | ) -> Result<Self, ReadError> { |
1977 | 0 | let args = (value_format1, value_format2); |
1978 | 0 | Self::read_at(data, offset, args) |
1979 | 0 | } |
1980 | | } |
1981 | | |
1982 | | impl Format<u16> for PairPosFormat2<'_> { |
1983 | | const FORMAT: u16 = 2; |
1984 | | } |
1985 | | |
1986 | | impl<'a> MinByteRange<'a> for PairPosFormat2<'a> { |
1987 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1988 | 0 | 0..self.class1_records_byte_range().end |
1989 | 0 | } |
1990 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1991 | 0 | let range = self.min_byte_range(); |
1992 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1993 | 0 | } |
1994 | | } |
1995 | | |
1996 | | impl ReadArgs for PairPosFormat2<'_> { |
1997 | | type Args = (); |
1998 | | } |
1999 | | |
2000 | | impl<'a> FontRead<'a> for PairPosFormat2<'a> { |
2001 | 210k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2002 | | #[allow(clippy::absurd_extreme_comparisons)] |
2003 | 210k | if data.len() < Self::MIN_SIZE { |
2004 | 520 | return Err(ReadError::OutOfBounds); |
2005 | 210k | } |
2006 | 210k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2007 | 0 | return Err(ReadError::OutOfBounds); |
2008 | | }; |
2009 | 210k | Ok(Self { data }) |
2010 | 210k | } |
2011 | | } |
2012 | | |
2013 | | /// The fields at the start of the table, which are read directly. |
2014 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2015 | | #[repr(C, packed)] |
2016 | | #[doc(hidden)] |
2017 | | pub struct PairPosFormat2FixedHeader { |
2018 | | pub pos_format: BigEndian<u16>, |
2019 | | pub coverage_offset: BigEndian<Offset16>, |
2020 | | pub value_format1: BigEndian<ValueFormat>, |
2021 | | pub value_format2: BigEndian<ValueFormat>, |
2022 | | pub class_def1_offset: BigEndian<Offset16>, |
2023 | | pub class_def2_offset: BigEndian<Offset16>, |
2024 | | pub class1_count: BigEndian<u16>, |
2025 | | pub class2_count: BigEndian<u16>, |
2026 | | } |
2027 | | |
2028 | | #[allow(clippy::absurd_extreme_comparisons)] |
2029 | | const _: () = assert!(std::mem::size_of::<PairPosFormat2FixedHeader>() <= PairPosFormat2::MIN_SIZE); |
2030 | | |
2031 | | /// [Pair Adjustment Positioning Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#pair-adjustment-positioning-format-2-class-pair-adjustment): Class Pair Adjustment |
2032 | | #[derive(Clone)] |
2033 | | pub struct PairPosFormat2<'a> { |
2034 | | data: TableDataRef<'a, PairPosFormat2FixedHeader>, |
2035 | | } |
2036 | | |
2037 | | #[allow(clippy::needless_lifetimes)] |
2038 | | impl<'a> PairPosFormat2<'a> { |
2039 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
2040 | | + Offset16::RAW_BYTE_LEN |
2041 | | + ValueFormat::RAW_BYTE_LEN |
2042 | | + ValueFormat::RAW_BYTE_LEN |
2043 | | + Offset16::RAW_BYTE_LEN |
2044 | | + Offset16::RAW_BYTE_LEN |
2045 | | + u16::RAW_BYTE_LEN |
2046 | | + u16::RAW_BYTE_LEN); |
2047 | | basic_table_impls!(impl_the_methods); |
2048 | | |
2049 | | /// Format identifier: format = 2 |
2050 | 0 | pub fn pos_format(&self) -> u16 { |
2051 | 0 | self.data.header().pos_format.get() |
2052 | 0 | } |
2053 | | |
2054 | | /// Offset to Coverage table, from beginning of PairPos subtable. |
2055 | 210k | pub fn coverage_offset(&self) -> Offset16 { |
2056 | 210k | self.data.header().coverage_offset.get() |
2057 | 210k | } |
2058 | | |
2059 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
2060 | 210k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
2061 | 210k | let data = self.offset_data(); |
2062 | 210k | self.coverage_offset().resolve(data) |
2063 | 210k | } |
2064 | | |
2065 | | /// ValueRecord definition — for the first glyph of the pair (may |
2066 | | /// be zero). |
2067 | 630k | pub fn value_format1(&self) -> ValueFormat { |
2068 | 630k | self.data.header().value_format1.get() |
2069 | 630k | } |
2070 | | |
2071 | | /// ValueRecord definition — for the second glyph of the pair |
2072 | | /// (may be zero). |
2073 | 630k | pub fn value_format2(&self) -> ValueFormat { |
2074 | 630k | self.data.header().value_format2.get() |
2075 | 630k | } |
2076 | | |
2077 | | /// Offset to ClassDef table, from beginning of PairPos subtable |
2078 | | /// — for the first glyph of the pair. |
2079 | 210k | pub fn class_def1_offset(&self) -> Offset16 { |
2080 | 210k | self.data.header().class_def1_offset.get() |
2081 | 210k | } |
2082 | | |
2083 | | /// Attempt to resolve [`class_def1_offset`][Self::class_def1_offset]. |
2084 | 210k | pub fn class_def1(&self) -> Result<ClassDef<'a>, ReadError> { |
2085 | 210k | let data = self.offset_data(); |
2086 | 210k | self.class_def1_offset().resolve(data) |
2087 | 210k | } |
2088 | | |
2089 | | /// Offset to ClassDef table, from beginning of PairPos subtable |
2090 | | /// — for the second glyph of the pair. |
2091 | 210k | pub fn class_def2_offset(&self) -> Offset16 { |
2092 | 210k | self.data.header().class_def2_offset.get() |
2093 | 210k | } |
2094 | | |
2095 | | /// Attempt to resolve [`class_def2_offset`][Self::class_def2_offset]. |
2096 | 210k | pub fn class_def2(&self) -> Result<ClassDef<'a>, ReadError> { |
2097 | 210k | let data = self.offset_data(); |
2098 | 210k | self.class_def2_offset().resolve(data) |
2099 | 210k | } |
2100 | | |
2101 | | /// Number of classes in classDef1 table — includes Class 0. |
2102 | 630k | pub fn class1_count(&self) -> u16 { |
2103 | 630k | self.data.header().class1_count.get() |
2104 | 630k | } |
2105 | | |
2106 | | /// Number of classes in classDef2 table — includes Class 0. |
2107 | 630k | pub fn class2_count(&self) -> u16 { |
2108 | 630k | self.data.header().class2_count.get() |
2109 | 630k | } |
2110 | | |
2111 | | /// Array of Class1 records, ordered by classes in classDef1. |
2112 | 0 | pub fn class1_records(&self) -> ComputedArray<'a, Class1Record<'a>> { |
2113 | 0 | let range = self.class1_records_byte_range(); |
2114 | 0 | ComputedArray::new( |
2115 | 0 | self.offset_data(), |
2116 | 0 | range, |
2117 | 0 | ( |
2118 | 0 | self.class2_count(), |
2119 | 0 | self.value_format1(), |
2120 | 0 | self.value_format2(), |
2121 | 0 | ), |
2122 | | ) |
2123 | 0 | .unwrap_or_default() |
2124 | 0 | } |
2125 | | |
2126 | 420k | pub fn pos_format_byte_range(&self) -> Range<usize> { |
2127 | 420k | let start = 0usize; |
2128 | 420k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2129 | 420k | start..end |
2130 | 420k | } |
2131 | | |
2132 | 420k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
2133 | 420k | let start = self.pos_format_byte_range().end; |
2134 | 420k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
2135 | 420k | start..end |
2136 | 420k | } |
2137 | | |
2138 | 420k | pub fn value_format1_byte_range(&self) -> Range<usize> { |
2139 | 420k | let start = self.coverage_offset_byte_range().end; |
2140 | 420k | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
2141 | 420k | start..end |
2142 | 420k | } |
2143 | | |
2144 | 420k | pub fn value_format2_byte_range(&self) -> Range<usize> { |
2145 | 420k | let start = self.value_format1_byte_range().end; |
2146 | 420k | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
2147 | 420k | start..end |
2148 | 420k | } |
2149 | | |
2150 | 420k | pub fn class_def1_offset_byte_range(&self) -> Range<usize> { |
2151 | 420k | let start = self.value_format2_byte_range().end; |
2152 | 420k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
2153 | 420k | start..end |
2154 | 420k | } |
2155 | | |
2156 | 420k | pub fn class_def2_offset_byte_range(&self) -> Range<usize> { |
2157 | 420k | let start = self.class_def1_offset_byte_range().end; |
2158 | 420k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
2159 | 420k | start..end |
2160 | 420k | } |
2161 | | |
2162 | 420k | pub fn class1_count_byte_range(&self) -> Range<usize> { |
2163 | 420k | let start = self.class_def2_offset_byte_range().end; |
2164 | 420k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2165 | 420k | start..end |
2166 | 420k | } |
2167 | | |
2168 | 420k | pub fn class2_count_byte_range(&self) -> Range<usize> { |
2169 | 420k | let start = self.class1_count_byte_range().end; |
2170 | 420k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2171 | 420k | start..end |
2172 | 420k | } |
2173 | | |
2174 | 210k | pub fn class1_records_byte_range(&self) -> Range<usize> { |
2175 | 210k | let class1_count = self.class1_count(); |
2176 | 210k | let start = self.class2_count_byte_range().end; |
2177 | 210k | let end = start.saturating_add( |
2178 | 210k | (transforms::to_usize(class1_count)).saturating_mul( |
2179 | 210k | <Class1Record as ComputeSize>::compute_size(( |
2180 | 210k | self.class2_count(), |
2181 | 210k | self.value_format1(), |
2182 | 210k | self.value_format2(), |
2183 | 210k | )) |
2184 | 210k | .unwrap_or(0), |
2185 | | ), |
2186 | | ); |
2187 | 210k | start..end |
2188 | 210k | } |
2189 | | } |
2190 | | |
2191 | | /// Part of [PairPosFormat2] |
2192 | | #[derive(Clone, Debug)] |
2193 | | pub struct Class1Record<'a> { |
2194 | | /// Array of Class2 records, ordered by classes in classDef2. |
2195 | | pub class2_records: ComputedArray<'a, Class2Record<'a>>, |
2196 | | } |
2197 | | |
2198 | | impl<'a> Class1Record<'a> { |
2199 | | /// Array of Class2 records, ordered by classes in classDef2. |
2200 | 0 | pub fn class2_records(&self) -> &ComputedArray<'a, Class2Record<'a>> { |
2201 | 0 | &self.class2_records |
2202 | 0 | } |
2203 | | } |
2204 | | |
2205 | | impl ReadArgs for Class1Record<'_> { |
2206 | | type Args = (u16, ValueFormat, ValueFormat); |
2207 | | } |
2208 | | |
2209 | | impl ComputeSize for Class1Record<'_> { |
2210 | | #[allow(clippy::needless_question_mark)] |
2211 | 216k | fn compute_size(args: (u16, ValueFormat, ValueFormat)) -> Result<usize, ReadError> { |
2212 | 216k | let (class2_count, value_format1, value_format2) = args; |
2213 | 216k | Ok((transforms::to_usize(class2_count)).saturating_mul( |
2214 | 216k | <Class2Record as ComputeSize>::compute_size((value_format1, value_format2)) |
2215 | 216k | .unwrap_or(0), |
2216 | 216k | )) |
2217 | 216k | } |
2218 | | } |
2219 | | |
2220 | | impl<'a> FontReadAt<'a> for Class1Record<'a> { |
2221 | 0 | fn read_at( |
2222 | 0 | data: FontData<'a>, |
2223 | 0 | offset: usize, |
2224 | 0 | args: (u16, ValueFormat, ValueFormat), |
2225 | 0 | ) -> Result<Self, ReadError> { |
2226 | 0 | let mut cursor = data.cursor(); |
2227 | 0 | cursor.advance_by(offset); |
2228 | 0 | let (class2_count, value_format1, value_format2) = args; |
2229 | | Ok(Self { |
2230 | 0 | class2_records: cursor.read_computed_array( |
2231 | 0 | transforms::to_usize(class2_count), |
2232 | 0 | (value_format1, value_format2), |
2233 | 0 | )?, |
2234 | | }) |
2235 | 0 | } |
2236 | | } |
2237 | | |
2238 | | #[allow(clippy::needless_lifetimes)] |
2239 | | impl<'a> Class1Record<'a> { |
2240 | | /// A constructor that requires additional arguments. |
2241 | | /// |
2242 | | /// This type requires some external state in order to be |
2243 | | /// parsed. |
2244 | 0 | pub fn read( |
2245 | 0 | data: FontData<'a>, |
2246 | 0 | offset: usize, |
2247 | 0 | class2_count: u16, |
2248 | 0 | value_format1: ValueFormat, |
2249 | 0 | value_format2: ValueFormat, |
2250 | 0 | ) -> Result<Self, ReadError> { |
2251 | 0 | let args = (class2_count, value_format1, value_format2); |
2252 | 0 | Self::read_at(data, offset, args) |
2253 | 0 | } |
2254 | | } |
2255 | | |
2256 | | /// Part of [PairPosFormat2] |
2257 | | #[derive(Clone, Debug)] |
2258 | | pub struct Class2Record<'a> { |
2259 | | /// Positioning for first glyph — empty if valueFormat1 = 0. |
2260 | | pub value_record1: ValueRecord<'a>, |
2261 | | /// Positioning for second glyph — empty if valueFormat2 = 0. |
2262 | | pub value_record2: ValueRecord<'a>, |
2263 | | } |
2264 | | |
2265 | | impl<'a> Class2Record<'a> { |
2266 | | /// Positioning for first glyph — empty if valueFormat1 = 0. |
2267 | 0 | pub fn value_record1(&self) -> &ValueRecord<'a> { |
2268 | 0 | &self.value_record1 |
2269 | 0 | } |
2270 | | |
2271 | | /// Positioning for second glyph — empty if valueFormat2 = 0. |
2272 | 0 | pub fn value_record2(&self) -> &ValueRecord<'a> { |
2273 | 0 | &self.value_record2 |
2274 | 0 | } |
2275 | | } |
2276 | | |
2277 | | impl ReadArgs for Class2Record<'_> { |
2278 | | type Args = (ValueFormat, ValueFormat); |
2279 | | } |
2280 | | |
2281 | | impl ComputeSize for Class2Record<'_> { |
2282 | | #[allow(clippy::needless_question_mark)] |
2283 | 216k | fn compute_size(args: (ValueFormat, ValueFormat)) -> Result<usize, ReadError> { |
2284 | 216k | let (value_format1, value_format2) = args; |
2285 | 216k | let mut result = 0usize; |
2286 | 216k | result = result |
2287 | 216k | .checked_add(<ValueRecord as ComputeSize>::compute_size(value_format1).unwrap_or(0)) |
2288 | 216k | .ok_or(ReadError::OutOfBounds)?; |
2289 | 216k | result = result |
2290 | 216k | .checked_add(<ValueRecord as ComputeSize>::compute_size(value_format2).unwrap_or(0)) |
2291 | 216k | .ok_or(ReadError::OutOfBounds)?; |
2292 | 216k | Ok(result) |
2293 | 216k | } |
2294 | | } |
2295 | | |
2296 | | impl<'a> FontReadAt<'a> for Class2Record<'a> { |
2297 | 0 | fn read_at( |
2298 | 0 | data: FontData<'a>, |
2299 | 0 | offset: usize, |
2300 | 0 | args: (ValueFormat, ValueFormat), |
2301 | 0 | ) -> Result<Self, ReadError> { |
2302 | 0 | let mut cursor = data.cursor(); |
2303 | 0 | cursor.advance_by(offset); |
2304 | 0 | let (value_format1, value_format2) = args; |
2305 | | Ok(Self { |
2306 | 0 | value_record1: cursor.read_at_with_args(value_format1)?, |
2307 | 0 | value_record2: cursor.read_at_with_args(value_format2)?, |
2308 | | }) |
2309 | 0 | } |
2310 | | } |
2311 | | |
2312 | | #[allow(clippy::needless_lifetimes)] |
2313 | | impl<'a> Class2Record<'a> { |
2314 | | /// A constructor that requires additional arguments. |
2315 | | /// |
2316 | | /// This type requires some external state in order to be |
2317 | | /// parsed. |
2318 | 0 | pub fn read( |
2319 | 0 | data: FontData<'a>, |
2320 | 0 | offset: usize, |
2321 | 0 | value_format1: ValueFormat, |
2322 | 0 | value_format2: ValueFormat, |
2323 | 0 | ) -> Result<Self, ReadError> { |
2324 | 0 | let args = (value_format1, value_format2); |
2325 | 0 | Self::read_at(data, offset, args) |
2326 | 0 | } |
2327 | | } |
2328 | | |
2329 | | impl Format<u16> for CursivePosFormat1<'_> { |
2330 | | const FORMAT: u16 = 1; |
2331 | | } |
2332 | | |
2333 | | impl<'a> MinByteRange<'a> for CursivePosFormat1<'a> { |
2334 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2335 | 0 | 0..self.entry_exit_record_byte_range().end |
2336 | 0 | } |
2337 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2338 | 0 | let range = self.min_byte_range(); |
2339 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2340 | 0 | } |
2341 | | } |
2342 | | |
2343 | | impl ReadArgs for CursivePosFormat1<'_> { |
2344 | | type Args = (); |
2345 | | } |
2346 | | |
2347 | | impl<'a> FontRead<'a> for CursivePosFormat1<'a> { |
2348 | 7.18k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2349 | | #[allow(clippy::absurd_extreme_comparisons)] |
2350 | 7.18k | if data.len() < Self::MIN_SIZE { |
2351 | 371 | return Err(ReadError::OutOfBounds); |
2352 | 6.81k | } |
2353 | 6.81k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2354 | 0 | return Err(ReadError::OutOfBounds); |
2355 | | }; |
2356 | 6.81k | Ok(Self { data }) |
2357 | 7.18k | } |
2358 | | } |
2359 | | |
2360 | | /// The fields at the start of the table, which are read directly. |
2361 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2362 | | #[repr(C, packed)] |
2363 | | #[doc(hidden)] |
2364 | | pub struct CursivePosFormat1FixedHeader { |
2365 | | pub pos_format: BigEndian<u16>, |
2366 | | pub coverage_offset: BigEndian<Offset16>, |
2367 | | pub entry_exit_count: BigEndian<u16>, |
2368 | | } |
2369 | | |
2370 | | #[allow(clippy::absurd_extreme_comparisons)] |
2371 | | const _: () = |
2372 | | assert!(std::mem::size_of::<CursivePosFormat1FixedHeader>() <= CursivePosFormat1::MIN_SIZE); |
2373 | | |
2374 | | /// [Cursive Attachment Positioning Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#cursive-attachment-positioning-format1-cursive-attachment): Cursvie attachment |
2375 | | #[derive(Clone)] |
2376 | | pub struct CursivePosFormat1<'a> { |
2377 | | data: TableDataRef<'a, CursivePosFormat1FixedHeader>, |
2378 | | } |
2379 | | |
2380 | | #[allow(clippy::needless_lifetimes)] |
2381 | | impl<'a> CursivePosFormat1<'a> { |
2382 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN); |
2383 | | basic_table_impls!(impl_the_methods); |
2384 | | |
2385 | | /// Format identifier: format = 1 |
2386 | 0 | pub fn pos_format(&self) -> u16 { |
2387 | 0 | self.data.header().pos_format.get() |
2388 | 0 | } |
2389 | | |
2390 | | /// Offset to Coverage table, from beginning of CursivePos subtable. |
2391 | 13.6k | pub fn coverage_offset(&self) -> Offset16 { |
2392 | 13.6k | self.data.header().coverage_offset.get() |
2393 | 13.6k | } |
2394 | | |
2395 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
2396 | 13.6k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
2397 | 13.6k | let data = self.offset_data(); |
2398 | 13.6k | self.coverage_offset().resolve(data) |
2399 | 13.6k | } |
2400 | | |
2401 | | /// Number of EntryExit records |
2402 | 6.81k | pub fn entry_exit_count(&self) -> u16 { |
2403 | 6.81k | self.data.header().entry_exit_count.get() |
2404 | 6.81k | } |
2405 | | |
2406 | | /// Array of EntryExit records, in Coverage index order. |
2407 | 0 | pub fn entry_exit_record(&self) -> &'a [EntryExitRecord] { |
2408 | 0 | let range = self.entry_exit_record_byte_range(); |
2409 | 0 | self.offset_data() |
2410 | 0 | .read_array(range) |
2411 | 0 | .ok() |
2412 | 0 | .unwrap_or_default() |
2413 | 0 | } |
2414 | | |
2415 | 6.81k | pub fn pos_format_byte_range(&self) -> Range<usize> { |
2416 | 6.81k | let start = 0usize; |
2417 | 6.81k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2418 | 6.81k | start..end |
2419 | 6.81k | } |
2420 | | |
2421 | 6.81k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
2422 | 6.81k | let start = self.pos_format_byte_range().end; |
2423 | 6.81k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
2424 | 6.81k | start..end |
2425 | 6.81k | } |
2426 | | |
2427 | 6.81k | pub fn entry_exit_count_byte_range(&self) -> Range<usize> { |
2428 | 6.81k | let start = self.coverage_offset_byte_range().end; |
2429 | 6.81k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2430 | 6.81k | start..end |
2431 | 6.81k | } |
2432 | | |
2433 | 6.81k | pub fn entry_exit_record_byte_range(&self) -> Range<usize> { |
2434 | 6.81k | let entry_exit_count = self.entry_exit_count(); |
2435 | 6.81k | let start = self.entry_exit_count_byte_range().end; |
2436 | 6.81k | let end = start.saturating_add( |
2437 | 6.81k | (transforms::to_usize(entry_exit_count)).saturating_mul(EntryExitRecord::RAW_BYTE_LEN), |
2438 | | ); |
2439 | 6.81k | start..end |
2440 | 6.81k | } |
2441 | | } |
2442 | | |
2443 | | const _: () = assert!(FontData::default_data_long_enough( |
2444 | | CursivePosFormat1::MIN_SIZE |
2445 | | )); |
2446 | | |
2447 | | impl Default for CursivePosFormat1<'_> { |
2448 | 0 | fn default() -> Self { |
2449 | | Self { |
2450 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
2451 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
2452 | | } |
2453 | 0 | } |
2454 | | } |
2455 | | |
2456 | | /// Part of [CursivePosFormat1] |
2457 | | #[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)] |
2458 | | #[repr(C)] |
2459 | | #[repr(packed)] |
2460 | | pub struct EntryExitRecord { |
2461 | | /// Offset to entryAnchor table, from beginning of CursivePos |
2462 | | /// subtable (may be NULL). |
2463 | | pub entry_anchor_offset: BigEndian<Nullable<Offset16>>, |
2464 | | /// Offset to exitAnchor table, from beginning of CursivePos |
2465 | | /// subtable (may be NULL). |
2466 | | pub exit_anchor_offset: BigEndian<Nullable<Offset16>>, |
2467 | | } |
2468 | | |
2469 | | impl EntryExitRecord { |
2470 | | /// Offset to entryAnchor table, from beginning of CursivePos |
2471 | | /// subtable (may be NULL). |
2472 | 0 | pub fn entry_anchor_offset(&self) -> Nullable<Offset16> { |
2473 | 0 | self.entry_anchor_offset.get() |
2474 | 0 | } |
2475 | | |
2476 | | /// Offset to entryAnchor table, from beginning of CursivePos |
2477 | | /// subtable (may be NULL). |
2478 | | /// |
2479 | | /// The `data` argument should be retrieved from the parent table |
2480 | | /// By calling its `offset_data` method. |
2481 | 0 | pub fn entry_anchor<'a>( |
2482 | 0 | &self, |
2483 | 0 | data: FontData<'a>, |
2484 | 0 | ) -> Option<Result<AnchorTable<'a>, ReadError>> { |
2485 | 0 | self.entry_anchor_offset().resolve(data) |
2486 | 0 | } |
2487 | | |
2488 | | /// Offset to exitAnchor table, from beginning of CursivePos |
2489 | | /// subtable (may be NULL). |
2490 | 0 | pub fn exit_anchor_offset(&self) -> Nullable<Offset16> { |
2491 | 0 | self.exit_anchor_offset.get() |
2492 | 0 | } |
2493 | | |
2494 | | /// Offset to exitAnchor table, from beginning of CursivePos |
2495 | | /// subtable (may be NULL). |
2496 | | /// |
2497 | | /// The `data` argument should be retrieved from the parent table |
2498 | | /// By calling its `offset_data` method. |
2499 | 0 | pub fn exit_anchor<'a>( |
2500 | 0 | &self, |
2501 | 0 | data: FontData<'a>, |
2502 | 0 | ) -> Option<Result<AnchorTable<'a>, ReadError>> { |
2503 | 0 | self.exit_anchor_offset().resolve(data) |
2504 | 0 | } |
2505 | | } |
2506 | | |
2507 | | impl FixedSize for EntryExitRecord { |
2508 | | const RAW_BYTE_LEN: usize = Offset16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN; |
2509 | | } |
2510 | | |
2511 | | impl Format<u16> for MarkBasePosFormat1<'_> { |
2512 | | const FORMAT: u16 = 1; |
2513 | | } |
2514 | | |
2515 | | impl<'a> MinByteRange<'a> for MarkBasePosFormat1<'a> { |
2516 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2517 | 0 | 0..self.base_array_offset_byte_range().end |
2518 | 0 | } |
2519 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2520 | 0 | let range = self.min_byte_range(); |
2521 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2522 | 0 | } |
2523 | | } |
2524 | | |
2525 | | impl ReadArgs for MarkBasePosFormat1<'_> { |
2526 | | type Args = (); |
2527 | | } |
2528 | | |
2529 | | impl<'a> FontRead<'a> for MarkBasePosFormat1<'a> { |
2530 | 7.14k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2531 | | #[allow(clippy::absurd_extreme_comparisons)] |
2532 | 7.14k | if data.len() < Self::MIN_SIZE { |
2533 | 237 | return Err(ReadError::OutOfBounds); |
2534 | 6.90k | } |
2535 | 6.90k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2536 | 0 | return Err(ReadError::OutOfBounds); |
2537 | | }; |
2538 | 6.90k | Ok(Self { data }) |
2539 | 7.14k | } |
2540 | | } |
2541 | | |
2542 | | /// The fields at the start of the table, which are read directly. |
2543 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2544 | | #[repr(C, packed)] |
2545 | | #[doc(hidden)] |
2546 | | pub struct MarkBasePosFormat1FixedHeader { |
2547 | | pub pos_format: BigEndian<u16>, |
2548 | | pub mark_coverage_offset: BigEndian<Offset16>, |
2549 | | pub base_coverage_offset: BigEndian<Offset16>, |
2550 | | pub mark_class_count: BigEndian<u16>, |
2551 | | pub mark_array_offset: BigEndian<Offset16>, |
2552 | | pub base_array_offset: BigEndian<Offset16>, |
2553 | | } |
2554 | | |
2555 | | #[allow(clippy::absurd_extreme_comparisons)] |
2556 | | const _: () = |
2557 | | assert!(std::mem::size_of::<MarkBasePosFormat1FixedHeader>() <= MarkBasePosFormat1::MIN_SIZE); |
2558 | | |
2559 | | /// [Mark-to-Base Attachment Positioning Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#mark-to-base-attachment-positioning-format-1-mark-to-base-attachment-point): Mark-to-base Attachment Point |
2560 | | #[derive(Clone)] |
2561 | | pub struct MarkBasePosFormat1<'a> { |
2562 | | data: TableDataRef<'a, MarkBasePosFormat1FixedHeader>, |
2563 | | } |
2564 | | |
2565 | | #[allow(clippy::needless_lifetimes)] |
2566 | | impl<'a> MarkBasePosFormat1<'a> { |
2567 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
2568 | | + Offset16::RAW_BYTE_LEN |
2569 | | + Offset16::RAW_BYTE_LEN |
2570 | | + u16::RAW_BYTE_LEN |
2571 | | + Offset16::RAW_BYTE_LEN |
2572 | | + Offset16::RAW_BYTE_LEN); |
2573 | | basic_table_impls!(impl_the_methods); |
2574 | | |
2575 | | /// Format identifier: format = 1 |
2576 | 0 | pub fn pos_format(&self) -> u16 { |
2577 | 0 | self.data.header().pos_format.get() |
2578 | 0 | } |
2579 | | |
2580 | | /// Offset to markCoverage table, from beginning of MarkBasePos |
2581 | | /// subtable. |
2582 | 6.90k | pub fn mark_coverage_offset(&self) -> Offset16 { |
2583 | 6.90k | self.data.header().mark_coverage_offset.get() |
2584 | 6.90k | } |
2585 | | |
2586 | | /// Attempt to resolve [`mark_coverage_offset`][Self::mark_coverage_offset]. |
2587 | 6.90k | pub fn mark_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
2588 | 6.90k | let data = self.offset_data(); |
2589 | 6.90k | self.mark_coverage_offset().resolve(data) |
2590 | 6.90k | } |
2591 | | |
2592 | | /// Offset to baseCoverage table, from beginning of MarkBasePos |
2593 | | /// subtable. |
2594 | 6.90k | pub fn base_coverage_offset(&self) -> Offset16 { |
2595 | 6.90k | self.data.header().base_coverage_offset.get() |
2596 | 6.90k | } |
2597 | | |
2598 | | /// Attempt to resolve [`base_coverage_offset`][Self::base_coverage_offset]. |
2599 | 6.90k | pub fn base_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
2600 | 6.90k | let data = self.offset_data(); |
2601 | 6.90k | self.base_coverage_offset().resolve(data) |
2602 | 6.90k | } |
2603 | | |
2604 | | /// Number of classes defined for marks |
2605 | 13.8k | pub fn mark_class_count(&self) -> u16 { |
2606 | 13.8k | self.data.header().mark_class_count.get() |
2607 | 13.8k | } |
2608 | | |
2609 | | /// Offset to MarkArray table, from beginning of MarkBasePos |
2610 | | /// subtable. |
2611 | 6.90k | pub fn mark_array_offset(&self) -> Offset16 { |
2612 | 6.90k | self.data.header().mark_array_offset.get() |
2613 | 6.90k | } |
2614 | | |
2615 | | /// Attempt to resolve [`mark_array_offset`][Self::mark_array_offset]. |
2616 | 6.90k | pub fn mark_array(&self) -> Result<MarkArray<'a>, ReadError> { |
2617 | 6.90k | let data = self.offset_data(); |
2618 | 6.90k | self.mark_array_offset().resolve(data) |
2619 | 6.90k | } |
2620 | | |
2621 | | /// Offset to BaseArray table, from beginning of MarkBasePos |
2622 | | /// subtable. |
2623 | 6.90k | pub fn base_array_offset(&self) -> Offset16 { |
2624 | 6.90k | self.data.header().base_array_offset.get() |
2625 | 6.90k | } |
2626 | | |
2627 | | /// Attempt to resolve [`base_array_offset`][Self::base_array_offset]. |
2628 | 6.90k | pub fn base_array(&self) -> Result<BaseArray<'a>, ReadError> { |
2629 | 6.90k | let data = self.offset_data(); |
2630 | 6.90k | let args = self.mark_class_count(); |
2631 | 6.90k | self.base_array_offset().resolve_with_args(data, args) |
2632 | 6.90k | } |
2633 | | |
2634 | 0 | pub fn pos_format_byte_range(&self) -> Range<usize> { |
2635 | 0 | let start = 0usize; |
2636 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2637 | 0 | start..end |
2638 | 0 | } |
2639 | | |
2640 | 0 | pub fn mark_coverage_offset_byte_range(&self) -> Range<usize> { |
2641 | 0 | let start = self.pos_format_byte_range().end; |
2642 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
2643 | 0 | start..end |
2644 | 0 | } |
2645 | | |
2646 | 0 | pub fn base_coverage_offset_byte_range(&self) -> Range<usize> { |
2647 | 0 | let start = self.mark_coverage_offset_byte_range().end; |
2648 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
2649 | 0 | start..end |
2650 | 0 | } |
2651 | | |
2652 | 0 | pub fn mark_class_count_byte_range(&self) -> Range<usize> { |
2653 | 0 | let start = self.base_coverage_offset_byte_range().end; |
2654 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2655 | 0 | start..end |
2656 | 0 | } |
2657 | | |
2658 | 0 | pub fn mark_array_offset_byte_range(&self) -> Range<usize> { |
2659 | 0 | let start = self.mark_class_count_byte_range().end; |
2660 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
2661 | 0 | start..end |
2662 | 0 | } |
2663 | | |
2664 | 0 | pub fn base_array_offset_byte_range(&self) -> Range<usize> { |
2665 | 0 | let start = self.mark_array_offset_byte_range().end; |
2666 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
2667 | 0 | start..end |
2668 | 0 | } |
2669 | | } |
2670 | | |
2671 | | const _: () = assert!(FontData::default_data_long_enough( |
2672 | | MarkBasePosFormat1::MIN_SIZE |
2673 | | )); |
2674 | | |
2675 | | impl Default for MarkBasePosFormat1<'_> { |
2676 | 0 | fn default() -> Self { |
2677 | | Self { |
2678 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
2679 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
2680 | | } |
2681 | 0 | } |
2682 | | } |
2683 | | |
2684 | | impl<'a> MinByteRange<'a> for BaseArray<'a> { |
2685 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2686 | 0 | 0..self.base_records_byte_range().end |
2687 | 0 | } |
2688 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2689 | 0 | let range = self.min_byte_range(); |
2690 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2691 | 0 | } |
2692 | | } |
2693 | | |
2694 | | impl ReadArgs for BaseArray<'_> { |
2695 | | type Args = u16; |
2696 | | } |
2697 | | |
2698 | | impl<'a> FontRead<'a> for BaseArray<'a> { |
2699 | 3.66k | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
2700 | 3.66k | let mark_class_count = args; |
2701 | | |
2702 | | #[allow(clippy::absurd_extreme_comparisons)] |
2703 | 3.66k | if data.len() < Self::MIN_SIZE { |
2704 | 139 | return Err(ReadError::OutOfBounds); |
2705 | 3.52k | } |
2706 | 3.52k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2707 | 0 | return Err(ReadError::OutOfBounds); |
2708 | | }; |
2709 | 3.52k | Ok(Self { |
2710 | 3.52k | data, |
2711 | 3.52k | mark_class_count, |
2712 | 3.52k | }) |
2713 | 3.66k | } |
2714 | | } |
2715 | | |
2716 | | impl<'a> BaseArray<'a> { |
2717 | | /// A constructor that requires additional arguments. |
2718 | | /// |
2719 | | /// This type requires some external state in order to be |
2720 | | /// parsed. |
2721 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
2722 | 0 | let args = mark_class_count; |
2723 | 0 | Self::read_with_args(data, args) |
2724 | 0 | } |
2725 | | } |
2726 | | |
2727 | | /// The fields at the start of the table, which are read directly. |
2728 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2729 | | #[repr(C, packed)] |
2730 | | #[doc(hidden)] |
2731 | | pub struct BaseArrayFixedHeader { |
2732 | | pub base_count: BigEndian<u16>, |
2733 | | } |
2734 | | |
2735 | | #[allow(clippy::absurd_extreme_comparisons)] |
2736 | | const _: () = assert!(std::mem::size_of::<BaseArrayFixedHeader>() <= BaseArray::MIN_SIZE); |
2737 | | |
2738 | | /// Part of [MarkBasePosFormat1] |
2739 | | #[derive(Clone)] |
2740 | | pub struct BaseArray<'a> { |
2741 | | data: TableDataRef<'a, BaseArrayFixedHeader>, |
2742 | | mark_class_count: u16, |
2743 | | } |
2744 | | |
2745 | | #[allow(clippy::needless_lifetimes)] |
2746 | | impl<'a> BaseArray<'a> { |
2747 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
2748 | | basic_table_impls!(impl_the_methods); |
2749 | | |
2750 | | /// Number of BaseRecords |
2751 | 0 | pub fn base_count(&self) -> u16 { |
2752 | 0 | self.data.header().base_count.get() |
2753 | 0 | } |
2754 | | |
2755 | | /// Array of BaseRecords, in order of baseCoverage Index. |
2756 | 0 | pub fn base_records(&self) -> ComputedArray<'a, BaseRecord<'a>> { |
2757 | 0 | let range = self.base_records_byte_range(); |
2758 | 0 | ComputedArray::new(self.offset_data(), range, self.mark_class_count()).unwrap_or_default() |
2759 | 0 | } |
2760 | | |
2761 | 0 | pub(crate) fn mark_class_count(&self) -> u16 { |
2762 | 0 | self.mark_class_count |
2763 | 0 | } |
2764 | | |
2765 | 0 | pub fn base_count_byte_range(&self) -> Range<usize> { |
2766 | 0 | let start = 0usize; |
2767 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2768 | 0 | start..end |
2769 | 0 | } |
2770 | | |
2771 | 0 | pub fn base_records_byte_range(&self) -> Range<usize> { |
2772 | 0 | let base_count = self.base_count(); |
2773 | 0 | let start = self.base_count_byte_range().end; |
2774 | 0 | let end = start.saturating_add((transforms::to_usize(base_count)).saturating_mul( |
2775 | 0 | <BaseRecord as ComputeSize>::compute_size(self.mark_class_count()).unwrap_or(0), |
2776 | | )); |
2777 | 0 | start..end |
2778 | 0 | } |
2779 | | } |
2780 | | |
2781 | | const _: () = assert!(FontData::default_data_long_enough(BaseArray::MIN_SIZE)); |
2782 | | |
2783 | | impl Default for BaseArray<'_> { |
2784 | 0 | fn default() -> Self { |
2785 | | Self { |
2786 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
2787 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
2788 | 0 | mark_class_count: Default::default(), |
2789 | | } |
2790 | 0 | } |
2791 | | } |
2792 | | |
2793 | | /// Part of [BaseArray] |
2794 | | #[derive(Clone, Debug)] |
2795 | | pub struct BaseRecord<'a> { |
2796 | | /// Array of offsets (one per mark class) to Anchor tables. Offsets |
2797 | | /// are from beginning of BaseArray table, ordered by class |
2798 | | /// (offsets may be NULL). |
2799 | | pub base_anchor_offsets: &'a [BigEndian<Nullable<Offset16>>], |
2800 | | } |
2801 | | |
2802 | | impl<'a> BaseRecord<'a> { |
2803 | | /// Array of offsets (one per mark class) to Anchor tables. Offsets |
2804 | | /// are from beginning of BaseArray table, ordered by class |
2805 | | /// (offsets may be NULL). |
2806 | 0 | pub fn base_anchor_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] { |
2807 | 0 | self.base_anchor_offsets |
2808 | 0 | } |
2809 | | |
2810 | | /// Array of offsets (one per mark class) to Anchor tables. Offsets |
2811 | | /// are from beginning of BaseArray table, ordered by class |
2812 | | /// (offsets may be NULL). |
2813 | | /// |
2814 | | /// The `data` argument should be retrieved from the parent table |
2815 | | /// By calling its `offset_data` method. |
2816 | 0 | pub fn base_anchors( |
2817 | 0 | &self, |
2818 | 0 | data: FontData<'a>, |
2819 | 0 | ) -> ArrayOfNullableOffsets<'a, AnchorTable<'a>, Offset16> { |
2820 | 0 | let offsets = self.base_anchor_offsets(); |
2821 | 0 | ArrayOfNullableOffsets::new(offsets, data, ()) |
2822 | 0 | } |
2823 | | } |
2824 | | |
2825 | | impl ReadArgs for BaseRecord<'_> { |
2826 | | type Args = u16; |
2827 | | } |
2828 | | |
2829 | | impl ComputeSize for BaseRecord<'_> { |
2830 | | #[allow(clippy::needless_question_mark)] |
2831 | 0 | fn compute_size(args: u16) -> Result<usize, ReadError> { |
2832 | 0 | let mark_class_count = args; |
2833 | 0 | Ok((transforms::to_usize(mark_class_count)).saturating_mul(Offset16::RAW_BYTE_LEN)) |
2834 | 0 | } |
2835 | | } |
2836 | | |
2837 | | impl<'a> FontRead<'a> for BaseRecord<'a> { |
2838 | 0 | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
2839 | 0 | let mut cursor = data.cursor(); |
2840 | 0 | let mark_class_count = args; |
2841 | | Ok(Self { |
2842 | 0 | base_anchor_offsets: cursor.read_array(transforms::to_usize(mark_class_count))?, |
2843 | | }) |
2844 | 0 | } |
2845 | | } |
2846 | | |
2847 | | crate::impl_font_read_at!(BaseRecord<'a>); |
2848 | | |
2849 | | #[allow(clippy::needless_lifetimes)] |
2850 | | impl<'a> BaseRecord<'a> { |
2851 | | /// A constructor that requires additional arguments. |
2852 | | /// |
2853 | | /// This type requires some external state in order to be |
2854 | | /// parsed. |
2855 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
2856 | 0 | let args = mark_class_count; |
2857 | 0 | Self::read_with_args(data, args) |
2858 | 0 | } |
2859 | | } |
2860 | | |
2861 | | impl Format<u16> for MarkLigPosFormat1<'_> { |
2862 | | const FORMAT: u16 = 1; |
2863 | | } |
2864 | | |
2865 | | impl<'a> MinByteRange<'a> for MarkLigPosFormat1<'a> { |
2866 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2867 | 0 | 0..self.ligature_array_offset_byte_range().end |
2868 | 0 | } |
2869 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2870 | 0 | let range = self.min_byte_range(); |
2871 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2872 | 0 | } |
2873 | | } |
2874 | | |
2875 | | impl ReadArgs for MarkLigPosFormat1<'_> { |
2876 | | type Args = (); |
2877 | | } |
2878 | | |
2879 | | impl<'a> FontRead<'a> for MarkLigPosFormat1<'a> { |
2880 | 8.48k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2881 | | #[allow(clippy::absurd_extreme_comparisons)] |
2882 | 8.48k | if data.len() < Self::MIN_SIZE { |
2883 | 262 | return Err(ReadError::OutOfBounds); |
2884 | 8.22k | } |
2885 | 8.22k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2886 | 0 | return Err(ReadError::OutOfBounds); |
2887 | | }; |
2888 | 8.22k | Ok(Self { data }) |
2889 | 8.48k | } |
2890 | | } |
2891 | | |
2892 | | /// The fields at the start of the table, which are read directly. |
2893 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2894 | | #[repr(C, packed)] |
2895 | | #[doc(hidden)] |
2896 | | pub struct MarkLigPosFormat1FixedHeader { |
2897 | | pub pos_format: BigEndian<u16>, |
2898 | | pub mark_coverage_offset: BigEndian<Offset16>, |
2899 | | pub ligature_coverage_offset: BigEndian<Offset16>, |
2900 | | pub mark_class_count: BigEndian<u16>, |
2901 | | pub mark_array_offset: BigEndian<Offset16>, |
2902 | | pub ligature_array_offset: BigEndian<Offset16>, |
2903 | | } |
2904 | | |
2905 | | #[allow(clippy::absurd_extreme_comparisons)] |
2906 | | const _: () = |
2907 | | assert!(std::mem::size_of::<MarkLigPosFormat1FixedHeader>() <= MarkLigPosFormat1::MIN_SIZE); |
2908 | | |
2909 | | /// [Mark-to-Ligature Positioning Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#mark-to-ligature-attachment-positioning-format-1-mark-to-ligature-attachment): Mark-to-Ligature Attachment |
2910 | | #[derive(Clone)] |
2911 | | pub struct MarkLigPosFormat1<'a> { |
2912 | | data: TableDataRef<'a, MarkLigPosFormat1FixedHeader>, |
2913 | | } |
2914 | | |
2915 | | #[allow(clippy::needless_lifetimes)] |
2916 | | impl<'a> MarkLigPosFormat1<'a> { |
2917 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
2918 | | + Offset16::RAW_BYTE_LEN |
2919 | | + Offset16::RAW_BYTE_LEN |
2920 | | + u16::RAW_BYTE_LEN |
2921 | | + Offset16::RAW_BYTE_LEN |
2922 | | + Offset16::RAW_BYTE_LEN); |
2923 | | basic_table_impls!(impl_the_methods); |
2924 | | |
2925 | | /// Format identifier: format = 1 |
2926 | 0 | pub fn pos_format(&self) -> u16 { |
2927 | 0 | self.data.header().pos_format.get() |
2928 | 0 | } |
2929 | | |
2930 | | /// Offset to markCoverage table, from beginning of MarkLigPos |
2931 | | /// subtable. |
2932 | 8.22k | pub fn mark_coverage_offset(&self) -> Offset16 { |
2933 | 8.22k | self.data.header().mark_coverage_offset.get() |
2934 | 8.22k | } |
2935 | | |
2936 | | /// Attempt to resolve [`mark_coverage_offset`][Self::mark_coverage_offset]. |
2937 | 8.22k | pub fn mark_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
2938 | 8.22k | let data = self.offset_data(); |
2939 | 8.22k | self.mark_coverage_offset().resolve(data) |
2940 | 8.22k | } |
2941 | | |
2942 | | /// Offset to ligatureCoverage table, from beginning of MarkLigPos |
2943 | | /// subtable. |
2944 | 8.22k | pub fn ligature_coverage_offset(&self) -> Offset16 { |
2945 | 8.22k | self.data.header().ligature_coverage_offset.get() |
2946 | 8.22k | } |
2947 | | |
2948 | | /// Attempt to resolve [`ligature_coverage_offset`][Self::ligature_coverage_offset]. |
2949 | 8.22k | pub fn ligature_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
2950 | 8.22k | let data = self.offset_data(); |
2951 | 8.22k | self.ligature_coverage_offset().resolve(data) |
2952 | 8.22k | } |
2953 | | |
2954 | | /// Number of defined mark classes |
2955 | 16.4k | pub fn mark_class_count(&self) -> u16 { |
2956 | 16.4k | self.data.header().mark_class_count.get() |
2957 | 16.4k | } |
2958 | | |
2959 | | /// Offset to MarkArray table, from beginning of MarkLigPos |
2960 | | /// subtable. |
2961 | 8.22k | pub fn mark_array_offset(&self) -> Offset16 { |
2962 | 8.22k | self.data.header().mark_array_offset.get() |
2963 | 8.22k | } |
2964 | | |
2965 | | /// Attempt to resolve [`mark_array_offset`][Self::mark_array_offset]. |
2966 | 8.22k | pub fn mark_array(&self) -> Result<MarkArray<'a>, ReadError> { |
2967 | 8.22k | let data = self.offset_data(); |
2968 | 8.22k | self.mark_array_offset().resolve(data) |
2969 | 8.22k | } |
2970 | | |
2971 | | /// Offset to LigatureArray table, from beginning of MarkLigPos |
2972 | | /// subtable. |
2973 | 8.22k | pub fn ligature_array_offset(&self) -> Offset16 { |
2974 | 8.22k | self.data.header().ligature_array_offset.get() |
2975 | 8.22k | } |
2976 | | |
2977 | | /// Attempt to resolve [`ligature_array_offset`][Self::ligature_array_offset]. |
2978 | 8.22k | pub fn ligature_array(&self) -> Result<LigatureArray<'a>, ReadError> { |
2979 | 8.22k | let data = self.offset_data(); |
2980 | 8.22k | let args = self.mark_class_count(); |
2981 | 8.22k | self.ligature_array_offset().resolve_with_args(data, args) |
2982 | 8.22k | } |
2983 | | |
2984 | 0 | pub fn pos_format_byte_range(&self) -> Range<usize> { |
2985 | 0 | let start = 0usize; |
2986 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2987 | 0 | start..end |
2988 | 0 | } |
2989 | | |
2990 | 0 | pub fn mark_coverage_offset_byte_range(&self) -> Range<usize> { |
2991 | 0 | let start = self.pos_format_byte_range().end; |
2992 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
2993 | 0 | start..end |
2994 | 0 | } |
2995 | | |
2996 | 0 | pub fn ligature_coverage_offset_byte_range(&self) -> Range<usize> { |
2997 | 0 | let start = self.mark_coverage_offset_byte_range().end; |
2998 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
2999 | 0 | start..end |
3000 | 0 | } |
3001 | | |
3002 | 0 | pub fn mark_class_count_byte_range(&self) -> Range<usize> { |
3003 | 0 | let start = self.ligature_coverage_offset_byte_range().end; |
3004 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
3005 | 0 | start..end |
3006 | 0 | } |
3007 | | |
3008 | 0 | pub fn mark_array_offset_byte_range(&self) -> Range<usize> { |
3009 | 0 | let start = self.mark_class_count_byte_range().end; |
3010 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
3011 | 0 | start..end |
3012 | 0 | } |
3013 | | |
3014 | 0 | pub fn ligature_array_offset_byte_range(&self) -> Range<usize> { |
3015 | 0 | let start = self.mark_array_offset_byte_range().end; |
3016 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
3017 | 0 | start..end |
3018 | 0 | } |
3019 | | } |
3020 | | |
3021 | | const _: () = assert!(FontData::default_data_long_enough( |
3022 | | MarkLigPosFormat1::MIN_SIZE |
3023 | | )); |
3024 | | |
3025 | | impl Default for MarkLigPosFormat1<'_> { |
3026 | 0 | fn default() -> Self { |
3027 | | Self { |
3028 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
3029 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
3030 | | } |
3031 | 0 | } |
3032 | | } |
3033 | | |
3034 | | impl<'a> MinByteRange<'a> for LigatureArray<'a> { |
3035 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3036 | 0 | 0..self.ligature_attach_offsets_byte_range().end |
3037 | 0 | } |
3038 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
3039 | 0 | let range = self.min_byte_range(); |
3040 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
3041 | 0 | } |
3042 | | } |
3043 | | |
3044 | | impl ReadArgs for LigatureArray<'_> { |
3045 | | type Args = u16; |
3046 | | } |
3047 | | |
3048 | | impl<'a> FontRead<'a> for LigatureArray<'a> { |
3049 | 4.91k | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
3050 | 4.91k | let mark_class_count = args; |
3051 | | |
3052 | | #[allow(clippy::absurd_extreme_comparisons)] |
3053 | 4.91k | if data.len() < Self::MIN_SIZE { |
3054 | 103 | return Err(ReadError::OutOfBounds); |
3055 | 4.80k | } |
3056 | 4.80k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
3057 | 0 | return Err(ReadError::OutOfBounds); |
3058 | | }; |
3059 | 4.80k | Ok(Self { |
3060 | 4.80k | data, |
3061 | 4.80k | mark_class_count, |
3062 | 4.80k | }) |
3063 | 4.91k | } |
3064 | | } |
3065 | | |
3066 | | impl<'a> LigatureArray<'a> { |
3067 | | /// A constructor that requires additional arguments. |
3068 | | /// |
3069 | | /// This type requires some external state in order to be |
3070 | | /// parsed. |
3071 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
3072 | 0 | let args = mark_class_count; |
3073 | 0 | Self::read_with_args(data, args) |
3074 | 0 | } |
3075 | | } |
3076 | | |
3077 | | /// The fields at the start of the table, which are read directly. |
3078 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
3079 | | #[repr(C, packed)] |
3080 | | #[doc(hidden)] |
3081 | | pub struct LigatureArrayFixedHeader { |
3082 | | pub ligature_count: BigEndian<u16>, |
3083 | | } |
3084 | | |
3085 | | #[allow(clippy::absurd_extreme_comparisons)] |
3086 | | const _: () = assert!(std::mem::size_of::<LigatureArrayFixedHeader>() <= LigatureArray::MIN_SIZE); |
3087 | | |
3088 | | /// Part of [MarkLigPosFormat1] |
3089 | | #[derive(Clone)] |
3090 | | pub struct LigatureArray<'a> { |
3091 | | data: TableDataRef<'a, LigatureArrayFixedHeader>, |
3092 | | mark_class_count: u16, |
3093 | | } |
3094 | | |
3095 | | #[allow(clippy::needless_lifetimes)] |
3096 | | impl<'a> LigatureArray<'a> { |
3097 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
3098 | | basic_table_impls!(impl_the_methods); |
3099 | | |
3100 | | /// Number of LigatureAttach table offsets |
3101 | 4.80k | pub fn ligature_count(&self) -> u16 { |
3102 | 4.80k | self.data.header().ligature_count.get() |
3103 | 4.80k | } |
3104 | | |
3105 | | /// Array of offsets to LigatureAttach tables. Offsets are from |
3106 | | /// beginning of LigatureArray table, ordered by ligatureCoverage |
3107 | | /// index. |
3108 | 0 | pub fn ligature_attach_offsets(&self) -> &'a [BigEndian<Offset16>] { |
3109 | 0 | let range = self.ligature_attach_offsets_byte_range(); |
3110 | 0 | self.offset_data() |
3111 | 0 | .read_array(range) |
3112 | 0 | .ok() |
3113 | 0 | .unwrap_or_default() |
3114 | 0 | } |
3115 | | |
3116 | | /// A dynamically resolving wrapper for [`ligature_attach_offsets`][Self::ligature_attach_offsets]. |
3117 | 0 | pub fn ligature_attaches(&self) -> ArrayOfOffsets<'a, LigatureAttach<'a>, Offset16> { |
3118 | 0 | let data = self.offset_data(); |
3119 | 0 | let offsets = self.ligature_attach_offsets(); |
3120 | 0 | let args = self.mark_class_count(); |
3121 | 0 | ArrayOfOffsets::new(offsets, data, args) |
3122 | 0 | } |
3123 | | |
3124 | 0 | pub(crate) fn mark_class_count(&self) -> u16 { |
3125 | 0 | self.mark_class_count |
3126 | 0 | } |
3127 | | |
3128 | 4.80k | pub fn ligature_count_byte_range(&self) -> Range<usize> { |
3129 | 4.80k | let start = 0usize; |
3130 | 4.80k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
3131 | 4.80k | start..end |
3132 | 4.80k | } |
3133 | | |
3134 | 4.80k | pub fn ligature_attach_offsets_byte_range(&self) -> Range<usize> { |
3135 | 4.80k | let ligature_count = self.ligature_count(); |
3136 | 4.80k | let start = self.ligature_count_byte_range().end; |
3137 | 4.80k | let end = start.saturating_add( |
3138 | 4.80k | (transforms::to_usize(ligature_count)).saturating_mul(Offset16::RAW_BYTE_LEN), |
3139 | | ); |
3140 | 4.80k | start..end |
3141 | 4.80k | } |
3142 | | } |
3143 | | |
3144 | | const _: () = assert!(FontData::default_data_long_enough(LigatureArray::MIN_SIZE)); |
3145 | | |
3146 | | impl Default for LigatureArray<'_> { |
3147 | 0 | fn default() -> Self { |
3148 | | Self { |
3149 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
3150 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
3151 | 0 | mark_class_count: Default::default(), |
3152 | | } |
3153 | 0 | } |
3154 | | } |
3155 | | |
3156 | | impl<'a> MinByteRange<'a> for LigatureAttach<'a> { |
3157 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3158 | 0 | 0..self.component_records_byte_range().end |
3159 | 0 | } |
3160 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
3161 | 0 | let range = self.min_byte_range(); |
3162 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
3163 | 0 | } |
3164 | | } |
3165 | | |
3166 | | impl ReadArgs for LigatureAttach<'_> { |
3167 | | type Args = u16; |
3168 | | } |
3169 | | |
3170 | | impl<'a> FontRead<'a> for LigatureAttach<'a> { |
3171 | 0 | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
3172 | 0 | let mark_class_count = args; |
3173 | | |
3174 | | #[allow(clippy::absurd_extreme_comparisons)] |
3175 | 0 | if data.len() < Self::MIN_SIZE { |
3176 | 0 | return Err(ReadError::OutOfBounds); |
3177 | 0 | } |
3178 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
3179 | 0 | return Err(ReadError::OutOfBounds); |
3180 | | }; |
3181 | 0 | Ok(Self { |
3182 | 0 | data, |
3183 | 0 | mark_class_count, |
3184 | 0 | }) |
3185 | 0 | } |
3186 | | } |
3187 | | |
3188 | | impl<'a> LigatureAttach<'a> { |
3189 | | /// A constructor that requires additional arguments. |
3190 | | /// |
3191 | | /// This type requires some external state in order to be |
3192 | | /// parsed. |
3193 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
3194 | 0 | let args = mark_class_count; |
3195 | 0 | Self::read_with_args(data, args) |
3196 | 0 | } |
3197 | | } |
3198 | | |
3199 | | /// The fields at the start of the table, which are read directly. |
3200 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
3201 | | #[repr(C, packed)] |
3202 | | #[doc(hidden)] |
3203 | | pub struct LigatureAttachFixedHeader { |
3204 | | pub component_count: BigEndian<u16>, |
3205 | | } |
3206 | | |
3207 | | #[allow(clippy::absurd_extreme_comparisons)] |
3208 | | const _: () = assert!(std::mem::size_of::<LigatureAttachFixedHeader>() <= LigatureAttach::MIN_SIZE); |
3209 | | |
3210 | | /// Part of [MarkLigPosFormat1] |
3211 | | #[derive(Clone)] |
3212 | | pub struct LigatureAttach<'a> { |
3213 | | data: TableDataRef<'a, LigatureAttachFixedHeader>, |
3214 | | mark_class_count: u16, |
3215 | | } |
3216 | | |
3217 | | #[allow(clippy::needless_lifetimes)] |
3218 | | impl<'a> LigatureAttach<'a> { |
3219 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
3220 | | basic_table_impls!(impl_the_methods); |
3221 | | |
3222 | | /// Number of ComponentRecords in this ligature |
3223 | 0 | pub fn component_count(&self) -> u16 { |
3224 | 0 | self.data.header().component_count.get() |
3225 | 0 | } |
3226 | | |
3227 | | /// Array of Component records, ordered in writing direction. |
3228 | 0 | pub fn component_records(&self) -> ComputedArray<'a, ComponentRecord<'a>> { |
3229 | 0 | let range = self.component_records_byte_range(); |
3230 | 0 | ComputedArray::new(self.offset_data(), range, self.mark_class_count()).unwrap_or_default() |
3231 | 0 | } |
3232 | | |
3233 | 0 | pub(crate) fn mark_class_count(&self) -> u16 { |
3234 | 0 | self.mark_class_count |
3235 | 0 | } |
3236 | | |
3237 | 0 | pub fn component_count_byte_range(&self) -> Range<usize> { |
3238 | 0 | let start = 0usize; |
3239 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
3240 | 0 | start..end |
3241 | 0 | } |
3242 | | |
3243 | 0 | pub fn component_records_byte_range(&self) -> Range<usize> { |
3244 | 0 | let component_count = self.component_count(); |
3245 | 0 | let start = self.component_count_byte_range().end; |
3246 | 0 | let end = start.saturating_add((transforms::to_usize(component_count)).saturating_mul( |
3247 | 0 | <ComponentRecord as ComputeSize>::compute_size(self.mark_class_count()).unwrap_or(0), |
3248 | | )); |
3249 | 0 | start..end |
3250 | 0 | } |
3251 | | } |
3252 | | |
3253 | | const _: () = assert!(FontData::default_data_long_enough(LigatureAttach::MIN_SIZE)); |
3254 | | |
3255 | | impl Default for LigatureAttach<'_> { |
3256 | 0 | fn default() -> Self { |
3257 | | Self { |
3258 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
3259 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
3260 | 0 | mark_class_count: Default::default(), |
3261 | | } |
3262 | 0 | } |
3263 | | } |
3264 | | |
3265 | | /// Part of [MarkLigPosFormat1] |
3266 | | #[derive(Clone, Debug)] |
3267 | | pub struct ComponentRecord<'a> { |
3268 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
3269 | | /// from beginning of LigatureAttach table, ordered by class |
3270 | | /// (offsets may be NULL). |
3271 | | pub ligature_anchor_offsets: &'a [BigEndian<Nullable<Offset16>>], |
3272 | | } |
3273 | | |
3274 | | impl<'a> ComponentRecord<'a> { |
3275 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
3276 | | /// from beginning of LigatureAttach table, ordered by class |
3277 | | /// (offsets may be NULL). |
3278 | 0 | pub fn ligature_anchor_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] { |
3279 | 0 | self.ligature_anchor_offsets |
3280 | 0 | } |
3281 | | |
3282 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
3283 | | /// from beginning of LigatureAttach table, ordered by class |
3284 | | /// (offsets may be NULL). |
3285 | | /// |
3286 | | /// The `data` argument should be retrieved from the parent table |
3287 | | /// By calling its `offset_data` method. |
3288 | 0 | pub fn ligature_anchors( |
3289 | 0 | &self, |
3290 | 0 | data: FontData<'a>, |
3291 | 0 | ) -> ArrayOfNullableOffsets<'a, AnchorTable<'a>, Offset16> { |
3292 | 0 | let offsets = self.ligature_anchor_offsets(); |
3293 | 0 | ArrayOfNullableOffsets::new(offsets, data, ()) |
3294 | 0 | } |
3295 | | } |
3296 | | |
3297 | | impl ReadArgs for ComponentRecord<'_> { |
3298 | | type Args = u16; |
3299 | | } |
3300 | | |
3301 | | impl ComputeSize for ComponentRecord<'_> { |
3302 | | #[allow(clippy::needless_question_mark)] |
3303 | 0 | fn compute_size(args: u16) -> Result<usize, ReadError> { |
3304 | 0 | let mark_class_count = args; |
3305 | 0 | Ok((transforms::to_usize(mark_class_count)).saturating_mul(Offset16::RAW_BYTE_LEN)) |
3306 | 0 | } |
3307 | | } |
3308 | | |
3309 | | impl<'a> FontRead<'a> for ComponentRecord<'a> { |
3310 | 0 | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
3311 | 0 | let mut cursor = data.cursor(); |
3312 | 0 | let mark_class_count = args; |
3313 | | Ok(Self { |
3314 | 0 | ligature_anchor_offsets: cursor.read_array(transforms::to_usize(mark_class_count))?, |
3315 | | }) |
3316 | 0 | } |
3317 | | } |
3318 | | |
3319 | | crate::impl_font_read_at!(ComponentRecord<'a>); |
3320 | | |
3321 | | #[allow(clippy::needless_lifetimes)] |
3322 | | impl<'a> ComponentRecord<'a> { |
3323 | | /// A constructor that requires additional arguments. |
3324 | | /// |
3325 | | /// This type requires some external state in order to be |
3326 | | /// parsed. |
3327 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
3328 | 0 | let args = mark_class_count; |
3329 | 0 | Self::read_with_args(data, args) |
3330 | 0 | } |
3331 | | } |
3332 | | |
3333 | | impl Format<u16> for MarkMarkPosFormat1<'_> { |
3334 | | const FORMAT: u16 = 1; |
3335 | | } |
3336 | | |
3337 | | impl<'a> MinByteRange<'a> for MarkMarkPosFormat1<'a> { |
3338 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3339 | 0 | 0..self.mark2_array_offset_byte_range().end |
3340 | 0 | } |
3341 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
3342 | 0 | let range = self.min_byte_range(); |
3343 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
3344 | 0 | } |
3345 | | } |
3346 | | |
3347 | | impl ReadArgs for MarkMarkPosFormat1<'_> { |
3348 | | type Args = (); |
3349 | | } |
3350 | | |
3351 | | impl<'a> FontRead<'a> for MarkMarkPosFormat1<'a> { |
3352 | 9.28k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3353 | | #[allow(clippy::absurd_extreme_comparisons)] |
3354 | 9.28k | if data.len() < Self::MIN_SIZE { |
3355 | 344 | return Err(ReadError::OutOfBounds); |
3356 | 8.94k | } |
3357 | 8.94k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
3358 | 0 | return Err(ReadError::OutOfBounds); |
3359 | | }; |
3360 | 8.94k | Ok(Self { data }) |
3361 | 9.28k | } |
3362 | | } |
3363 | | |
3364 | | /// The fields at the start of the table, which are read directly. |
3365 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
3366 | | #[repr(C, packed)] |
3367 | | #[doc(hidden)] |
3368 | | pub struct MarkMarkPosFormat1FixedHeader { |
3369 | | pub pos_format: BigEndian<u16>, |
3370 | | pub mark1_coverage_offset: BigEndian<Offset16>, |
3371 | | pub mark2_coverage_offset: BigEndian<Offset16>, |
3372 | | pub mark_class_count: BigEndian<u16>, |
3373 | | pub mark1_array_offset: BigEndian<Offset16>, |
3374 | | pub mark2_array_offset: BigEndian<Offset16>, |
3375 | | } |
3376 | | |
3377 | | #[allow(clippy::absurd_extreme_comparisons)] |
3378 | | const _: () = |
3379 | | assert!(std::mem::size_of::<MarkMarkPosFormat1FixedHeader>() <= MarkMarkPosFormat1::MIN_SIZE); |
3380 | | |
3381 | | /// [Mark-to-Mark Attachment Positioning Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#mark-to-mark-attachment-positioning-format-1-mark-to-mark-attachment): Mark-to-Mark Attachment |
3382 | | #[derive(Clone)] |
3383 | | pub struct MarkMarkPosFormat1<'a> { |
3384 | | data: TableDataRef<'a, MarkMarkPosFormat1FixedHeader>, |
3385 | | } |
3386 | | |
3387 | | #[allow(clippy::needless_lifetimes)] |
3388 | | impl<'a> MarkMarkPosFormat1<'a> { |
3389 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
3390 | | + Offset16::RAW_BYTE_LEN |
3391 | | + Offset16::RAW_BYTE_LEN |
3392 | | + u16::RAW_BYTE_LEN |
3393 | | + Offset16::RAW_BYTE_LEN |
3394 | | + Offset16::RAW_BYTE_LEN); |
3395 | | basic_table_impls!(impl_the_methods); |
3396 | | |
3397 | | /// Format identifier: format = 1 |
3398 | 0 | pub fn pos_format(&self) -> u16 { |
3399 | 0 | self.data.header().pos_format.get() |
3400 | 0 | } |
3401 | | |
3402 | | /// Offset to Combining Mark Coverage table, from beginning of |
3403 | | /// MarkMarkPos subtable. |
3404 | 8.94k | pub fn mark1_coverage_offset(&self) -> Offset16 { |
3405 | 8.94k | self.data.header().mark1_coverage_offset.get() |
3406 | 8.94k | } |
3407 | | |
3408 | | /// Attempt to resolve [`mark1_coverage_offset`][Self::mark1_coverage_offset]. |
3409 | 8.94k | pub fn mark1_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
3410 | 8.94k | let data = self.offset_data(); |
3411 | 8.94k | self.mark1_coverage_offset().resolve(data) |
3412 | 8.94k | } |
3413 | | |
3414 | | /// Offset to Base Mark Coverage table, from beginning of |
3415 | | /// MarkMarkPos subtable. |
3416 | 8.94k | pub fn mark2_coverage_offset(&self) -> Offset16 { |
3417 | 8.94k | self.data.header().mark2_coverage_offset.get() |
3418 | 8.94k | } |
3419 | | |
3420 | | /// Attempt to resolve [`mark2_coverage_offset`][Self::mark2_coverage_offset]. |
3421 | 8.94k | pub fn mark2_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
3422 | 8.94k | let data = self.offset_data(); |
3423 | 8.94k | self.mark2_coverage_offset().resolve(data) |
3424 | 8.94k | } |
3425 | | |
3426 | | /// Number of Combining Mark classes defined |
3427 | 17.8k | pub fn mark_class_count(&self) -> u16 { |
3428 | 17.8k | self.data.header().mark_class_count.get() |
3429 | 17.8k | } |
3430 | | |
3431 | | /// Offset to MarkArray table for mark1, from beginning of |
3432 | | /// MarkMarkPos subtable. |
3433 | 8.94k | pub fn mark1_array_offset(&self) -> Offset16 { |
3434 | 8.94k | self.data.header().mark1_array_offset.get() |
3435 | 8.94k | } |
3436 | | |
3437 | | /// Attempt to resolve [`mark1_array_offset`][Self::mark1_array_offset]. |
3438 | 8.94k | pub fn mark1_array(&self) -> Result<MarkArray<'a>, ReadError> { |
3439 | 8.94k | let data = self.offset_data(); |
3440 | 8.94k | self.mark1_array_offset().resolve(data) |
3441 | 8.94k | } |
3442 | | |
3443 | | /// Offset to Mark2Array table for mark2, from beginning of |
3444 | | /// MarkMarkPos subtable. |
3445 | 8.94k | pub fn mark2_array_offset(&self) -> Offset16 { |
3446 | 8.94k | self.data.header().mark2_array_offset.get() |
3447 | 8.94k | } |
3448 | | |
3449 | | /// Attempt to resolve [`mark2_array_offset`][Self::mark2_array_offset]. |
3450 | 8.94k | pub fn mark2_array(&self) -> Result<Mark2Array<'a>, ReadError> { |
3451 | 8.94k | let data = self.offset_data(); |
3452 | 8.94k | let args = self.mark_class_count(); |
3453 | 8.94k | self.mark2_array_offset().resolve_with_args(data, args) |
3454 | 8.94k | } |
3455 | | |
3456 | 0 | pub fn pos_format_byte_range(&self) -> Range<usize> { |
3457 | 0 | let start = 0usize; |
3458 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
3459 | 0 | start..end |
3460 | 0 | } |
3461 | | |
3462 | 0 | pub fn mark1_coverage_offset_byte_range(&self) -> Range<usize> { |
3463 | 0 | let start = self.pos_format_byte_range().end; |
3464 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
3465 | 0 | start..end |
3466 | 0 | } |
3467 | | |
3468 | 0 | pub fn mark2_coverage_offset_byte_range(&self) -> Range<usize> { |
3469 | 0 | let start = self.mark1_coverage_offset_byte_range().end; |
3470 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
3471 | 0 | start..end |
3472 | 0 | } |
3473 | | |
3474 | 0 | pub fn mark_class_count_byte_range(&self) -> Range<usize> { |
3475 | 0 | let start = self.mark2_coverage_offset_byte_range().end; |
3476 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
3477 | 0 | start..end |
3478 | 0 | } |
3479 | | |
3480 | 0 | pub fn mark1_array_offset_byte_range(&self) -> Range<usize> { |
3481 | 0 | let start = self.mark_class_count_byte_range().end; |
3482 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
3483 | 0 | start..end |
3484 | 0 | } |
3485 | | |
3486 | 0 | pub fn mark2_array_offset_byte_range(&self) -> Range<usize> { |
3487 | 0 | let start = self.mark1_array_offset_byte_range().end; |
3488 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
3489 | 0 | start..end |
3490 | 0 | } |
3491 | | } |
3492 | | |
3493 | | const _: () = assert!(FontData::default_data_long_enough( |
3494 | | MarkMarkPosFormat1::MIN_SIZE |
3495 | | )); |
3496 | | |
3497 | | impl Default for MarkMarkPosFormat1<'_> { |
3498 | 0 | fn default() -> Self { |
3499 | | Self { |
3500 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
3501 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
3502 | | } |
3503 | 0 | } |
3504 | | } |
3505 | | |
3506 | | impl<'a> MinByteRange<'a> for Mark2Array<'a> { |
3507 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3508 | 0 | 0..self.mark2_records_byte_range().end |
3509 | 0 | } |
3510 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
3511 | 0 | let range = self.min_byte_range(); |
3512 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
3513 | 0 | } |
3514 | | } |
3515 | | |
3516 | | impl ReadArgs for Mark2Array<'_> { |
3517 | | type Args = u16; |
3518 | | } |
3519 | | |
3520 | | impl<'a> FontRead<'a> for Mark2Array<'a> { |
3521 | 4.68k | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
3522 | 4.68k | let mark_class_count = args; |
3523 | | |
3524 | | #[allow(clippy::absurd_extreme_comparisons)] |
3525 | 4.68k | if data.len() < Self::MIN_SIZE { |
3526 | 10 | return Err(ReadError::OutOfBounds); |
3527 | 4.67k | } |
3528 | 4.67k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
3529 | 0 | return Err(ReadError::OutOfBounds); |
3530 | | }; |
3531 | 4.67k | Ok(Self { |
3532 | 4.67k | data, |
3533 | 4.67k | mark_class_count, |
3534 | 4.67k | }) |
3535 | 4.68k | } |
3536 | | } |
3537 | | |
3538 | | impl<'a> Mark2Array<'a> { |
3539 | | /// A constructor that requires additional arguments. |
3540 | | /// |
3541 | | /// This type requires some external state in order to be |
3542 | | /// parsed. |
3543 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
3544 | 0 | let args = mark_class_count; |
3545 | 0 | Self::read_with_args(data, args) |
3546 | 0 | } |
3547 | | } |
3548 | | |
3549 | | /// The fields at the start of the table, which are read directly. |
3550 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
3551 | | #[repr(C, packed)] |
3552 | | #[doc(hidden)] |
3553 | | pub struct Mark2ArrayFixedHeader { |
3554 | | pub mark2_count: BigEndian<u16>, |
3555 | | } |
3556 | | |
3557 | | #[allow(clippy::absurd_extreme_comparisons)] |
3558 | | const _: () = assert!(std::mem::size_of::<Mark2ArrayFixedHeader>() <= Mark2Array::MIN_SIZE); |
3559 | | |
3560 | | /// Part of [MarkMarkPosFormat1]Class2Record |
3561 | | #[derive(Clone)] |
3562 | | pub struct Mark2Array<'a> { |
3563 | | data: TableDataRef<'a, Mark2ArrayFixedHeader>, |
3564 | | mark_class_count: u16, |
3565 | | } |
3566 | | |
3567 | | #[allow(clippy::needless_lifetimes)] |
3568 | | impl<'a> Mark2Array<'a> { |
3569 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
3570 | | basic_table_impls!(impl_the_methods); |
3571 | | |
3572 | | /// Number of Mark2 records |
3573 | 0 | pub fn mark2_count(&self) -> u16 { |
3574 | 0 | self.data.header().mark2_count.get() |
3575 | 0 | } |
3576 | | |
3577 | | /// Array of Mark2Records, in Coverage order. |
3578 | 0 | pub fn mark2_records(&self) -> ComputedArray<'a, Mark2Record<'a>> { |
3579 | 0 | let range = self.mark2_records_byte_range(); |
3580 | 0 | ComputedArray::new(self.offset_data(), range, self.mark_class_count()).unwrap_or_default() |
3581 | 0 | } |
3582 | | |
3583 | 0 | pub(crate) fn mark_class_count(&self) -> u16 { |
3584 | 0 | self.mark_class_count |
3585 | 0 | } |
3586 | | |
3587 | 0 | pub fn mark2_count_byte_range(&self) -> Range<usize> { |
3588 | 0 | let start = 0usize; |
3589 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
3590 | 0 | start..end |
3591 | 0 | } |
3592 | | |
3593 | 0 | pub fn mark2_records_byte_range(&self) -> Range<usize> { |
3594 | 0 | let mark2_count = self.mark2_count(); |
3595 | 0 | let start = self.mark2_count_byte_range().end; |
3596 | 0 | let end = start.saturating_add((transforms::to_usize(mark2_count)).saturating_mul( |
3597 | 0 | <Mark2Record as ComputeSize>::compute_size(self.mark_class_count()).unwrap_or(0), |
3598 | | )); |
3599 | 0 | start..end |
3600 | 0 | } |
3601 | | } |
3602 | | |
3603 | | const _: () = assert!(FontData::default_data_long_enough(Mark2Array::MIN_SIZE)); |
3604 | | |
3605 | | impl Default for Mark2Array<'_> { |
3606 | 0 | fn default() -> Self { |
3607 | | Self { |
3608 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
3609 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
3610 | 0 | mark_class_count: Default::default(), |
3611 | | } |
3612 | 0 | } |
3613 | | } |
3614 | | |
3615 | | /// Part of [MarkMarkPosFormat1] |
3616 | | #[derive(Clone, Debug)] |
3617 | | pub struct Mark2Record<'a> { |
3618 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
3619 | | /// from beginning of Mark2Array table, in class order (offsets may |
3620 | | /// be NULL). |
3621 | | pub mark2_anchor_offsets: &'a [BigEndian<Nullable<Offset16>>], |
3622 | | } |
3623 | | |
3624 | | impl<'a> Mark2Record<'a> { |
3625 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
3626 | | /// from beginning of Mark2Array table, in class order (offsets may |
3627 | | /// be NULL). |
3628 | 0 | pub fn mark2_anchor_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] { |
3629 | 0 | self.mark2_anchor_offsets |
3630 | 0 | } |
3631 | | |
3632 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
3633 | | /// from beginning of Mark2Array table, in class order (offsets may |
3634 | | /// be NULL). |
3635 | | /// |
3636 | | /// The `data` argument should be retrieved from the parent table |
3637 | | /// By calling its `offset_data` method. |
3638 | 0 | pub fn mark2_anchors( |
3639 | 0 | &self, |
3640 | 0 | data: FontData<'a>, |
3641 | 0 | ) -> ArrayOfNullableOffsets<'a, AnchorTable<'a>, Offset16> { |
3642 | 0 | let offsets = self.mark2_anchor_offsets(); |
3643 | 0 | ArrayOfNullableOffsets::new(offsets, data, ()) |
3644 | 0 | } |
3645 | | } |
3646 | | |
3647 | | impl ReadArgs for Mark2Record<'_> { |
3648 | | type Args = u16; |
3649 | | } |
3650 | | |
3651 | | impl ComputeSize for Mark2Record<'_> { |
3652 | | #[allow(clippy::needless_question_mark)] |
3653 | 0 | fn compute_size(args: u16) -> Result<usize, ReadError> { |
3654 | 0 | let mark_class_count = args; |
3655 | 0 | Ok((transforms::to_usize(mark_class_count)).saturating_mul(Offset16::RAW_BYTE_LEN)) |
3656 | 0 | } |
3657 | | } |
3658 | | |
3659 | | impl<'a> FontRead<'a> for Mark2Record<'a> { |
3660 | 0 | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
3661 | 0 | let mut cursor = data.cursor(); |
3662 | 0 | let mark_class_count = args; |
3663 | | Ok(Self { |
3664 | 0 | mark2_anchor_offsets: cursor.read_array(transforms::to_usize(mark_class_count))?, |
3665 | | }) |
3666 | 0 | } |
3667 | | } |
3668 | | |
3669 | | crate::impl_font_read_at!(Mark2Record<'a>); |
3670 | | |
3671 | | #[allow(clippy::needless_lifetimes)] |
3672 | | impl<'a> Mark2Record<'a> { |
3673 | | /// A constructor that requires additional arguments. |
3674 | | /// |
3675 | | /// This type requires some external state in order to be |
3676 | | /// parsed. |
3677 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
3678 | 0 | let args = mark_class_count; |
3679 | 0 | Self::read_with_args(data, args) |
3680 | 0 | } |
3681 | | } |
3682 | | |
3683 | | impl Format<u16> for ExtensionPosFormat1<'_> { |
3684 | | const FORMAT: u16 = 1; |
3685 | | } |
3686 | | |
3687 | | impl Discriminant for ExtensionPosFormat1<'_, ()> { |
3688 | 0 | fn read_discriminant(data: FontData<'_>) -> Result<u16, ReadError> { |
3689 | 0 | data.read_at(u16::RAW_BYTE_LEN) |
3690 | 0 | } |
3691 | | } |
3692 | | |
3693 | | impl<'a, T> MinByteRange<'a> for ExtensionPosFormat1<'a, T> { |
3694 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3695 | 0 | 0..self.extension_offset_byte_range().end |
3696 | 0 | } |
3697 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
3698 | 0 | let range = self.min_byte_range(); |
3699 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
3700 | 0 | } |
3701 | | } |
3702 | | |
3703 | | impl<T> ReadArgs for ExtensionPosFormat1<'_, T> { |
3704 | | type Args = (); |
3705 | | } |
3706 | | |
3707 | | impl<'a, T> FontRead<'a> for ExtensionPosFormat1<'a, T> { |
3708 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3709 | | #[allow(clippy::absurd_extreme_comparisons)] |
3710 | 0 | if data.len() < Self::MIN_SIZE { |
3711 | 0 | return Err(ReadError::OutOfBounds); |
3712 | 0 | } |
3713 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
3714 | 0 | return Err(ReadError::OutOfBounds); |
3715 | | }; |
3716 | 0 | Ok(Self { |
3717 | 0 | data, |
3718 | 0 | offset_type: std::marker::PhantomData, |
3719 | 0 | }) |
3720 | 0 | } Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::CursivePos> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::MarkLigPos> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::MarkBasePos> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::MarkMarkPos> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::PairPos> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::SinglePos> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::layout::SequenceContext> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::layout::ChainedSequenceContext> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1 as read_fonts::read::FontRead>::read_with_args |
3721 | | } |
3722 | | |
3723 | | impl<'a, T> ExtensionPosFormat1<'a, T> { |
3724 | | #[allow(dead_code)] |
3725 | | /// Replace the specific generic type on this implementation with `()` |
3726 | 0 | pub(crate) fn of_unit_type(&self) -> ExtensionPosFormat1<'a, ()> { |
3727 | 0 | ExtensionPosFormat1 { |
3728 | 0 | data: self.data, |
3729 | 0 | offset_type: std::marker::PhantomData, |
3730 | 0 | } |
3731 | 0 | } |
3732 | | } |
3733 | | |
3734 | | /// The fields at the start of the table, which are read directly. |
3735 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
3736 | | #[repr(C, packed)] |
3737 | | #[doc(hidden)] |
3738 | | pub struct ExtensionPosFormat1FixedHeader { |
3739 | | pub pos_format: BigEndian<u16>, |
3740 | | pub extension_lookup_type: BigEndian<u16>, |
3741 | | pub extension_offset: BigEndian<Offset32>, |
3742 | | } |
3743 | | |
3744 | | #[allow(clippy::absurd_extreme_comparisons)] |
3745 | | const _: () = assert!( |
3746 | | std::mem::size_of::<ExtensionPosFormat1FixedHeader>() <= ExtensionPosFormat1::<()>::MIN_SIZE |
3747 | | ); |
3748 | | |
3749 | | /// [Extension Positioning Subtable Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#extension-positioning-subtable-format-1) |
3750 | | #[derive(Clone)] |
3751 | | pub struct ExtensionPosFormat1<'a, T = ()> { |
3752 | | data: TableDataRef<'a, ExtensionPosFormat1FixedHeader>, |
3753 | | offset_type: std::marker::PhantomData<*const T>, |
3754 | | } |
3755 | | |
3756 | | #[allow(clippy::needless_lifetimes)] |
3757 | | impl<'a, T> ExtensionPosFormat1<'a, T> { |
3758 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN); |
3759 | | basic_table_impls!(impl_the_methods); |
3760 | | |
3761 | | /// Format identifier: format = 1 |
3762 | 0 | pub fn pos_format(&self) -> u16 { |
3763 | 0 | self.data.header().pos_format.get() |
3764 | 0 | } |
3765 | | |
3766 | | /// Lookup type of subtable referenced by extensionOffset (i.e. the |
3767 | | /// extension subtable). |
3768 | 0 | pub fn extension_lookup_type(&self) -> u16 { |
3769 | 0 | self.data.header().extension_lookup_type.get() |
3770 | 0 | } |
3771 | | |
3772 | | /// Offset to the extension subtable, of lookup type |
3773 | | /// extensionLookupType, relative to the start of the |
3774 | | /// ExtensionPosFormat1 subtable. |
3775 | 0 | pub fn extension_offset(&self) -> Offset32 { |
3776 | 0 | self.data.header().extension_offset.get() |
3777 | 0 | } Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::CursivePos>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::MarkLigPos>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::MarkBasePos>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::MarkMarkPos>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::PairPos>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::SinglePos>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::layout::SequenceContext>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::layout::ChainedSequenceContext>>::extension_offset |
3778 | | |
3779 | | /// Attempt to resolve [`extension_offset`][Self::extension_offset]. |
3780 | 0 | pub fn extension(&self) -> Result<T, ReadError> |
3781 | 0 | where |
3782 | 0 | T: FontRead<'a, Args = ()>, |
3783 | | { |
3784 | 0 | let data = self.offset_data(); |
3785 | 0 | self.extension_offset().resolve(data) |
3786 | 0 | } Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::CursivePos>>::extension Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::MarkLigPos>>::extension Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::MarkBasePos>>::extension Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::MarkMarkPos>>::extension Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::PairPos>>::extension Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::gpos::SinglePos>>::extension Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::layout::SequenceContext>>::extension Unexecuted instantiation: <read_fonts::tables::gpos::ExtensionPosFormat1<read_fonts::tables::layout::ChainedSequenceContext>>::extension |
3787 | | |
3788 | 0 | pub fn pos_format_byte_range(&self) -> Range<usize> { |
3789 | 0 | let start = 0usize; |
3790 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
3791 | 0 | start..end |
3792 | 0 | } |
3793 | | |
3794 | 0 | pub fn extension_lookup_type_byte_range(&self) -> Range<usize> { |
3795 | 0 | let start = self.pos_format_byte_range().end; |
3796 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
3797 | 0 | start..end |
3798 | 0 | } |
3799 | | |
3800 | 0 | pub fn extension_offset_byte_range(&self) -> Range<usize> { |
3801 | 0 | let start = self.extension_lookup_type_byte_range().end; |
3802 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
3803 | 0 | start..end |
3804 | 0 | } |
3805 | | } |
3806 | | |
3807 | | const _: () = assert!(FontData::default_data_long_enough( |
3808 | | ExtensionPosFormat1::<()>::MIN_SIZE |
3809 | | )); |
3810 | | |
3811 | | impl<T> Default for ExtensionPosFormat1<'_, T> { |
3812 | 0 | fn default() -> Self { |
3813 | | Self { |
3814 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
3815 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
3816 | 0 | offset_type: std::marker::PhantomData, |
3817 | | } |
3818 | 0 | } |
3819 | | } |
3820 | | |
3821 | | /// A [GPOS Extension Positioning](https://learn.microsoft.com/en-us/typography/opentype/spec/gpos#lookuptype-9-extension-positioning) subtable |
3822 | | pub enum ExtensionSubtable<'a> { |
3823 | | Single(ExtensionPosFormat1<'a, SinglePos<'a>>), |
3824 | | Pair(ExtensionPosFormat1<'a, PairPos<'a>>), |
3825 | | Cursive(ExtensionPosFormat1<'a, CursivePos<'a>>), |
3826 | | MarkToBase(ExtensionPosFormat1<'a, MarkBasePos<'a>>), |
3827 | | MarkToLig(ExtensionPosFormat1<'a, MarkLigPos<'a>>), |
3828 | | MarkToMark(ExtensionPosFormat1<'a, MarkMarkPos<'a>>), |
3829 | | Contextual(ExtensionPosFormat1<'a, PositionSequenceContext<'a>>), |
3830 | | ChainContextual(ExtensionPosFormat1<'a, PositionChainContext<'a>>), |
3831 | | } |
3832 | | |
3833 | | impl Default for ExtensionSubtable<'_> { |
3834 | 0 | fn default() -> Self { |
3835 | 0 | Self::Single(Default::default()) |
3836 | 0 | } |
3837 | | } |
3838 | | |
3839 | | impl ReadArgs for ExtensionSubtable<'_> { |
3840 | | type Args = (); |
3841 | | } |
3842 | | |
3843 | | impl<'a> FontRead<'a> for ExtensionSubtable<'a> { |
3844 | 0 | fn read_with_args(bytes: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3845 | 0 | let discriminant = ExtensionPosFormat1::read_discriminant(bytes)?; |
3846 | 0 | match discriminant { |
3847 | 0 | 1 => Ok(ExtensionSubtable::Single(FontRead::read(bytes)?)), |
3848 | 0 | 2 => Ok(ExtensionSubtable::Pair(FontRead::read(bytes)?)), |
3849 | 0 | 3 => Ok(ExtensionSubtable::Cursive(FontRead::read(bytes)?)), |
3850 | 0 | 4 => Ok(ExtensionSubtable::MarkToBase(FontRead::read(bytes)?)), |
3851 | 0 | 5 => Ok(ExtensionSubtable::MarkToLig(FontRead::read(bytes)?)), |
3852 | 0 | 6 => Ok(ExtensionSubtable::MarkToMark(FontRead::read(bytes)?)), |
3853 | 0 | 7 => Ok(ExtensionSubtable::Contextual(FontRead::read(bytes)?)), |
3854 | 0 | 8 => Ok(ExtensionSubtable::ChainContextual(FontRead::read(bytes)?)), |
3855 | 0 | other => Err(ReadError::InvalidFormat(other.into())), |
3856 | | } |
3857 | 0 | } |
3858 | | } |
3859 | | |
3860 | | impl<'a> ExtensionSubtable<'a> { |
3861 | | #[allow(dead_code)] |
3862 | | /// Return the inner table, removing the specific generics. |
3863 | | /// |
3864 | | /// This lets us return a single concrete type we can call methods on. |
3865 | 0 | pub(crate) fn of_unit_type(&self) -> ExtensionPosFormat1<'a, ()> { |
3866 | 0 | match self { |
3867 | 0 | ExtensionSubtable::Single(inner) => inner.of_unit_type(), |
3868 | 0 | ExtensionSubtable::Pair(inner) => inner.of_unit_type(), |
3869 | 0 | ExtensionSubtable::Cursive(inner) => inner.of_unit_type(), |
3870 | 0 | ExtensionSubtable::MarkToBase(inner) => inner.of_unit_type(), |
3871 | 0 | ExtensionSubtable::MarkToLig(inner) => inner.of_unit_type(), |
3872 | 0 | ExtensionSubtable::MarkToMark(inner) => inner.of_unit_type(), |
3873 | 0 | ExtensionSubtable::Contextual(inner) => inner.of_unit_type(), |
3874 | 0 | ExtensionSubtable::ChainContextual(inner) => inner.of_unit_type(), |
3875 | | } |
3876 | 0 | } |
3877 | | } |
3878 | | |
3879 | | impl Format<u16> for SinglePosFormat3<'_> { |
3880 | | const FORMAT: u16 = 3; |
3881 | | } |
3882 | | |
3883 | | impl<'a> MinByteRange<'a> for SinglePosFormat3<'a> { |
3884 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3885 | 0 | 0..self.value_record_byte_range().end |
3886 | 0 | } |
3887 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
3888 | 0 | let range = self.min_byte_range(); |
3889 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
3890 | 0 | } |
3891 | | } |
3892 | | |
3893 | | impl ReadArgs for SinglePosFormat3<'_> { |
3894 | | type Args = (); |
3895 | | } |
3896 | | |
3897 | | impl<'a> FontRead<'a> for SinglePosFormat3<'a> { |
3898 | 950 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3899 | | #[allow(clippy::absurd_extreme_comparisons)] |
3900 | 950 | if data.len() < Self::MIN_SIZE { |
3901 | 222 | return Err(ReadError::OutOfBounds); |
3902 | 728 | } |
3903 | 728 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
3904 | 0 | return Err(ReadError::OutOfBounds); |
3905 | | }; |
3906 | 728 | Ok(Self { data }) |
3907 | 950 | } |
3908 | | } |
3909 | | |
3910 | | /// The fields at the start of the table, which are read directly. |
3911 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
3912 | | #[repr(C, packed)] |
3913 | | #[doc(hidden)] |
3914 | | pub struct SinglePosFormat3FixedHeader { |
3915 | | pub pos_format: BigEndian<u16>, |
3916 | | pub coverage_offset: BigEndian<Offset32>, |
3917 | | pub value_format: BigEndian<ValueFormat>, |
3918 | | } |
3919 | | |
3920 | | #[allow(clippy::absurd_extreme_comparisons)] |
3921 | | const _: () = |
3922 | | assert!(std::mem::size_of::<SinglePosFormat3FixedHeader>() <= SinglePosFormat3::MIN_SIZE); |
3923 | | |
3924 | | /// SinglePosFormat3 (ISO/IEC 14496-22:2026). |
3925 | | #[derive(Clone)] |
3926 | | pub struct SinglePosFormat3<'a> { |
3927 | | data: TableDataRef<'a, SinglePosFormat3FixedHeader>, |
3928 | | } |
3929 | | |
3930 | | #[allow(clippy::needless_lifetimes)] |
3931 | | impl<'a> SinglePosFormat3<'a> { |
3932 | | pub const MIN_SIZE: usize = |
3933 | | (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + ValueFormat::RAW_BYTE_LEN); |
3934 | | basic_table_impls!(impl_the_methods); |
3935 | | |
3936 | | /// Format identifier: format = 3 |
3937 | 0 | pub fn pos_format(&self) -> u16 { |
3938 | 0 | self.data.header().pos_format.get() |
3939 | 0 | } |
3940 | | |
3941 | | /// Offset to Coverage table, from beginning of SinglePos subtable. |
3942 | 728 | pub fn coverage_offset(&self) -> Offset32 { |
3943 | 728 | self.data.header().coverage_offset.get() |
3944 | 728 | } |
3945 | | |
3946 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
3947 | 728 | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
3948 | 728 | let data = self.offset_data(); |
3949 | 728 | self.coverage_offset().resolve(data) |
3950 | 728 | } |
3951 | | |
3952 | | /// Defines the types of data in the ValueRecord. |
3953 | 1.45k | pub fn value_format(&self) -> ValueFormat { |
3954 | 1.45k | self.data.header().value_format.get() |
3955 | 1.45k | } |
3956 | | |
3957 | | /// Defines positioning value(s) — applied to all glyphs in the |
3958 | | /// Coverage table. |
3959 | 0 | pub fn value_record(&self) -> ValueRecord<'a> { |
3960 | 0 | let range = self.value_record_byte_range(); |
3961 | 0 | ValueRecord::read_at(self.offset_data(), range.start, self.value_format()) |
3962 | 0 | .unwrap_or_default() |
3963 | 0 | } |
3964 | | |
3965 | 728 | pub fn pos_format_byte_range(&self) -> Range<usize> { |
3966 | 728 | let start = 0usize; |
3967 | 728 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
3968 | 728 | start..end |
3969 | 728 | } |
3970 | | |
3971 | 728 | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
3972 | 728 | let start = self.pos_format_byte_range().end; |
3973 | 728 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
3974 | 728 | start..end |
3975 | 728 | } |
3976 | | |
3977 | 728 | pub fn value_format_byte_range(&self) -> Range<usize> { |
3978 | 728 | let start = self.coverage_offset_byte_range().end; |
3979 | 728 | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
3980 | 728 | start..end |
3981 | 728 | } |
3982 | | |
3983 | 728 | pub fn value_record_byte_range(&self) -> Range<usize> { |
3984 | 728 | let start = self.value_format_byte_range().end; |
3985 | 728 | let end = start.saturating_add( |
3986 | 728 | <ValueRecord as ComputeSize>::compute_size(self.value_format()).unwrap_or(0), |
3987 | | ); |
3988 | 728 | start..end |
3989 | 728 | } |
3990 | | } |
3991 | | |
3992 | | impl Format<u16> for SinglePosFormat4<'_> { |
3993 | | const FORMAT: u16 = 4; |
3994 | | } |
3995 | | |
3996 | | impl<'a> MinByteRange<'a> for SinglePosFormat4<'a> { |
3997 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3998 | 0 | 0..self.value_records_byte_range().end |
3999 | 0 | } |
4000 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
4001 | 0 | let range = self.min_byte_range(); |
4002 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
4003 | 0 | } |
4004 | | } |
4005 | | |
4006 | | impl ReadArgs for SinglePosFormat4<'_> { |
4007 | | type Args = (); |
4008 | | } |
4009 | | |
4010 | | impl<'a> FontRead<'a> for SinglePosFormat4<'a> { |
4011 | 1.12k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4012 | | #[allow(clippy::absurd_extreme_comparisons)] |
4013 | 1.12k | if data.len() < Self::MIN_SIZE { |
4014 | 259 | return Err(ReadError::OutOfBounds); |
4015 | 865 | } |
4016 | 865 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
4017 | 0 | return Err(ReadError::OutOfBounds); |
4018 | | }; |
4019 | 865 | Ok(Self { data }) |
4020 | 1.12k | } |
4021 | | } |
4022 | | |
4023 | | /// The fields at the start of the table, which are read directly. |
4024 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
4025 | | #[repr(C, packed)] |
4026 | | #[doc(hidden)] |
4027 | | pub struct SinglePosFormat4FixedHeader { |
4028 | | pub pos_format: BigEndian<u16>, |
4029 | | pub coverage_offset: BigEndian<Offset32>, |
4030 | | pub value_format: BigEndian<ValueFormat>, |
4031 | | pub value_count: BigEndian<Uint24>, |
4032 | | } |
4033 | | |
4034 | | #[allow(clippy::absurd_extreme_comparisons)] |
4035 | | const _: () = |
4036 | | assert!(std::mem::size_of::<SinglePosFormat4FixedHeader>() <= SinglePosFormat4::MIN_SIZE); |
4037 | | |
4038 | | /// SinglePosFormat4 (ISO/IEC 14496-22:2026). |
4039 | | #[derive(Clone)] |
4040 | | pub struct SinglePosFormat4<'a> { |
4041 | | data: TableDataRef<'a, SinglePosFormat4FixedHeader>, |
4042 | | } |
4043 | | |
4044 | | #[allow(clippy::needless_lifetimes)] |
4045 | | impl<'a> SinglePosFormat4<'a> { |
4046 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
4047 | | + Offset32::RAW_BYTE_LEN |
4048 | | + ValueFormat::RAW_BYTE_LEN |
4049 | | + Uint24::RAW_BYTE_LEN); |
4050 | | basic_table_impls!(impl_the_methods); |
4051 | | |
4052 | | /// Format identifier: format = 4 |
4053 | 0 | pub fn pos_format(&self) -> u16 { |
4054 | 0 | self.data.header().pos_format.get() |
4055 | 0 | } |
4056 | | |
4057 | | /// Offset to Coverage table, from beginning of SinglePos subtable. |
4058 | 865 | pub fn coverage_offset(&self) -> Offset32 { |
4059 | 865 | self.data.header().coverage_offset.get() |
4060 | 865 | } |
4061 | | |
4062 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
4063 | 865 | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
4064 | 865 | let data = self.offset_data(); |
4065 | 865 | self.coverage_offset().resolve(data) |
4066 | 865 | } |
4067 | | |
4068 | | /// Defines the types of data in the ValueRecords. |
4069 | 1.73k | pub fn value_format(&self) -> ValueFormat { |
4070 | 1.73k | self.data.header().value_format.get() |
4071 | 1.73k | } |
4072 | | |
4073 | | /// Number of ValueRecords — must equal glyphCount in the |
4074 | | /// Coverage table. |
4075 | 1.73k | pub fn value_count(&self) -> Uint24 { |
4076 | 1.73k | self.data.header().value_count.get() |
4077 | 1.73k | } |
4078 | | |
4079 | | /// Array of ValueRecords — positioning values applied to glyphs. |
4080 | 0 | pub fn value_records(&self) -> ComputedArray<'a, ValueRecord<'a>> { |
4081 | 0 | let range = self.value_records_byte_range(); |
4082 | 0 | ComputedArray::new(self.offset_data(), range, self.value_format()).unwrap_or_default() |
4083 | 0 | } |
4084 | | |
4085 | 865 | pub fn pos_format_byte_range(&self) -> Range<usize> { |
4086 | 865 | let start = 0usize; |
4087 | 865 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
4088 | 865 | start..end |
4089 | 865 | } |
4090 | | |
4091 | 865 | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
4092 | 865 | let start = self.pos_format_byte_range().end; |
4093 | 865 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
4094 | 865 | start..end |
4095 | 865 | } |
4096 | | |
4097 | 865 | pub fn value_format_byte_range(&self) -> Range<usize> { |
4098 | 865 | let start = self.coverage_offset_byte_range().end; |
4099 | 865 | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
4100 | 865 | start..end |
4101 | 865 | } |
4102 | | |
4103 | 865 | pub fn value_count_byte_range(&self) -> Range<usize> { |
4104 | 865 | let start = self.value_format_byte_range().end; |
4105 | 865 | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
4106 | 865 | start..end |
4107 | 865 | } |
4108 | | |
4109 | 865 | pub fn value_records_byte_range(&self) -> Range<usize> { |
4110 | 865 | let value_count = self.value_count(); |
4111 | 865 | let start = self.value_count_byte_range().end; |
4112 | 865 | let end = start.saturating_add((transforms::to_usize(value_count)).saturating_mul( |
4113 | 865 | <ValueRecord as ComputeSize>::compute_size(self.value_format()).unwrap_or(0), |
4114 | | )); |
4115 | 865 | start..end |
4116 | 865 | } |
4117 | | } |
4118 | | |
4119 | | impl Format<u16> for PairPosFormat3<'_> { |
4120 | | const FORMAT: u16 = 3; |
4121 | | } |
4122 | | |
4123 | | impl<'a> MinByteRange<'a> for PairPosFormat3<'a> { |
4124 | 0 | fn min_byte_range(&self) -> Range<usize> { |
4125 | 0 | 0..self.pair_set_offsets_byte_range().end |
4126 | 0 | } |
4127 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
4128 | 0 | let range = self.min_byte_range(); |
4129 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
4130 | 0 | } |
4131 | | } |
4132 | | |
4133 | | impl ReadArgs for PairPosFormat3<'_> { |
4134 | | type Args = (); |
4135 | | } |
4136 | | |
4137 | | impl<'a> FontRead<'a> for PairPosFormat3<'a> { |
4138 | 6.18k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4139 | | #[allow(clippy::absurd_extreme_comparisons)] |
4140 | 6.18k | if data.len() < Self::MIN_SIZE { |
4141 | 517 | return Err(ReadError::OutOfBounds); |
4142 | 5.66k | } |
4143 | 5.66k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
4144 | 0 | return Err(ReadError::OutOfBounds); |
4145 | | }; |
4146 | 5.66k | Ok(Self { data }) |
4147 | 6.18k | } |
4148 | | } |
4149 | | |
4150 | | /// The fields at the start of the table, which are read directly. |
4151 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
4152 | | #[repr(C, packed)] |
4153 | | #[doc(hidden)] |
4154 | | pub struct PairPosFormat3FixedHeader { |
4155 | | pub pos_format: BigEndian<u16>, |
4156 | | pub coverage_offset: BigEndian<Offset32>, |
4157 | | pub value_format1: BigEndian<ValueFormat>, |
4158 | | pub value_format2: BigEndian<ValueFormat>, |
4159 | | pub pair_set_count: BigEndian<Uint24>, |
4160 | | } |
4161 | | |
4162 | | #[allow(clippy::absurd_extreme_comparisons)] |
4163 | | const _: () = assert!(std::mem::size_of::<PairPosFormat3FixedHeader>() <= PairPosFormat3::MIN_SIZE); |
4164 | | |
4165 | | /// PairPosFormat3 (ISO/IEC 14496-22:2026). |
4166 | | #[derive(Clone)] |
4167 | | pub struct PairPosFormat3<'a> { |
4168 | | data: TableDataRef<'a, PairPosFormat3FixedHeader>, |
4169 | | } |
4170 | | |
4171 | | #[allow(clippy::needless_lifetimes)] |
4172 | | impl<'a> PairPosFormat3<'a> { |
4173 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
4174 | | + Offset32::RAW_BYTE_LEN |
4175 | | + ValueFormat::RAW_BYTE_LEN |
4176 | | + ValueFormat::RAW_BYTE_LEN |
4177 | | + Uint24::RAW_BYTE_LEN); |
4178 | | basic_table_impls!(impl_the_methods); |
4179 | | |
4180 | | /// Format identifier: format = 3 |
4181 | 0 | pub fn pos_format(&self) -> u16 { |
4182 | 0 | self.data.header().pos_format.get() |
4183 | 0 | } |
4184 | | |
4185 | | /// Offset to Coverage table, from beginning of PairPos subtable. |
4186 | 5.66k | pub fn coverage_offset(&self) -> Offset32 { |
4187 | 5.66k | self.data.header().coverage_offset.get() |
4188 | 5.66k | } |
4189 | | |
4190 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
4191 | 5.66k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
4192 | 5.66k | let data = self.offset_data(); |
4193 | 5.66k | self.coverage_offset().resolve(data) |
4194 | 5.66k | } |
4195 | | |
4196 | | /// Defines the types of data in valueRecord1 — for the first |
4197 | | /// glyph in the pair (may be zero). |
4198 | 5.66k | pub fn value_format1(&self) -> ValueFormat { |
4199 | 5.66k | self.data.header().value_format1.get() |
4200 | 5.66k | } |
4201 | | |
4202 | | /// Defines the types of data in valueRecord2 — for the second |
4203 | | /// glyph in the pair (may be zero). |
4204 | 5.66k | pub fn value_format2(&self) -> ValueFormat { |
4205 | 5.66k | self.data.header().value_format2.get() |
4206 | 5.66k | } |
4207 | | |
4208 | | /// Number of PairSet tables |
4209 | 5.66k | pub fn pair_set_count(&self) -> Uint24 { |
4210 | 5.66k | self.data.header().pair_set_count.get() |
4211 | 5.66k | } |
4212 | | |
4213 | | /// Array of offsets to PairSet tables. Offsets are from beginning |
4214 | | /// of PairPos subtable, ordered by Coverage Index. |
4215 | 0 | pub fn pair_set_offsets(&self) -> &'a [BigEndian<Offset24>] { |
4216 | 0 | let range = self.pair_set_offsets_byte_range(); |
4217 | 0 | self.offset_data() |
4218 | 0 | .read_array(range) |
4219 | 0 | .ok() |
4220 | 0 | .unwrap_or_default() |
4221 | 0 | } |
4222 | | |
4223 | | /// A dynamically resolving wrapper for [`pair_set_offsets`][Self::pair_set_offsets]. |
4224 | 0 | pub fn pair_sets(&self) -> ArrayOfOffsets<'a, PairSet2<'a>, Offset24> { |
4225 | 0 | let data = self.offset_data(); |
4226 | 0 | let offsets = self.pair_set_offsets(); |
4227 | 0 | let args = (self.value_format1(), self.value_format2()); |
4228 | 0 | ArrayOfOffsets::new(offsets, data, args) |
4229 | 0 | } |
4230 | | |
4231 | 5.66k | pub fn pos_format_byte_range(&self) -> Range<usize> { |
4232 | 5.66k | let start = 0usize; |
4233 | 5.66k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
4234 | 5.66k | start..end |
4235 | 5.66k | } |
4236 | | |
4237 | 5.66k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
4238 | 5.66k | let start = self.pos_format_byte_range().end; |
4239 | 5.66k | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
4240 | 5.66k | start..end |
4241 | 5.66k | } |
4242 | | |
4243 | 5.66k | pub fn value_format1_byte_range(&self) -> Range<usize> { |
4244 | 5.66k | let start = self.coverage_offset_byte_range().end; |
4245 | 5.66k | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
4246 | 5.66k | start..end |
4247 | 5.66k | } |
4248 | | |
4249 | 5.66k | pub fn value_format2_byte_range(&self) -> Range<usize> { |
4250 | 5.66k | let start = self.value_format1_byte_range().end; |
4251 | 5.66k | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
4252 | 5.66k | start..end |
4253 | 5.66k | } |
4254 | | |
4255 | 5.66k | pub fn pair_set_count_byte_range(&self) -> Range<usize> { |
4256 | 5.66k | let start = self.value_format2_byte_range().end; |
4257 | 5.66k | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
4258 | 5.66k | start..end |
4259 | 5.66k | } |
4260 | | |
4261 | 5.66k | pub fn pair_set_offsets_byte_range(&self) -> Range<usize> { |
4262 | 5.66k | let pair_set_count = self.pair_set_count(); |
4263 | 5.66k | let start = self.pair_set_count_byte_range().end; |
4264 | 5.66k | let end = start.saturating_add( |
4265 | 5.66k | (transforms::to_usize(pair_set_count)).saturating_mul(Offset24::RAW_BYTE_LEN), |
4266 | | ); |
4267 | 5.66k | start..end |
4268 | 5.66k | } |
4269 | | } |
4270 | | |
4271 | | impl<'a> MinByteRange<'a> for PairSet2<'a> { |
4272 | 0 | fn min_byte_range(&self) -> Range<usize> { |
4273 | 0 | 0..self.pair_value_records_byte_range().end |
4274 | 0 | } |
4275 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
4276 | 0 | let range = self.min_byte_range(); |
4277 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
4278 | 0 | } |
4279 | | } |
4280 | | |
4281 | | impl ReadArgs for PairSet2<'_> { |
4282 | | type Args = (ValueFormat, ValueFormat); |
4283 | | } |
4284 | | |
4285 | | impl<'a> FontRead<'a> for PairSet2<'a> { |
4286 | 0 | fn read_with_args( |
4287 | 0 | data: FontData<'a>, |
4288 | 0 | args: (ValueFormat, ValueFormat), |
4289 | 0 | ) -> Result<Self, ReadError> { |
4290 | 0 | let (value_format1, value_format2) = args; |
4291 | | |
4292 | | #[allow(clippy::absurd_extreme_comparisons)] |
4293 | 0 | if data.len() < Self::MIN_SIZE { |
4294 | 0 | return Err(ReadError::OutOfBounds); |
4295 | 0 | } |
4296 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
4297 | 0 | return Err(ReadError::OutOfBounds); |
4298 | | }; |
4299 | 0 | Ok(Self { |
4300 | 0 | data, |
4301 | 0 | value_format1, |
4302 | 0 | value_format2, |
4303 | 0 | }) |
4304 | 0 | } |
4305 | | } |
4306 | | |
4307 | | impl<'a> PairSet2<'a> { |
4308 | | /// A constructor that requires additional arguments. |
4309 | | /// |
4310 | | /// This type requires some external state in order to be |
4311 | | /// parsed. |
4312 | 0 | pub fn read( |
4313 | 0 | data: FontData<'a>, |
4314 | 0 | value_format1: ValueFormat, |
4315 | 0 | value_format2: ValueFormat, |
4316 | 0 | ) -> Result<Self, ReadError> { |
4317 | 0 | let args = (value_format1, value_format2); |
4318 | 0 | Self::read_with_args(data, args) |
4319 | 0 | } |
4320 | | } |
4321 | | |
4322 | | /// The fields at the start of the table, which are read directly. |
4323 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
4324 | | #[repr(C, packed)] |
4325 | | #[doc(hidden)] |
4326 | | pub struct PairSet2FixedHeader { |
4327 | | pub pair_value_count: BigEndian<Uint24>, |
4328 | | } |
4329 | | |
4330 | | #[allow(clippy::absurd_extreme_comparisons)] |
4331 | | const _: () = assert!(std::mem::size_of::<PairSet2FixedHeader>() <= PairSet2::MIN_SIZE); |
4332 | | |
4333 | | /// PairSet2 (ISO/IEC 14496-22:2026). |
4334 | | #[derive(Clone)] |
4335 | | pub struct PairSet2<'a> { |
4336 | | data: TableDataRef<'a, PairSet2FixedHeader>, |
4337 | | value_format1: ValueFormat, |
4338 | | value_format2: ValueFormat, |
4339 | | } |
4340 | | |
4341 | | #[allow(clippy::needless_lifetimes)] |
4342 | | impl<'a> PairSet2<'a> { |
4343 | | pub const MIN_SIZE: usize = Uint24::RAW_BYTE_LEN; |
4344 | | basic_table_impls!(impl_the_methods); |
4345 | | |
4346 | | /// Number of PairValueRecords |
4347 | 0 | pub fn pair_value_count(&self) -> Uint24 { |
4348 | 0 | self.data.header().pair_value_count.get() |
4349 | 0 | } |
4350 | | |
4351 | | /// Array of PairValueRecords, ordered by glyph ID of the second |
4352 | | /// glyph. |
4353 | 0 | pub fn pair_value_records(&self) -> ComputedArray<'a, PairValueRecord2<'a>> { |
4354 | 0 | let range = self.pair_value_records_byte_range(); |
4355 | 0 | ComputedArray::new( |
4356 | 0 | self.offset_data(), |
4357 | 0 | range, |
4358 | 0 | (self.value_format1(), self.value_format2()), |
4359 | | ) |
4360 | 0 | .unwrap_or_default() |
4361 | 0 | } |
4362 | | |
4363 | 0 | pub(crate) fn value_format1(&self) -> ValueFormat { |
4364 | 0 | self.value_format1 |
4365 | 0 | } |
4366 | | |
4367 | 0 | pub(crate) fn value_format2(&self) -> ValueFormat { |
4368 | 0 | self.value_format2 |
4369 | 0 | } |
4370 | | |
4371 | 0 | pub fn pair_value_count_byte_range(&self) -> Range<usize> { |
4372 | 0 | let start = 0usize; |
4373 | 0 | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
4374 | 0 | start..end |
4375 | 0 | } |
4376 | | |
4377 | 0 | pub fn pair_value_records_byte_range(&self) -> Range<usize> { |
4378 | 0 | let pair_value_count = self.pair_value_count(); |
4379 | 0 | let start = self.pair_value_count_byte_range().end; |
4380 | 0 | let end = start.saturating_add( |
4381 | 0 | (transforms::to_usize(pair_value_count)).saturating_mul( |
4382 | 0 | <PairValueRecord2 as ComputeSize>::compute_size(( |
4383 | 0 | self.value_format1(), |
4384 | 0 | self.value_format2(), |
4385 | 0 | )) |
4386 | 0 | .unwrap_or(0), |
4387 | | ), |
4388 | | ); |
4389 | 0 | start..end |
4390 | 0 | } |
4391 | | } |
4392 | | |
4393 | | const _: () = assert!(FontData::default_data_long_enough(PairSet2::MIN_SIZE)); |
4394 | | |
4395 | | impl Default for PairSet2<'_> { |
4396 | 0 | fn default() -> Self { |
4397 | | Self { |
4398 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
4399 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
4400 | 0 | value_format1: Default::default(), |
4401 | 0 | value_format2: Default::default(), |
4402 | | } |
4403 | 0 | } |
4404 | | } |
4405 | | |
4406 | | /// PairValueRecord2 (ISO/IEC 14496-22:2026). |
4407 | | #[derive(Clone, Debug)] |
4408 | | pub struct PairValueRecord2<'a> { |
4409 | | /// Glyph ID of second glyph in the pair (first glyph is listed in |
4410 | | /// the Coverage table). |
4411 | | pub second_glyph: BigEndian<GlyphId24>, |
4412 | | /// Positioning data for the first glyph in the pair. |
4413 | | pub value_record1: ValueRecord<'a>, |
4414 | | /// Positioning data for the second glyph in the pair. |
4415 | | pub value_record2: ValueRecord<'a>, |
4416 | | } |
4417 | | |
4418 | | impl<'a> PairValueRecord2<'a> { |
4419 | | /// Glyph ID of second glyph in the pair (first glyph is listed in |
4420 | | /// the Coverage table). |
4421 | 0 | pub fn second_glyph(&self) -> GlyphId24 { |
4422 | 0 | self.second_glyph.get() |
4423 | 0 | } |
4424 | | |
4425 | | /// Positioning data for the first glyph in the pair. |
4426 | 0 | pub fn value_record1(&self) -> &ValueRecord<'a> { |
4427 | 0 | &self.value_record1 |
4428 | 0 | } |
4429 | | |
4430 | | /// Positioning data for the second glyph in the pair. |
4431 | 0 | pub fn value_record2(&self) -> &ValueRecord<'a> { |
4432 | 0 | &self.value_record2 |
4433 | 0 | } |
4434 | | } |
4435 | | |
4436 | | impl ReadArgs for PairValueRecord2<'_> { |
4437 | | type Args = (ValueFormat, ValueFormat); |
4438 | | } |
4439 | | |
4440 | | impl ComputeSize for PairValueRecord2<'_> { |
4441 | | #[allow(clippy::needless_question_mark)] |
4442 | 0 | fn compute_size(args: (ValueFormat, ValueFormat)) -> Result<usize, ReadError> { |
4443 | 0 | let (value_format1, value_format2) = args; |
4444 | 0 | let mut result = 0usize; |
4445 | 0 | result = result |
4446 | 0 | .checked_add(GlyphId24::RAW_BYTE_LEN) |
4447 | 0 | .ok_or(ReadError::OutOfBounds)?; |
4448 | 0 | result = result |
4449 | 0 | .checked_add(<ValueRecord as ComputeSize>::compute_size(value_format1).unwrap_or(0)) |
4450 | 0 | .ok_or(ReadError::OutOfBounds)?; |
4451 | 0 | result = result |
4452 | 0 | .checked_add(<ValueRecord as ComputeSize>::compute_size(value_format2).unwrap_or(0)) |
4453 | 0 | .ok_or(ReadError::OutOfBounds)?; |
4454 | 0 | Ok(result) |
4455 | 0 | } |
4456 | | } |
4457 | | |
4458 | | impl<'a> FontReadAt<'a> for PairValueRecord2<'a> { |
4459 | 0 | fn read_at( |
4460 | 0 | data: FontData<'a>, |
4461 | 0 | offset: usize, |
4462 | 0 | args: (ValueFormat, ValueFormat), |
4463 | 0 | ) -> Result<Self, ReadError> { |
4464 | 0 | let mut cursor = data.cursor(); |
4465 | 0 | cursor.advance_by(offset); |
4466 | 0 | let (value_format1, value_format2) = args; |
4467 | | Ok(Self { |
4468 | 0 | second_glyph: cursor.read_be()?, |
4469 | 0 | value_record1: cursor.read_at_with_args(value_format1)?, |
4470 | 0 | value_record2: cursor.read_at_with_args(value_format2)?, |
4471 | | }) |
4472 | 0 | } |
4473 | | } |
4474 | | |
4475 | | #[allow(clippy::needless_lifetimes)] |
4476 | | impl<'a> PairValueRecord2<'a> { |
4477 | | /// A constructor that requires additional arguments. |
4478 | | /// |
4479 | | /// This type requires some external state in order to be |
4480 | | /// parsed. |
4481 | 0 | pub fn read( |
4482 | 0 | data: FontData<'a>, |
4483 | 0 | offset: usize, |
4484 | 0 | value_format1: ValueFormat, |
4485 | 0 | value_format2: ValueFormat, |
4486 | 0 | ) -> Result<Self, ReadError> { |
4487 | 0 | let args = (value_format1, value_format2); |
4488 | 0 | Self::read_at(data, offset, args) |
4489 | 0 | } |
4490 | | } |
4491 | | |
4492 | | impl Format<u16> for PairPosFormat4<'_> { |
4493 | | const FORMAT: u16 = 4; |
4494 | | } |
4495 | | |
4496 | | impl<'a> MinByteRange<'a> for PairPosFormat4<'a> { |
4497 | 0 | fn min_byte_range(&self) -> Range<usize> { |
4498 | 0 | 0..self.class1_records_byte_range().end |
4499 | 0 | } |
4500 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
4501 | 0 | let range = self.min_byte_range(); |
4502 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
4503 | 0 | } |
4504 | | } |
4505 | | |
4506 | | impl ReadArgs for PairPosFormat4<'_> { |
4507 | | type Args = (); |
4508 | | } |
4509 | | |
4510 | | impl<'a> FontRead<'a> for PairPosFormat4<'a> { |
4511 | 6.30k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4512 | | #[allow(clippy::absurd_extreme_comparisons)] |
4513 | 6.30k | if data.len() < Self::MIN_SIZE { |
4514 | 547 | return Err(ReadError::OutOfBounds); |
4515 | 5.75k | } |
4516 | 5.75k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
4517 | 0 | return Err(ReadError::OutOfBounds); |
4518 | | }; |
4519 | 5.75k | Ok(Self { data }) |
4520 | 6.30k | } |
4521 | | } |
4522 | | |
4523 | | /// The fields at the start of the table, which are read directly. |
4524 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
4525 | | #[repr(C, packed)] |
4526 | | #[doc(hidden)] |
4527 | | pub struct PairPosFormat4FixedHeader { |
4528 | | pub pos_format: BigEndian<u16>, |
4529 | | pub coverage_offset: BigEndian<Offset32>, |
4530 | | pub value_format1: BigEndian<ValueFormat>, |
4531 | | pub value_format2: BigEndian<ValueFormat>, |
4532 | | pub class_def1_offset: BigEndian<Offset32>, |
4533 | | pub class_def2_offset: BigEndian<Offset32>, |
4534 | | pub class1_count: BigEndian<u16>, |
4535 | | pub class2_count: BigEndian<u16>, |
4536 | | } |
4537 | | |
4538 | | #[allow(clippy::absurd_extreme_comparisons)] |
4539 | | const _: () = assert!(std::mem::size_of::<PairPosFormat4FixedHeader>() <= PairPosFormat4::MIN_SIZE); |
4540 | | |
4541 | | /// PairPosFormat4 (ISO/IEC 14496-22:2026). |
4542 | | #[derive(Clone)] |
4543 | | pub struct PairPosFormat4<'a> { |
4544 | | data: TableDataRef<'a, PairPosFormat4FixedHeader>, |
4545 | | } |
4546 | | |
4547 | | #[allow(clippy::needless_lifetimes)] |
4548 | | impl<'a> PairPosFormat4<'a> { |
4549 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
4550 | | + Offset32::RAW_BYTE_LEN |
4551 | | + ValueFormat::RAW_BYTE_LEN |
4552 | | + ValueFormat::RAW_BYTE_LEN |
4553 | | + Offset32::RAW_BYTE_LEN |
4554 | | + Offset32::RAW_BYTE_LEN |
4555 | | + u16::RAW_BYTE_LEN |
4556 | | + u16::RAW_BYTE_LEN); |
4557 | | basic_table_impls!(impl_the_methods); |
4558 | | |
4559 | | /// Format identifier: format = 4 |
4560 | 0 | pub fn pos_format(&self) -> u16 { |
4561 | 0 | self.data.header().pos_format.get() |
4562 | 0 | } |
4563 | | |
4564 | | /// Offset to Coverage table, from beginning of PairPos subtable. |
4565 | 5.75k | pub fn coverage_offset(&self) -> Offset32 { |
4566 | 5.75k | self.data.header().coverage_offset.get() |
4567 | 5.75k | } |
4568 | | |
4569 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
4570 | 5.75k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
4571 | 5.75k | let data = self.offset_data(); |
4572 | 5.75k | self.coverage_offset().resolve(data) |
4573 | 5.75k | } |
4574 | | |
4575 | | /// ValueRecord definition — for the first glyph of the pair (may |
4576 | | /// be zero). |
4577 | 17.2k | pub fn value_format1(&self) -> ValueFormat { |
4578 | 17.2k | self.data.header().value_format1.get() |
4579 | 17.2k | } |
4580 | | |
4581 | | /// ValueRecord definition — for the second glyph of the pair |
4582 | | /// (may be zero). |
4583 | 17.2k | pub fn value_format2(&self) -> ValueFormat { |
4584 | 17.2k | self.data.header().value_format2.get() |
4585 | 17.2k | } |
4586 | | |
4587 | | /// Offset to ClassDef table, from beginning of PairPos subtable |
4588 | | /// — for the first glyph of the pair. |
4589 | 5.75k | pub fn class_def1_offset(&self) -> Offset32 { |
4590 | 5.75k | self.data.header().class_def1_offset.get() |
4591 | 5.75k | } |
4592 | | |
4593 | | /// Attempt to resolve [`class_def1_offset`][Self::class_def1_offset]. |
4594 | 5.75k | pub fn class_def1(&self) -> Result<ClassDef<'a>, ReadError> { |
4595 | 5.75k | let data = self.offset_data(); |
4596 | 5.75k | self.class_def1_offset().resolve(data) |
4597 | 5.75k | } |
4598 | | |
4599 | | /// Offset to ClassDef table, from beginning of PairPos subtable |
4600 | | /// — for the second glyph of the pair. |
4601 | 5.75k | pub fn class_def2_offset(&self) -> Offset32 { |
4602 | 5.75k | self.data.header().class_def2_offset.get() |
4603 | 5.75k | } |
4604 | | |
4605 | | /// Attempt to resolve [`class_def2_offset`][Self::class_def2_offset]. |
4606 | 5.75k | pub fn class_def2(&self) -> Result<ClassDef<'a>, ReadError> { |
4607 | 5.75k | let data = self.offset_data(); |
4608 | 5.75k | self.class_def2_offset().resolve(data) |
4609 | 5.75k | } |
4610 | | |
4611 | | /// Number of classes in classDef1 table — includes Class 0. |
4612 | 17.2k | pub fn class1_count(&self) -> u16 { |
4613 | 17.2k | self.data.header().class1_count.get() |
4614 | 17.2k | } |
4615 | | |
4616 | | /// Number of classes in classDef2 table — includes Class 0. |
4617 | 17.2k | pub fn class2_count(&self) -> u16 { |
4618 | 17.2k | self.data.header().class2_count.get() |
4619 | 17.2k | } |
4620 | | |
4621 | | /// Array of Class1 records, ordered by classes in classDef1. |
4622 | 0 | pub fn class1_records(&self) -> ComputedArray<'a, Class1Record<'a>> { |
4623 | 0 | let range = self.class1_records_byte_range(); |
4624 | 0 | ComputedArray::new( |
4625 | 0 | self.offset_data(), |
4626 | 0 | range, |
4627 | 0 | ( |
4628 | 0 | self.class2_count(), |
4629 | 0 | self.value_format1(), |
4630 | 0 | self.value_format2(), |
4631 | 0 | ), |
4632 | | ) |
4633 | 0 | .unwrap_or_default() |
4634 | 0 | } |
4635 | | |
4636 | 11.5k | pub fn pos_format_byte_range(&self) -> Range<usize> { |
4637 | 11.5k | let start = 0usize; |
4638 | 11.5k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
4639 | 11.5k | start..end |
4640 | 11.5k | } |
4641 | | |
4642 | 11.5k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
4643 | 11.5k | let start = self.pos_format_byte_range().end; |
4644 | 11.5k | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
4645 | 11.5k | start..end |
4646 | 11.5k | } |
4647 | | |
4648 | 11.5k | pub fn value_format1_byte_range(&self) -> Range<usize> { |
4649 | 11.5k | let start = self.coverage_offset_byte_range().end; |
4650 | 11.5k | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
4651 | 11.5k | start..end |
4652 | 11.5k | } |
4653 | | |
4654 | 11.5k | pub fn value_format2_byte_range(&self) -> Range<usize> { |
4655 | 11.5k | let start = self.value_format1_byte_range().end; |
4656 | 11.5k | let end = start.saturating_add(ValueFormat::RAW_BYTE_LEN); |
4657 | 11.5k | start..end |
4658 | 11.5k | } |
4659 | | |
4660 | 11.5k | pub fn class_def1_offset_byte_range(&self) -> Range<usize> { |
4661 | 11.5k | let start = self.value_format2_byte_range().end; |
4662 | 11.5k | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
4663 | 11.5k | start..end |
4664 | 11.5k | } |
4665 | | |
4666 | 11.5k | pub fn class_def2_offset_byte_range(&self) -> Range<usize> { |
4667 | 11.5k | let start = self.class_def1_offset_byte_range().end; |
4668 | 11.5k | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
4669 | 11.5k | start..end |
4670 | 11.5k | } |
4671 | | |
4672 | 11.5k | pub fn class1_count_byte_range(&self) -> Range<usize> { |
4673 | 11.5k | let start = self.class_def2_offset_byte_range().end; |
4674 | 11.5k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
4675 | 11.5k | start..end |
4676 | 11.5k | } |
4677 | | |
4678 | 11.5k | pub fn class2_count_byte_range(&self) -> Range<usize> { |
4679 | 11.5k | let start = self.class1_count_byte_range().end; |
4680 | 11.5k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
4681 | 11.5k | start..end |
4682 | 11.5k | } |
4683 | | |
4684 | 5.75k | pub fn class1_records_byte_range(&self) -> Range<usize> { |
4685 | 5.75k | let class1_count = self.class1_count(); |
4686 | 5.75k | let start = self.class2_count_byte_range().end; |
4687 | 5.75k | let end = start.saturating_add( |
4688 | 5.75k | (transforms::to_usize(class1_count)).saturating_mul( |
4689 | 5.75k | <Class1Record as ComputeSize>::compute_size(( |
4690 | 5.75k | self.class2_count(), |
4691 | 5.75k | self.value_format1(), |
4692 | 5.75k | self.value_format2(), |
4693 | 5.75k | )) |
4694 | 5.75k | .unwrap_or(0), |
4695 | | ), |
4696 | | ); |
4697 | 5.75k | start..end |
4698 | 5.75k | } |
4699 | | } |
4700 | | |
4701 | | impl Format<u16> for CursivePosFormat2<'_> { |
4702 | | const FORMAT: u16 = 2; |
4703 | | } |
4704 | | |
4705 | | impl<'a> MinByteRange<'a> for CursivePosFormat2<'a> { |
4706 | 0 | fn min_byte_range(&self) -> Range<usize> { |
4707 | 0 | 0..self.entry_exit_record_byte_range().end |
4708 | 0 | } |
4709 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
4710 | 0 | let range = self.min_byte_range(); |
4711 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
4712 | 0 | } |
4713 | | } |
4714 | | |
4715 | | impl ReadArgs for CursivePosFormat2<'_> { |
4716 | | type Args = (); |
4717 | | } |
4718 | | |
4719 | | impl<'a> FontRead<'a> for CursivePosFormat2<'a> { |
4720 | 4.53k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4721 | | #[allow(clippy::absurd_extreme_comparisons)] |
4722 | 4.53k | if data.len() < Self::MIN_SIZE { |
4723 | 283 | return Err(ReadError::OutOfBounds); |
4724 | 4.25k | } |
4725 | 4.25k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
4726 | 0 | return Err(ReadError::OutOfBounds); |
4727 | | }; |
4728 | 4.25k | Ok(Self { data }) |
4729 | 4.53k | } |
4730 | | } |
4731 | | |
4732 | | /// The fields at the start of the table, which are read directly. |
4733 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
4734 | | #[repr(C, packed)] |
4735 | | #[doc(hidden)] |
4736 | | pub struct CursivePosFormat2FixedHeader { |
4737 | | pub pos_format: BigEndian<u16>, |
4738 | | pub coverage_offset: BigEndian<Offset32>, |
4739 | | pub entry_exit_count: BigEndian<Uint24>, |
4740 | | } |
4741 | | |
4742 | | #[allow(clippy::absurd_extreme_comparisons)] |
4743 | | const _: () = |
4744 | | assert!(std::mem::size_of::<CursivePosFormat2FixedHeader>() <= CursivePosFormat2::MIN_SIZE); |
4745 | | |
4746 | | /// CursivePosFormat2 (ISO/IEC 14496-22:2026). |
4747 | | #[derive(Clone)] |
4748 | | pub struct CursivePosFormat2<'a> { |
4749 | | data: TableDataRef<'a, CursivePosFormat2FixedHeader>, |
4750 | | } |
4751 | | |
4752 | | #[allow(clippy::needless_lifetimes)] |
4753 | | impl<'a> CursivePosFormat2<'a> { |
4754 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN); |
4755 | | basic_table_impls!(impl_the_methods); |
4756 | | |
4757 | | /// Format identifier: format = 2 |
4758 | 0 | pub fn pos_format(&self) -> u16 { |
4759 | 0 | self.data.header().pos_format.get() |
4760 | 0 | } |
4761 | | |
4762 | | /// Offset to Coverage table, from beginning of CursivePos subtable. |
4763 | 8.50k | pub fn coverage_offset(&self) -> Offset32 { |
4764 | 8.50k | self.data.header().coverage_offset.get() |
4765 | 8.50k | } |
4766 | | |
4767 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
4768 | 8.50k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
4769 | 8.50k | let data = self.offset_data(); |
4770 | 8.50k | self.coverage_offset().resolve(data) |
4771 | 8.50k | } |
4772 | | |
4773 | | /// Number of EntryExit records |
4774 | 4.25k | pub fn entry_exit_count(&self) -> Uint24 { |
4775 | 4.25k | self.data.header().entry_exit_count.get() |
4776 | 4.25k | } |
4777 | | |
4778 | | /// Array of EntryExit records, in Coverage index order. |
4779 | 0 | pub fn entry_exit_record(&self) -> &'a [EntryExitRecord2] { |
4780 | 0 | let range = self.entry_exit_record_byte_range(); |
4781 | 0 | self.offset_data() |
4782 | 0 | .read_array(range) |
4783 | 0 | .ok() |
4784 | 0 | .unwrap_or_default() |
4785 | 0 | } |
4786 | | |
4787 | 4.25k | pub fn pos_format_byte_range(&self) -> Range<usize> { |
4788 | 4.25k | let start = 0usize; |
4789 | 4.25k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
4790 | 4.25k | start..end |
4791 | 4.25k | } |
4792 | | |
4793 | 4.25k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
4794 | 4.25k | let start = self.pos_format_byte_range().end; |
4795 | 4.25k | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
4796 | 4.25k | start..end |
4797 | 4.25k | } |
4798 | | |
4799 | 4.25k | pub fn entry_exit_count_byte_range(&self) -> Range<usize> { |
4800 | 4.25k | let start = self.coverage_offset_byte_range().end; |
4801 | 4.25k | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
4802 | 4.25k | start..end |
4803 | 4.25k | } |
4804 | | |
4805 | 4.25k | pub fn entry_exit_record_byte_range(&self) -> Range<usize> { |
4806 | 4.25k | let entry_exit_count = self.entry_exit_count(); |
4807 | 4.25k | let start = self.entry_exit_count_byte_range().end; |
4808 | 4.25k | let end = start.saturating_add( |
4809 | 4.25k | (transforms::to_usize(entry_exit_count)).saturating_mul(EntryExitRecord2::RAW_BYTE_LEN), |
4810 | | ); |
4811 | 4.25k | start..end |
4812 | 4.25k | } |
4813 | | } |
4814 | | |
4815 | | /// EntryExitRecord2 (ISO/IEC 14496-22:2026). |
4816 | | #[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)] |
4817 | | #[repr(C)] |
4818 | | #[repr(packed)] |
4819 | | pub struct EntryExitRecord2 { |
4820 | | /// Offset to entryAnchor table, from beginning of CursivePos |
4821 | | /// subtable (may be NULL). |
4822 | | pub entry_anchor_offset: BigEndian<Nullable<Offset24>>, |
4823 | | /// Offset to exitAnchor table, from beginning of CursivePos |
4824 | | /// subtable (may be NULL). |
4825 | | pub exit_anchor_offset: BigEndian<Nullable<Offset24>>, |
4826 | | } |
4827 | | |
4828 | | impl EntryExitRecord2 { |
4829 | | /// Offset to entryAnchor table, from beginning of CursivePos |
4830 | | /// subtable (may be NULL). |
4831 | 0 | pub fn entry_anchor_offset(&self) -> Nullable<Offset24> { |
4832 | 0 | self.entry_anchor_offset.get() |
4833 | 0 | } |
4834 | | |
4835 | | /// Offset to entryAnchor table, from beginning of CursivePos |
4836 | | /// subtable (may be NULL). |
4837 | | /// |
4838 | | /// The `data` argument should be retrieved from the parent table |
4839 | | /// By calling its `offset_data` method. |
4840 | 0 | pub fn entry_anchor<'a>( |
4841 | 0 | &self, |
4842 | 0 | data: FontData<'a>, |
4843 | 0 | ) -> Option<Result<AnchorTable<'a>, ReadError>> { |
4844 | 0 | self.entry_anchor_offset().resolve(data) |
4845 | 0 | } |
4846 | | |
4847 | | /// Offset to exitAnchor table, from beginning of CursivePos |
4848 | | /// subtable (may be NULL). |
4849 | 0 | pub fn exit_anchor_offset(&self) -> Nullable<Offset24> { |
4850 | 0 | self.exit_anchor_offset.get() |
4851 | 0 | } |
4852 | | |
4853 | | /// Offset to exitAnchor table, from beginning of CursivePos |
4854 | | /// subtable (may be NULL). |
4855 | | /// |
4856 | | /// The `data` argument should be retrieved from the parent table |
4857 | | /// By calling its `offset_data` method. |
4858 | 0 | pub fn exit_anchor<'a>( |
4859 | 0 | &self, |
4860 | 0 | data: FontData<'a>, |
4861 | 0 | ) -> Option<Result<AnchorTable<'a>, ReadError>> { |
4862 | 0 | self.exit_anchor_offset().resolve(data) |
4863 | 0 | } |
4864 | | } |
4865 | | |
4866 | | impl FixedSize for EntryExitRecord2 { |
4867 | | const RAW_BYTE_LEN: usize = Offset24::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN; |
4868 | | } |
4869 | | |
4870 | | impl Format<u16> for MarkBasePosFormat2<'_> { |
4871 | | const FORMAT: u16 = 2; |
4872 | | } |
4873 | | |
4874 | | impl<'a> MinByteRange<'a> for MarkBasePosFormat2<'a> { |
4875 | 0 | fn min_byte_range(&self) -> Range<usize> { |
4876 | 0 | 0..self.base_array_offset_byte_range().end |
4877 | 0 | } |
4878 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
4879 | 0 | let range = self.min_byte_range(); |
4880 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
4881 | 0 | } |
4882 | | } |
4883 | | |
4884 | | impl ReadArgs for MarkBasePosFormat2<'_> { |
4885 | | type Args = (); |
4886 | | } |
4887 | | |
4888 | | impl<'a> FontRead<'a> for MarkBasePosFormat2<'a> { |
4889 | 5.98k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4890 | | #[allow(clippy::absurd_extreme_comparisons)] |
4891 | 5.98k | if data.len() < Self::MIN_SIZE { |
4892 | 381 | return Err(ReadError::OutOfBounds); |
4893 | 5.60k | } |
4894 | 5.60k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
4895 | 0 | return Err(ReadError::OutOfBounds); |
4896 | | }; |
4897 | 5.60k | Ok(Self { data }) |
4898 | 5.98k | } |
4899 | | } |
4900 | | |
4901 | | /// The fields at the start of the table, which are read directly. |
4902 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
4903 | | #[repr(C, packed)] |
4904 | | #[doc(hidden)] |
4905 | | pub struct MarkBasePosFormat2FixedHeader { |
4906 | | pub pos_format: BigEndian<u16>, |
4907 | | pub mark_coverage_offset: BigEndian<Offset32>, |
4908 | | pub base_coverage_offset: BigEndian<Offset32>, |
4909 | | pub mark_class_count: BigEndian<u16>, |
4910 | | pub mark_array_offset: BigEndian<Offset32>, |
4911 | | pub base_array_offset: BigEndian<Offset32>, |
4912 | | } |
4913 | | |
4914 | | #[allow(clippy::absurd_extreme_comparisons)] |
4915 | | const _: () = |
4916 | | assert!(std::mem::size_of::<MarkBasePosFormat2FixedHeader>() <= MarkBasePosFormat2::MIN_SIZE); |
4917 | | |
4918 | | /// MarkBasePosFormat2 (ISO/IEC 14496-22:2026). |
4919 | | #[derive(Clone)] |
4920 | | pub struct MarkBasePosFormat2<'a> { |
4921 | | data: TableDataRef<'a, MarkBasePosFormat2FixedHeader>, |
4922 | | } |
4923 | | |
4924 | | #[allow(clippy::needless_lifetimes)] |
4925 | | impl<'a> MarkBasePosFormat2<'a> { |
4926 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
4927 | | + Offset32::RAW_BYTE_LEN |
4928 | | + Offset32::RAW_BYTE_LEN |
4929 | | + u16::RAW_BYTE_LEN |
4930 | | + Offset32::RAW_BYTE_LEN |
4931 | | + Offset32::RAW_BYTE_LEN); |
4932 | | basic_table_impls!(impl_the_methods); |
4933 | | |
4934 | | /// Format identifier: format = 2 |
4935 | 0 | pub fn pos_format(&self) -> u16 { |
4936 | 0 | self.data.header().pos_format.get() |
4937 | 0 | } |
4938 | | |
4939 | | /// Offset to markCoverage table, from beginning of MarkBasePos |
4940 | | /// subtable. |
4941 | 5.60k | pub fn mark_coverage_offset(&self) -> Offset32 { |
4942 | 5.60k | self.data.header().mark_coverage_offset.get() |
4943 | 5.60k | } |
4944 | | |
4945 | | /// Attempt to resolve [`mark_coverage_offset`][Self::mark_coverage_offset]. |
4946 | 5.60k | pub fn mark_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
4947 | 5.60k | let data = self.offset_data(); |
4948 | 5.60k | self.mark_coverage_offset().resolve(data) |
4949 | 5.60k | } |
4950 | | |
4951 | | /// Offset to baseCoverage table, from beginning of MarkBasePos |
4952 | | /// subtable. |
4953 | 5.60k | pub fn base_coverage_offset(&self) -> Offset32 { |
4954 | 5.60k | self.data.header().base_coverage_offset.get() |
4955 | 5.60k | } |
4956 | | |
4957 | | /// Attempt to resolve [`base_coverage_offset`][Self::base_coverage_offset]. |
4958 | 5.60k | pub fn base_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
4959 | 5.60k | let data = self.offset_data(); |
4960 | 5.60k | self.base_coverage_offset().resolve(data) |
4961 | 5.60k | } |
4962 | | |
4963 | | /// Number of classes defined for marks |
4964 | 11.2k | pub fn mark_class_count(&self) -> u16 { |
4965 | 11.2k | self.data.header().mark_class_count.get() |
4966 | 11.2k | } |
4967 | | |
4968 | | /// Offset to MarkArray table, from beginning of MarkBasePos |
4969 | | /// subtable. |
4970 | 5.60k | pub fn mark_array_offset(&self) -> Offset32 { |
4971 | 5.60k | self.data.header().mark_array_offset.get() |
4972 | 5.60k | } |
4973 | | |
4974 | | /// Attempt to resolve [`mark_array_offset`][Self::mark_array_offset]. |
4975 | 5.60k | pub fn mark_array(&self) -> Result<MarkArray2<'a>, ReadError> { |
4976 | 5.60k | let data = self.offset_data(); |
4977 | 5.60k | self.mark_array_offset().resolve(data) |
4978 | 5.60k | } |
4979 | | |
4980 | | /// Offset to BaseArray table, from beginning of MarkBasePos |
4981 | | /// subtable. |
4982 | 5.60k | pub fn base_array_offset(&self) -> Offset32 { |
4983 | 5.60k | self.data.header().base_array_offset.get() |
4984 | 5.60k | } |
4985 | | |
4986 | | /// Attempt to resolve [`base_array_offset`][Self::base_array_offset]. |
4987 | 5.60k | pub fn base_array(&self) -> Result<BaseArray2<'a>, ReadError> { |
4988 | 5.60k | let data = self.offset_data(); |
4989 | 5.60k | let args = self.mark_class_count(); |
4990 | 5.60k | self.base_array_offset().resolve_with_args(data, args) |
4991 | 5.60k | } |
4992 | | |
4993 | 0 | pub fn pos_format_byte_range(&self) -> Range<usize> { |
4994 | 0 | let start = 0usize; |
4995 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
4996 | 0 | start..end |
4997 | 0 | } |
4998 | | |
4999 | 0 | pub fn mark_coverage_offset_byte_range(&self) -> Range<usize> { |
5000 | 0 | let start = self.pos_format_byte_range().end; |
5001 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5002 | 0 | start..end |
5003 | 0 | } |
5004 | | |
5005 | 0 | pub fn base_coverage_offset_byte_range(&self) -> Range<usize> { |
5006 | 0 | let start = self.mark_coverage_offset_byte_range().end; |
5007 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5008 | 0 | start..end |
5009 | 0 | } |
5010 | | |
5011 | 0 | pub fn mark_class_count_byte_range(&self) -> Range<usize> { |
5012 | 0 | let start = self.base_coverage_offset_byte_range().end; |
5013 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
5014 | 0 | start..end |
5015 | 0 | } |
5016 | | |
5017 | 0 | pub fn mark_array_offset_byte_range(&self) -> Range<usize> { |
5018 | 0 | let start = self.mark_class_count_byte_range().end; |
5019 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5020 | 0 | start..end |
5021 | 0 | } |
5022 | | |
5023 | 0 | pub fn base_array_offset_byte_range(&self) -> Range<usize> { |
5024 | 0 | let start = self.mark_array_offset_byte_range().end; |
5025 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5026 | 0 | start..end |
5027 | 0 | } |
5028 | | } |
5029 | | |
5030 | | impl<'a> MinByteRange<'a> for BaseArray2<'a> { |
5031 | 0 | fn min_byte_range(&self) -> Range<usize> { |
5032 | 0 | 0..self.base_records_byte_range().end |
5033 | 0 | } |
5034 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
5035 | 0 | let range = self.min_byte_range(); |
5036 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
5037 | 0 | } |
5038 | | } |
5039 | | |
5040 | | impl ReadArgs for BaseArray2<'_> { |
5041 | | type Args = u16; |
5042 | | } |
5043 | | |
5044 | | impl<'a> FontRead<'a> for BaseArray2<'a> { |
5045 | 2.00k | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
5046 | 2.00k | let mark_class_count = args; |
5047 | | |
5048 | | #[allow(clippy::absurd_extreme_comparisons)] |
5049 | 2.00k | if data.len() < Self::MIN_SIZE { |
5050 | 6 | return Err(ReadError::OutOfBounds); |
5051 | 2.00k | } |
5052 | 2.00k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
5053 | 0 | return Err(ReadError::OutOfBounds); |
5054 | | }; |
5055 | 2.00k | Ok(Self { |
5056 | 2.00k | data, |
5057 | 2.00k | mark_class_count, |
5058 | 2.00k | }) |
5059 | 2.00k | } |
5060 | | } |
5061 | | |
5062 | | impl<'a> BaseArray2<'a> { |
5063 | | /// A constructor that requires additional arguments. |
5064 | | /// |
5065 | | /// This type requires some external state in order to be |
5066 | | /// parsed. |
5067 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
5068 | 0 | let args = mark_class_count; |
5069 | 0 | Self::read_with_args(data, args) |
5070 | 0 | } |
5071 | | } |
5072 | | |
5073 | | /// The fields at the start of the table, which are read directly. |
5074 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
5075 | | #[repr(C, packed)] |
5076 | | #[doc(hidden)] |
5077 | | pub struct BaseArray2FixedHeader { |
5078 | | pub base_count: BigEndian<Uint24>, |
5079 | | } |
5080 | | |
5081 | | #[allow(clippy::absurd_extreme_comparisons)] |
5082 | | const _: () = assert!(std::mem::size_of::<BaseArray2FixedHeader>() <= BaseArray2::MIN_SIZE); |
5083 | | |
5084 | | /// BaseArray2 (ISO/IEC 14496-22:2026). |
5085 | | #[derive(Clone)] |
5086 | | pub struct BaseArray2<'a> { |
5087 | | data: TableDataRef<'a, BaseArray2FixedHeader>, |
5088 | | mark_class_count: u16, |
5089 | | } |
5090 | | |
5091 | | #[allow(clippy::needless_lifetimes)] |
5092 | | impl<'a> BaseArray2<'a> { |
5093 | | pub const MIN_SIZE: usize = Uint24::RAW_BYTE_LEN; |
5094 | | basic_table_impls!(impl_the_methods); |
5095 | | |
5096 | | /// Number of BaseRecords |
5097 | 0 | pub fn base_count(&self) -> Uint24 { |
5098 | 0 | self.data.header().base_count.get() |
5099 | 0 | } |
5100 | | |
5101 | | /// Array of BaseRecords, in order of baseCoverage Index. |
5102 | 0 | pub fn base_records(&self) -> ComputedArray<'a, BaseRecord2<'a>> { |
5103 | 0 | let range = self.base_records_byte_range(); |
5104 | 0 | ComputedArray::new(self.offset_data(), range, self.mark_class_count()).unwrap_or_default() |
5105 | 0 | } |
5106 | | |
5107 | 0 | pub(crate) fn mark_class_count(&self) -> u16 { |
5108 | 0 | self.mark_class_count |
5109 | 0 | } |
5110 | | |
5111 | 0 | pub fn base_count_byte_range(&self) -> Range<usize> { |
5112 | 0 | let start = 0usize; |
5113 | 0 | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
5114 | 0 | start..end |
5115 | 0 | } |
5116 | | |
5117 | 0 | pub fn base_records_byte_range(&self) -> Range<usize> { |
5118 | 0 | let base_count = self.base_count(); |
5119 | 0 | let start = self.base_count_byte_range().end; |
5120 | 0 | let end = start.saturating_add((transforms::to_usize(base_count)).saturating_mul( |
5121 | 0 | <BaseRecord2 as ComputeSize>::compute_size(self.mark_class_count()).unwrap_or(0), |
5122 | | )); |
5123 | 0 | start..end |
5124 | 0 | } |
5125 | | } |
5126 | | |
5127 | | const _: () = assert!(FontData::default_data_long_enough(BaseArray2::MIN_SIZE)); |
5128 | | |
5129 | | impl Default for BaseArray2<'_> { |
5130 | 0 | fn default() -> Self { |
5131 | | Self { |
5132 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
5133 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
5134 | 0 | mark_class_count: Default::default(), |
5135 | | } |
5136 | 0 | } |
5137 | | } |
5138 | | |
5139 | | /// BaseRecord2 (ISO/IEC 14496-22:2026). |
5140 | | #[derive(Clone, Debug)] |
5141 | | pub struct BaseRecord2<'a> { |
5142 | | /// Array of offsets (one per mark class) to Anchor tables. Offsets |
5143 | | /// are from beginning of BaseArray table, ordered by class |
5144 | | /// (offsets may be NULL). |
5145 | | pub base_anchor_offsets: &'a [BigEndian<Nullable<Offset24>>], |
5146 | | } |
5147 | | |
5148 | | impl<'a> BaseRecord2<'a> { |
5149 | | /// Array of offsets (one per mark class) to Anchor tables. Offsets |
5150 | | /// are from beginning of BaseArray table, ordered by class |
5151 | | /// (offsets may be NULL). |
5152 | 0 | pub fn base_anchor_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] { |
5153 | 0 | self.base_anchor_offsets |
5154 | 0 | } |
5155 | | |
5156 | | /// Array of offsets (one per mark class) to Anchor tables. Offsets |
5157 | | /// are from beginning of BaseArray table, ordered by class |
5158 | | /// (offsets may be NULL). |
5159 | | /// |
5160 | | /// The `data` argument should be retrieved from the parent table |
5161 | | /// By calling its `offset_data` method. |
5162 | 0 | pub fn base_anchors( |
5163 | 0 | &self, |
5164 | 0 | data: FontData<'a>, |
5165 | 0 | ) -> ArrayOfNullableOffsets<'a, AnchorTable<'a>, Offset24> { |
5166 | 0 | let offsets = self.base_anchor_offsets(); |
5167 | 0 | ArrayOfNullableOffsets::new(offsets, data, ()) |
5168 | 0 | } |
5169 | | } |
5170 | | |
5171 | | impl ReadArgs for BaseRecord2<'_> { |
5172 | | type Args = u16; |
5173 | | } |
5174 | | |
5175 | | impl ComputeSize for BaseRecord2<'_> { |
5176 | | #[allow(clippy::needless_question_mark)] |
5177 | 0 | fn compute_size(args: u16) -> Result<usize, ReadError> { |
5178 | 0 | let mark_class_count = args; |
5179 | 0 | Ok((transforms::to_usize(mark_class_count)).saturating_mul(Offset24::RAW_BYTE_LEN)) |
5180 | 0 | } |
5181 | | } |
5182 | | |
5183 | | impl<'a> FontRead<'a> for BaseRecord2<'a> { |
5184 | 0 | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
5185 | 0 | let mut cursor = data.cursor(); |
5186 | 0 | let mark_class_count = args; |
5187 | | Ok(Self { |
5188 | 0 | base_anchor_offsets: cursor.read_array(transforms::to_usize(mark_class_count))?, |
5189 | | }) |
5190 | 0 | } |
5191 | | } |
5192 | | |
5193 | | crate::impl_font_read_at!(BaseRecord2<'a>); |
5194 | | |
5195 | | #[allow(clippy::needless_lifetimes)] |
5196 | | impl<'a> BaseRecord2<'a> { |
5197 | | /// A constructor that requires additional arguments. |
5198 | | /// |
5199 | | /// This type requires some external state in order to be |
5200 | | /// parsed. |
5201 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
5202 | 0 | let args = mark_class_count; |
5203 | 0 | Self::read_with_args(data, args) |
5204 | 0 | } |
5205 | | } |
5206 | | |
5207 | | impl Format<u16> for MarkLigPosFormat2<'_> { |
5208 | | const FORMAT: u16 = 2; |
5209 | | } |
5210 | | |
5211 | | impl<'a> MinByteRange<'a> for MarkLigPosFormat2<'a> { |
5212 | 0 | fn min_byte_range(&self) -> Range<usize> { |
5213 | 0 | 0..self.ligature_array_offset_byte_range().end |
5214 | 0 | } |
5215 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
5216 | 0 | let range = self.min_byte_range(); |
5217 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
5218 | 0 | } |
5219 | | } |
5220 | | |
5221 | | impl ReadArgs for MarkLigPosFormat2<'_> { |
5222 | | type Args = (); |
5223 | | } |
5224 | | |
5225 | | impl<'a> FontRead<'a> for MarkLigPosFormat2<'a> { |
5226 | 5.04k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
5227 | | #[allow(clippy::absurd_extreme_comparisons)] |
5228 | 5.04k | if data.len() < Self::MIN_SIZE { |
5229 | 238 | return Err(ReadError::OutOfBounds); |
5230 | 4.81k | } |
5231 | 4.81k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
5232 | 0 | return Err(ReadError::OutOfBounds); |
5233 | | }; |
5234 | 4.81k | Ok(Self { data }) |
5235 | 5.04k | } |
5236 | | } |
5237 | | |
5238 | | /// The fields at the start of the table, which are read directly. |
5239 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
5240 | | #[repr(C, packed)] |
5241 | | #[doc(hidden)] |
5242 | | pub struct MarkLigPosFormat2FixedHeader { |
5243 | | pub pos_format: BigEndian<u16>, |
5244 | | pub mark_coverage_offset: BigEndian<Offset32>, |
5245 | | pub ligature_coverage_offset: BigEndian<Offset32>, |
5246 | | pub mark_class_count: BigEndian<u16>, |
5247 | | pub mark_array_offset: BigEndian<Offset32>, |
5248 | | pub ligature_array_offset: BigEndian<Offset32>, |
5249 | | } |
5250 | | |
5251 | | #[allow(clippy::absurd_extreme_comparisons)] |
5252 | | const _: () = |
5253 | | assert!(std::mem::size_of::<MarkLigPosFormat2FixedHeader>() <= MarkLigPosFormat2::MIN_SIZE); |
5254 | | |
5255 | | /// MarkLigPosFormat2 (ISO/IEC 14496-22:2026). |
5256 | | #[derive(Clone)] |
5257 | | pub struct MarkLigPosFormat2<'a> { |
5258 | | data: TableDataRef<'a, MarkLigPosFormat2FixedHeader>, |
5259 | | } |
5260 | | |
5261 | | #[allow(clippy::needless_lifetimes)] |
5262 | | impl<'a> MarkLigPosFormat2<'a> { |
5263 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
5264 | | + Offset32::RAW_BYTE_LEN |
5265 | | + Offset32::RAW_BYTE_LEN |
5266 | | + u16::RAW_BYTE_LEN |
5267 | | + Offset32::RAW_BYTE_LEN |
5268 | | + Offset32::RAW_BYTE_LEN); |
5269 | | basic_table_impls!(impl_the_methods); |
5270 | | |
5271 | | /// Format identifier: format = 2 |
5272 | 0 | pub fn pos_format(&self) -> u16 { |
5273 | 0 | self.data.header().pos_format.get() |
5274 | 0 | } |
5275 | | |
5276 | | /// Offset to markCoverage table, from beginning of MarkLigPos |
5277 | | /// subtable. |
5278 | 4.81k | pub fn mark_coverage_offset(&self) -> Offset32 { |
5279 | 4.81k | self.data.header().mark_coverage_offset.get() |
5280 | 4.81k | } |
5281 | | |
5282 | | /// Attempt to resolve [`mark_coverage_offset`][Self::mark_coverage_offset]. |
5283 | 4.81k | pub fn mark_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
5284 | 4.81k | let data = self.offset_data(); |
5285 | 4.81k | self.mark_coverage_offset().resolve(data) |
5286 | 4.81k | } |
5287 | | |
5288 | | /// Offset to ligatureCoverage table, from beginning of MarkLigPos |
5289 | | /// subtable. |
5290 | 4.81k | pub fn ligature_coverage_offset(&self) -> Offset32 { |
5291 | 4.81k | self.data.header().ligature_coverage_offset.get() |
5292 | 4.81k | } |
5293 | | |
5294 | | /// Attempt to resolve [`ligature_coverage_offset`][Self::ligature_coverage_offset]. |
5295 | 4.81k | pub fn ligature_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
5296 | 4.81k | let data = self.offset_data(); |
5297 | 4.81k | self.ligature_coverage_offset().resolve(data) |
5298 | 4.81k | } |
5299 | | |
5300 | | /// Number of defined mark classes |
5301 | 9.62k | pub fn mark_class_count(&self) -> u16 { |
5302 | 9.62k | self.data.header().mark_class_count.get() |
5303 | 9.62k | } |
5304 | | |
5305 | | /// Offset to MarkArray table, from beginning of MarkLigPos |
5306 | | /// subtable. |
5307 | 4.81k | pub fn mark_array_offset(&self) -> Offset32 { |
5308 | 4.81k | self.data.header().mark_array_offset.get() |
5309 | 4.81k | } |
5310 | | |
5311 | | /// Attempt to resolve [`mark_array_offset`][Self::mark_array_offset]. |
5312 | 4.81k | pub fn mark_array(&self) -> Result<MarkArray2<'a>, ReadError> { |
5313 | 4.81k | let data = self.offset_data(); |
5314 | 4.81k | self.mark_array_offset().resolve(data) |
5315 | 4.81k | } |
5316 | | |
5317 | | /// Offset to LigatureArray table, from beginning of MarkLigPos |
5318 | | /// subtable. |
5319 | 4.81k | pub fn ligature_array_offset(&self) -> Offset32 { |
5320 | 4.81k | self.data.header().ligature_array_offset.get() |
5321 | 4.81k | } |
5322 | | |
5323 | | /// Attempt to resolve [`ligature_array_offset`][Self::ligature_array_offset]. |
5324 | 4.81k | pub fn ligature_array(&self) -> Result<LigatureArray2<'a>, ReadError> { |
5325 | 4.81k | let data = self.offset_data(); |
5326 | 4.81k | let args = self.mark_class_count(); |
5327 | 4.81k | self.ligature_array_offset().resolve_with_args(data, args) |
5328 | 4.81k | } |
5329 | | |
5330 | 0 | pub fn pos_format_byte_range(&self) -> Range<usize> { |
5331 | 0 | let start = 0usize; |
5332 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
5333 | 0 | start..end |
5334 | 0 | } |
5335 | | |
5336 | 0 | pub fn mark_coverage_offset_byte_range(&self) -> Range<usize> { |
5337 | 0 | let start = self.pos_format_byte_range().end; |
5338 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5339 | 0 | start..end |
5340 | 0 | } |
5341 | | |
5342 | 0 | pub fn ligature_coverage_offset_byte_range(&self) -> Range<usize> { |
5343 | 0 | let start = self.mark_coverage_offset_byte_range().end; |
5344 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5345 | 0 | start..end |
5346 | 0 | } |
5347 | | |
5348 | 0 | pub fn mark_class_count_byte_range(&self) -> Range<usize> { |
5349 | 0 | let start = self.ligature_coverage_offset_byte_range().end; |
5350 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
5351 | 0 | start..end |
5352 | 0 | } |
5353 | | |
5354 | 0 | pub fn mark_array_offset_byte_range(&self) -> Range<usize> { |
5355 | 0 | let start = self.mark_class_count_byte_range().end; |
5356 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5357 | 0 | start..end |
5358 | 0 | } |
5359 | | |
5360 | 0 | pub fn ligature_array_offset_byte_range(&self) -> Range<usize> { |
5361 | 0 | let start = self.mark_array_offset_byte_range().end; |
5362 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5363 | 0 | start..end |
5364 | 0 | } |
5365 | | } |
5366 | | |
5367 | | impl<'a> MinByteRange<'a> for LigatureArray2<'a> { |
5368 | 0 | fn min_byte_range(&self) -> Range<usize> { |
5369 | 0 | 0..self.ligature_attach_offsets_byte_range().end |
5370 | 0 | } |
5371 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
5372 | 0 | let range = self.min_byte_range(); |
5373 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
5374 | 0 | } |
5375 | | } |
5376 | | |
5377 | | impl ReadArgs for LigatureArray2<'_> { |
5378 | | type Args = u16; |
5379 | | } |
5380 | | |
5381 | | impl<'a> FontRead<'a> for LigatureArray2<'a> { |
5382 | 1.83k | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
5383 | 1.83k | let mark_class_count = args; |
5384 | | |
5385 | | #[allow(clippy::absurd_extreme_comparisons)] |
5386 | 1.83k | if data.len() < Self::MIN_SIZE { |
5387 | 777 | return Err(ReadError::OutOfBounds); |
5388 | 1.05k | } |
5389 | 1.05k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
5390 | 0 | return Err(ReadError::OutOfBounds); |
5391 | | }; |
5392 | 1.05k | Ok(Self { |
5393 | 1.05k | data, |
5394 | 1.05k | mark_class_count, |
5395 | 1.05k | }) |
5396 | 1.83k | } |
5397 | | } |
5398 | | |
5399 | | impl<'a> LigatureArray2<'a> { |
5400 | | /// A constructor that requires additional arguments. |
5401 | | /// |
5402 | | /// This type requires some external state in order to be |
5403 | | /// parsed. |
5404 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
5405 | 0 | let args = mark_class_count; |
5406 | 0 | Self::read_with_args(data, args) |
5407 | 0 | } |
5408 | | } |
5409 | | |
5410 | | /// The fields at the start of the table, which are read directly. |
5411 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
5412 | | #[repr(C, packed)] |
5413 | | #[doc(hidden)] |
5414 | | pub struct LigatureArray2FixedHeader { |
5415 | | pub ligature_count: BigEndian<Uint24>, |
5416 | | } |
5417 | | |
5418 | | #[allow(clippy::absurd_extreme_comparisons)] |
5419 | | const _: () = assert!(std::mem::size_of::<LigatureArray2FixedHeader>() <= LigatureArray2::MIN_SIZE); |
5420 | | |
5421 | | /// LigatureArray2 (ISO/IEC 14496-22:2026). |
5422 | | #[derive(Clone)] |
5423 | | pub struct LigatureArray2<'a> { |
5424 | | data: TableDataRef<'a, LigatureArray2FixedHeader>, |
5425 | | mark_class_count: u16, |
5426 | | } |
5427 | | |
5428 | | #[allow(clippy::needless_lifetimes)] |
5429 | | impl<'a> LigatureArray2<'a> { |
5430 | | pub const MIN_SIZE: usize = Uint24::RAW_BYTE_LEN; |
5431 | | basic_table_impls!(impl_the_methods); |
5432 | | |
5433 | | /// Number of LigatureAttach table offsets |
5434 | 1.05k | pub fn ligature_count(&self) -> Uint24 { |
5435 | 1.05k | self.data.header().ligature_count.get() |
5436 | 1.05k | } |
5437 | | |
5438 | | /// Array of offsets to LigatureAttach tables. Offsets are from |
5439 | | /// beginning of LigatureArray2 table, ordered by ligatureCoverage |
5440 | | /// index. |
5441 | 0 | pub fn ligature_attach_offsets(&self) -> &'a [BigEndian<Offset24>] { |
5442 | 0 | let range = self.ligature_attach_offsets_byte_range(); |
5443 | 0 | self.offset_data() |
5444 | 0 | .read_array(range) |
5445 | 0 | .ok() |
5446 | 0 | .unwrap_or_default() |
5447 | 0 | } |
5448 | | |
5449 | | /// A dynamically resolving wrapper for [`ligature_attach_offsets`][Self::ligature_attach_offsets]. |
5450 | 0 | pub fn ligature_attaches(&self) -> ArrayOfOffsets<'a, LigatureAttach2<'a>, Offset24> { |
5451 | 0 | let data = self.offset_data(); |
5452 | 0 | let offsets = self.ligature_attach_offsets(); |
5453 | 0 | let args = self.mark_class_count(); |
5454 | 0 | ArrayOfOffsets::new(offsets, data, args) |
5455 | 0 | } |
5456 | | |
5457 | 0 | pub(crate) fn mark_class_count(&self) -> u16 { |
5458 | 0 | self.mark_class_count |
5459 | 0 | } |
5460 | | |
5461 | 1.05k | pub fn ligature_count_byte_range(&self) -> Range<usize> { |
5462 | 1.05k | let start = 0usize; |
5463 | 1.05k | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
5464 | 1.05k | start..end |
5465 | 1.05k | } |
5466 | | |
5467 | 1.05k | pub fn ligature_attach_offsets_byte_range(&self) -> Range<usize> { |
5468 | 1.05k | let ligature_count = self.ligature_count(); |
5469 | 1.05k | let start = self.ligature_count_byte_range().end; |
5470 | 1.05k | let end = start.saturating_add( |
5471 | 1.05k | (transforms::to_usize(ligature_count)).saturating_mul(Offset24::RAW_BYTE_LEN), |
5472 | | ); |
5473 | 1.05k | start..end |
5474 | 1.05k | } |
5475 | | } |
5476 | | |
5477 | | const _: () = assert!(FontData::default_data_long_enough(LigatureArray2::MIN_SIZE)); |
5478 | | |
5479 | | impl Default for LigatureArray2<'_> { |
5480 | 0 | fn default() -> Self { |
5481 | | Self { |
5482 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
5483 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
5484 | 0 | mark_class_count: Default::default(), |
5485 | | } |
5486 | 0 | } |
5487 | | } |
5488 | | |
5489 | | impl<'a> MinByteRange<'a> for LigatureAttach2<'a> { |
5490 | 0 | fn min_byte_range(&self) -> Range<usize> { |
5491 | 0 | 0..self.component_records_byte_range().end |
5492 | 0 | } |
5493 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
5494 | 0 | let range = self.min_byte_range(); |
5495 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
5496 | 0 | } |
5497 | | } |
5498 | | |
5499 | | impl ReadArgs for LigatureAttach2<'_> { |
5500 | | type Args = u16; |
5501 | | } |
5502 | | |
5503 | | impl<'a> FontRead<'a> for LigatureAttach2<'a> { |
5504 | 0 | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
5505 | 0 | let mark_class_count = args; |
5506 | | |
5507 | | #[allow(clippy::absurd_extreme_comparisons)] |
5508 | 0 | if data.len() < Self::MIN_SIZE { |
5509 | 0 | return Err(ReadError::OutOfBounds); |
5510 | 0 | } |
5511 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
5512 | 0 | return Err(ReadError::OutOfBounds); |
5513 | | }; |
5514 | 0 | Ok(Self { |
5515 | 0 | data, |
5516 | 0 | mark_class_count, |
5517 | 0 | }) |
5518 | 0 | } |
5519 | | } |
5520 | | |
5521 | | impl<'a> LigatureAttach2<'a> { |
5522 | | /// A constructor that requires additional arguments. |
5523 | | /// |
5524 | | /// This type requires some external state in order to be |
5525 | | /// parsed. |
5526 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
5527 | 0 | let args = mark_class_count; |
5528 | 0 | Self::read_with_args(data, args) |
5529 | 0 | } |
5530 | | } |
5531 | | |
5532 | | /// The fields at the start of the table, which are read directly. |
5533 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
5534 | | #[repr(C, packed)] |
5535 | | #[doc(hidden)] |
5536 | | pub struct LigatureAttach2FixedHeader { |
5537 | | pub component_count: BigEndian<u16>, |
5538 | | } |
5539 | | |
5540 | | #[allow(clippy::absurd_extreme_comparisons)] |
5541 | | const _: () = |
5542 | | assert!(std::mem::size_of::<LigatureAttach2FixedHeader>() <= LigatureAttach2::MIN_SIZE); |
5543 | | |
5544 | | /// LigatureAttach2 (ISO/IEC 14496-22:2026). |
5545 | | #[derive(Clone)] |
5546 | | pub struct LigatureAttach2<'a> { |
5547 | | data: TableDataRef<'a, LigatureAttach2FixedHeader>, |
5548 | | mark_class_count: u16, |
5549 | | } |
5550 | | |
5551 | | #[allow(clippy::needless_lifetimes)] |
5552 | | impl<'a> LigatureAttach2<'a> { |
5553 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
5554 | | basic_table_impls!(impl_the_methods); |
5555 | | |
5556 | | /// Number of ComponentRecords in this ligature |
5557 | 0 | pub fn component_count(&self) -> u16 { |
5558 | 0 | self.data.header().component_count.get() |
5559 | 0 | } |
5560 | | |
5561 | | /// Array of Component records, ordered in writing direction. |
5562 | 0 | pub fn component_records(&self) -> ComputedArray<'a, ComponentRecord2<'a>> { |
5563 | 0 | let range = self.component_records_byte_range(); |
5564 | 0 | ComputedArray::new(self.offset_data(), range, self.mark_class_count()).unwrap_or_default() |
5565 | 0 | } |
5566 | | |
5567 | 0 | pub(crate) fn mark_class_count(&self) -> u16 { |
5568 | 0 | self.mark_class_count |
5569 | 0 | } |
5570 | | |
5571 | 0 | pub fn component_count_byte_range(&self) -> Range<usize> { |
5572 | 0 | let start = 0usize; |
5573 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
5574 | 0 | start..end |
5575 | 0 | } |
5576 | | |
5577 | 0 | pub fn component_records_byte_range(&self) -> Range<usize> { |
5578 | 0 | let component_count = self.component_count(); |
5579 | 0 | let start = self.component_count_byte_range().end; |
5580 | 0 | let end = start.saturating_add((transforms::to_usize(component_count)).saturating_mul( |
5581 | 0 | <ComponentRecord2 as ComputeSize>::compute_size(self.mark_class_count()).unwrap_or(0), |
5582 | | )); |
5583 | 0 | start..end |
5584 | 0 | } |
5585 | | } |
5586 | | |
5587 | | const _: () = assert!(FontData::default_data_long_enough( |
5588 | | LigatureAttach2::MIN_SIZE |
5589 | | )); |
5590 | | |
5591 | | impl Default for LigatureAttach2<'_> { |
5592 | 0 | fn default() -> Self { |
5593 | | Self { |
5594 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
5595 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
5596 | 0 | mark_class_count: Default::default(), |
5597 | | } |
5598 | 0 | } |
5599 | | } |
5600 | | |
5601 | | /// ComponentRecord2 (ISO/IEC 14496-22:2026). |
5602 | | #[derive(Clone, Debug)] |
5603 | | pub struct ComponentRecord2<'a> { |
5604 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
5605 | | /// from beginning of LigatureAttach table, ordered by class |
5606 | | /// (offsets may be NULL). |
5607 | | pub ligature_anchor_offsets: &'a [BigEndian<Nullable<Offset24>>], |
5608 | | } |
5609 | | |
5610 | | impl<'a> ComponentRecord2<'a> { |
5611 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
5612 | | /// from beginning of LigatureAttach table, ordered by class |
5613 | | /// (offsets may be NULL). |
5614 | 0 | pub fn ligature_anchor_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] { |
5615 | 0 | self.ligature_anchor_offsets |
5616 | 0 | } |
5617 | | |
5618 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
5619 | | /// from beginning of LigatureAttach table, ordered by class |
5620 | | /// (offsets may be NULL). |
5621 | | /// |
5622 | | /// The `data` argument should be retrieved from the parent table |
5623 | | /// By calling its `offset_data` method. |
5624 | 0 | pub fn ligature_anchors( |
5625 | 0 | &self, |
5626 | 0 | data: FontData<'a>, |
5627 | 0 | ) -> ArrayOfNullableOffsets<'a, AnchorTable<'a>, Offset24> { |
5628 | 0 | let offsets = self.ligature_anchor_offsets(); |
5629 | 0 | ArrayOfNullableOffsets::new(offsets, data, ()) |
5630 | 0 | } |
5631 | | } |
5632 | | |
5633 | | impl ReadArgs for ComponentRecord2<'_> { |
5634 | | type Args = u16; |
5635 | | } |
5636 | | |
5637 | | impl ComputeSize for ComponentRecord2<'_> { |
5638 | | #[allow(clippy::needless_question_mark)] |
5639 | 0 | fn compute_size(args: u16) -> Result<usize, ReadError> { |
5640 | 0 | let mark_class_count = args; |
5641 | 0 | Ok((transforms::to_usize(mark_class_count)).saturating_mul(Offset24::RAW_BYTE_LEN)) |
5642 | 0 | } |
5643 | | } |
5644 | | |
5645 | | impl<'a> FontRead<'a> for ComponentRecord2<'a> { |
5646 | 0 | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
5647 | 0 | let mut cursor = data.cursor(); |
5648 | 0 | let mark_class_count = args; |
5649 | | Ok(Self { |
5650 | 0 | ligature_anchor_offsets: cursor.read_array(transforms::to_usize(mark_class_count))?, |
5651 | | }) |
5652 | 0 | } |
5653 | | } |
5654 | | |
5655 | | crate::impl_font_read_at!(ComponentRecord2<'a>); |
5656 | | |
5657 | | #[allow(clippy::needless_lifetimes)] |
5658 | | impl<'a> ComponentRecord2<'a> { |
5659 | | /// A constructor that requires additional arguments. |
5660 | | /// |
5661 | | /// This type requires some external state in order to be |
5662 | | /// parsed. |
5663 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
5664 | 0 | let args = mark_class_count; |
5665 | 0 | Self::read_with_args(data, args) |
5666 | 0 | } |
5667 | | } |
5668 | | |
5669 | | impl Format<u16> for MarkMarkPosFormat2<'_> { |
5670 | | const FORMAT: u16 = 2; |
5671 | | } |
5672 | | |
5673 | | impl<'a> MinByteRange<'a> for MarkMarkPosFormat2<'a> { |
5674 | 0 | fn min_byte_range(&self) -> Range<usize> { |
5675 | 0 | 0..self.mark2_array_offset_byte_range().end |
5676 | 0 | } |
5677 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
5678 | 0 | let range = self.min_byte_range(); |
5679 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
5680 | 0 | } |
5681 | | } |
5682 | | |
5683 | | impl ReadArgs for MarkMarkPosFormat2<'_> { |
5684 | | type Args = (); |
5685 | | } |
5686 | | |
5687 | | impl<'a> FontRead<'a> for MarkMarkPosFormat2<'a> { |
5688 | 7.05k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
5689 | | #[allow(clippy::absurd_extreme_comparisons)] |
5690 | 7.05k | if data.len() < Self::MIN_SIZE { |
5691 | 240 | return Err(ReadError::OutOfBounds); |
5692 | 6.81k | } |
5693 | 6.81k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
5694 | 0 | return Err(ReadError::OutOfBounds); |
5695 | | }; |
5696 | 6.81k | Ok(Self { data }) |
5697 | 7.05k | } |
5698 | | } |
5699 | | |
5700 | | /// The fields at the start of the table, which are read directly. |
5701 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
5702 | | #[repr(C, packed)] |
5703 | | #[doc(hidden)] |
5704 | | pub struct MarkMarkPosFormat2FixedHeader { |
5705 | | pub pos_format: BigEndian<u16>, |
5706 | | pub mark1_coverage_offset: BigEndian<Offset32>, |
5707 | | pub mark2_coverage_offset: BigEndian<Offset32>, |
5708 | | pub mark_class_count: BigEndian<u16>, |
5709 | | pub mark1_array_offset: BigEndian<Offset32>, |
5710 | | pub mark2_array_offset: BigEndian<Offset32>, |
5711 | | } |
5712 | | |
5713 | | #[allow(clippy::absurd_extreme_comparisons)] |
5714 | | const _: () = |
5715 | | assert!(std::mem::size_of::<MarkMarkPosFormat2FixedHeader>() <= MarkMarkPosFormat2::MIN_SIZE); |
5716 | | |
5717 | | /// MarkMarkPosFormat2 (ISO/IEC 14496-22:2026). |
5718 | | #[derive(Clone)] |
5719 | | pub struct MarkMarkPosFormat2<'a> { |
5720 | | data: TableDataRef<'a, MarkMarkPosFormat2FixedHeader>, |
5721 | | } |
5722 | | |
5723 | | #[allow(clippy::needless_lifetimes)] |
5724 | | impl<'a> MarkMarkPosFormat2<'a> { |
5725 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
5726 | | + Offset32::RAW_BYTE_LEN |
5727 | | + Offset32::RAW_BYTE_LEN |
5728 | | + u16::RAW_BYTE_LEN |
5729 | | + Offset32::RAW_BYTE_LEN |
5730 | | + Offset32::RAW_BYTE_LEN); |
5731 | | basic_table_impls!(impl_the_methods); |
5732 | | |
5733 | | /// Format identifier: format = 2 |
5734 | 0 | pub fn pos_format(&self) -> u16 { |
5735 | 0 | self.data.header().pos_format.get() |
5736 | 0 | } |
5737 | | |
5738 | | /// Offset to Combining Mark Coverage table, from beginning of |
5739 | | /// MarkMarkPos subtable. |
5740 | 6.81k | pub fn mark1_coverage_offset(&self) -> Offset32 { |
5741 | 6.81k | self.data.header().mark1_coverage_offset.get() |
5742 | 6.81k | } |
5743 | | |
5744 | | /// Attempt to resolve [`mark1_coverage_offset`][Self::mark1_coverage_offset]. |
5745 | 6.81k | pub fn mark1_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
5746 | 6.81k | let data = self.offset_data(); |
5747 | 6.81k | self.mark1_coverage_offset().resolve(data) |
5748 | 6.81k | } |
5749 | | |
5750 | | /// Offset to Base Mark Coverage table, from beginning of |
5751 | | /// MarkMarkPos subtable. |
5752 | 6.81k | pub fn mark2_coverage_offset(&self) -> Offset32 { |
5753 | 6.81k | self.data.header().mark2_coverage_offset.get() |
5754 | 6.81k | } |
5755 | | |
5756 | | /// Attempt to resolve [`mark2_coverage_offset`][Self::mark2_coverage_offset]. |
5757 | 6.81k | pub fn mark2_coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
5758 | 6.81k | let data = self.offset_data(); |
5759 | 6.81k | self.mark2_coverage_offset().resolve(data) |
5760 | 6.81k | } |
5761 | | |
5762 | | /// Number of Combining Mark classes defined |
5763 | 13.6k | pub fn mark_class_count(&self) -> u16 { |
5764 | 13.6k | self.data.header().mark_class_count.get() |
5765 | 13.6k | } |
5766 | | |
5767 | | /// Offset to MarkArray table for mark1, from beginning of |
5768 | | /// MarkMarkPos subtable. |
5769 | 6.81k | pub fn mark1_array_offset(&self) -> Offset32 { |
5770 | 6.81k | self.data.header().mark1_array_offset.get() |
5771 | 6.81k | } |
5772 | | |
5773 | | /// Attempt to resolve [`mark1_array_offset`][Self::mark1_array_offset]. |
5774 | 6.81k | pub fn mark1_array(&self) -> Result<MarkArray2<'a>, ReadError> { |
5775 | 6.81k | let data = self.offset_data(); |
5776 | 6.81k | self.mark1_array_offset().resolve(data) |
5777 | 6.81k | } |
5778 | | |
5779 | | /// Offset to Mark2Array table for mark2, from beginning of |
5780 | | /// MarkMarkPos subtable. |
5781 | 6.81k | pub fn mark2_array_offset(&self) -> Offset32 { |
5782 | 6.81k | self.data.header().mark2_array_offset.get() |
5783 | 6.81k | } |
5784 | | |
5785 | | /// Attempt to resolve [`mark2_array_offset`][Self::mark2_array_offset]. |
5786 | 6.81k | pub fn mark2_array(&self) -> Result<Mark2Array2<'a>, ReadError> { |
5787 | 6.81k | let data = self.offset_data(); |
5788 | 6.81k | let args = self.mark_class_count(); |
5789 | 6.81k | self.mark2_array_offset().resolve_with_args(data, args) |
5790 | 6.81k | } |
5791 | | |
5792 | 0 | pub fn pos_format_byte_range(&self) -> Range<usize> { |
5793 | 0 | let start = 0usize; |
5794 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
5795 | 0 | start..end |
5796 | 0 | } |
5797 | | |
5798 | 0 | pub fn mark1_coverage_offset_byte_range(&self) -> Range<usize> { |
5799 | 0 | let start = self.pos_format_byte_range().end; |
5800 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5801 | 0 | start..end |
5802 | 0 | } |
5803 | | |
5804 | 0 | pub fn mark2_coverage_offset_byte_range(&self) -> Range<usize> { |
5805 | 0 | let start = self.mark1_coverage_offset_byte_range().end; |
5806 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5807 | 0 | start..end |
5808 | 0 | } |
5809 | | |
5810 | 0 | pub fn mark_class_count_byte_range(&self) -> Range<usize> { |
5811 | 0 | let start = self.mark2_coverage_offset_byte_range().end; |
5812 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
5813 | 0 | start..end |
5814 | 0 | } |
5815 | | |
5816 | 0 | pub fn mark1_array_offset_byte_range(&self) -> Range<usize> { |
5817 | 0 | let start = self.mark_class_count_byte_range().end; |
5818 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5819 | 0 | start..end |
5820 | 0 | } |
5821 | | |
5822 | 0 | pub fn mark2_array_offset_byte_range(&self) -> Range<usize> { |
5823 | 0 | let start = self.mark1_array_offset_byte_range().end; |
5824 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
5825 | 0 | start..end |
5826 | 0 | } |
5827 | | } |
5828 | | |
5829 | | impl<'a> MinByteRange<'a> for Mark2Array2<'a> { |
5830 | 0 | fn min_byte_range(&self) -> Range<usize> { |
5831 | 0 | 0..self.mark2_records_byte_range().end |
5832 | 0 | } |
5833 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
5834 | 0 | let range = self.min_byte_range(); |
5835 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
5836 | 0 | } |
5837 | | } |
5838 | | |
5839 | | impl ReadArgs for Mark2Array2<'_> { |
5840 | | type Args = u16; |
5841 | | } |
5842 | | |
5843 | | impl<'a> FontRead<'a> for Mark2Array2<'a> { |
5844 | 1.64k | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
5845 | 1.64k | let mark_class_count = args; |
5846 | | |
5847 | | #[allow(clippy::absurd_extreme_comparisons)] |
5848 | 1.64k | if data.len() < Self::MIN_SIZE { |
5849 | 213 | return Err(ReadError::OutOfBounds); |
5850 | 1.43k | } |
5851 | 1.43k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
5852 | 0 | return Err(ReadError::OutOfBounds); |
5853 | | }; |
5854 | 1.43k | Ok(Self { |
5855 | 1.43k | data, |
5856 | 1.43k | mark_class_count, |
5857 | 1.43k | }) |
5858 | 1.64k | } |
5859 | | } |
5860 | | |
5861 | | impl<'a> Mark2Array2<'a> { |
5862 | | /// A constructor that requires additional arguments. |
5863 | | /// |
5864 | | /// This type requires some external state in order to be |
5865 | | /// parsed. |
5866 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
5867 | 0 | let args = mark_class_count; |
5868 | 0 | Self::read_with_args(data, args) |
5869 | 0 | } |
5870 | | } |
5871 | | |
5872 | | /// The fields at the start of the table, which are read directly. |
5873 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
5874 | | #[repr(C, packed)] |
5875 | | #[doc(hidden)] |
5876 | | pub struct Mark2Array2FixedHeader { |
5877 | | pub mark2_count: BigEndian<u16>, |
5878 | | } |
5879 | | |
5880 | | #[allow(clippy::absurd_extreme_comparisons)] |
5881 | | const _: () = assert!(std::mem::size_of::<Mark2Array2FixedHeader>() <= Mark2Array2::MIN_SIZE); |
5882 | | |
5883 | | /// Mark2Array2 (ISO/IEC 14496-22:2026). |
5884 | | #[derive(Clone)] |
5885 | | pub struct Mark2Array2<'a> { |
5886 | | data: TableDataRef<'a, Mark2Array2FixedHeader>, |
5887 | | mark_class_count: u16, |
5888 | | } |
5889 | | |
5890 | | #[allow(clippy::needless_lifetimes)] |
5891 | | impl<'a> Mark2Array2<'a> { |
5892 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
5893 | | basic_table_impls!(impl_the_methods); |
5894 | | |
5895 | | /// Number of Mark2 records |
5896 | 0 | pub fn mark2_count(&self) -> u16 { |
5897 | 0 | self.data.header().mark2_count.get() |
5898 | 0 | } |
5899 | | |
5900 | | /// Array of Mark2Records, in Coverage order. |
5901 | 0 | pub fn mark2_records(&self) -> ComputedArray<'a, Mark2Record2<'a>> { |
5902 | 0 | let range = self.mark2_records_byte_range(); |
5903 | 0 | ComputedArray::new(self.offset_data(), range, self.mark_class_count()).unwrap_or_default() |
5904 | 0 | } |
5905 | | |
5906 | 0 | pub(crate) fn mark_class_count(&self) -> u16 { |
5907 | 0 | self.mark_class_count |
5908 | 0 | } |
5909 | | |
5910 | 0 | pub fn mark2_count_byte_range(&self) -> Range<usize> { |
5911 | 0 | let start = 0usize; |
5912 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
5913 | 0 | start..end |
5914 | 0 | } |
5915 | | |
5916 | 0 | pub fn mark2_records_byte_range(&self) -> Range<usize> { |
5917 | 0 | let mark2_count = self.mark2_count(); |
5918 | 0 | let start = self.mark2_count_byte_range().end; |
5919 | 0 | let end = start.saturating_add((transforms::to_usize(mark2_count)).saturating_mul( |
5920 | 0 | <Mark2Record2 as ComputeSize>::compute_size(self.mark_class_count()).unwrap_or(0), |
5921 | | )); |
5922 | 0 | start..end |
5923 | 0 | } |
5924 | | } |
5925 | | |
5926 | | const _: () = assert!(FontData::default_data_long_enough(Mark2Array2::MIN_SIZE)); |
5927 | | |
5928 | | impl Default for Mark2Array2<'_> { |
5929 | 0 | fn default() -> Self { |
5930 | | Self { |
5931 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
5932 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
5933 | 0 | mark_class_count: Default::default(), |
5934 | | } |
5935 | 0 | } |
5936 | | } |
5937 | | |
5938 | | /// Mark2Record2 (ISO/IEC 14496-22:2026). |
5939 | | #[derive(Clone, Debug)] |
5940 | | pub struct Mark2Record2<'a> { |
5941 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
5942 | | /// from beginning of Mark2Array table, in class order (offsets may |
5943 | | /// be NULL). |
5944 | | pub mark2_anchor_offsets: &'a [BigEndian<Nullable<Offset24>>], |
5945 | | } |
5946 | | |
5947 | | impl<'a> Mark2Record2<'a> { |
5948 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
5949 | | /// from beginning of Mark2Array table, in class order (offsets may |
5950 | | /// be NULL). |
5951 | 0 | pub fn mark2_anchor_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] { |
5952 | 0 | self.mark2_anchor_offsets |
5953 | 0 | } |
5954 | | |
5955 | | /// Array of offsets (one per class) to Anchor tables. Offsets are |
5956 | | /// from beginning of Mark2Array table, in class order (offsets may |
5957 | | /// be NULL). |
5958 | | /// |
5959 | | /// The `data` argument should be retrieved from the parent table |
5960 | | /// By calling its `offset_data` method. |
5961 | 0 | pub fn mark2_anchors( |
5962 | 0 | &self, |
5963 | 0 | data: FontData<'a>, |
5964 | 0 | ) -> ArrayOfNullableOffsets<'a, AnchorTable<'a>, Offset24> { |
5965 | 0 | let offsets = self.mark2_anchor_offsets(); |
5966 | 0 | ArrayOfNullableOffsets::new(offsets, data, ()) |
5967 | 0 | } |
5968 | | } |
5969 | | |
5970 | | impl ReadArgs for Mark2Record2<'_> { |
5971 | | type Args = u16; |
5972 | | } |
5973 | | |
5974 | | impl ComputeSize for Mark2Record2<'_> { |
5975 | | #[allow(clippy::needless_question_mark)] |
5976 | 0 | fn compute_size(args: u16) -> Result<usize, ReadError> { |
5977 | 0 | let mark_class_count = args; |
5978 | 0 | Ok((transforms::to_usize(mark_class_count)).saturating_mul(Offset24::RAW_BYTE_LEN)) |
5979 | 0 | } |
5980 | | } |
5981 | | |
5982 | | impl<'a> FontRead<'a> for Mark2Record2<'a> { |
5983 | 0 | fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> { |
5984 | 0 | let mut cursor = data.cursor(); |
5985 | 0 | let mark_class_count = args; |
5986 | | Ok(Self { |
5987 | 0 | mark2_anchor_offsets: cursor.read_array(transforms::to_usize(mark_class_count))?, |
5988 | | }) |
5989 | 0 | } |
5990 | | } |
5991 | | |
5992 | | crate::impl_font_read_at!(Mark2Record2<'a>); |
5993 | | |
5994 | | #[allow(clippy::needless_lifetimes)] |
5995 | | impl<'a> Mark2Record2<'a> { |
5996 | | /// A constructor that requires additional arguments. |
5997 | | /// |
5998 | | /// This type requires some external state in order to be |
5999 | | /// parsed. |
6000 | 0 | pub fn read(data: FontData<'a>, mark_class_count: u16) -> Result<Self, ReadError> { |
6001 | 0 | let args = mark_class_count; |
6002 | 0 | Self::read_with_args(data, args) |
6003 | 0 | } |
6004 | | } |
6005 | | |
6006 | | impl<'a> MinByteRange<'a> for MarkArray2<'a> { |
6007 | 0 | fn min_byte_range(&self) -> Range<usize> { |
6008 | 0 | 0..self.mark_records_byte_range().end |
6009 | 0 | } |
6010 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
6011 | 0 | let range = self.min_byte_range(); |
6012 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
6013 | 0 | } |
6014 | | } |
6015 | | |
6016 | | impl ReadArgs for MarkArray2<'_> { |
6017 | | type Args = (); |
6018 | | } |
6019 | | |
6020 | | impl<'a> FontRead<'a> for MarkArray2<'a> { |
6021 | 3.06k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
6022 | | #[allow(clippy::absurd_extreme_comparisons)] |
6023 | 3.06k | if data.len() < Self::MIN_SIZE { |
6024 | 205 | return Err(ReadError::OutOfBounds); |
6025 | 2.85k | } |
6026 | 2.85k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
6027 | 0 | return Err(ReadError::OutOfBounds); |
6028 | | }; |
6029 | 2.85k | Ok(Self { data }) |
6030 | 3.06k | } |
6031 | | } |
6032 | | |
6033 | | /// The fields at the start of the table, which are read directly. |
6034 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
6035 | | #[repr(C, packed)] |
6036 | | #[doc(hidden)] |
6037 | | pub struct MarkArray2FixedHeader { |
6038 | | pub mark_count: BigEndian<Uint24>, |
6039 | | } |
6040 | | |
6041 | | #[allow(clippy::absurd_extreme_comparisons)] |
6042 | | const _: () = assert!(std::mem::size_of::<MarkArray2FixedHeader>() <= MarkArray2::MIN_SIZE); |
6043 | | |
6044 | | /// MarkArray2 (ISO/IEC 14496-22:2026). |
6045 | | #[derive(Clone)] |
6046 | | pub struct MarkArray2<'a> { |
6047 | | data: TableDataRef<'a, MarkArray2FixedHeader>, |
6048 | | } |
6049 | | |
6050 | | #[allow(clippy::needless_lifetimes)] |
6051 | | impl<'a> MarkArray2<'a> { |
6052 | | pub const MIN_SIZE: usize = Uint24::RAW_BYTE_LEN; |
6053 | | basic_table_impls!(impl_the_methods); |
6054 | | |
6055 | | /// Number of MarkRecords |
6056 | 2.85k | pub fn mark_count(&self) -> Uint24 { |
6057 | 2.85k | self.data.header().mark_count.get() |
6058 | 2.85k | } |
6059 | | |
6060 | | /// Array of MarkRecords, ordered by corresponding glyphs in the |
6061 | | /// associated mark Coverage table. |
6062 | 0 | pub fn mark_records(&self) -> &'a [MarkRecord2] { |
6063 | 0 | let range = self.mark_records_byte_range(); |
6064 | 0 | self.offset_data() |
6065 | 0 | .read_array(range) |
6066 | 0 | .ok() |
6067 | 0 | .unwrap_or_default() |
6068 | 0 | } |
6069 | | |
6070 | 0 | pub fn mark_count_byte_range(&self) -> Range<usize> { |
6071 | 0 | let start = 0usize; |
6072 | 0 | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
6073 | 0 | start..end |
6074 | 0 | } |
6075 | | |
6076 | 0 | pub fn mark_records_byte_range(&self) -> Range<usize> { |
6077 | 0 | let mark_count = self.mark_count(); |
6078 | 0 | let start = self.mark_count_byte_range().end; |
6079 | 0 | let end = start.saturating_add( |
6080 | 0 | (transforms::to_usize(mark_count)).saturating_mul(MarkRecord2::RAW_BYTE_LEN), |
6081 | | ); |
6082 | 0 | start..end |
6083 | 0 | } |
6084 | | } |
6085 | | |
6086 | | const _: () = assert!(FontData::default_data_long_enough(MarkArray2::MIN_SIZE)); |
6087 | | |
6088 | | impl Default for MarkArray2<'_> { |
6089 | 0 | fn default() -> Self { |
6090 | | Self { |
6091 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
6092 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
6093 | | } |
6094 | 0 | } |
6095 | | } |
6096 | | |
6097 | | /// MarkRecord2 (ISO/IEC 14496-22:2026). |
6098 | | #[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)] |
6099 | | #[repr(C)] |
6100 | | #[repr(packed)] |
6101 | | pub struct MarkRecord2 { |
6102 | | /// Class defined for the associated mark. |
6103 | | pub mark_class: BigEndian<u16>, |
6104 | | /// Offset to Anchor table, from beginning of MarkArray table. |
6105 | | pub mark_anchor_offset: BigEndian<Offset24>, |
6106 | | } |
6107 | | |
6108 | | impl MarkRecord2 { |
6109 | | /// Class defined for the associated mark. |
6110 | 0 | pub fn mark_class(&self) -> u16 { |
6111 | 0 | self.mark_class.get() |
6112 | 0 | } |
6113 | | |
6114 | | /// Offset to Anchor table, from beginning of MarkArray table. |
6115 | 0 | pub fn mark_anchor_offset(&self) -> Offset24 { |
6116 | 0 | self.mark_anchor_offset.get() |
6117 | 0 | } |
6118 | | |
6119 | | /// Offset to Anchor table, from beginning of MarkArray table. |
6120 | | /// |
6121 | | /// The `data` argument should be retrieved from the parent table |
6122 | | /// By calling its `offset_data` method. |
6123 | 0 | pub fn mark_anchor<'a>(&self, data: FontData<'a>) -> Result<AnchorTable<'a>, ReadError> { |
6124 | 0 | self.mark_anchor_offset().resolve(data) |
6125 | 0 | } |
6126 | | } |
6127 | | |
6128 | | impl FixedSize for MarkRecord2 { |
6129 | | const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN; |
6130 | | } |
6131 | | |
6132 | | /// CursivePos (ISO/IEC 14496-22:2026). |
6133 | | #[derive(Clone)] |
6134 | | pub enum CursivePos<'a> { |
6135 | | Format1(CursivePosFormat1<'a>), |
6136 | | Format2(CursivePosFormat2<'a>), |
6137 | | } |
6138 | | |
6139 | | impl Default for CursivePos<'_> { |
6140 | 0 | fn default() -> Self { |
6141 | 0 | Self::Format1(Default::default()) |
6142 | 0 | } |
6143 | | } |
6144 | | |
6145 | | impl<'a> CursivePos<'a> { |
6146 | | ///Return the `FontData` used to resolve offsets for this table. |
6147 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
6148 | 0 | match self { |
6149 | 0 | Self::Format1(item) => item.offset_data(), |
6150 | 0 | Self::Format2(item) => item.offset_data(), |
6151 | | } |
6152 | 0 | } |
6153 | | |
6154 | | /// Format identifier: format = 1 |
6155 | 0 | pub fn pos_format(&self) -> u16 { |
6156 | 0 | match self { |
6157 | 0 | Self::Format1(item) => item.pos_format(), |
6158 | 0 | Self::Format2(item) => item.pos_format(), |
6159 | | } |
6160 | 0 | } |
6161 | | } |
6162 | | |
6163 | | impl ReadArgs for CursivePos<'_> { |
6164 | | type Args = (); |
6165 | | } |
6166 | | |
6167 | | impl<'a> FontRead<'a> for CursivePos<'a> { |
6168 | | #[inline] |
6169 | 113k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
6170 | 113k | let format: u16 = data.read_at(0usize)?; |
6171 | 113k | match format { |
6172 | 7.18k | CursivePosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
6173 | 4.53k | CursivePosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
6174 | 101k | other => Err(ReadError::InvalidFormat(other.into())), |
6175 | | } |
6176 | 113k | } <read_fonts::tables::gpos::CursivePos as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 6169 | 113k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 6170 | 113k | let format: u16 = data.read_at(0usize)?; | 6171 | 113k | match format { | 6172 | 7.18k | CursivePosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 6173 | 4.53k | CursivePosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 6174 | 101k | other => Err(ReadError::InvalidFormat(other.into())), | 6175 | | } | 6176 | 113k | } |
Unexecuted instantiation: <read_fonts::tables::gpos::CursivePos as read_fonts::read::FontRead>::read_with_args |
6177 | | } |
6178 | | |
6179 | | impl<'a> MinByteRange<'a> for CursivePos<'a> { |
6180 | 0 | fn min_byte_range(&self) -> Range<usize> { |
6181 | 0 | match self { |
6182 | 0 | Self::Format1(item) => item.min_byte_range(), |
6183 | 0 | Self::Format2(item) => item.min_byte_range(), |
6184 | | } |
6185 | 0 | } |
6186 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
6187 | 0 | match self { |
6188 | 0 | Self::Format1(item) => item.min_table_bytes(), |
6189 | 0 | Self::Format2(item) => item.min_table_bytes(), |
6190 | | } |
6191 | 0 | } |
6192 | | } |
6193 | | |
6194 | | /// MarkBasePos (ISO/IEC 14496-22:2026). |
6195 | | #[derive(Clone)] |
6196 | | pub enum MarkBasePos<'a> { |
6197 | | Format1(MarkBasePosFormat1<'a>), |
6198 | | Format2(MarkBasePosFormat2<'a>), |
6199 | | } |
6200 | | |
6201 | | impl Default for MarkBasePos<'_> { |
6202 | 0 | fn default() -> Self { |
6203 | 0 | Self::Format1(Default::default()) |
6204 | 0 | } |
6205 | | } |
6206 | | |
6207 | | impl<'a> MarkBasePos<'a> { |
6208 | | ///Return the `FontData` used to resolve offsets for this table. |
6209 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
6210 | 0 | match self { |
6211 | 0 | Self::Format1(item) => item.offset_data(), |
6212 | 0 | Self::Format2(item) => item.offset_data(), |
6213 | | } |
6214 | 0 | } |
6215 | | |
6216 | | /// Format identifier: format = 1 |
6217 | 0 | pub fn pos_format(&self) -> u16 { |
6218 | 0 | match self { |
6219 | 0 | Self::Format1(item) => item.pos_format(), |
6220 | 0 | Self::Format2(item) => item.pos_format(), |
6221 | | } |
6222 | 0 | } |
6223 | | |
6224 | | /// Number of classes defined for marks |
6225 | 0 | pub fn mark_class_count(&self) -> u16 { |
6226 | 0 | match self { |
6227 | 0 | Self::Format1(item) => item.mark_class_count(), |
6228 | 0 | Self::Format2(item) => item.mark_class_count(), |
6229 | | } |
6230 | 0 | } |
6231 | | } |
6232 | | |
6233 | | impl ReadArgs for MarkBasePos<'_> { |
6234 | | type Args = (); |
6235 | | } |
6236 | | |
6237 | | impl<'a> FontRead<'a> for MarkBasePos<'a> { |
6238 | | #[inline] |
6239 | 100k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
6240 | 100k | let format: u16 = data.read_at(0usize)?; |
6241 | 99.8k | match format { |
6242 | 7.14k | MarkBasePosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
6243 | 5.98k | MarkBasePosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
6244 | 86.7k | other => Err(ReadError::InvalidFormat(other.into())), |
6245 | | } |
6246 | 100k | } <read_fonts::tables::gpos::MarkBasePos as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 6239 | 100k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 6240 | 100k | let format: u16 = data.read_at(0usize)?; | 6241 | 99.8k | match format { | 6242 | 7.14k | MarkBasePosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 6243 | 5.98k | MarkBasePosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 6244 | 86.7k | other => Err(ReadError::InvalidFormat(other.into())), | 6245 | | } | 6246 | 100k | } |
Unexecuted instantiation: <read_fonts::tables::gpos::MarkBasePos as read_fonts::read::FontRead>::read_with_args |
6247 | | } |
6248 | | |
6249 | | impl<'a> MinByteRange<'a> for MarkBasePos<'a> { |
6250 | 0 | fn min_byte_range(&self) -> Range<usize> { |
6251 | 0 | match self { |
6252 | 0 | Self::Format1(item) => item.min_byte_range(), |
6253 | 0 | Self::Format2(item) => item.min_byte_range(), |
6254 | | } |
6255 | 0 | } |
6256 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
6257 | 0 | match self { |
6258 | 0 | Self::Format1(item) => item.min_table_bytes(), |
6259 | 0 | Self::Format2(item) => item.min_table_bytes(), |
6260 | | } |
6261 | 0 | } |
6262 | | } |
6263 | | |
6264 | | /// MarkLigPos (ISO/IEC 14496-22:2026). |
6265 | | #[derive(Clone)] |
6266 | | pub enum MarkLigPos<'a> { |
6267 | | Format1(MarkLigPosFormat1<'a>), |
6268 | | Format2(MarkLigPosFormat2<'a>), |
6269 | | } |
6270 | | |
6271 | | impl Default for MarkLigPos<'_> { |
6272 | 0 | fn default() -> Self { |
6273 | 0 | Self::Format1(Default::default()) |
6274 | 0 | } |
6275 | | } |
6276 | | |
6277 | | impl<'a> MarkLigPos<'a> { |
6278 | | ///Return the `FontData` used to resolve offsets for this table. |
6279 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
6280 | 0 | match self { |
6281 | 0 | Self::Format1(item) => item.offset_data(), |
6282 | 0 | Self::Format2(item) => item.offset_data(), |
6283 | | } |
6284 | 0 | } |
6285 | | |
6286 | | /// Format identifier: format = 1 |
6287 | 0 | pub fn pos_format(&self) -> u16 { |
6288 | 0 | match self { |
6289 | 0 | Self::Format1(item) => item.pos_format(), |
6290 | 0 | Self::Format2(item) => item.pos_format(), |
6291 | | } |
6292 | 0 | } |
6293 | | |
6294 | | /// Number of defined mark classes |
6295 | 0 | pub fn mark_class_count(&self) -> u16 { |
6296 | 0 | match self { |
6297 | 0 | Self::Format1(item) => item.mark_class_count(), |
6298 | 0 | Self::Format2(item) => item.mark_class_count(), |
6299 | | } |
6300 | 0 | } |
6301 | | } |
6302 | | |
6303 | | impl ReadArgs for MarkLigPos<'_> { |
6304 | | type Args = (); |
6305 | | } |
6306 | | |
6307 | | impl<'a> FontRead<'a> for MarkLigPos<'a> { |
6308 | | #[inline] |
6309 | 117k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
6310 | 117k | let format: u16 = data.read_at(0usize)?; |
6311 | 116k | match format { |
6312 | 8.48k | MarkLigPosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
6313 | 5.04k | MarkLigPosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
6314 | 103k | other => Err(ReadError::InvalidFormat(other.into())), |
6315 | | } |
6316 | 117k | } <read_fonts::tables::gpos::MarkLigPos as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 6309 | 117k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 6310 | 117k | let format: u16 = data.read_at(0usize)?; | 6311 | 116k | match format { | 6312 | 8.48k | MarkLigPosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 6313 | 5.04k | MarkLigPosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 6314 | 103k | other => Err(ReadError::InvalidFormat(other.into())), | 6315 | | } | 6316 | 117k | } |
Unexecuted instantiation: <read_fonts::tables::gpos::MarkLigPos as read_fonts::read::FontRead>::read_with_args |
6317 | | } |
6318 | | |
6319 | | impl<'a> MinByteRange<'a> for MarkLigPos<'a> { |
6320 | 0 | fn min_byte_range(&self) -> Range<usize> { |
6321 | 0 | match self { |
6322 | 0 | Self::Format1(item) => item.min_byte_range(), |
6323 | 0 | Self::Format2(item) => item.min_byte_range(), |
6324 | | } |
6325 | 0 | } |
6326 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
6327 | 0 | match self { |
6328 | 0 | Self::Format1(item) => item.min_table_bytes(), |
6329 | 0 | Self::Format2(item) => item.min_table_bytes(), |
6330 | | } |
6331 | 0 | } |
6332 | | } |
6333 | | |
6334 | | /// MarkMarkPos (ISO/IEC 14496-22:2026). |
6335 | | #[derive(Clone)] |
6336 | | pub enum MarkMarkPos<'a> { |
6337 | | Format1(MarkMarkPosFormat1<'a>), |
6338 | | Format2(MarkMarkPosFormat2<'a>), |
6339 | | } |
6340 | | |
6341 | | impl Default for MarkMarkPos<'_> { |
6342 | 0 | fn default() -> Self { |
6343 | 0 | Self::Format1(Default::default()) |
6344 | 0 | } |
6345 | | } |
6346 | | |
6347 | | impl<'a> MarkMarkPos<'a> { |
6348 | | ///Return the `FontData` used to resolve offsets for this table. |
6349 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
6350 | 0 | match self { |
6351 | 0 | Self::Format1(item) => item.offset_data(), |
6352 | 0 | Self::Format2(item) => item.offset_data(), |
6353 | | } |
6354 | 0 | } |
6355 | | |
6356 | | /// Format identifier: format = 1 |
6357 | 0 | pub fn pos_format(&self) -> u16 { |
6358 | 0 | match self { |
6359 | 0 | Self::Format1(item) => item.pos_format(), |
6360 | 0 | Self::Format2(item) => item.pos_format(), |
6361 | | } |
6362 | 0 | } |
6363 | | |
6364 | | /// Number of Combining Mark classes defined |
6365 | 0 | pub fn mark_class_count(&self) -> u16 { |
6366 | 0 | match self { |
6367 | 0 | Self::Format1(item) => item.mark_class_count(), |
6368 | 0 | Self::Format2(item) => item.mark_class_count(), |
6369 | | } |
6370 | 0 | } |
6371 | | } |
6372 | | |
6373 | | impl ReadArgs for MarkMarkPos<'_> { |
6374 | | type Args = (); |
6375 | | } |
6376 | | |
6377 | | impl<'a> FontRead<'a> for MarkMarkPos<'a> { |
6378 | | #[inline] |
6379 | 94.9k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
6380 | 94.9k | let format: u16 = data.read_at(0usize)?; |
6381 | 94.6k | match format { |
6382 | 9.28k | MarkMarkPosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
6383 | 7.05k | MarkMarkPosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
6384 | 78.3k | other => Err(ReadError::InvalidFormat(other.into())), |
6385 | | } |
6386 | 94.9k | } <read_fonts::tables::gpos::MarkMarkPos as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 6379 | 94.9k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 6380 | 94.9k | let format: u16 = data.read_at(0usize)?; | 6381 | 94.6k | match format { | 6382 | 9.28k | MarkMarkPosFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 6383 | 7.05k | MarkMarkPosFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 6384 | 78.3k | other => Err(ReadError::InvalidFormat(other.into())), | 6385 | | } | 6386 | 94.9k | } |
Unexecuted instantiation: <read_fonts::tables::gpos::MarkMarkPos as read_fonts::read::FontRead>::read_with_args |
6387 | | } |
6388 | | |
6389 | | impl<'a> MinByteRange<'a> for MarkMarkPos<'a> { |
6390 | 0 | fn min_byte_range(&self) -> Range<usize> { |
6391 | 0 | match self { |
6392 | 0 | Self::Format1(item) => item.min_byte_range(), |
6393 | 0 | Self::Format2(item) => item.min_byte_range(), |
6394 | | } |
6395 | 0 | } |
6396 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
6397 | 0 | match self { |
6398 | 0 | Self::Format1(item) => item.min_table_bytes(), |
6399 | 0 | Self::Format2(item) => item.min_table_bytes(), |
6400 | | } |
6401 | 0 | } |
6402 | | } |