/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.47.0/generated/generated_gsub.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 Gsub<'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 Gsub<'_> { |
19 | | /// `GSUB` |
20 | | const TAG: Tag = Tag::new(b"GSUB"); |
21 | | } |
22 | | |
23 | | impl ReadArgs for Gsub<'_> { |
24 | | type Args = (); |
25 | | } |
26 | | |
27 | | impl<'a> FontRead<'a> for Gsub<'a> { |
28 | 245k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
29 | | #[allow(clippy::absurd_extreme_comparisons)] |
30 | 245k | if data.len() < Self::MIN_SIZE { |
31 | 10 | return Err(ReadError::OutOfBounds); |
32 | 245k | } |
33 | 245k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
34 | 0 | return Err(ReadError::OutOfBounds); |
35 | | }; |
36 | 245k | Ok(Self { data }) |
37 | 245k | } |
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 GsubFixedHeader { |
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::<GsubFixedHeader>() <= Gsub::MIN_SIZE); |
53 | | |
54 | | /// [GSUB](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#gsub-header) |
55 | | #[derive(Clone)] |
56 | | pub struct Gsub<'a> { |
57 | | data: TableDataRef<'a, GsubFixedHeader>, |
58 | | } |
59 | | |
60 | | #[allow(clippy::needless_lifetimes)] |
61 | | impl<'a> Gsub<'a> { |
62 | | pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN |
63 | | + Offset16::RAW_BYTE_LEN |
64 | | + Offset16::RAW_BYTE_LEN |
65 | | + Offset16::RAW_BYTE_LEN); |
66 | | basic_table_impls!(impl_the_methods); |
67 | | |
68 | | /// The major and minor version of the GSUB table, as a tuple (u16, u16) |
69 | 1.83M | pub fn version(&self) -> MajorMinor { |
70 | 1.83M | self.data.header().version.get() |
71 | 1.83M | } |
72 | | |
73 | | /// Offset to ScriptList table, from beginning of GSUB table |
74 | 98.5k | pub fn script_list_offset(&self) -> Nullable<Offset16> { |
75 | 98.5k | self.data.header().script_list_offset.get() |
76 | 98.5k | } |
77 | | |
78 | | /// Offset to FeatureList table, from beginning of GSUB table |
79 | 74.1k | pub fn feature_list_offset(&self) -> Nullable<Offset16> { |
80 | 74.1k | self.data.header().feature_list_offset.get() |
81 | 74.1k | } |
82 | | |
83 | | /// Offset to LookupList table, from beginning of GSUB table |
84 | 245k | pub fn lookup_list_offset(&self) -> Nullable<Offset16> { |
85 | 245k | self.data.header().lookup_list_offset.get() |
86 | 245k | } |
87 | | |
88 | | /// Offset to FeatureVariations table, from beginning of the GSUB |
89 | | /// table (may be NULL) |
90 | 14.0k | pub fn feature_variations_offset(&self) -> Option<Nullable<Offset32>> { |
91 | 14.0k | let range = self.feature_variations_offset_byte_range(); |
92 | 14.0k | (!range.is_empty()) |
93 | 14.0k | .then(|| self.offset_data().read_at(range.start).ok()) |
94 | 14.0k | .flatten() |
95 | 14.0k | } |
96 | | |
97 | | /// Attempt to resolve [`feature_variations_offset`][Self::feature_variations_offset]. |
98 | 14.0k | pub fn feature_variations(&self) -> Option<Result<FeatureVariations<'a>, ReadError>> { |
99 | 14.0k | let data = self.offset_data(); |
100 | 14.0k | self.feature_variations_offset().map(|x| x.resolve(data))? |
101 | 14.0k | } |
102 | | |
103 | | /// 32-bit offset to ScriptList, taking precedence when nonzero. |
104 | 98.5k | pub fn script_list2_offset(&self) -> Option<Nullable<Offset32>> { |
105 | 98.5k | let range = self.script_list2_offset_byte_range(); |
106 | 98.5k | (!range.is_empty()) |
107 | 98.5k | .then(|| self.offset_data().read_at(range.start).ok()) |
108 | 98.5k | .flatten() |
109 | 98.5k | } |
110 | | |
111 | | /// Attempt to resolve [`script_list2_offset`][Self::script_list2_offset]. |
112 | 0 | pub fn script_list2(&self) -> Option<Result<ScriptList<'a>, ReadError>> { |
113 | 0 | let data = self.offset_data(); |
114 | 0 | self.script_list2_offset().map(|x| x.resolve(data))? |
115 | 0 | } |
116 | | |
117 | | /// 32-bit offset to FeatureList, taking precedence when nonzero. |
118 | 74.1k | pub fn feature_list2_offset(&self) -> Option<Nullable<Offset32>> { |
119 | 74.1k | let range = self.feature_list2_offset_byte_range(); |
120 | 74.1k | (!range.is_empty()) |
121 | 74.1k | .then(|| self.offset_data().read_at(range.start).ok()) |
122 | 74.1k | .flatten() |
123 | 74.1k | } |
124 | | |
125 | | /// Attempt to resolve [`feature_list2_offset`][Self::feature_list2_offset]. |
126 | 0 | pub fn feature_list2(&self) -> Option<Result<FeatureList<'a>, ReadError>> { |
127 | 0 | let data = self.offset_data(); |
128 | 0 | self.feature_list2_offset().map(|x| x.resolve(data))? |
129 | 0 | } |
130 | | |
131 | | /// 32-bit offset to LookupList2, taking precedence when nonzero. |
132 | 245k | pub fn lookup_list2_offset(&self) -> Option<Nullable<Offset32>> { |
133 | 245k | let range = self.lookup_list2_offset_byte_range(); |
134 | 245k | (!range.is_empty()) |
135 | 245k | .then(|| self.offset_data().read_at(range.start).ok()) |
136 | 245k | .flatten() |
137 | 245k | } |
138 | | |
139 | | /// Attempt to resolve [`lookup_list2_offset`][Self::lookup_list2_offset]. |
140 | 0 | pub fn lookup_list2(&self) -> Option<Result<SubstitutionLookupList2<'a>, ReadError>> { |
141 | 0 | let data = self.offset_data(); |
142 | 0 | self.lookup_list2_offset().map(|x| x.resolve(data))? |
143 | 0 | } |
144 | | |
145 | 431k | pub fn version_byte_range(&self) -> Range<usize> { |
146 | 431k | let start = 0usize; |
147 | 431k | let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN); |
148 | 431k | start..end |
149 | 431k | } |
150 | | |
151 | 431k | pub fn script_list_offset_byte_range(&self) -> Range<usize> { |
152 | 431k | let start = self.version_byte_range().end; |
153 | 431k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
154 | 431k | start..end |
155 | 431k | } |
156 | | |
157 | 431k | pub fn feature_list_offset_byte_range(&self) -> Range<usize> { |
158 | 431k | let start = self.script_list_offset_byte_range().end; |
159 | 431k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
160 | 431k | start..end |
161 | 431k | } |
162 | | |
163 | 431k | pub fn lookup_list_offset_byte_range(&self) -> Range<usize> { |
164 | 431k | let start = self.feature_list_offset_byte_range().end; |
165 | 431k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
166 | 431k | start..end |
167 | 431k | } |
168 | | |
169 | 431k | pub fn feature_variations_offset_byte_range(&self) -> Range<usize> { |
170 | 431k | let start = self.lookup_list_offset_byte_range().end; |
171 | 431k | let end = if self.version().compatible((1u16, 1u16)) { |
172 | 1.63k | start.saturating_add(Offset32::RAW_BYTE_LEN) |
173 | | } else { |
174 | 430k | start |
175 | | }; |
176 | 431k | start..end |
177 | 431k | } |
178 | | |
179 | 417k | pub fn script_list2_offset_byte_range(&self) -> Range<usize> { |
180 | 417k | let start = self.feature_variations_offset_byte_range().end; |
181 | 417k | let end = if self.version().compatible((1u16, 2u16)) { |
182 | 675 | start.saturating_add(Offset32::RAW_BYTE_LEN) |
183 | | } else { |
184 | 417k | start |
185 | | }; |
186 | 417k | start..end |
187 | 417k | } |
188 | | |
189 | 319k | pub fn feature_list2_offset_byte_range(&self) -> Range<usize> { |
190 | 319k | let start = self.script_list2_offset_byte_range().end; |
191 | 319k | let end = if self.version().compatible((1u16, 2u16)) { |
192 | 379 | start.saturating_add(Offset32::RAW_BYTE_LEN) |
193 | | } else { |
194 | 318k | start |
195 | | }; |
196 | 319k | start..end |
197 | 319k | } |
198 | | |
199 | 245k | pub fn lookup_list2_offset_byte_range(&self) -> Range<usize> { |
200 | 245k | let start = self.feature_list2_offset_byte_range().end; |
201 | 245k | let end = if self.version().compatible((1u16, 2u16)) { |
202 | 340 | start.saturating_add(Offset32::RAW_BYTE_LEN) |
203 | | } else { |
204 | 244k | start |
205 | | }; |
206 | 245k | start..end |
207 | 245k | } |
208 | | } |
209 | | |
210 | | const _: () = assert!(FontData::default_data_long_enough(Gsub::MIN_SIZE)); |
211 | | |
212 | | impl Default for Gsub<'_> { |
213 | 0 | fn default() -> Self { |
214 | | Self { |
215 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
216 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
217 | | } |
218 | 0 | } |
219 | | } |
220 | | |
221 | | /// A [GSUB Lookup](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#gsubLookupTypeEnum) subtable. |
222 | | pub enum SubstitutionLookup<'a> { |
223 | | Single(Lookup<'a, SingleSubst<'a>>), |
224 | | Multiple(Lookup<'a, MultipleSubst<'a>>), |
225 | | Alternate(Lookup<'a, AlternateSubst<'a>>), |
226 | | Ligature(Lookup<'a, LigatureSubst<'a>>), |
227 | | Contextual(Lookup<'a, SubstitutionSequenceContext<'a>>), |
228 | | ChainContextual(Lookup<'a, SubstitutionChainContext<'a>>), |
229 | | Extension(Lookup<'a, ExtensionSubtable<'a>>), |
230 | | Reverse(Lookup<'a, ReverseChainSingleSubst<'a>>), |
231 | | } |
232 | | |
233 | | impl Default for SubstitutionLookup<'_> { |
234 | 0 | fn default() -> Self { |
235 | 0 | Self::Single(Default::default()) |
236 | 0 | } |
237 | | } |
238 | | |
239 | | impl ReadArgs for SubstitutionLookup<'_> { |
240 | | type Args = (); |
241 | | } |
242 | | |
243 | | impl<'a> FontRead<'a> for SubstitutionLookup<'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(SubstitutionLookup::Single(FontRead::read(bytes)?)), |
248 | 0 | 2 => Ok(SubstitutionLookup::Multiple(FontRead::read(bytes)?)), |
249 | 0 | 3 => Ok(SubstitutionLookup::Alternate(FontRead::read(bytes)?)), |
250 | 0 | 4 => Ok(SubstitutionLookup::Ligature(FontRead::read(bytes)?)), |
251 | 0 | 5 => Ok(SubstitutionLookup::Contextual(FontRead::read(bytes)?)), |
252 | 0 | 6 => Ok(SubstitutionLookup::ChainContextual(FontRead::read(bytes)?)), |
253 | 0 | 7 => Ok(SubstitutionLookup::Extension(FontRead::read(bytes)?)), |
254 | 0 | 8 => Ok(SubstitutionLookup::Reverse(FontRead::read(bytes)?)), |
255 | 0 | other => Err(ReadError::InvalidFormat(other.into())), |
256 | | } |
257 | 0 | } |
258 | | } |
259 | | |
260 | | impl<'a> SubstitutionLookup<'a> { |
261 | | #[allow(dead_code)] |
262 | | /// Return the inner table, removing the specific generics. |
263 | | /// |
264 | | /// This lets us return a single concrete type we can call methods on. |
265 | 0 | pub(crate) fn of_unit_type(&self) -> Lookup<'a, ()> { |
266 | 0 | match self { |
267 | 0 | SubstitutionLookup::Single(inner) => inner.of_unit_type(), |
268 | 0 | SubstitutionLookup::Multiple(inner) => inner.of_unit_type(), |
269 | 0 | SubstitutionLookup::Alternate(inner) => inner.of_unit_type(), |
270 | 0 | SubstitutionLookup::Ligature(inner) => inner.of_unit_type(), |
271 | 0 | SubstitutionLookup::Contextual(inner) => inner.of_unit_type(), |
272 | 0 | SubstitutionLookup::ChainContextual(inner) => inner.of_unit_type(), |
273 | 0 | SubstitutionLookup::Extension(inner) => inner.of_unit_type(), |
274 | 0 | SubstitutionLookup::Reverse(inner) => inner.of_unit_type(), |
275 | | } |
276 | 0 | } |
277 | | } |
278 | | |
279 | | /// LookupType 1: [Single Substitution](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#lookuptype-1-single-substitution-subtable) Subtable |
280 | | #[derive(Clone)] |
281 | | pub enum SingleSubst<'a> { |
282 | | Format1(SingleSubstFormat1<'a>), |
283 | | Format2(SingleSubstFormat2<'a>), |
284 | | Format3(SingleSubstFormat3<'a>), |
285 | | Format4(SingleSubstFormat4<'a>), |
286 | | } |
287 | | |
288 | | impl Default for SingleSubst<'_> { |
289 | 0 | fn default() -> Self { |
290 | 0 | Self::Format1(Default::default()) |
291 | 0 | } |
292 | | } |
293 | | |
294 | | impl<'a> SingleSubst<'a> { |
295 | | ///Return the `FontData` used to resolve offsets for this table. |
296 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
297 | 0 | match self { |
298 | 0 | Self::Format1(item) => item.offset_data(), |
299 | 0 | Self::Format2(item) => item.offset_data(), |
300 | 0 | Self::Format3(item) => item.offset_data(), |
301 | 0 | Self::Format4(item) => item.offset_data(), |
302 | | } |
303 | 0 | } |
304 | | |
305 | | /// Format identifier: format = 1 |
306 | 0 | pub fn subst_format(&self) -> u16 { |
307 | 0 | match self { |
308 | 0 | Self::Format1(item) => item.subst_format(), |
309 | 0 | Self::Format2(item) => item.subst_format(), |
310 | 0 | Self::Format3(item) => item.subst_format(), |
311 | 0 | Self::Format4(item) => item.subst_format(), |
312 | | } |
313 | 0 | } |
314 | | } |
315 | | |
316 | | impl ReadArgs for SingleSubst<'_> { |
317 | | type Args = (); |
318 | | } |
319 | | |
320 | | impl<'a> FontRead<'a> for SingleSubst<'a> { |
321 | | #[inline] |
322 | 72.9k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
323 | 72.9k | let format: u16 = data.read_at(0usize)?; |
324 | 72.5k | match format { |
325 | 25.9k | SingleSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
326 | 2.98k | SingleSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
327 | 1.00k | SingleSubstFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)), |
328 | 1.29k | SingleSubstFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)), |
329 | 41.3k | other => Err(ReadError::InvalidFormat(other.into())), |
330 | | } |
331 | 72.9k | } <read_fonts::tables::gsub::SingleSubst as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 322 | 72.9k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 323 | 72.9k | let format: u16 = data.read_at(0usize)?; | 324 | 72.5k | match format { | 325 | 25.9k | SingleSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 326 | 2.98k | SingleSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 327 | 1.00k | SingleSubstFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)), | 328 | 1.29k | SingleSubstFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)), | 329 | 41.3k | other => Err(ReadError::InvalidFormat(other.into())), | 330 | | } | 331 | 72.9k | } |
Unexecuted instantiation: <read_fonts::tables::gsub::SingleSubst as read_fonts::read::FontRead>::read_with_args |
332 | | } |
333 | | |
334 | | impl<'a> MinByteRange<'a> for SingleSubst<'a> { |
335 | 0 | fn min_byte_range(&self) -> Range<usize> { |
336 | 0 | match self { |
337 | 0 | Self::Format1(item) => item.min_byte_range(), |
338 | 0 | Self::Format2(item) => item.min_byte_range(), |
339 | 0 | Self::Format3(item) => item.min_byte_range(), |
340 | 0 | Self::Format4(item) => item.min_byte_range(), |
341 | | } |
342 | 0 | } |
343 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
344 | 0 | match self { |
345 | 0 | Self::Format1(item) => item.min_table_bytes(), |
346 | 0 | Self::Format2(item) => item.min_table_bytes(), |
347 | 0 | Self::Format3(item) => item.min_table_bytes(), |
348 | 0 | Self::Format4(item) => item.min_table_bytes(), |
349 | | } |
350 | 0 | } |
351 | | } |
352 | | |
353 | | impl Format<u16> for SingleSubstFormat1<'_> { |
354 | | const FORMAT: u16 = 1; |
355 | | } |
356 | | |
357 | | impl<'a> MinByteRange<'a> for SingleSubstFormat1<'a> { |
358 | 0 | fn min_byte_range(&self) -> Range<usize> { |
359 | 0 | 0..self.delta_glyph_id_byte_range().end |
360 | 0 | } |
361 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
362 | 0 | let range = self.min_byte_range(); |
363 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
364 | 0 | } |
365 | | } |
366 | | |
367 | | impl ReadArgs for SingleSubstFormat1<'_> { |
368 | | type Args = (); |
369 | | } |
370 | | |
371 | | impl<'a> FontRead<'a> for SingleSubstFormat1<'a> { |
372 | 25.9k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
373 | | #[allow(clippy::absurd_extreme_comparisons)] |
374 | 25.9k | if data.len() < Self::MIN_SIZE { |
375 | 290 | return Err(ReadError::OutOfBounds); |
376 | 25.6k | } |
377 | 25.6k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
378 | 0 | return Err(ReadError::OutOfBounds); |
379 | | }; |
380 | 25.6k | Ok(Self { data }) |
381 | 25.9k | } |
382 | | } |
383 | | |
384 | | /// The fields at the start of the table, which are read directly. |
385 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
386 | | #[repr(C, packed)] |
387 | | #[doc(hidden)] |
388 | | pub struct SingleSubstFormat1FixedHeader { |
389 | | pub subst_format: BigEndian<u16>, |
390 | | pub coverage_offset: BigEndian<Offset16>, |
391 | | pub delta_glyph_id: BigEndian<i16>, |
392 | | } |
393 | | |
394 | | #[allow(clippy::absurd_extreme_comparisons)] |
395 | | const _: () = |
396 | | assert!(std::mem::size_of::<SingleSubstFormat1FixedHeader>() <= SingleSubstFormat1::MIN_SIZE); |
397 | | |
398 | | /// [Single Substitution Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#11-single-substitution-format-1) |
399 | | #[derive(Clone)] |
400 | | pub struct SingleSubstFormat1<'a> { |
401 | | data: TableDataRef<'a, SingleSubstFormat1FixedHeader>, |
402 | | } |
403 | | |
404 | | #[allow(clippy::needless_lifetimes)] |
405 | | impl<'a> SingleSubstFormat1<'a> { |
406 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN); |
407 | | basic_table_impls!(impl_the_methods); |
408 | | |
409 | | /// Format identifier: format = 1 |
410 | 0 | pub fn subst_format(&self) -> u16 { |
411 | 0 | self.data.header().subst_format.get() |
412 | 0 | } |
413 | | |
414 | | /// Offset to Coverage table, from beginning of substitution |
415 | | /// subtable |
416 | 25.6k | pub fn coverage_offset(&self) -> Offset16 { |
417 | 25.6k | self.data.header().coverage_offset.get() |
418 | 25.6k | } |
419 | | |
420 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
421 | 25.6k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
422 | 25.6k | let data = self.offset_data(); |
423 | 25.6k | self.coverage_offset().resolve(data) |
424 | 25.6k | } |
425 | | |
426 | | /// Add to original glyph ID to get substitute glyph ID |
427 | 25.6k | pub fn delta_glyph_id(&self) -> i16 { |
428 | 25.6k | self.data.header().delta_glyph_id.get() |
429 | 25.6k | } |
430 | | |
431 | 0 | pub fn subst_format_byte_range(&self) -> Range<usize> { |
432 | 0 | let start = 0usize; |
433 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
434 | 0 | start..end |
435 | 0 | } |
436 | | |
437 | 0 | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
438 | 0 | let start = self.subst_format_byte_range().end; |
439 | 0 | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
440 | 0 | start..end |
441 | 0 | } |
442 | | |
443 | 0 | pub fn delta_glyph_id_byte_range(&self) -> Range<usize> { |
444 | 0 | let start = self.coverage_offset_byte_range().end; |
445 | 0 | let end = start.saturating_add(i16::RAW_BYTE_LEN); |
446 | 0 | start..end |
447 | 0 | } |
448 | | } |
449 | | |
450 | | const _: () = assert!(FontData::default_data_long_enough( |
451 | | SingleSubstFormat1::MIN_SIZE |
452 | | )); |
453 | | |
454 | | impl Default for SingleSubstFormat1<'_> { |
455 | 0 | fn default() -> Self { |
456 | | Self { |
457 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
458 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
459 | | } |
460 | 0 | } |
461 | | } |
462 | | |
463 | | impl Format<u16> for SingleSubstFormat2<'_> { |
464 | | const FORMAT: u16 = 2; |
465 | | } |
466 | | |
467 | | impl<'a> MinByteRange<'a> for SingleSubstFormat2<'a> { |
468 | 0 | fn min_byte_range(&self) -> Range<usize> { |
469 | 0 | 0..self.substitute_glyph_ids_byte_range().end |
470 | 0 | } |
471 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
472 | 0 | let range = self.min_byte_range(); |
473 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
474 | 0 | } |
475 | | } |
476 | | |
477 | | impl ReadArgs for SingleSubstFormat2<'_> { |
478 | | type Args = (); |
479 | | } |
480 | | |
481 | | impl<'a> FontRead<'a> for SingleSubstFormat2<'a> { |
482 | 2.98k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
483 | | #[allow(clippy::absurd_extreme_comparisons)] |
484 | 2.98k | if data.len() < Self::MIN_SIZE { |
485 | 249 | return Err(ReadError::OutOfBounds); |
486 | 2.74k | } |
487 | 2.74k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
488 | 0 | return Err(ReadError::OutOfBounds); |
489 | | }; |
490 | 2.74k | Ok(Self { data }) |
491 | 2.98k | } |
492 | | } |
493 | | |
494 | | /// The fields at the start of the table, which are read directly. |
495 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
496 | | #[repr(C, packed)] |
497 | | #[doc(hidden)] |
498 | | pub struct SingleSubstFormat2FixedHeader { |
499 | | pub subst_format: BigEndian<u16>, |
500 | | pub coverage_offset: BigEndian<Offset16>, |
501 | | pub glyph_count: BigEndian<u16>, |
502 | | } |
503 | | |
504 | | #[allow(clippy::absurd_extreme_comparisons)] |
505 | | const _: () = |
506 | | assert!(std::mem::size_of::<SingleSubstFormat2FixedHeader>() <= SingleSubstFormat2::MIN_SIZE); |
507 | | |
508 | | /// [Single Substitution Format 2](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#12-single-substitution-format-2) |
509 | | #[derive(Clone)] |
510 | | pub struct SingleSubstFormat2<'a> { |
511 | | data: TableDataRef<'a, SingleSubstFormat2FixedHeader>, |
512 | | } |
513 | | |
514 | | #[allow(clippy::needless_lifetimes)] |
515 | | impl<'a> SingleSubstFormat2<'a> { |
516 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN); |
517 | | basic_table_impls!(impl_the_methods); |
518 | | |
519 | | /// Format identifier: format = 2 |
520 | 0 | pub fn subst_format(&self) -> u16 { |
521 | 0 | self.data.header().subst_format.get() |
522 | 0 | } |
523 | | |
524 | | /// Offset to Coverage table, from beginning of substitution |
525 | | /// subtable |
526 | 2.74k | pub fn coverage_offset(&self) -> Offset16 { |
527 | 2.74k | self.data.header().coverage_offset.get() |
528 | 2.74k | } |
529 | | |
530 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
531 | 2.74k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
532 | 2.74k | let data = self.offset_data(); |
533 | 2.74k | self.coverage_offset().resolve(data) |
534 | 2.74k | } |
535 | | |
536 | | /// Number of glyph IDs in the substituteGlyphIDs array |
537 | 2.74k | pub fn glyph_count(&self) -> u16 { |
538 | 2.74k | self.data.header().glyph_count.get() |
539 | 2.74k | } |
540 | | |
541 | | /// Array of substitute glyph IDs — ordered by Coverage index |
542 | 0 | pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId16>] { |
543 | 0 | let range = self.substitute_glyph_ids_byte_range(); |
544 | 0 | self.offset_data() |
545 | 0 | .read_array(range) |
546 | 0 | .ok() |
547 | 0 | .unwrap_or_default() |
548 | 0 | } |
549 | | |
550 | 2.74k | pub fn subst_format_byte_range(&self) -> Range<usize> { |
551 | 2.74k | let start = 0usize; |
552 | 2.74k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
553 | 2.74k | start..end |
554 | 2.74k | } |
555 | | |
556 | 2.74k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
557 | 2.74k | let start = self.subst_format_byte_range().end; |
558 | 2.74k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
559 | 2.74k | start..end |
560 | 2.74k | } |
561 | | |
562 | 2.74k | pub fn glyph_count_byte_range(&self) -> Range<usize> { |
563 | 2.74k | let start = self.coverage_offset_byte_range().end; |
564 | 2.74k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
565 | 2.74k | start..end |
566 | 2.74k | } |
567 | | |
568 | 2.74k | pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> { |
569 | 2.74k | let glyph_count = self.glyph_count(); |
570 | 2.74k | let start = self.glyph_count_byte_range().end; |
571 | 2.74k | let end = start.saturating_add( |
572 | 2.74k | (transforms::to_usize(glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN), |
573 | | ); |
574 | 2.74k | start..end |
575 | 2.74k | } |
576 | | } |
577 | | |
578 | | impl Format<u16> for MultipleSubstFormat1<'_> { |
579 | | const FORMAT: u16 = 1; |
580 | | } |
581 | | |
582 | | impl<'a> MinByteRange<'a> for MultipleSubstFormat1<'a> { |
583 | 0 | fn min_byte_range(&self) -> Range<usize> { |
584 | 0 | 0..self.sequence_offsets_byte_range().end |
585 | 0 | } |
586 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
587 | 0 | let range = self.min_byte_range(); |
588 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
589 | 0 | } |
590 | | } |
591 | | |
592 | | impl ReadArgs for MultipleSubstFormat1<'_> { |
593 | | type Args = (); |
594 | | } |
595 | | |
596 | | impl<'a> FontRead<'a> for MultipleSubstFormat1<'a> { |
597 | 33.0k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
598 | | #[allow(clippy::absurd_extreme_comparisons)] |
599 | 33.0k | if data.len() < Self::MIN_SIZE { |
600 | 265 | return Err(ReadError::OutOfBounds); |
601 | 32.7k | } |
602 | 32.7k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
603 | 0 | return Err(ReadError::OutOfBounds); |
604 | | }; |
605 | 32.7k | Ok(Self { data }) |
606 | 33.0k | } |
607 | | } |
608 | | |
609 | | /// The fields at the start of the table, which are read directly. |
610 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
611 | | #[repr(C, packed)] |
612 | | #[doc(hidden)] |
613 | | pub struct MultipleSubstFormat1FixedHeader { |
614 | | pub subst_format: BigEndian<u16>, |
615 | | pub coverage_offset: BigEndian<Offset16>, |
616 | | pub sequence_count: BigEndian<u16>, |
617 | | } |
618 | | |
619 | | #[allow(clippy::absurd_extreme_comparisons)] |
620 | | const _: () = assert!( |
621 | | std::mem::size_of::<MultipleSubstFormat1FixedHeader>() <= MultipleSubstFormat1::MIN_SIZE |
622 | | ); |
623 | | |
624 | | /// [Multiple Substitution Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#21-multiple-substitution-format-1) |
625 | | #[derive(Clone)] |
626 | | pub struct MultipleSubstFormat1<'a> { |
627 | | data: TableDataRef<'a, MultipleSubstFormat1FixedHeader>, |
628 | | } |
629 | | |
630 | | #[allow(clippy::needless_lifetimes)] |
631 | | impl<'a> MultipleSubstFormat1<'a> { |
632 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN); |
633 | | basic_table_impls!(impl_the_methods); |
634 | | |
635 | | /// Format identifier: format = 1 |
636 | 0 | pub fn subst_format(&self) -> u16 { |
637 | 0 | self.data.header().subst_format.get() |
638 | 0 | } |
639 | | |
640 | | /// Offset to Coverage table, from beginning of substitution |
641 | | /// subtable |
642 | 32.7k | pub fn coverage_offset(&self) -> Offset16 { |
643 | 32.7k | self.data.header().coverage_offset.get() |
644 | 32.7k | } |
645 | | |
646 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
647 | 32.7k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
648 | 32.7k | let data = self.offset_data(); |
649 | 32.7k | self.coverage_offset().resolve(data) |
650 | 32.7k | } |
651 | | |
652 | | /// Number of Sequence table offsets in the sequenceOffsets array |
653 | 32.7k | pub fn sequence_count(&self) -> u16 { |
654 | 32.7k | self.data.header().sequence_count.get() |
655 | 32.7k | } |
656 | | |
657 | | /// Array of offsets to Sequence tables. Offsets are from beginning |
658 | | /// of substitution subtable, ordered by Coverage index |
659 | 0 | pub fn sequence_offsets(&self) -> &'a [BigEndian<Offset16>] { |
660 | 0 | let range = self.sequence_offsets_byte_range(); |
661 | 0 | self.offset_data() |
662 | 0 | .read_array(range) |
663 | 0 | .ok() |
664 | 0 | .unwrap_or_default() |
665 | 0 | } |
666 | | |
667 | | /// A dynamically resolving wrapper for [`sequence_offsets`][Self::sequence_offsets]. |
668 | 0 | pub fn sequences(&self) -> ArrayOfOffsets<'a, Sequence<'a>, Offset16> { |
669 | 0 | let data = self.offset_data(); |
670 | 0 | let offsets = self.sequence_offsets(); |
671 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
672 | 0 | } |
673 | | |
674 | 32.7k | pub fn subst_format_byte_range(&self) -> Range<usize> { |
675 | 32.7k | let start = 0usize; |
676 | 32.7k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
677 | 32.7k | start..end |
678 | 32.7k | } |
679 | | |
680 | 32.7k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
681 | 32.7k | let start = self.subst_format_byte_range().end; |
682 | 32.7k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
683 | 32.7k | start..end |
684 | 32.7k | } |
685 | | |
686 | 32.7k | pub fn sequence_count_byte_range(&self) -> Range<usize> { |
687 | 32.7k | let start = self.coverage_offset_byte_range().end; |
688 | 32.7k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
689 | 32.7k | start..end |
690 | 32.7k | } |
691 | | |
692 | 32.7k | pub fn sequence_offsets_byte_range(&self) -> Range<usize> { |
693 | 32.7k | let sequence_count = self.sequence_count(); |
694 | 32.7k | let start = self.sequence_count_byte_range().end; |
695 | 32.7k | let end = start.saturating_add( |
696 | 32.7k | (transforms::to_usize(sequence_count)).saturating_mul(Offset16::RAW_BYTE_LEN), |
697 | | ); |
698 | 32.7k | start..end |
699 | 32.7k | } |
700 | | } |
701 | | |
702 | | const _: () = assert!(FontData::default_data_long_enough( |
703 | | MultipleSubstFormat1::MIN_SIZE |
704 | | )); |
705 | | |
706 | | impl Default for MultipleSubstFormat1<'_> { |
707 | 0 | fn default() -> Self { |
708 | | Self { |
709 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
710 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
711 | | } |
712 | 0 | } |
713 | | } |
714 | | |
715 | | impl<'a> MinByteRange<'a> for Sequence<'a> { |
716 | 0 | fn min_byte_range(&self) -> Range<usize> { |
717 | 0 | 0..self.substitute_glyph_ids_byte_range().end |
718 | 0 | } |
719 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
720 | 0 | let range = self.min_byte_range(); |
721 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
722 | 0 | } |
723 | | } |
724 | | |
725 | | impl ReadArgs for Sequence<'_> { |
726 | | type Args = (); |
727 | | } |
728 | | |
729 | | impl<'a> FontRead<'a> for Sequence<'a> { |
730 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
731 | | #[allow(clippy::absurd_extreme_comparisons)] |
732 | 0 | if data.len() < Self::MIN_SIZE { |
733 | 0 | return Err(ReadError::OutOfBounds); |
734 | 0 | } |
735 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
736 | 0 | return Err(ReadError::OutOfBounds); |
737 | | }; |
738 | 0 | Ok(Self { data }) |
739 | 0 | } |
740 | | } |
741 | | |
742 | | /// The fields at the start of the table, which are read directly. |
743 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
744 | | #[repr(C, packed)] |
745 | | #[doc(hidden)] |
746 | | pub struct SequenceFixedHeader { |
747 | | pub glyph_count: BigEndian<u16>, |
748 | | } |
749 | | |
750 | | #[allow(clippy::absurd_extreme_comparisons)] |
751 | | const _: () = assert!(std::mem::size_of::<SequenceFixedHeader>() <= Sequence::MIN_SIZE); |
752 | | |
753 | | /// Part of [MultipleSubstFormat1] |
754 | | #[derive(Clone)] |
755 | | pub struct Sequence<'a> { |
756 | | data: TableDataRef<'a, SequenceFixedHeader>, |
757 | | } |
758 | | |
759 | | #[allow(clippy::needless_lifetimes)] |
760 | | impl<'a> Sequence<'a> { |
761 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
762 | | basic_table_impls!(impl_the_methods); |
763 | | |
764 | | /// Number of glyph IDs in the substituteGlyphIDs array. This must |
765 | | /// always be greater than 0. |
766 | 0 | pub fn glyph_count(&self) -> u16 { |
767 | 0 | self.data.header().glyph_count.get() |
768 | 0 | } |
769 | | |
770 | | /// String of glyph IDs to substitute |
771 | 0 | pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId16>] { |
772 | 0 | let range = self.substitute_glyph_ids_byte_range(); |
773 | 0 | self.offset_data() |
774 | 0 | .read_array(range) |
775 | 0 | .ok() |
776 | 0 | .unwrap_or_default() |
777 | 0 | } |
778 | | |
779 | 0 | pub fn glyph_count_byte_range(&self) -> Range<usize> { |
780 | 0 | let start = 0usize; |
781 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
782 | 0 | start..end |
783 | 0 | } |
784 | | |
785 | 0 | pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> { |
786 | 0 | let glyph_count = self.glyph_count(); |
787 | 0 | let start = self.glyph_count_byte_range().end; |
788 | 0 | let end = start.saturating_add( |
789 | 0 | (transforms::to_usize(glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN), |
790 | | ); |
791 | 0 | start..end |
792 | 0 | } |
793 | | } |
794 | | |
795 | | const _: () = assert!(FontData::default_data_long_enough(Sequence::MIN_SIZE)); |
796 | | |
797 | | impl Default for Sequence<'_> { |
798 | 0 | fn default() -> Self { |
799 | | Self { |
800 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
801 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
802 | | } |
803 | 0 | } |
804 | | } |
805 | | |
806 | | impl Format<u16> for AlternateSubstFormat1<'_> { |
807 | | const FORMAT: u16 = 1; |
808 | | } |
809 | | |
810 | | impl<'a> MinByteRange<'a> for AlternateSubstFormat1<'a> { |
811 | 0 | fn min_byte_range(&self) -> Range<usize> { |
812 | 0 | 0..self.alternate_set_offsets_byte_range().end |
813 | 0 | } |
814 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
815 | 0 | let range = self.min_byte_range(); |
816 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
817 | 0 | } |
818 | | } |
819 | | |
820 | | impl ReadArgs for AlternateSubstFormat1<'_> { |
821 | | type Args = (); |
822 | | } |
823 | | |
824 | | impl<'a> FontRead<'a> for AlternateSubstFormat1<'a> { |
825 | 2.23k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
826 | | #[allow(clippy::absurd_extreme_comparisons)] |
827 | 2.23k | if data.len() < Self::MIN_SIZE { |
828 | 253 | return Err(ReadError::OutOfBounds); |
829 | 1.98k | } |
830 | 1.98k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
831 | 0 | return Err(ReadError::OutOfBounds); |
832 | | }; |
833 | 1.98k | Ok(Self { data }) |
834 | 2.23k | } |
835 | | } |
836 | | |
837 | | /// The fields at the start of the table, which are read directly. |
838 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
839 | | #[repr(C, packed)] |
840 | | #[doc(hidden)] |
841 | | pub struct AlternateSubstFormat1FixedHeader { |
842 | | pub subst_format: BigEndian<u16>, |
843 | | pub coverage_offset: BigEndian<Offset16>, |
844 | | pub alternate_set_count: BigEndian<u16>, |
845 | | } |
846 | | |
847 | | #[allow(clippy::absurd_extreme_comparisons)] |
848 | | const _: () = assert!( |
849 | | std::mem::size_of::<AlternateSubstFormat1FixedHeader>() <= AlternateSubstFormat1::MIN_SIZE |
850 | | ); |
851 | | |
852 | | /// [Alternate Substitution Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#31-alternate-substitution-format-1) |
853 | | #[derive(Clone)] |
854 | | pub struct AlternateSubstFormat1<'a> { |
855 | | data: TableDataRef<'a, AlternateSubstFormat1FixedHeader>, |
856 | | } |
857 | | |
858 | | #[allow(clippy::needless_lifetimes)] |
859 | | impl<'a> AlternateSubstFormat1<'a> { |
860 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN); |
861 | | basic_table_impls!(impl_the_methods); |
862 | | |
863 | | /// Format identifier: format = 1 |
864 | 0 | pub fn subst_format(&self) -> u16 { |
865 | 0 | self.data.header().subst_format.get() |
866 | 0 | } |
867 | | |
868 | | /// Offset to Coverage table, from beginning of substitution |
869 | | /// subtable |
870 | 1.98k | pub fn coverage_offset(&self) -> Offset16 { |
871 | 1.98k | self.data.header().coverage_offset.get() |
872 | 1.98k | } |
873 | | |
874 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
875 | 1.98k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
876 | 1.98k | let data = self.offset_data(); |
877 | 1.98k | self.coverage_offset().resolve(data) |
878 | 1.98k | } |
879 | | |
880 | | /// Number of AlternateSet tables |
881 | 1.98k | pub fn alternate_set_count(&self) -> u16 { |
882 | 1.98k | self.data.header().alternate_set_count.get() |
883 | 1.98k | } |
884 | | |
885 | | /// Array of offsets to AlternateSet tables. Offsets are from |
886 | | /// beginning of substitution subtable, ordered by Coverage index |
887 | 0 | pub fn alternate_set_offsets(&self) -> &'a [BigEndian<Offset16>] { |
888 | 0 | let range = self.alternate_set_offsets_byte_range(); |
889 | 0 | self.offset_data() |
890 | 0 | .read_array(range) |
891 | 0 | .ok() |
892 | 0 | .unwrap_or_default() |
893 | 0 | } |
894 | | |
895 | | /// A dynamically resolving wrapper for [`alternate_set_offsets`][Self::alternate_set_offsets]. |
896 | 0 | pub fn alternate_sets(&self) -> ArrayOfOffsets<'a, AlternateSet<'a>, Offset16> { |
897 | 0 | let data = self.offset_data(); |
898 | 0 | let offsets = self.alternate_set_offsets(); |
899 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
900 | 0 | } |
901 | | |
902 | 1.98k | pub fn subst_format_byte_range(&self) -> Range<usize> { |
903 | 1.98k | let start = 0usize; |
904 | 1.98k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
905 | 1.98k | start..end |
906 | 1.98k | } |
907 | | |
908 | 1.98k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
909 | 1.98k | let start = self.subst_format_byte_range().end; |
910 | 1.98k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
911 | 1.98k | start..end |
912 | 1.98k | } |
913 | | |
914 | 1.98k | pub fn alternate_set_count_byte_range(&self) -> Range<usize> { |
915 | 1.98k | let start = self.coverage_offset_byte_range().end; |
916 | 1.98k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
917 | 1.98k | start..end |
918 | 1.98k | } |
919 | | |
920 | 1.98k | pub fn alternate_set_offsets_byte_range(&self) -> Range<usize> { |
921 | 1.98k | let alternate_set_count = self.alternate_set_count(); |
922 | 1.98k | let start = self.alternate_set_count_byte_range().end; |
923 | 1.98k | let end = start.saturating_add( |
924 | 1.98k | (transforms::to_usize(alternate_set_count)).saturating_mul(Offset16::RAW_BYTE_LEN), |
925 | | ); |
926 | 1.98k | start..end |
927 | 1.98k | } |
928 | | } |
929 | | |
930 | | const _: () = assert!(FontData::default_data_long_enough( |
931 | | AlternateSubstFormat1::MIN_SIZE |
932 | | )); |
933 | | |
934 | | impl Default for AlternateSubstFormat1<'_> { |
935 | 0 | fn default() -> Self { |
936 | | Self { |
937 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
938 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
939 | | } |
940 | 0 | } |
941 | | } |
942 | | |
943 | | impl<'a> MinByteRange<'a> for AlternateSet<'a> { |
944 | 0 | fn min_byte_range(&self) -> Range<usize> { |
945 | 0 | 0..self.alternate_glyph_ids_byte_range().end |
946 | 0 | } |
947 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
948 | 0 | let range = self.min_byte_range(); |
949 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
950 | 0 | } |
951 | | } |
952 | | |
953 | | impl ReadArgs for AlternateSet<'_> { |
954 | | type Args = (); |
955 | | } |
956 | | |
957 | | impl<'a> FontRead<'a> for AlternateSet<'a> { |
958 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
959 | | #[allow(clippy::absurd_extreme_comparisons)] |
960 | 0 | if data.len() < Self::MIN_SIZE { |
961 | 0 | return Err(ReadError::OutOfBounds); |
962 | 0 | } |
963 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
964 | 0 | return Err(ReadError::OutOfBounds); |
965 | | }; |
966 | 0 | Ok(Self { data }) |
967 | 0 | } |
968 | | } |
969 | | |
970 | | /// The fields at the start of the table, which are read directly. |
971 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
972 | | #[repr(C, packed)] |
973 | | #[doc(hidden)] |
974 | | pub struct AlternateSetFixedHeader { |
975 | | pub glyph_count: BigEndian<u16>, |
976 | | } |
977 | | |
978 | | #[allow(clippy::absurd_extreme_comparisons)] |
979 | | const _: () = assert!(std::mem::size_of::<AlternateSetFixedHeader>() <= AlternateSet::MIN_SIZE); |
980 | | |
981 | | /// Part of [AlternateSubstFormat1] |
982 | | #[derive(Clone)] |
983 | | pub struct AlternateSet<'a> { |
984 | | data: TableDataRef<'a, AlternateSetFixedHeader>, |
985 | | } |
986 | | |
987 | | #[allow(clippy::needless_lifetimes)] |
988 | | impl<'a> AlternateSet<'a> { |
989 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
990 | | basic_table_impls!(impl_the_methods); |
991 | | |
992 | | /// Number of glyph IDs in the alternateGlyphIDs array |
993 | 0 | pub fn glyph_count(&self) -> u16 { |
994 | 0 | self.data.header().glyph_count.get() |
995 | 0 | } |
996 | | |
997 | | /// Array of alternate glyph IDs, in arbitrary order |
998 | 0 | pub fn alternate_glyph_ids(&self) -> &'a [BigEndian<GlyphId16>] { |
999 | 0 | let range = self.alternate_glyph_ids_byte_range(); |
1000 | 0 | self.offset_data() |
1001 | 0 | .read_array(range) |
1002 | 0 | .ok() |
1003 | 0 | .unwrap_or_default() |
1004 | 0 | } |
1005 | | |
1006 | 0 | pub fn glyph_count_byte_range(&self) -> Range<usize> { |
1007 | 0 | let start = 0usize; |
1008 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1009 | 0 | start..end |
1010 | 0 | } |
1011 | | |
1012 | 0 | pub fn alternate_glyph_ids_byte_range(&self) -> Range<usize> { |
1013 | 0 | let glyph_count = self.glyph_count(); |
1014 | 0 | let start = self.glyph_count_byte_range().end; |
1015 | 0 | let end = start.saturating_add( |
1016 | 0 | (transforms::to_usize(glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN), |
1017 | | ); |
1018 | 0 | start..end |
1019 | 0 | } |
1020 | | } |
1021 | | |
1022 | | const _: () = assert!(FontData::default_data_long_enough(AlternateSet::MIN_SIZE)); |
1023 | | |
1024 | | impl Default for AlternateSet<'_> { |
1025 | 0 | fn default() -> Self { |
1026 | | Self { |
1027 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
1028 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
1029 | | } |
1030 | 0 | } |
1031 | | } |
1032 | | |
1033 | | impl Format<u16> for LigatureSubstFormat1<'_> { |
1034 | | const FORMAT: u16 = 1; |
1035 | | } |
1036 | | |
1037 | | impl<'a> MinByteRange<'a> for LigatureSubstFormat1<'a> { |
1038 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1039 | 0 | 0..self.ligature_set_offsets_byte_range().end |
1040 | 0 | } |
1041 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1042 | 0 | let range = self.min_byte_range(); |
1043 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1044 | 0 | } |
1045 | | } |
1046 | | |
1047 | | impl ReadArgs for LigatureSubstFormat1<'_> { |
1048 | | type Args = (); |
1049 | | } |
1050 | | |
1051 | | impl<'a> FontRead<'a> for LigatureSubstFormat1<'a> { |
1052 | 16.1k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1053 | | #[allow(clippy::absurd_extreme_comparisons)] |
1054 | 16.1k | if data.len() < Self::MIN_SIZE { |
1055 | 224 | return Err(ReadError::OutOfBounds); |
1056 | 15.9k | } |
1057 | 15.9k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1058 | 0 | return Err(ReadError::OutOfBounds); |
1059 | | }; |
1060 | 15.9k | Ok(Self { data }) |
1061 | 16.1k | } |
1062 | | } |
1063 | | |
1064 | | /// The fields at the start of the table, which are read directly. |
1065 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1066 | | #[repr(C, packed)] |
1067 | | #[doc(hidden)] |
1068 | | pub struct LigatureSubstFormat1FixedHeader { |
1069 | | pub subst_format: BigEndian<u16>, |
1070 | | pub coverage_offset: BigEndian<Offset16>, |
1071 | | pub ligature_set_count: BigEndian<u16>, |
1072 | | } |
1073 | | |
1074 | | #[allow(clippy::absurd_extreme_comparisons)] |
1075 | | const _: () = assert!( |
1076 | | std::mem::size_of::<LigatureSubstFormat1FixedHeader>() <= LigatureSubstFormat1::MIN_SIZE |
1077 | | ); |
1078 | | |
1079 | | /// [Ligature Substitution Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#41-ligature-substitution-format-1) |
1080 | | #[derive(Clone)] |
1081 | | pub struct LigatureSubstFormat1<'a> { |
1082 | | data: TableDataRef<'a, LigatureSubstFormat1FixedHeader>, |
1083 | | } |
1084 | | |
1085 | | #[allow(clippy::needless_lifetimes)] |
1086 | | impl<'a> LigatureSubstFormat1<'a> { |
1087 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN); |
1088 | | basic_table_impls!(impl_the_methods); |
1089 | | |
1090 | | /// Format identifier: format = 1 |
1091 | 0 | pub fn subst_format(&self) -> u16 { |
1092 | 0 | self.data.header().subst_format.get() |
1093 | 0 | } |
1094 | | |
1095 | | /// Offset to Coverage table, from beginning of substitution |
1096 | | /// subtable |
1097 | 15.9k | pub fn coverage_offset(&self) -> Offset16 { |
1098 | 15.9k | self.data.header().coverage_offset.get() |
1099 | 15.9k | } |
1100 | | |
1101 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
1102 | 15.9k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
1103 | 15.9k | let data = self.offset_data(); |
1104 | 15.9k | self.coverage_offset().resolve(data) |
1105 | 15.9k | } |
1106 | | |
1107 | | /// Number of LigatureSet tables |
1108 | 15.9k | pub fn ligature_set_count(&self) -> u16 { |
1109 | 15.9k | self.data.header().ligature_set_count.get() |
1110 | 15.9k | } |
1111 | | |
1112 | | /// Array of offsets to LigatureSet tables. Offsets are from |
1113 | | /// beginning of substitution subtable, ordered by Coverage index |
1114 | 0 | pub fn ligature_set_offsets(&self) -> &'a [BigEndian<Offset16>] { |
1115 | 0 | let range = self.ligature_set_offsets_byte_range(); |
1116 | 0 | self.offset_data() |
1117 | 0 | .read_array(range) |
1118 | 0 | .ok() |
1119 | 0 | .unwrap_or_default() |
1120 | 0 | } |
1121 | | |
1122 | | /// A dynamically resolving wrapper for [`ligature_set_offsets`][Self::ligature_set_offsets]. |
1123 | 0 | pub fn ligature_sets(&self) -> ArrayOfOffsets<'a, LigatureSet<'a>, Offset16> { |
1124 | 0 | let data = self.offset_data(); |
1125 | 0 | let offsets = self.ligature_set_offsets(); |
1126 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
1127 | 0 | } |
1128 | | |
1129 | 15.9k | pub fn subst_format_byte_range(&self) -> Range<usize> { |
1130 | 15.9k | let start = 0usize; |
1131 | 15.9k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1132 | 15.9k | start..end |
1133 | 15.9k | } |
1134 | | |
1135 | 15.9k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
1136 | 15.9k | let start = self.subst_format_byte_range().end; |
1137 | 15.9k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
1138 | 15.9k | start..end |
1139 | 15.9k | } |
1140 | | |
1141 | 15.9k | pub fn ligature_set_count_byte_range(&self) -> Range<usize> { |
1142 | 15.9k | let start = self.coverage_offset_byte_range().end; |
1143 | 15.9k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1144 | 15.9k | start..end |
1145 | 15.9k | } |
1146 | | |
1147 | 15.9k | pub fn ligature_set_offsets_byte_range(&self) -> Range<usize> { |
1148 | 15.9k | let ligature_set_count = self.ligature_set_count(); |
1149 | 15.9k | let start = self.ligature_set_count_byte_range().end; |
1150 | 15.9k | let end = start.saturating_add( |
1151 | 15.9k | (transforms::to_usize(ligature_set_count)).saturating_mul(Offset16::RAW_BYTE_LEN), |
1152 | | ); |
1153 | 15.9k | start..end |
1154 | 15.9k | } |
1155 | | } |
1156 | | |
1157 | | const _: () = assert!(FontData::default_data_long_enough( |
1158 | | LigatureSubstFormat1::MIN_SIZE |
1159 | | )); |
1160 | | |
1161 | | impl Default for LigatureSubstFormat1<'_> { |
1162 | 0 | fn default() -> Self { |
1163 | | Self { |
1164 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
1165 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
1166 | | } |
1167 | 0 | } |
1168 | | } |
1169 | | |
1170 | | impl<'a> MinByteRange<'a> for LigatureSet<'a> { |
1171 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1172 | 0 | 0..self.ligature_offsets_byte_range().end |
1173 | 0 | } |
1174 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1175 | 0 | let range = self.min_byte_range(); |
1176 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1177 | 0 | } |
1178 | | } |
1179 | | |
1180 | | impl ReadArgs for LigatureSet<'_> { |
1181 | | type Args = (); |
1182 | | } |
1183 | | |
1184 | | impl<'a> FontRead<'a> for LigatureSet<'a> { |
1185 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1186 | | #[allow(clippy::absurd_extreme_comparisons)] |
1187 | 0 | if data.len() < Self::MIN_SIZE { |
1188 | 0 | return Err(ReadError::OutOfBounds); |
1189 | 0 | } |
1190 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1191 | 0 | return Err(ReadError::OutOfBounds); |
1192 | | }; |
1193 | 0 | Ok(Self { data }) |
1194 | 0 | } |
1195 | | } |
1196 | | |
1197 | | /// The fields at the start of the table, which are read directly. |
1198 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1199 | | #[repr(C, packed)] |
1200 | | #[doc(hidden)] |
1201 | | pub struct LigatureSetFixedHeader { |
1202 | | pub ligature_count: BigEndian<u16>, |
1203 | | } |
1204 | | |
1205 | | #[allow(clippy::absurd_extreme_comparisons)] |
1206 | | const _: () = assert!(std::mem::size_of::<LigatureSetFixedHeader>() <= LigatureSet::MIN_SIZE); |
1207 | | |
1208 | | /// Part of [LigatureSubstFormat1] |
1209 | | #[derive(Clone)] |
1210 | | pub struct LigatureSet<'a> { |
1211 | | data: TableDataRef<'a, LigatureSetFixedHeader>, |
1212 | | } |
1213 | | |
1214 | | #[allow(clippy::needless_lifetimes)] |
1215 | | impl<'a> LigatureSet<'a> { |
1216 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
1217 | | basic_table_impls!(impl_the_methods); |
1218 | | |
1219 | | /// Number of Ligature tables |
1220 | 0 | pub fn ligature_count(&self) -> u16 { |
1221 | 0 | self.data.header().ligature_count.get() |
1222 | 0 | } |
1223 | | |
1224 | | /// Array of offsets to Ligature tables. Offsets are from beginning |
1225 | | /// of LigatureSet table, ordered by preference. |
1226 | 0 | pub fn ligature_offsets(&self) -> &'a [BigEndian<Offset16>] { |
1227 | 0 | let range = self.ligature_offsets_byte_range(); |
1228 | 0 | self.offset_data() |
1229 | 0 | .read_array(range) |
1230 | 0 | .ok() |
1231 | 0 | .unwrap_or_default() |
1232 | 0 | } |
1233 | | |
1234 | | /// A dynamically resolving wrapper for [`ligature_offsets`][Self::ligature_offsets]. |
1235 | 0 | pub fn ligatures(&self) -> ArrayOfOffsets<'a, Ligature<'a>, Offset16> { |
1236 | 0 | let data = self.offset_data(); |
1237 | 0 | let offsets = self.ligature_offsets(); |
1238 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
1239 | 0 | } |
1240 | | |
1241 | 0 | pub fn ligature_count_byte_range(&self) -> Range<usize> { |
1242 | 0 | let start = 0usize; |
1243 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1244 | 0 | start..end |
1245 | 0 | } |
1246 | | |
1247 | 0 | pub fn ligature_offsets_byte_range(&self) -> Range<usize> { |
1248 | 0 | let ligature_count = self.ligature_count(); |
1249 | 0 | let start = self.ligature_count_byte_range().end; |
1250 | 0 | let end = start.saturating_add( |
1251 | 0 | (transforms::to_usize(ligature_count)).saturating_mul(Offset16::RAW_BYTE_LEN), |
1252 | | ); |
1253 | 0 | start..end |
1254 | 0 | } |
1255 | | } |
1256 | | |
1257 | | const _: () = assert!(FontData::default_data_long_enough(LigatureSet::MIN_SIZE)); |
1258 | | |
1259 | | impl Default for LigatureSet<'_> { |
1260 | 0 | fn default() -> Self { |
1261 | | Self { |
1262 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
1263 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
1264 | | } |
1265 | 0 | } |
1266 | | } |
1267 | | |
1268 | | impl<'a> MinByteRange<'a> for Ligature<'a> { |
1269 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1270 | 0 | 0..self.component_glyph_ids_byte_range().end |
1271 | 0 | } |
1272 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1273 | 0 | let range = self.min_byte_range(); |
1274 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1275 | 0 | } |
1276 | | } |
1277 | | |
1278 | | impl ReadArgs for Ligature<'_> { |
1279 | | type Args = (); |
1280 | | } |
1281 | | |
1282 | | impl<'a> FontRead<'a> for Ligature<'a> { |
1283 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1284 | | #[allow(clippy::absurd_extreme_comparisons)] |
1285 | 0 | if data.len() < Self::MIN_SIZE { |
1286 | 0 | return Err(ReadError::OutOfBounds); |
1287 | 0 | } |
1288 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1289 | 0 | return Err(ReadError::OutOfBounds); |
1290 | | }; |
1291 | 0 | Ok(Self { data }) |
1292 | 0 | } |
1293 | | } |
1294 | | |
1295 | | /// The fields at the start of the table, which are read directly. |
1296 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1297 | | #[repr(C, packed)] |
1298 | | #[doc(hidden)] |
1299 | | pub struct LigatureFixedHeader { |
1300 | | pub ligature_glyph: BigEndian<GlyphId16>, |
1301 | | pub component_count: BigEndian<u16>, |
1302 | | } |
1303 | | |
1304 | | #[allow(clippy::absurd_extreme_comparisons)] |
1305 | | const _: () = assert!(std::mem::size_of::<LigatureFixedHeader>() <= Ligature::MIN_SIZE); |
1306 | | |
1307 | | /// Part of [LigatureSubstFormat1] |
1308 | | #[derive(Clone)] |
1309 | | pub struct Ligature<'a> { |
1310 | | data: TableDataRef<'a, LigatureFixedHeader>, |
1311 | | } |
1312 | | |
1313 | | #[allow(clippy::needless_lifetimes)] |
1314 | | impl<'a> Ligature<'a> { |
1315 | | pub const MIN_SIZE: usize = (GlyphId16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN); |
1316 | | basic_table_impls!(impl_the_methods); |
1317 | | |
1318 | | /// glyph ID of ligature to substitute |
1319 | 0 | pub fn ligature_glyph(&self) -> GlyphId16 { |
1320 | 0 | self.data.header().ligature_glyph.get() |
1321 | 0 | } |
1322 | | |
1323 | | /// Number of components in the ligature |
1324 | 0 | pub fn component_count(&self) -> u16 { |
1325 | 0 | self.data.header().component_count.get() |
1326 | 0 | } |
1327 | | |
1328 | | /// Array of component glyph IDs — start with the second |
1329 | | /// component, ordered in writing direction |
1330 | 0 | pub fn component_glyph_ids(&self) -> &'a [BigEndian<GlyphId16>] { |
1331 | 0 | let range = self.component_glyph_ids_byte_range(); |
1332 | 0 | self.offset_data() |
1333 | 0 | .read_array(range) |
1334 | 0 | .ok() |
1335 | 0 | .unwrap_or_default() |
1336 | 0 | } |
1337 | | |
1338 | 0 | pub fn ligature_glyph_byte_range(&self) -> Range<usize> { |
1339 | 0 | let start = 0usize; |
1340 | 0 | let end = start.saturating_add(GlyphId16::RAW_BYTE_LEN); |
1341 | 0 | start..end |
1342 | 0 | } |
1343 | | |
1344 | 0 | pub fn component_count_byte_range(&self) -> Range<usize> { |
1345 | 0 | let start = self.ligature_glyph_byte_range().end; |
1346 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1347 | 0 | start..end |
1348 | 0 | } |
1349 | | |
1350 | 0 | pub fn component_glyph_ids_byte_range(&self) -> Range<usize> { |
1351 | 0 | let component_count = self.component_count(); |
1352 | 0 | let start = self.component_count_byte_range().end; |
1353 | 0 | let end = start.saturating_add( |
1354 | 0 | (transforms::subtract(component_count, 1_usize)) |
1355 | 0 | .saturating_mul(GlyphId16::RAW_BYTE_LEN), |
1356 | | ); |
1357 | 0 | start..end |
1358 | 0 | } |
1359 | | } |
1360 | | |
1361 | | const _: () = assert!(FontData::default_data_long_enough(Ligature::MIN_SIZE)); |
1362 | | |
1363 | | impl Default for Ligature<'_> { |
1364 | 0 | fn default() -> Self { |
1365 | | Self { |
1366 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
1367 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
1368 | | } |
1369 | 0 | } |
1370 | | } |
1371 | | |
1372 | | impl Format<u16> for ExtensionSubstFormat1<'_> { |
1373 | | const FORMAT: u16 = 1; |
1374 | | } |
1375 | | |
1376 | | impl Discriminant for ExtensionSubstFormat1<'_, ()> { |
1377 | 0 | fn read_discriminant(data: FontData<'_>) -> Result<u16, ReadError> { |
1378 | 0 | data.read_at(u16::RAW_BYTE_LEN) |
1379 | 0 | } |
1380 | | } |
1381 | | |
1382 | | impl<'a, T> MinByteRange<'a> for ExtensionSubstFormat1<'a, T> { |
1383 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1384 | 0 | 0..self.extension_offset_byte_range().end |
1385 | 0 | } |
1386 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1387 | 0 | let range = self.min_byte_range(); |
1388 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1389 | 0 | } |
1390 | | } |
1391 | | |
1392 | | impl<T> ReadArgs for ExtensionSubstFormat1<'_, T> { |
1393 | | type Args = (); |
1394 | | } |
1395 | | |
1396 | | impl<'a, T> FontRead<'a> for ExtensionSubstFormat1<'a, T> { |
1397 | 42.3k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1398 | | #[allow(clippy::absurd_extreme_comparisons)] |
1399 | 42.3k | if data.len() < Self::MIN_SIZE { |
1400 | 639 | return Err(ReadError::OutOfBounds); |
1401 | 41.7k | } |
1402 | 41.7k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1403 | 0 | return Err(ReadError::OutOfBounds); |
1404 | | }; |
1405 | 41.7k | Ok(Self { |
1406 | 41.7k | data, |
1407 | 41.7k | offset_type: std::marker::PhantomData, |
1408 | 41.7k | }) |
1409 | 42.3k | } Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::SingleSubst> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::LigatureSubst> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::MultipleSubst> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::AlternateSubst> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::ReverseChainSingleSubst> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::layout::SequenceContext> as read_fonts::read::FontRead>::read_with_args Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::layout::ChainedSequenceContext> as read_fonts::read::FontRead>::read_with_args <read_fonts::tables::gsub::ExtensionSubstFormat1 as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 1397 | 42.3k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 1398 | | #[allow(clippy::absurd_extreme_comparisons)] | 1399 | 42.3k | if data.len() < Self::MIN_SIZE { | 1400 | 639 | return Err(ReadError::OutOfBounds); | 1401 | 41.7k | } | 1402 | 41.7k | let Some(data) = TableDataRef::new(data.as_bytes()) else { | 1403 | 0 | return Err(ReadError::OutOfBounds); | 1404 | | }; | 1405 | 41.7k | Ok(Self { | 1406 | 41.7k | data, | 1407 | 41.7k | offset_type: std::marker::PhantomData, | 1408 | 41.7k | }) | 1409 | 42.3k | } |
|
1410 | | } |
1411 | | |
1412 | | impl<'a, T> ExtensionSubstFormat1<'a, T> { |
1413 | | #[allow(dead_code)] |
1414 | | /// Replace the specific generic type on this implementation with `()` |
1415 | 0 | pub(crate) fn of_unit_type(&self) -> ExtensionSubstFormat1<'a, ()> { |
1416 | 0 | ExtensionSubstFormat1 { |
1417 | 0 | data: self.data, |
1418 | 0 | offset_type: std::marker::PhantomData, |
1419 | 0 | } |
1420 | 0 | } |
1421 | | } |
1422 | | |
1423 | | /// The fields at the start of the table, which are read directly. |
1424 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1425 | | #[repr(C, packed)] |
1426 | | #[doc(hidden)] |
1427 | | pub struct ExtensionSubstFormat1FixedHeader { |
1428 | | pub subst_format: BigEndian<u16>, |
1429 | | pub extension_lookup_type: BigEndian<u16>, |
1430 | | pub extension_offset: BigEndian<Offset32>, |
1431 | | } |
1432 | | |
1433 | | #[allow(clippy::absurd_extreme_comparisons)] |
1434 | | const _: () = assert!( |
1435 | | std::mem::size_of::<ExtensionSubstFormat1FixedHeader>() |
1436 | | <= ExtensionSubstFormat1::<()>::MIN_SIZE |
1437 | | ); |
1438 | | |
1439 | | /// [Extension Substitution Subtable Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#71-extension-substitution-subtable-format-1) |
1440 | | #[derive(Clone)] |
1441 | | pub struct ExtensionSubstFormat1<'a, T = ()> { |
1442 | | data: TableDataRef<'a, ExtensionSubstFormat1FixedHeader>, |
1443 | | offset_type: std::marker::PhantomData<*const T>, |
1444 | | } |
1445 | | |
1446 | | #[allow(clippy::needless_lifetimes)] |
1447 | | impl<'a, T> ExtensionSubstFormat1<'a, T> { |
1448 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN); |
1449 | | basic_table_impls!(impl_the_methods); |
1450 | | |
1451 | | /// Format identifier. Set to 1. |
1452 | 0 | pub fn subst_format(&self) -> u16 { |
1453 | 0 | self.data.header().subst_format.get() |
1454 | 0 | } |
1455 | | |
1456 | | /// Lookup type of subtable referenced by extensionOffset (that is, |
1457 | | /// the extension subtable). |
1458 | 41.7k | pub fn extension_lookup_type(&self) -> u16 { |
1459 | 41.7k | self.data.header().extension_lookup_type.get() |
1460 | 41.7k | } |
1461 | | |
1462 | | /// Offset to the extension subtable, of lookup type |
1463 | | /// extensionLookupType, relative to the start of the |
1464 | | /// ExtensionSubstFormat1 subtable. |
1465 | 40.7k | pub fn extension_offset(&self) -> Offset32 { |
1466 | 40.7k | self.data.header().extension_offset.get() |
1467 | 40.7k | } <read_fonts::tables::gsub::ExtensionSubstFormat1>::extension_offset Line | Count | Source | 1465 | 40.7k | pub fn extension_offset(&self) -> Offset32 { | 1466 | 40.7k | self.data.header().extension_offset.get() | 1467 | 40.7k | } |
Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::SingleSubst>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::LigatureSubst>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::MultipleSubst>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::AlternateSubst>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::ReverseChainSingleSubst>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::layout::SequenceContext>>::extension_offset Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::layout::ChainedSequenceContext>>::extension_offset |
1468 | | |
1469 | | /// Attempt to resolve [`extension_offset`][Self::extension_offset]. |
1470 | 0 | pub fn extension(&self) -> Result<T, ReadError> |
1471 | 0 | where |
1472 | 0 | T: FontRead<'a, Args = ()>, |
1473 | | { |
1474 | 0 | let data = self.offset_data(); |
1475 | 0 | self.extension_offset().resolve(data) |
1476 | 0 | } Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::SingleSubst>>::extension Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::LigatureSubst>>::extension Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::MultipleSubst>>::extension Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::AlternateSubst>>::extension Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::gsub::ReverseChainSingleSubst>>::extension Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::layout::SequenceContext>>::extension Unexecuted instantiation: <read_fonts::tables::gsub::ExtensionSubstFormat1<read_fonts::tables::layout::ChainedSequenceContext>>::extension |
1477 | | |
1478 | 0 | pub fn subst_format_byte_range(&self) -> Range<usize> { |
1479 | 0 | let start = 0usize; |
1480 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1481 | 0 | start..end |
1482 | 0 | } |
1483 | | |
1484 | 0 | pub fn extension_lookup_type_byte_range(&self) -> Range<usize> { |
1485 | 0 | let start = self.subst_format_byte_range().end; |
1486 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1487 | 0 | start..end |
1488 | 0 | } |
1489 | | |
1490 | 0 | pub fn extension_offset_byte_range(&self) -> Range<usize> { |
1491 | 0 | let start = self.extension_lookup_type_byte_range().end; |
1492 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
1493 | 0 | start..end |
1494 | 0 | } |
1495 | | } |
1496 | | |
1497 | | const _: () = assert!(FontData::default_data_long_enough( |
1498 | | ExtensionSubstFormat1::<()>::MIN_SIZE |
1499 | | )); |
1500 | | |
1501 | | impl<T> Default for ExtensionSubstFormat1<'_, T> { |
1502 | 0 | fn default() -> Self { |
1503 | | Self { |
1504 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
1505 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
1506 | 0 | offset_type: std::marker::PhantomData, |
1507 | | } |
1508 | 0 | } |
1509 | | } |
1510 | | |
1511 | | /// A [GSUB Extension Substitution](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#ES) subtable |
1512 | | pub enum ExtensionSubtable<'a> { |
1513 | | Single(ExtensionSubstFormat1<'a, SingleSubst<'a>>), |
1514 | | Multiple(ExtensionSubstFormat1<'a, MultipleSubst<'a>>), |
1515 | | Alternate(ExtensionSubstFormat1<'a, AlternateSubst<'a>>), |
1516 | | Ligature(ExtensionSubstFormat1<'a, LigatureSubst<'a>>), |
1517 | | Contextual(ExtensionSubstFormat1<'a, SubstitutionSequenceContext<'a>>), |
1518 | | ChainContextual(ExtensionSubstFormat1<'a, SubstitutionChainContext<'a>>), |
1519 | | Reverse(ExtensionSubstFormat1<'a, ReverseChainSingleSubst<'a>>), |
1520 | | } |
1521 | | |
1522 | | impl Default for ExtensionSubtable<'_> { |
1523 | 0 | fn default() -> Self { |
1524 | 0 | Self::Single(Default::default()) |
1525 | 0 | } |
1526 | | } |
1527 | | |
1528 | | impl ReadArgs for ExtensionSubtable<'_> { |
1529 | | type Args = (); |
1530 | | } |
1531 | | |
1532 | | impl<'a> FontRead<'a> for ExtensionSubtable<'a> { |
1533 | 0 | fn read_with_args(bytes: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1534 | 0 | let discriminant = ExtensionSubstFormat1::read_discriminant(bytes)?; |
1535 | 0 | match discriminant { |
1536 | 0 | 1 => Ok(ExtensionSubtable::Single(FontRead::read(bytes)?)), |
1537 | 0 | 2 => Ok(ExtensionSubtable::Multiple(FontRead::read(bytes)?)), |
1538 | 0 | 3 => Ok(ExtensionSubtable::Alternate(FontRead::read(bytes)?)), |
1539 | 0 | 4 => Ok(ExtensionSubtable::Ligature(FontRead::read(bytes)?)), |
1540 | 0 | 5 => Ok(ExtensionSubtable::Contextual(FontRead::read(bytes)?)), |
1541 | 0 | 6 => Ok(ExtensionSubtable::ChainContextual(FontRead::read(bytes)?)), |
1542 | 0 | 8 => Ok(ExtensionSubtable::Reverse(FontRead::read(bytes)?)), |
1543 | 0 | other => Err(ReadError::InvalidFormat(other.into())), |
1544 | | } |
1545 | 0 | } |
1546 | | } |
1547 | | |
1548 | | impl<'a> ExtensionSubtable<'a> { |
1549 | | #[allow(dead_code)] |
1550 | | /// Return the inner table, removing the specific generics. |
1551 | | /// |
1552 | | /// This lets us return a single concrete type we can call methods on. |
1553 | 0 | pub(crate) fn of_unit_type(&self) -> ExtensionSubstFormat1<'a, ()> { |
1554 | 0 | match self { |
1555 | 0 | ExtensionSubtable::Single(inner) => inner.of_unit_type(), |
1556 | 0 | ExtensionSubtable::Multiple(inner) => inner.of_unit_type(), |
1557 | 0 | ExtensionSubtable::Alternate(inner) => inner.of_unit_type(), |
1558 | 0 | ExtensionSubtable::Ligature(inner) => inner.of_unit_type(), |
1559 | 0 | ExtensionSubtable::Contextual(inner) => inner.of_unit_type(), |
1560 | 0 | ExtensionSubtable::ChainContextual(inner) => inner.of_unit_type(), |
1561 | 0 | ExtensionSubtable::Reverse(inner) => inner.of_unit_type(), |
1562 | | } |
1563 | 0 | } |
1564 | | } |
1565 | | |
1566 | | impl Format<u16> for ReverseChainSingleSubstFormat1<'_> { |
1567 | | const FORMAT: u16 = 1; |
1568 | | } |
1569 | | |
1570 | | impl<'a> MinByteRange<'a> for ReverseChainSingleSubstFormat1<'a> { |
1571 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1572 | 0 | 0..self.substitute_glyph_ids_byte_range().end |
1573 | 0 | } |
1574 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1575 | 0 | let range = self.min_byte_range(); |
1576 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1577 | 0 | } |
1578 | | } |
1579 | | |
1580 | | impl ReadArgs for ReverseChainSingleSubstFormat1<'_> { |
1581 | | type Args = (); |
1582 | | } |
1583 | | |
1584 | | impl<'a> FontRead<'a> for ReverseChainSingleSubstFormat1<'a> { |
1585 | 12.1k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1586 | | #[allow(clippy::absurd_extreme_comparisons)] |
1587 | 12.1k | if data.len() < Self::MIN_SIZE { |
1588 | 328 | return Err(ReadError::OutOfBounds); |
1589 | 11.8k | } |
1590 | 11.8k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1591 | 0 | return Err(ReadError::OutOfBounds); |
1592 | | }; |
1593 | 11.8k | Ok(Self { data }) |
1594 | 12.1k | } |
1595 | | } |
1596 | | |
1597 | | /// The fields at the start of the table, which are read directly. |
1598 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1599 | | #[repr(C, packed)] |
1600 | | #[doc(hidden)] |
1601 | | pub struct ReverseChainSingleSubstFormat1FixedHeader { |
1602 | | pub subst_format: BigEndian<u16>, |
1603 | | pub coverage_offset: BigEndian<Offset16>, |
1604 | | pub backtrack_glyph_count: BigEndian<u16>, |
1605 | | } |
1606 | | |
1607 | | #[allow(clippy::absurd_extreme_comparisons)] |
1608 | | const _: () = assert!( |
1609 | | std::mem::size_of::<ReverseChainSingleSubstFormat1FixedHeader>() |
1610 | | <= ReverseChainSingleSubstFormat1::MIN_SIZE |
1611 | | ); |
1612 | | |
1613 | | /// [Reverse Chaining Contextual Single Substitution Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#81-reverse-chaining-contextual-single-substitution-format-1-coverage-based-glyph-contexts) |
1614 | | #[derive(Clone)] |
1615 | | pub struct ReverseChainSingleSubstFormat1<'a> { |
1616 | | data: TableDataRef<'a, ReverseChainSingleSubstFormat1FixedHeader>, |
1617 | | } |
1618 | | |
1619 | | #[allow(clippy::needless_lifetimes)] |
1620 | | impl<'a> ReverseChainSingleSubstFormat1<'a> { |
1621 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
1622 | | + Offset16::RAW_BYTE_LEN |
1623 | | + u16::RAW_BYTE_LEN |
1624 | | + u16::RAW_BYTE_LEN |
1625 | | + u16::RAW_BYTE_LEN); |
1626 | | basic_table_impls!(impl_the_methods); |
1627 | | |
1628 | | /// Format identifier: format = 1 |
1629 | 0 | pub fn subst_format(&self) -> u16 { |
1630 | 0 | self.data.header().subst_format.get() |
1631 | 0 | } |
1632 | | |
1633 | | /// Offset to Coverage table, from beginning of substitution |
1634 | | /// subtable. |
1635 | 11.8k | pub fn coverage_offset(&self) -> Offset16 { |
1636 | 11.8k | self.data.header().coverage_offset.get() |
1637 | 11.8k | } |
1638 | | |
1639 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
1640 | 11.8k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
1641 | 11.8k | let data = self.offset_data(); |
1642 | 11.8k | self.coverage_offset().resolve(data) |
1643 | 11.8k | } |
1644 | | |
1645 | | /// Number of glyphs in the backtrack sequence. |
1646 | 68.1k | pub fn backtrack_glyph_count(&self) -> u16 { |
1647 | 68.1k | self.data.header().backtrack_glyph_count.get() |
1648 | 68.1k | } |
1649 | | |
1650 | | /// Array of offsets to coverage tables in backtrack sequence, in |
1651 | | /// glyph sequence order. |
1652 | 0 | pub fn backtrack_coverage_offsets(&self) -> &'a [BigEndian<Offset16>] { |
1653 | 0 | let range = self.backtrack_coverage_offsets_byte_range(); |
1654 | 0 | self.offset_data() |
1655 | 0 | .read_array(range) |
1656 | 0 | .ok() |
1657 | 0 | .unwrap_or_default() |
1658 | 0 | } |
1659 | | |
1660 | | /// A dynamically resolving wrapper for [`backtrack_coverage_offsets`][Self::backtrack_coverage_offsets]. |
1661 | 0 | pub fn backtrack_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> { |
1662 | 0 | let data = self.offset_data(); |
1663 | 0 | let offsets = self.backtrack_coverage_offsets(); |
1664 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
1665 | 0 | } |
1666 | | |
1667 | | /// Number of glyphs in lookahead sequence. |
1668 | 30.5k | pub fn lookahead_glyph_count(&self) -> u16 { |
1669 | 30.5k | let range = self.lookahead_glyph_count_byte_range(); |
1670 | 30.5k | self.offset_data() |
1671 | 30.5k | .read_at(range.start) |
1672 | 30.5k | .ok() |
1673 | 30.5k | .unwrap_or_default() |
1674 | 30.5k | } |
1675 | | |
1676 | | /// Array of offsets to coverage tables in lookahead sequence, in |
1677 | | /// glyph sequence order. |
1678 | 0 | pub fn lookahead_coverage_offsets(&self) -> &'a [BigEndian<Offset16>] { |
1679 | 0 | let range = self.lookahead_coverage_offsets_byte_range(); |
1680 | 0 | self.offset_data() |
1681 | 0 | .read_array(range) |
1682 | 0 | .ok() |
1683 | 0 | .unwrap_or_default() |
1684 | 0 | } |
1685 | | |
1686 | | /// A dynamically resolving wrapper for [`lookahead_coverage_offsets`][Self::lookahead_coverage_offsets]. |
1687 | 0 | pub fn lookahead_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> { |
1688 | 0 | let data = self.offset_data(); |
1689 | 0 | let offsets = self.lookahead_coverage_offsets(); |
1690 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
1691 | 0 | } |
1692 | | |
1693 | | /// Number of glyph IDs in the substituteGlyphIDs array. |
1694 | 11.8k | pub fn glyph_count(&self) -> u16 { |
1695 | 11.8k | let range = self.glyph_count_byte_range(); |
1696 | 11.8k | self.offset_data() |
1697 | 11.8k | .read_at(range.start) |
1698 | 11.8k | .ok() |
1699 | 11.8k | .unwrap_or_default() |
1700 | 11.8k | } |
1701 | | |
1702 | | /// Array of substitute glyph IDs — ordered by Coverage index. |
1703 | 0 | pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId16>] { |
1704 | 0 | let range = self.substitute_glyph_ids_byte_range(); |
1705 | 0 | self.offset_data() |
1706 | 0 | .read_array(range) |
1707 | 0 | .ok() |
1708 | 0 | .unwrap_or_default() |
1709 | 0 | } |
1710 | | |
1711 | 68.1k | pub fn subst_format_byte_range(&self) -> Range<usize> { |
1712 | 68.1k | let start = 0usize; |
1713 | 68.1k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1714 | 68.1k | start..end |
1715 | 68.1k | } |
1716 | | |
1717 | 68.1k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
1718 | 68.1k | let start = self.subst_format_byte_range().end; |
1719 | 68.1k | let end = start.saturating_add(Offset16::RAW_BYTE_LEN); |
1720 | 68.1k | start..end |
1721 | 68.1k | } |
1722 | | |
1723 | 68.1k | pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> { |
1724 | 68.1k | let start = self.coverage_offset_byte_range().end; |
1725 | 68.1k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1726 | 68.1k | start..end |
1727 | 68.1k | } |
1728 | | |
1729 | 68.1k | pub fn backtrack_coverage_offsets_byte_range(&self) -> Range<usize> { |
1730 | 68.1k | let backtrack_glyph_count = self.backtrack_glyph_count(); |
1731 | 68.1k | let start = self.backtrack_glyph_count_byte_range().end; |
1732 | 68.1k | let end = start.saturating_add( |
1733 | 68.1k | (transforms::to_usize(backtrack_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN), |
1734 | | ); |
1735 | 68.1k | start..end |
1736 | 68.1k | } |
1737 | | |
1738 | 61.0k | pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> { |
1739 | 61.0k | let start = self.backtrack_coverage_offsets_byte_range().end; |
1740 | 61.0k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1741 | 61.0k | start..end |
1742 | 61.0k | } |
1743 | | |
1744 | 30.5k | pub fn lookahead_coverage_offsets_byte_range(&self) -> Range<usize> { |
1745 | 30.5k | let lookahead_glyph_count = self.lookahead_glyph_count(); |
1746 | 30.5k | let start = self.lookahead_glyph_count_byte_range().end; |
1747 | 30.5k | let end = start.saturating_add( |
1748 | 30.5k | (transforms::to_usize(lookahead_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN), |
1749 | | ); |
1750 | 30.5k | start..end |
1751 | 30.5k | } |
1752 | | |
1753 | 23.6k | pub fn glyph_count_byte_range(&self) -> Range<usize> { |
1754 | 23.6k | let start = self.lookahead_coverage_offsets_byte_range().end; |
1755 | 23.6k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1756 | 23.6k | start..end |
1757 | 23.6k | } |
1758 | | |
1759 | 11.8k | pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> { |
1760 | 11.8k | let glyph_count = self.glyph_count(); |
1761 | 11.8k | let start = self.glyph_count_byte_range().end; |
1762 | 11.8k | let end = start.saturating_add( |
1763 | 11.8k | (transforms::to_usize(glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN), |
1764 | | ); |
1765 | 11.8k | start..end |
1766 | 11.8k | } |
1767 | | } |
1768 | | |
1769 | | const _: () = assert!(FontData::default_data_long_enough( |
1770 | | ReverseChainSingleSubstFormat1::MIN_SIZE |
1771 | | )); |
1772 | | |
1773 | | impl Default for ReverseChainSingleSubstFormat1<'_> { |
1774 | 0 | fn default() -> Self { |
1775 | | Self { |
1776 | 0 | data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes()) |
1777 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
1778 | | } |
1779 | 0 | } |
1780 | | } |
1781 | | |
1782 | | impl Format<u16> for SingleSubstFormat3<'_> { |
1783 | | const FORMAT: u16 = 3; |
1784 | | } |
1785 | | |
1786 | | impl<'a> MinByteRange<'a> for SingleSubstFormat3<'a> { |
1787 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1788 | 0 | 0..self.delta_glyph_id_byte_range().end |
1789 | 0 | } |
1790 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1791 | 0 | let range = self.min_byte_range(); |
1792 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1793 | 0 | } |
1794 | | } |
1795 | | |
1796 | | impl ReadArgs for SingleSubstFormat3<'_> { |
1797 | | type Args = (); |
1798 | | } |
1799 | | |
1800 | | impl<'a> FontRead<'a> for SingleSubstFormat3<'a> { |
1801 | 1.00k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1802 | | #[allow(clippy::absurd_extreme_comparisons)] |
1803 | 1.00k | if data.len() < Self::MIN_SIZE { |
1804 | 208 | return Err(ReadError::OutOfBounds); |
1805 | 796 | } |
1806 | 796 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1807 | 0 | return Err(ReadError::OutOfBounds); |
1808 | | }; |
1809 | 796 | Ok(Self { data }) |
1810 | 1.00k | } |
1811 | | } |
1812 | | |
1813 | | /// The fields at the start of the table, which are read directly. |
1814 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1815 | | #[repr(C, packed)] |
1816 | | #[doc(hidden)] |
1817 | | pub struct SingleSubstFormat3FixedHeader { |
1818 | | pub subst_format: BigEndian<u16>, |
1819 | | pub coverage_offset: BigEndian<Offset32>, |
1820 | | pub delta_glyph_id: BigEndian<Int24>, |
1821 | | } |
1822 | | |
1823 | | #[allow(clippy::absurd_extreme_comparisons)] |
1824 | | const _: () = |
1825 | | assert!(std::mem::size_of::<SingleSubstFormat3FixedHeader>() <= SingleSubstFormat3::MIN_SIZE); |
1826 | | |
1827 | | /// SingleSubstFormat3 (ISO/IEC 14496-22:2026). |
1828 | | #[derive(Clone)] |
1829 | | pub struct SingleSubstFormat3<'a> { |
1830 | | data: TableDataRef<'a, SingleSubstFormat3FixedHeader>, |
1831 | | } |
1832 | | |
1833 | | #[allow(clippy::needless_lifetimes)] |
1834 | | impl<'a> SingleSubstFormat3<'a> { |
1835 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Int24::RAW_BYTE_LEN); |
1836 | | basic_table_impls!(impl_the_methods); |
1837 | | |
1838 | | /// Format identifier: format = 3 |
1839 | 0 | pub fn subst_format(&self) -> u16 { |
1840 | 0 | self.data.header().subst_format.get() |
1841 | 0 | } |
1842 | | |
1843 | | /// Offset to Coverage table, from beginning of substitution |
1844 | | /// subtable |
1845 | 796 | pub fn coverage_offset(&self) -> Offset32 { |
1846 | 796 | self.data.header().coverage_offset.get() |
1847 | 796 | } |
1848 | | |
1849 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
1850 | 796 | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
1851 | 796 | let data = self.offset_data(); |
1852 | 796 | self.coverage_offset().resolve(data) |
1853 | 796 | } |
1854 | | |
1855 | | /// Add to original glyph ID to get substitute glyph ID |
1856 | 796 | pub fn delta_glyph_id(&self) -> Int24 { |
1857 | 796 | self.data.header().delta_glyph_id.get() |
1858 | 796 | } |
1859 | | |
1860 | 0 | pub fn subst_format_byte_range(&self) -> Range<usize> { |
1861 | 0 | let start = 0usize; |
1862 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1863 | 0 | start..end |
1864 | 0 | } |
1865 | | |
1866 | 0 | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
1867 | 0 | let start = self.subst_format_byte_range().end; |
1868 | 0 | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
1869 | 0 | start..end |
1870 | 0 | } |
1871 | | |
1872 | 0 | pub fn delta_glyph_id_byte_range(&self) -> Range<usize> { |
1873 | 0 | let start = self.coverage_offset_byte_range().end; |
1874 | 0 | let end = start.saturating_add(Int24::RAW_BYTE_LEN); |
1875 | 0 | start..end |
1876 | 0 | } |
1877 | | } |
1878 | | |
1879 | | impl Format<u16> for SingleSubstFormat4<'_> { |
1880 | | const FORMAT: u16 = 4; |
1881 | | } |
1882 | | |
1883 | | impl<'a> MinByteRange<'a> for SingleSubstFormat4<'a> { |
1884 | 0 | fn min_byte_range(&self) -> Range<usize> { |
1885 | 0 | 0..self.substitute_glyph_ids_byte_range().end |
1886 | 0 | } |
1887 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
1888 | 0 | let range = self.min_byte_range(); |
1889 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
1890 | 0 | } |
1891 | | } |
1892 | | |
1893 | | impl ReadArgs for SingleSubstFormat4<'_> { |
1894 | | type Args = (); |
1895 | | } |
1896 | | |
1897 | | impl<'a> FontRead<'a> for SingleSubstFormat4<'a> { |
1898 | 1.29k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1899 | | #[allow(clippy::absurd_extreme_comparisons)] |
1900 | 1.29k | if data.len() < Self::MIN_SIZE { |
1901 | 207 | return Err(ReadError::OutOfBounds); |
1902 | 1.08k | } |
1903 | 1.08k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
1904 | 0 | return Err(ReadError::OutOfBounds); |
1905 | | }; |
1906 | 1.08k | Ok(Self { data }) |
1907 | 1.29k | } |
1908 | | } |
1909 | | |
1910 | | /// The fields at the start of the table, which are read directly. |
1911 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
1912 | | #[repr(C, packed)] |
1913 | | #[doc(hidden)] |
1914 | | pub struct SingleSubstFormat4FixedHeader { |
1915 | | pub subst_format: BigEndian<u16>, |
1916 | | pub coverage_offset: BigEndian<Offset32>, |
1917 | | pub glyph_count: BigEndian<Uint24>, |
1918 | | } |
1919 | | |
1920 | | #[allow(clippy::absurd_extreme_comparisons)] |
1921 | | const _: () = |
1922 | | assert!(std::mem::size_of::<SingleSubstFormat4FixedHeader>() <= SingleSubstFormat4::MIN_SIZE); |
1923 | | |
1924 | | /// SingleSubstFormat4 (ISO/IEC 14496-22:2026). |
1925 | | #[derive(Clone)] |
1926 | | pub struct SingleSubstFormat4<'a> { |
1927 | | data: TableDataRef<'a, SingleSubstFormat4FixedHeader>, |
1928 | | } |
1929 | | |
1930 | | #[allow(clippy::needless_lifetimes)] |
1931 | | impl<'a> SingleSubstFormat4<'a> { |
1932 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN); |
1933 | | basic_table_impls!(impl_the_methods); |
1934 | | |
1935 | | /// Format identifier: format = 4 |
1936 | 0 | pub fn subst_format(&self) -> u16 { |
1937 | 0 | self.data.header().subst_format.get() |
1938 | 0 | } |
1939 | | |
1940 | | /// Offset to Coverage table, from beginning of substitution |
1941 | | /// subtable |
1942 | 1.08k | pub fn coverage_offset(&self) -> Offset32 { |
1943 | 1.08k | self.data.header().coverage_offset.get() |
1944 | 1.08k | } |
1945 | | |
1946 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
1947 | 1.08k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
1948 | 1.08k | let data = self.offset_data(); |
1949 | 1.08k | self.coverage_offset().resolve(data) |
1950 | 1.08k | } |
1951 | | |
1952 | | /// Number of glyph IDs in the substituteGlyphIDs array |
1953 | 1.08k | pub fn glyph_count(&self) -> Uint24 { |
1954 | 1.08k | self.data.header().glyph_count.get() |
1955 | 1.08k | } |
1956 | | |
1957 | | /// Array of substitute glyph IDs — ordered by Coverage index |
1958 | 0 | pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId24>] { |
1959 | 0 | let range = self.substitute_glyph_ids_byte_range(); |
1960 | 0 | self.offset_data() |
1961 | 0 | .read_array(range) |
1962 | 0 | .ok() |
1963 | 0 | .unwrap_or_default() |
1964 | 0 | } |
1965 | | |
1966 | 1.08k | pub fn subst_format_byte_range(&self) -> Range<usize> { |
1967 | 1.08k | let start = 0usize; |
1968 | 1.08k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
1969 | 1.08k | start..end |
1970 | 1.08k | } |
1971 | | |
1972 | 1.08k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
1973 | 1.08k | let start = self.subst_format_byte_range().end; |
1974 | 1.08k | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
1975 | 1.08k | start..end |
1976 | 1.08k | } |
1977 | | |
1978 | 1.08k | pub fn glyph_count_byte_range(&self) -> Range<usize> { |
1979 | 1.08k | let start = self.coverage_offset_byte_range().end; |
1980 | 1.08k | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
1981 | 1.08k | start..end |
1982 | 1.08k | } |
1983 | | |
1984 | 1.08k | pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> { |
1985 | 1.08k | let glyph_count = self.glyph_count(); |
1986 | 1.08k | let start = self.glyph_count_byte_range().end; |
1987 | 1.08k | let end = start.saturating_add( |
1988 | 1.08k | (transforms::to_usize(glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN), |
1989 | | ); |
1990 | 1.08k | start..end |
1991 | 1.08k | } |
1992 | | } |
1993 | | |
1994 | | impl Format<u16> for MultipleSubstFormat2<'_> { |
1995 | | const FORMAT: u16 = 2; |
1996 | | } |
1997 | | |
1998 | | impl<'a> MinByteRange<'a> for MultipleSubstFormat2<'a> { |
1999 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2000 | 0 | 0..self.sequence_offsets_byte_range().end |
2001 | 0 | } |
2002 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2003 | 0 | let range = self.min_byte_range(); |
2004 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2005 | 0 | } |
2006 | | } |
2007 | | |
2008 | | impl ReadArgs for MultipleSubstFormat2<'_> { |
2009 | | type Args = (); |
2010 | | } |
2011 | | |
2012 | | impl<'a> FontRead<'a> for MultipleSubstFormat2<'a> { |
2013 | 239k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2014 | | #[allow(clippy::absurd_extreme_comparisons)] |
2015 | 239k | if data.len() < Self::MIN_SIZE { |
2016 | 294 | return Err(ReadError::OutOfBounds); |
2017 | 238k | } |
2018 | 238k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2019 | 0 | return Err(ReadError::OutOfBounds); |
2020 | | }; |
2021 | 238k | Ok(Self { data }) |
2022 | 239k | } |
2023 | | } |
2024 | | |
2025 | | /// The fields at the start of the table, which are read directly. |
2026 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2027 | | #[repr(C, packed)] |
2028 | | #[doc(hidden)] |
2029 | | pub struct MultipleSubstFormat2FixedHeader { |
2030 | | pub subst_format: BigEndian<u16>, |
2031 | | pub coverage_offset: BigEndian<Offset32>, |
2032 | | pub sequence_count: BigEndian<Uint24>, |
2033 | | } |
2034 | | |
2035 | | #[allow(clippy::absurd_extreme_comparisons)] |
2036 | | const _: () = assert!( |
2037 | | std::mem::size_of::<MultipleSubstFormat2FixedHeader>() <= MultipleSubstFormat2::MIN_SIZE |
2038 | | ); |
2039 | | |
2040 | | /// MultipleSubstFormat2 (ISO/IEC 14496-22:2026). |
2041 | | #[derive(Clone)] |
2042 | | pub struct MultipleSubstFormat2<'a> { |
2043 | | data: TableDataRef<'a, MultipleSubstFormat2FixedHeader>, |
2044 | | } |
2045 | | |
2046 | | #[allow(clippy::needless_lifetimes)] |
2047 | | impl<'a> MultipleSubstFormat2<'a> { |
2048 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN); |
2049 | | basic_table_impls!(impl_the_methods); |
2050 | | |
2051 | | /// Format identifier: format = 2 |
2052 | 0 | pub fn subst_format(&self) -> u16 { |
2053 | 0 | self.data.header().subst_format.get() |
2054 | 0 | } |
2055 | | |
2056 | | /// Offset to Coverage table, from beginning of substitution |
2057 | | /// subtable |
2058 | 238k | pub fn coverage_offset(&self) -> Offset32 { |
2059 | 238k | self.data.header().coverage_offset.get() |
2060 | 238k | } |
2061 | | |
2062 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
2063 | 238k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
2064 | 238k | let data = self.offset_data(); |
2065 | 238k | self.coverage_offset().resolve(data) |
2066 | 238k | } |
2067 | | |
2068 | | /// Number of Sequence table offsets in the sequenceOffsets array |
2069 | 238k | pub fn sequence_count(&self) -> Uint24 { |
2070 | 238k | self.data.header().sequence_count.get() |
2071 | 238k | } |
2072 | | |
2073 | | /// Array of offsets to Sequence tables. Offsets are from beginning |
2074 | | /// of substitution subtable, ordered by Coverage index |
2075 | 0 | pub fn sequence_offsets(&self) -> &'a [BigEndian<Offset24>] { |
2076 | 0 | let range = self.sequence_offsets_byte_range(); |
2077 | 0 | self.offset_data() |
2078 | 0 | .read_array(range) |
2079 | 0 | .ok() |
2080 | 0 | .unwrap_or_default() |
2081 | 0 | } |
2082 | | |
2083 | | /// A dynamically resolving wrapper for [`sequence_offsets`][Self::sequence_offsets]. |
2084 | 0 | pub fn sequences(&self) -> ArrayOfOffsets<'a, Sequence2<'a>, Offset24> { |
2085 | 0 | let data = self.offset_data(); |
2086 | 0 | let offsets = self.sequence_offsets(); |
2087 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
2088 | 0 | } |
2089 | | |
2090 | 238k | pub fn subst_format_byte_range(&self) -> Range<usize> { |
2091 | 238k | let start = 0usize; |
2092 | 238k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2093 | 238k | start..end |
2094 | 238k | } |
2095 | | |
2096 | 238k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
2097 | 238k | let start = self.subst_format_byte_range().end; |
2098 | 238k | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
2099 | 238k | start..end |
2100 | 238k | } |
2101 | | |
2102 | 238k | pub fn sequence_count_byte_range(&self) -> Range<usize> { |
2103 | 238k | let start = self.coverage_offset_byte_range().end; |
2104 | 238k | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
2105 | 238k | start..end |
2106 | 238k | } |
2107 | | |
2108 | 238k | pub fn sequence_offsets_byte_range(&self) -> Range<usize> { |
2109 | 238k | let sequence_count = self.sequence_count(); |
2110 | 238k | let start = self.sequence_count_byte_range().end; |
2111 | 238k | let end = start.saturating_add( |
2112 | 238k | (transforms::to_usize(sequence_count)).saturating_mul(Offset24::RAW_BYTE_LEN), |
2113 | | ); |
2114 | 238k | start..end |
2115 | 238k | } |
2116 | | } |
2117 | | |
2118 | | impl Format<u16> for AlternateSubstFormat2<'_> { |
2119 | | const FORMAT: u16 = 2; |
2120 | | } |
2121 | | |
2122 | | impl<'a> MinByteRange<'a> for AlternateSubstFormat2<'a> { |
2123 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2124 | 0 | 0..self.alternate_set_offsets_byte_range().end |
2125 | 0 | } |
2126 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2127 | 0 | let range = self.min_byte_range(); |
2128 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2129 | 0 | } |
2130 | | } |
2131 | | |
2132 | | impl ReadArgs for AlternateSubstFormat2<'_> { |
2133 | | type Args = (); |
2134 | | } |
2135 | | |
2136 | | impl<'a> FontRead<'a> for AlternateSubstFormat2<'a> { |
2137 | 1.49k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2138 | | #[allow(clippy::absurd_extreme_comparisons)] |
2139 | 1.49k | if data.len() < Self::MIN_SIZE { |
2140 | 227 | return Err(ReadError::OutOfBounds); |
2141 | 1.26k | } |
2142 | 1.26k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2143 | 0 | return Err(ReadError::OutOfBounds); |
2144 | | }; |
2145 | 1.26k | Ok(Self { data }) |
2146 | 1.49k | } |
2147 | | } |
2148 | | |
2149 | | /// The fields at the start of the table, which are read directly. |
2150 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2151 | | #[repr(C, packed)] |
2152 | | #[doc(hidden)] |
2153 | | pub struct AlternateSubstFormat2FixedHeader { |
2154 | | pub subst_format: BigEndian<u16>, |
2155 | | pub coverage_offset: BigEndian<Offset32>, |
2156 | | pub alternate_set_count: BigEndian<Uint24>, |
2157 | | } |
2158 | | |
2159 | | #[allow(clippy::absurd_extreme_comparisons)] |
2160 | | const _: () = assert!( |
2161 | | std::mem::size_of::<AlternateSubstFormat2FixedHeader>() <= AlternateSubstFormat2::MIN_SIZE |
2162 | | ); |
2163 | | |
2164 | | /// AlternateSubstFormat2 (ISO/IEC 14496-22:2026). |
2165 | | #[derive(Clone)] |
2166 | | pub struct AlternateSubstFormat2<'a> { |
2167 | | data: TableDataRef<'a, AlternateSubstFormat2FixedHeader>, |
2168 | | } |
2169 | | |
2170 | | #[allow(clippy::needless_lifetimes)] |
2171 | | impl<'a> AlternateSubstFormat2<'a> { |
2172 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN); |
2173 | | basic_table_impls!(impl_the_methods); |
2174 | | |
2175 | | /// Format identifier: format = 2 |
2176 | 0 | pub fn subst_format(&self) -> u16 { |
2177 | 0 | self.data.header().subst_format.get() |
2178 | 0 | } |
2179 | | |
2180 | | /// Offset to Coverage table, from beginning of substitution |
2181 | | /// subtable |
2182 | 1.26k | pub fn coverage_offset(&self) -> Offset32 { |
2183 | 1.26k | self.data.header().coverage_offset.get() |
2184 | 1.26k | } |
2185 | | |
2186 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
2187 | 1.26k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
2188 | 1.26k | let data = self.offset_data(); |
2189 | 1.26k | self.coverage_offset().resolve(data) |
2190 | 1.26k | } |
2191 | | |
2192 | | /// Number of AlternateSet tables |
2193 | 1.26k | pub fn alternate_set_count(&self) -> Uint24 { |
2194 | 1.26k | self.data.header().alternate_set_count.get() |
2195 | 1.26k | } |
2196 | | |
2197 | | /// Array of offsets to AlternateSet tables. Offsets are from |
2198 | | /// beginning of substitution subtable, ordered by Coverage index |
2199 | 0 | pub fn alternate_set_offsets(&self) -> &'a [BigEndian<Offset24>] { |
2200 | 0 | let range = self.alternate_set_offsets_byte_range(); |
2201 | 0 | self.offset_data() |
2202 | 0 | .read_array(range) |
2203 | 0 | .ok() |
2204 | 0 | .unwrap_or_default() |
2205 | 0 | } |
2206 | | |
2207 | | /// A dynamically resolving wrapper for [`alternate_set_offsets`][Self::alternate_set_offsets]. |
2208 | 0 | pub fn alternate_sets(&self) -> ArrayOfOffsets<'a, AlternateSet2<'a>, Offset24> { |
2209 | 0 | let data = self.offset_data(); |
2210 | 0 | let offsets = self.alternate_set_offsets(); |
2211 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
2212 | 0 | } |
2213 | | |
2214 | 1.26k | pub fn subst_format_byte_range(&self) -> Range<usize> { |
2215 | 1.26k | let start = 0usize; |
2216 | 1.26k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2217 | 1.26k | start..end |
2218 | 1.26k | } |
2219 | | |
2220 | 1.26k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
2221 | 1.26k | let start = self.subst_format_byte_range().end; |
2222 | 1.26k | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
2223 | 1.26k | start..end |
2224 | 1.26k | } |
2225 | | |
2226 | 1.26k | pub fn alternate_set_count_byte_range(&self) -> Range<usize> { |
2227 | 1.26k | let start = self.coverage_offset_byte_range().end; |
2228 | 1.26k | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
2229 | 1.26k | start..end |
2230 | 1.26k | } |
2231 | | |
2232 | 1.26k | pub fn alternate_set_offsets_byte_range(&self) -> Range<usize> { |
2233 | 1.26k | let alternate_set_count = self.alternate_set_count(); |
2234 | 1.26k | let start = self.alternate_set_count_byte_range().end; |
2235 | 1.26k | let end = start.saturating_add( |
2236 | 1.26k | (transforms::to_usize(alternate_set_count)).saturating_mul(Offset24::RAW_BYTE_LEN), |
2237 | | ); |
2238 | 1.26k | start..end |
2239 | 1.26k | } |
2240 | | } |
2241 | | |
2242 | | impl Format<u16> for LigatureSubstFormat2<'_> { |
2243 | | const FORMAT: u16 = 2; |
2244 | | } |
2245 | | |
2246 | | impl<'a> MinByteRange<'a> for LigatureSubstFormat2<'a> { |
2247 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2248 | 0 | 0..self.ligature_set_offsets_byte_range().end |
2249 | 0 | } |
2250 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2251 | 0 | let range = self.min_byte_range(); |
2252 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2253 | 0 | } |
2254 | | } |
2255 | | |
2256 | | impl ReadArgs for LigatureSubstFormat2<'_> { |
2257 | | type Args = (); |
2258 | | } |
2259 | | |
2260 | | impl<'a> FontRead<'a> for LigatureSubstFormat2<'a> { |
2261 | 11.5k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2262 | | #[allow(clippy::absurd_extreme_comparisons)] |
2263 | 11.5k | if data.len() < Self::MIN_SIZE { |
2264 | 281 | return Err(ReadError::OutOfBounds); |
2265 | 11.2k | } |
2266 | 11.2k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2267 | 0 | return Err(ReadError::OutOfBounds); |
2268 | | }; |
2269 | 11.2k | Ok(Self { data }) |
2270 | 11.5k | } |
2271 | | } |
2272 | | |
2273 | | /// The fields at the start of the table, which are read directly. |
2274 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2275 | | #[repr(C, packed)] |
2276 | | #[doc(hidden)] |
2277 | | pub struct LigatureSubstFormat2FixedHeader { |
2278 | | pub subst_format: BigEndian<u16>, |
2279 | | pub coverage_offset: BigEndian<Offset32>, |
2280 | | pub ligature_set_count: BigEndian<Uint24>, |
2281 | | } |
2282 | | |
2283 | | #[allow(clippy::absurd_extreme_comparisons)] |
2284 | | const _: () = assert!( |
2285 | | std::mem::size_of::<LigatureSubstFormat2FixedHeader>() <= LigatureSubstFormat2::MIN_SIZE |
2286 | | ); |
2287 | | |
2288 | | /// LigatureSubstFormat2 (ISO/IEC 14496-22:2026). |
2289 | | #[derive(Clone)] |
2290 | | pub struct LigatureSubstFormat2<'a> { |
2291 | | data: TableDataRef<'a, LigatureSubstFormat2FixedHeader>, |
2292 | | } |
2293 | | |
2294 | | #[allow(clippy::needless_lifetimes)] |
2295 | | impl<'a> LigatureSubstFormat2<'a> { |
2296 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN); |
2297 | | basic_table_impls!(impl_the_methods); |
2298 | | |
2299 | | /// Format identifier: format = 2 |
2300 | 0 | pub fn subst_format(&self) -> u16 { |
2301 | 0 | self.data.header().subst_format.get() |
2302 | 0 | } |
2303 | | |
2304 | | /// Offset to Coverage table, from beginning of substitution |
2305 | | /// subtable |
2306 | 11.2k | pub fn coverage_offset(&self) -> Offset32 { |
2307 | 11.2k | self.data.header().coverage_offset.get() |
2308 | 11.2k | } |
2309 | | |
2310 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
2311 | 11.2k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
2312 | 11.2k | let data = self.offset_data(); |
2313 | 11.2k | self.coverage_offset().resolve(data) |
2314 | 11.2k | } |
2315 | | |
2316 | | /// Number of LigatureSet tables |
2317 | 11.2k | pub fn ligature_set_count(&self) -> Uint24 { |
2318 | 11.2k | self.data.header().ligature_set_count.get() |
2319 | 11.2k | } |
2320 | | |
2321 | | /// Array of offsets to LigatureSet tables. Offsets are from |
2322 | | /// beginning of substitution subtable, ordered by Coverage index |
2323 | 0 | pub fn ligature_set_offsets(&self) -> &'a [BigEndian<Offset24>] { |
2324 | 0 | let range = self.ligature_set_offsets_byte_range(); |
2325 | 0 | self.offset_data() |
2326 | 0 | .read_array(range) |
2327 | 0 | .ok() |
2328 | 0 | .unwrap_or_default() |
2329 | 0 | } |
2330 | | |
2331 | | /// A dynamically resolving wrapper for [`ligature_set_offsets`][Self::ligature_set_offsets]. |
2332 | 0 | pub fn ligature_sets(&self) -> ArrayOfOffsets<'a, LigatureSet2<'a>, Offset24> { |
2333 | 0 | let data = self.offset_data(); |
2334 | 0 | let offsets = self.ligature_set_offsets(); |
2335 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
2336 | 0 | } |
2337 | | |
2338 | 11.2k | pub fn subst_format_byte_range(&self) -> Range<usize> { |
2339 | 11.2k | let start = 0usize; |
2340 | 11.2k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2341 | 11.2k | start..end |
2342 | 11.2k | } |
2343 | | |
2344 | 11.2k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
2345 | 11.2k | let start = self.subst_format_byte_range().end; |
2346 | 11.2k | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
2347 | 11.2k | start..end |
2348 | 11.2k | } |
2349 | | |
2350 | 11.2k | pub fn ligature_set_count_byte_range(&self) -> Range<usize> { |
2351 | 11.2k | let start = self.coverage_offset_byte_range().end; |
2352 | 11.2k | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
2353 | 11.2k | start..end |
2354 | 11.2k | } |
2355 | | |
2356 | 11.2k | pub fn ligature_set_offsets_byte_range(&self) -> Range<usize> { |
2357 | 11.2k | let ligature_set_count = self.ligature_set_count(); |
2358 | 11.2k | let start = self.ligature_set_count_byte_range().end; |
2359 | 11.2k | let end = start.saturating_add( |
2360 | 11.2k | (transforms::to_usize(ligature_set_count)).saturating_mul(Offset24::RAW_BYTE_LEN), |
2361 | | ); |
2362 | 11.2k | start..end |
2363 | 11.2k | } |
2364 | | } |
2365 | | |
2366 | | impl Format<u16> for ReverseChainSingleSubstFormat2<'_> { |
2367 | | const FORMAT: u16 = 2; |
2368 | | } |
2369 | | |
2370 | | impl<'a> MinByteRange<'a> for ReverseChainSingleSubstFormat2<'a> { |
2371 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2372 | 0 | 0..self.substitute_glyph_ids_byte_range().end |
2373 | 0 | } |
2374 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2375 | 0 | let range = self.min_byte_range(); |
2376 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2377 | 0 | } |
2378 | | } |
2379 | | |
2380 | | impl ReadArgs for ReverseChainSingleSubstFormat2<'_> { |
2381 | | type Args = (); |
2382 | | } |
2383 | | |
2384 | | impl<'a> FontRead<'a> for ReverseChainSingleSubstFormat2<'a> { |
2385 | 6.76k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2386 | | #[allow(clippy::absurd_extreme_comparisons)] |
2387 | 6.76k | if data.len() < Self::MIN_SIZE { |
2388 | 259 | return Err(ReadError::OutOfBounds); |
2389 | 6.50k | } |
2390 | 6.50k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2391 | 0 | return Err(ReadError::OutOfBounds); |
2392 | | }; |
2393 | 6.50k | Ok(Self { data }) |
2394 | 6.76k | } |
2395 | | } |
2396 | | |
2397 | | /// The fields at the start of the table, which are read directly. |
2398 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2399 | | #[repr(C, packed)] |
2400 | | #[doc(hidden)] |
2401 | | pub struct ReverseChainSingleSubstFormat2FixedHeader { |
2402 | | pub subst_format: BigEndian<u16>, |
2403 | | pub coverage_offset: BigEndian<Offset32>, |
2404 | | pub backtrack_glyph_count: BigEndian<u16>, |
2405 | | } |
2406 | | |
2407 | | #[allow(clippy::absurd_extreme_comparisons)] |
2408 | | const _: () = assert!( |
2409 | | std::mem::size_of::<ReverseChainSingleSubstFormat2FixedHeader>() |
2410 | | <= ReverseChainSingleSubstFormat2::MIN_SIZE |
2411 | | ); |
2412 | | |
2413 | | /// ReverseChainSingleSubstFormat2 (ISO/IEC 14496-22:2026). |
2414 | | #[derive(Clone)] |
2415 | | pub struct ReverseChainSingleSubstFormat2<'a> { |
2416 | | data: TableDataRef<'a, ReverseChainSingleSubstFormat2FixedHeader>, |
2417 | | } |
2418 | | |
2419 | | #[allow(clippy::needless_lifetimes)] |
2420 | | impl<'a> ReverseChainSingleSubstFormat2<'a> { |
2421 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN |
2422 | | + Offset32::RAW_BYTE_LEN |
2423 | | + u16::RAW_BYTE_LEN |
2424 | | + u16::RAW_BYTE_LEN |
2425 | | + Uint24::RAW_BYTE_LEN); |
2426 | | basic_table_impls!(impl_the_methods); |
2427 | | |
2428 | | /// Format identifier: format = 2 |
2429 | 0 | pub fn subst_format(&self) -> u16 { |
2430 | 0 | self.data.header().subst_format.get() |
2431 | 0 | } |
2432 | | |
2433 | | /// Offset to Coverage table, from beginning of substitution |
2434 | | /// subtable. |
2435 | 6.50k | pub fn coverage_offset(&self) -> Offset32 { |
2436 | 6.50k | self.data.header().coverage_offset.get() |
2437 | 6.50k | } |
2438 | | |
2439 | | /// Attempt to resolve [`coverage_offset`][Self::coverage_offset]. |
2440 | 6.50k | pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> { |
2441 | 6.50k | let data = self.offset_data(); |
2442 | 6.50k | self.coverage_offset().resolve(data) |
2443 | 6.50k | } |
2444 | | |
2445 | | /// Number of glyphs in the backtrack sequence. |
2446 | 31.1k | pub fn backtrack_glyph_count(&self) -> u16 { |
2447 | 31.1k | self.data.header().backtrack_glyph_count.get() |
2448 | 31.1k | } |
2449 | | |
2450 | | /// Array of offsets to coverage tables in backtrack sequence, in |
2451 | | /// glyph sequence order. |
2452 | 0 | pub fn backtrack_coverage_offsets(&self) -> &'a [BigEndian<Offset24>] { |
2453 | 0 | let range = self.backtrack_coverage_offsets_byte_range(); |
2454 | 0 | self.offset_data() |
2455 | 0 | .read_array(range) |
2456 | 0 | .ok() |
2457 | 0 | .unwrap_or_default() |
2458 | 0 | } |
2459 | | |
2460 | | /// A dynamically resolving wrapper for [`backtrack_coverage_offsets`][Self::backtrack_coverage_offsets]. |
2461 | 0 | pub fn backtrack_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset24> { |
2462 | 0 | let data = self.offset_data(); |
2463 | 0 | let offsets = self.backtrack_coverage_offsets(); |
2464 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
2465 | 0 | } |
2466 | | |
2467 | | /// Number of glyphs in lookahead sequence. |
2468 | 14.7k | pub fn lookahead_glyph_count(&self) -> u16 { |
2469 | 14.7k | let range = self.lookahead_glyph_count_byte_range(); |
2470 | 14.7k | self.offset_data() |
2471 | 14.7k | .read_at(range.start) |
2472 | 14.7k | .ok() |
2473 | 14.7k | .unwrap_or_default() |
2474 | 14.7k | } |
2475 | | |
2476 | | /// Array of offsets to coverage tables in lookahead sequence, in |
2477 | | /// glyph sequence order. |
2478 | 0 | pub fn lookahead_coverage_offsets(&self) -> &'a [BigEndian<Offset24>] { |
2479 | 0 | let range = self.lookahead_coverage_offsets_byte_range(); |
2480 | 0 | self.offset_data() |
2481 | 0 | .read_array(range) |
2482 | 0 | .ok() |
2483 | 0 | .unwrap_or_default() |
2484 | 0 | } |
2485 | | |
2486 | | /// A dynamically resolving wrapper for [`lookahead_coverage_offsets`][Self::lookahead_coverage_offsets]. |
2487 | 0 | pub fn lookahead_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset24> { |
2488 | 0 | let data = self.offset_data(); |
2489 | 0 | let offsets = self.lookahead_coverage_offsets(); |
2490 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
2491 | 0 | } |
2492 | | |
2493 | | /// Number of glyph IDs in the substituteGlyphIDs array. |
2494 | 6.50k | pub fn glyph_count(&self) -> Uint24 { |
2495 | 6.50k | let range = self.glyph_count_byte_range(); |
2496 | 6.50k | self.offset_data() |
2497 | 6.50k | .read_at(range.start) |
2498 | 6.50k | .ok() |
2499 | 6.50k | .unwrap_or_default() |
2500 | 6.50k | } |
2501 | | |
2502 | | /// Array of substitute glyph IDs — ordered by Coverage index. |
2503 | 0 | pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId24>] { |
2504 | 0 | let range = self.substitute_glyph_ids_byte_range(); |
2505 | 0 | self.offset_data() |
2506 | 0 | .read_array(range) |
2507 | 0 | .ok() |
2508 | 0 | .unwrap_or_default() |
2509 | 0 | } |
2510 | | |
2511 | 31.1k | pub fn subst_format_byte_range(&self) -> Range<usize> { |
2512 | 31.1k | let start = 0usize; |
2513 | 31.1k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2514 | 31.1k | start..end |
2515 | 31.1k | } |
2516 | | |
2517 | 31.1k | pub fn coverage_offset_byte_range(&self) -> Range<usize> { |
2518 | 31.1k | let start = self.subst_format_byte_range().end; |
2519 | 31.1k | let end = start.saturating_add(Offset32::RAW_BYTE_LEN); |
2520 | 31.1k | start..end |
2521 | 31.1k | } |
2522 | | |
2523 | 31.1k | pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> { |
2524 | 31.1k | let start = self.coverage_offset_byte_range().end; |
2525 | 31.1k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2526 | 31.1k | start..end |
2527 | 31.1k | } |
2528 | | |
2529 | 31.1k | pub fn backtrack_coverage_offsets_byte_range(&self) -> Range<usize> { |
2530 | 31.1k | let backtrack_glyph_count = self.backtrack_glyph_count(); |
2531 | 31.1k | let start = self.backtrack_glyph_count_byte_range().end; |
2532 | 31.1k | let end = start.saturating_add( |
2533 | 31.1k | (transforms::to_usize(backtrack_glyph_count)).saturating_mul(Offset24::RAW_BYTE_LEN), |
2534 | | ); |
2535 | 31.1k | start..end |
2536 | 31.1k | } |
2537 | | |
2538 | 29.4k | pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> { |
2539 | 29.4k | let start = self.backtrack_coverage_offsets_byte_range().end; |
2540 | 29.4k | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2541 | 29.4k | start..end |
2542 | 29.4k | } |
2543 | | |
2544 | 14.7k | pub fn lookahead_coverage_offsets_byte_range(&self) -> Range<usize> { |
2545 | 14.7k | let lookahead_glyph_count = self.lookahead_glyph_count(); |
2546 | 14.7k | let start = self.lookahead_glyph_count_byte_range().end; |
2547 | 14.7k | let end = start.saturating_add( |
2548 | 14.7k | (transforms::to_usize(lookahead_glyph_count)).saturating_mul(Offset24::RAW_BYTE_LEN), |
2549 | | ); |
2550 | 14.7k | start..end |
2551 | 14.7k | } |
2552 | | |
2553 | 13.0k | pub fn glyph_count_byte_range(&self) -> Range<usize> { |
2554 | 13.0k | let start = self.lookahead_coverage_offsets_byte_range().end; |
2555 | 13.0k | let end = start.saturating_add(Uint24::RAW_BYTE_LEN); |
2556 | 13.0k | start..end |
2557 | 13.0k | } |
2558 | | |
2559 | 6.50k | pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> { |
2560 | 6.50k | let glyph_count = self.glyph_count(); |
2561 | 6.50k | let start = self.glyph_count_byte_range().end; |
2562 | 6.50k | let end = start.saturating_add( |
2563 | 6.50k | (transforms::to_usize(glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN), |
2564 | | ); |
2565 | 6.50k | start..end |
2566 | 6.50k | } |
2567 | | } |
2568 | | |
2569 | | impl<'a> MinByteRange<'a> for Sequence2<'a> { |
2570 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2571 | 0 | 0..self.substitute_glyph_ids_byte_range().end |
2572 | 0 | } |
2573 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2574 | 0 | let range = self.min_byte_range(); |
2575 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2576 | 0 | } |
2577 | | } |
2578 | | |
2579 | | impl ReadArgs for Sequence2<'_> { |
2580 | | type Args = (); |
2581 | | } |
2582 | | |
2583 | | impl<'a> FontRead<'a> for Sequence2<'a> { |
2584 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2585 | | #[allow(clippy::absurd_extreme_comparisons)] |
2586 | 0 | if data.len() < Self::MIN_SIZE { |
2587 | 0 | return Err(ReadError::OutOfBounds); |
2588 | 0 | } |
2589 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2590 | 0 | return Err(ReadError::OutOfBounds); |
2591 | | }; |
2592 | 0 | Ok(Self { data }) |
2593 | 0 | } |
2594 | | } |
2595 | | |
2596 | | /// The fields at the start of the table, which are read directly. |
2597 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2598 | | #[repr(C, packed)] |
2599 | | #[doc(hidden)] |
2600 | | pub struct Sequence2FixedHeader { |
2601 | | pub glyph_count: BigEndian<u16>, |
2602 | | } |
2603 | | |
2604 | | #[allow(clippy::absurd_extreme_comparisons)] |
2605 | | const _: () = assert!(std::mem::size_of::<Sequence2FixedHeader>() <= Sequence2::MIN_SIZE); |
2606 | | |
2607 | | /// Sequence2 (ISO/IEC 14496-22:2026). |
2608 | | #[derive(Clone)] |
2609 | | pub struct Sequence2<'a> { |
2610 | | data: TableDataRef<'a, Sequence2FixedHeader>, |
2611 | | } |
2612 | | |
2613 | | #[allow(clippy::needless_lifetimes)] |
2614 | | impl<'a> Sequence2<'a> { |
2615 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
2616 | | basic_table_impls!(impl_the_methods); |
2617 | | |
2618 | | /// Number of glyph IDs in the substituteGlyphIDs array. This must |
2619 | | /// always be greater than 0. |
2620 | 0 | pub fn glyph_count(&self) -> u16 { |
2621 | 0 | self.data.header().glyph_count.get() |
2622 | 0 | } |
2623 | | |
2624 | | /// String of glyph IDs to substitute |
2625 | 0 | pub fn substitute_glyph_ids(&self) -> &'a [BigEndian<GlyphId24>] { |
2626 | 0 | let range = self.substitute_glyph_ids_byte_range(); |
2627 | 0 | self.offset_data() |
2628 | 0 | .read_array(range) |
2629 | 0 | .ok() |
2630 | 0 | .unwrap_or_default() |
2631 | 0 | } |
2632 | | |
2633 | 0 | pub fn glyph_count_byte_range(&self) -> Range<usize> { |
2634 | 0 | let start = 0usize; |
2635 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2636 | 0 | start..end |
2637 | 0 | } |
2638 | | |
2639 | 0 | pub fn substitute_glyph_ids_byte_range(&self) -> Range<usize> { |
2640 | 0 | let glyph_count = self.glyph_count(); |
2641 | 0 | let start = self.glyph_count_byte_range().end; |
2642 | 0 | let end = start.saturating_add( |
2643 | 0 | (transforms::to_usize(glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN), |
2644 | | ); |
2645 | 0 | start..end |
2646 | 0 | } |
2647 | | } |
2648 | | |
2649 | | const _: () = assert!(FontData::default_data_long_enough(Sequence2::MIN_SIZE)); |
2650 | | |
2651 | | impl Default for Sequence2<'_> { |
2652 | 0 | fn default() -> Self { |
2653 | | Self { |
2654 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
2655 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
2656 | | } |
2657 | 0 | } |
2658 | | } |
2659 | | |
2660 | | impl<'a> MinByteRange<'a> for AlternateSet2<'a> { |
2661 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2662 | 0 | 0..self.alternate_glyph_ids_byte_range().end |
2663 | 0 | } |
2664 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2665 | 0 | let range = self.min_byte_range(); |
2666 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2667 | 0 | } |
2668 | | } |
2669 | | |
2670 | | impl ReadArgs for AlternateSet2<'_> { |
2671 | | type Args = (); |
2672 | | } |
2673 | | |
2674 | | impl<'a> FontRead<'a> for AlternateSet2<'a> { |
2675 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2676 | | #[allow(clippy::absurd_extreme_comparisons)] |
2677 | 0 | if data.len() < Self::MIN_SIZE { |
2678 | 0 | return Err(ReadError::OutOfBounds); |
2679 | 0 | } |
2680 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2681 | 0 | return Err(ReadError::OutOfBounds); |
2682 | | }; |
2683 | 0 | Ok(Self { data }) |
2684 | 0 | } |
2685 | | } |
2686 | | |
2687 | | /// The fields at the start of the table, which are read directly. |
2688 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2689 | | #[repr(C, packed)] |
2690 | | #[doc(hidden)] |
2691 | | pub struct AlternateSet2FixedHeader { |
2692 | | pub glyph_count: BigEndian<u16>, |
2693 | | } |
2694 | | |
2695 | | #[allow(clippy::absurd_extreme_comparisons)] |
2696 | | const _: () = assert!(std::mem::size_of::<AlternateSet2FixedHeader>() <= AlternateSet2::MIN_SIZE); |
2697 | | |
2698 | | /// AlternateSet2 (ISO/IEC 14496-22:2026). |
2699 | | #[derive(Clone)] |
2700 | | pub struct AlternateSet2<'a> { |
2701 | | data: TableDataRef<'a, AlternateSet2FixedHeader>, |
2702 | | } |
2703 | | |
2704 | | #[allow(clippy::needless_lifetimes)] |
2705 | | impl<'a> AlternateSet2<'a> { |
2706 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
2707 | | basic_table_impls!(impl_the_methods); |
2708 | | |
2709 | | /// Number of glyph IDs in the alternateGlyphIDs array |
2710 | 0 | pub fn glyph_count(&self) -> u16 { |
2711 | 0 | self.data.header().glyph_count.get() |
2712 | 0 | } |
2713 | | |
2714 | | /// Array of alternate glyph IDs, in arbitrary order |
2715 | 0 | pub fn alternate_glyph_ids(&self) -> &'a [BigEndian<GlyphId24>] { |
2716 | 0 | let range = self.alternate_glyph_ids_byte_range(); |
2717 | 0 | self.offset_data() |
2718 | 0 | .read_array(range) |
2719 | 0 | .ok() |
2720 | 0 | .unwrap_or_default() |
2721 | 0 | } |
2722 | | |
2723 | 0 | pub fn glyph_count_byte_range(&self) -> Range<usize> { |
2724 | 0 | let start = 0usize; |
2725 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2726 | 0 | start..end |
2727 | 0 | } |
2728 | | |
2729 | 0 | pub fn alternate_glyph_ids_byte_range(&self) -> Range<usize> { |
2730 | 0 | let glyph_count = self.glyph_count(); |
2731 | 0 | let start = self.glyph_count_byte_range().end; |
2732 | 0 | let end = start.saturating_add( |
2733 | 0 | (transforms::to_usize(glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN), |
2734 | | ); |
2735 | 0 | start..end |
2736 | 0 | } |
2737 | | } |
2738 | | |
2739 | | const _: () = assert!(FontData::default_data_long_enough(AlternateSet2::MIN_SIZE)); |
2740 | | |
2741 | | impl Default for AlternateSet2<'_> { |
2742 | 0 | fn default() -> Self { |
2743 | | Self { |
2744 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
2745 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
2746 | | } |
2747 | 0 | } |
2748 | | } |
2749 | | |
2750 | | impl<'a> MinByteRange<'a> for LigatureSet2<'a> { |
2751 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2752 | 0 | 0..self.ligature_offsets_byte_range().end |
2753 | 0 | } |
2754 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2755 | 0 | let range = self.min_byte_range(); |
2756 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2757 | 0 | } |
2758 | | } |
2759 | | |
2760 | | impl ReadArgs for LigatureSet2<'_> { |
2761 | | type Args = (); |
2762 | | } |
2763 | | |
2764 | | impl<'a> FontRead<'a> for LigatureSet2<'a> { |
2765 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2766 | | #[allow(clippy::absurd_extreme_comparisons)] |
2767 | 0 | if data.len() < Self::MIN_SIZE { |
2768 | 0 | return Err(ReadError::OutOfBounds); |
2769 | 0 | } |
2770 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2771 | 0 | return Err(ReadError::OutOfBounds); |
2772 | | }; |
2773 | 0 | Ok(Self { data }) |
2774 | 0 | } |
2775 | | } |
2776 | | |
2777 | | /// The fields at the start of the table, which are read directly. |
2778 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2779 | | #[repr(C, packed)] |
2780 | | #[doc(hidden)] |
2781 | | pub struct LigatureSet2FixedHeader { |
2782 | | pub ligature_count: BigEndian<u16>, |
2783 | | } |
2784 | | |
2785 | | #[allow(clippy::absurd_extreme_comparisons)] |
2786 | | const _: () = assert!(std::mem::size_of::<LigatureSet2FixedHeader>() <= LigatureSet2::MIN_SIZE); |
2787 | | |
2788 | | /// LigatureSet2 (ISO/IEC 14496-22:2026). |
2789 | | #[derive(Clone)] |
2790 | | pub struct LigatureSet2<'a> { |
2791 | | data: TableDataRef<'a, LigatureSet2FixedHeader>, |
2792 | | } |
2793 | | |
2794 | | #[allow(clippy::needless_lifetimes)] |
2795 | | impl<'a> LigatureSet2<'a> { |
2796 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
2797 | | basic_table_impls!(impl_the_methods); |
2798 | | |
2799 | | /// Number of Ligature tables |
2800 | 0 | pub fn ligature_count(&self) -> u16 { |
2801 | 0 | self.data.header().ligature_count.get() |
2802 | 0 | } |
2803 | | |
2804 | | /// Array of offsets to Ligature tables. Offsets are from beginning |
2805 | | /// of LigatureSet2 table, ordered by preference. |
2806 | 0 | pub fn ligature_offsets(&self) -> &'a [BigEndian<Offset24>] { |
2807 | 0 | let range = self.ligature_offsets_byte_range(); |
2808 | 0 | self.offset_data() |
2809 | 0 | .read_array(range) |
2810 | 0 | .ok() |
2811 | 0 | .unwrap_or_default() |
2812 | 0 | } |
2813 | | |
2814 | | /// A dynamically resolving wrapper for [`ligature_offsets`][Self::ligature_offsets]. |
2815 | 0 | pub fn ligatures(&self) -> ArrayOfOffsets<'a, Ligature2<'a>, Offset24> { |
2816 | 0 | let data = self.offset_data(); |
2817 | 0 | let offsets = self.ligature_offsets(); |
2818 | 0 | ArrayOfOffsets::new(offsets, data, ()) |
2819 | 0 | } |
2820 | | |
2821 | 0 | pub fn ligature_count_byte_range(&self) -> Range<usize> { |
2822 | 0 | let start = 0usize; |
2823 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2824 | 0 | start..end |
2825 | 0 | } |
2826 | | |
2827 | 0 | pub fn ligature_offsets_byte_range(&self) -> Range<usize> { |
2828 | 0 | let ligature_count = self.ligature_count(); |
2829 | 0 | let start = self.ligature_count_byte_range().end; |
2830 | 0 | let end = start.saturating_add( |
2831 | 0 | (transforms::to_usize(ligature_count)).saturating_mul(Offset24::RAW_BYTE_LEN), |
2832 | | ); |
2833 | 0 | start..end |
2834 | 0 | } |
2835 | | } |
2836 | | |
2837 | | const _: () = assert!(FontData::default_data_long_enough(LigatureSet2::MIN_SIZE)); |
2838 | | |
2839 | | impl Default for LigatureSet2<'_> { |
2840 | 0 | fn default() -> Self { |
2841 | | Self { |
2842 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
2843 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
2844 | | } |
2845 | 0 | } |
2846 | | } |
2847 | | |
2848 | | impl<'a> MinByteRange<'a> for Ligature2<'a> { |
2849 | 0 | fn min_byte_range(&self) -> Range<usize> { |
2850 | 0 | 0..self.component_glyph_ids_byte_range().end |
2851 | 0 | } |
2852 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
2853 | 0 | let range = self.min_byte_range(); |
2854 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
2855 | 0 | } |
2856 | | } |
2857 | | |
2858 | | impl ReadArgs for Ligature2<'_> { |
2859 | | type Args = (); |
2860 | | } |
2861 | | |
2862 | | impl<'a> FontRead<'a> for Ligature2<'a> { |
2863 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2864 | | #[allow(clippy::absurd_extreme_comparisons)] |
2865 | 0 | if data.len() < Self::MIN_SIZE { |
2866 | 0 | return Err(ReadError::OutOfBounds); |
2867 | 0 | } |
2868 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
2869 | 0 | return Err(ReadError::OutOfBounds); |
2870 | | }; |
2871 | 0 | Ok(Self { data }) |
2872 | 0 | } |
2873 | | } |
2874 | | |
2875 | | /// The fields at the start of the table, which are read directly. |
2876 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
2877 | | #[repr(C, packed)] |
2878 | | #[doc(hidden)] |
2879 | | pub struct Ligature2FixedHeader { |
2880 | | pub ligature_glyph: BigEndian<GlyphId24>, |
2881 | | pub component_count: BigEndian<u16>, |
2882 | | } |
2883 | | |
2884 | | #[allow(clippy::absurd_extreme_comparisons)] |
2885 | | const _: () = assert!(std::mem::size_of::<Ligature2FixedHeader>() <= Ligature2::MIN_SIZE); |
2886 | | |
2887 | | /// Ligature2 (ISO/IEC 14496-22:2026). |
2888 | | #[derive(Clone)] |
2889 | | pub struct Ligature2<'a> { |
2890 | | data: TableDataRef<'a, Ligature2FixedHeader>, |
2891 | | } |
2892 | | |
2893 | | #[allow(clippy::needless_lifetimes)] |
2894 | | impl<'a> Ligature2<'a> { |
2895 | | pub const MIN_SIZE: usize = (GlyphId24::RAW_BYTE_LEN + u16::RAW_BYTE_LEN); |
2896 | | basic_table_impls!(impl_the_methods); |
2897 | | |
2898 | | /// glyph ID of ligature to substitute |
2899 | 0 | pub fn ligature_glyph(&self) -> GlyphId24 { |
2900 | 0 | self.data.header().ligature_glyph.get() |
2901 | 0 | } |
2902 | | |
2903 | | /// Number of components in the ligature |
2904 | 0 | pub fn component_count(&self) -> u16 { |
2905 | 0 | self.data.header().component_count.get() |
2906 | 0 | } |
2907 | | |
2908 | | /// Array of component glyph IDs — start with the second |
2909 | | /// component, ordered in writing direction |
2910 | 0 | pub fn component_glyph_ids(&self) -> &'a [BigEndian<GlyphId24>] { |
2911 | 0 | let range = self.component_glyph_ids_byte_range(); |
2912 | 0 | self.offset_data() |
2913 | 0 | .read_array(range) |
2914 | 0 | .ok() |
2915 | 0 | .unwrap_or_default() |
2916 | 0 | } |
2917 | | |
2918 | 0 | pub fn ligature_glyph_byte_range(&self) -> Range<usize> { |
2919 | 0 | let start = 0usize; |
2920 | 0 | let end = start.saturating_add(GlyphId24::RAW_BYTE_LEN); |
2921 | 0 | start..end |
2922 | 0 | } |
2923 | | |
2924 | 0 | pub fn component_count_byte_range(&self) -> Range<usize> { |
2925 | 0 | let start = self.ligature_glyph_byte_range().end; |
2926 | 0 | let end = start.saturating_add(u16::RAW_BYTE_LEN); |
2927 | 0 | start..end |
2928 | 0 | } |
2929 | | |
2930 | 0 | pub fn component_glyph_ids_byte_range(&self) -> Range<usize> { |
2931 | 0 | let component_count = self.component_count(); |
2932 | 0 | let start = self.component_count_byte_range().end; |
2933 | 0 | let end = start.saturating_add( |
2934 | 0 | (transforms::subtract(component_count, 1_usize)) |
2935 | 0 | .saturating_mul(GlyphId24::RAW_BYTE_LEN), |
2936 | | ); |
2937 | 0 | start..end |
2938 | 0 | } |
2939 | | } |
2940 | | |
2941 | | const _: () = assert!(FontData::default_data_long_enough(Ligature2::MIN_SIZE)); |
2942 | | |
2943 | | impl Default for Ligature2<'_> { |
2944 | 0 | fn default() -> Self { |
2945 | | Self { |
2946 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
2947 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
2948 | | } |
2949 | 0 | } |
2950 | | } |
2951 | | |
2952 | | /// MultipleSubst (ISO/IEC 14496-22:2026). |
2953 | | #[derive(Clone)] |
2954 | | pub enum MultipleSubst<'a> { |
2955 | | Format1(MultipleSubstFormat1<'a>), |
2956 | | Format2(MultipleSubstFormat2<'a>), |
2957 | | } |
2958 | | |
2959 | | impl Default for MultipleSubst<'_> { |
2960 | 0 | fn default() -> Self { |
2961 | 0 | Self::Format1(Default::default()) |
2962 | 0 | } |
2963 | | } |
2964 | | |
2965 | | impl<'a> MultipleSubst<'a> { |
2966 | | ///Return the `FontData` used to resolve offsets for this table. |
2967 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
2968 | 0 | match self { |
2969 | 0 | Self::Format1(item) => item.offset_data(), |
2970 | 0 | Self::Format2(item) => item.offset_data(), |
2971 | | } |
2972 | 0 | } |
2973 | | |
2974 | | /// Format identifier: format = 1 |
2975 | 0 | pub fn subst_format(&self) -> u16 { |
2976 | 0 | match self { |
2977 | 0 | Self::Format1(item) => item.subst_format(), |
2978 | 0 | Self::Format2(item) => item.subst_format(), |
2979 | | } |
2980 | 0 | } |
2981 | | } |
2982 | | |
2983 | | impl ReadArgs for MultipleSubst<'_> { |
2984 | | type Args = (); |
2985 | | } |
2986 | | |
2987 | | impl<'a> FontRead<'a> for MultipleSubst<'a> { |
2988 | | #[inline] |
2989 | 725k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2990 | 725k | let format: u16 = data.read_at(0usize)?; |
2991 | 724k | match format { |
2992 | 33.0k | MultipleSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
2993 | 239k | MultipleSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
2994 | 452k | other => Err(ReadError::InvalidFormat(other.into())), |
2995 | | } |
2996 | 725k | } <read_fonts::tables::gsub::MultipleSubst as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 2989 | 725k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 2990 | 725k | let format: u16 = data.read_at(0usize)?; | 2991 | 724k | match format { | 2992 | 33.0k | MultipleSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 2993 | 239k | MultipleSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 2994 | 452k | other => Err(ReadError::InvalidFormat(other.into())), | 2995 | | } | 2996 | 725k | } |
Unexecuted instantiation: <read_fonts::tables::gsub::MultipleSubst as read_fonts::read::FontRead>::read_with_args |
2997 | | } |
2998 | | |
2999 | | impl<'a> MinByteRange<'a> for MultipleSubst<'a> { |
3000 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3001 | 0 | match self { |
3002 | 0 | Self::Format1(item) => item.min_byte_range(), |
3003 | 0 | Self::Format2(item) => item.min_byte_range(), |
3004 | | } |
3005 | 0 | } |
3006 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
3007 | 0 | match self { |
3008 | 0 | Self::Format1(item) => item.min_table_bytes(), |
3009 | 0 | Self::Format2(item) => item.min_table_bytes(), |
3010 | | } |
3011 | 0 | } |
3012 | | } |
3013 | | |
3014 | | /// AlternateSubst (ISO/IEC 14496-22:2026). |
3015 | | #[derive(Clone)] |
3016 | | pub enum AlternateSubst<'a> { |
3017 | | Format1(AlternateSubstFormat1<'a>), |
3018 | | Format2(AlternateSubstFormat2<'a>), |
3019 | | } |
3020 | | |
3021 | | impl Default for AlternateSubst<'_> { |
3022 | 0 | fn default() -> Self { |
3023 | 0 | Self::Format1(Default::default()) |
3024 | 0 | } |
3025 | | } |
3026 | | |
3027 | | impl<'a> AlternateSubst<'a> { |
3028 | | ///Return the `FontData` used to resolve offsets for this table. |
3029 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
3030 | 0 | match self { |
3031 | 0 | Self::Format1(item) => item.offset_data(), |
3032 | 0 | Self::Format2(item) => item.offset_data(), |
3033 | | } |
3034 | 0 | } |
3035 | | |
3036 | | /// Format identifier: format = 1 |
3037 | 0 | pub fn subst_format(&self) -> u16 { |
3038 | 0 | match self { |
3039 | 0 | Self::Format1(item) => item.subst_format(), |
3040 | 0 | Self::Format2(item) => item.subst_format(), |
3041 | | } |
3042 | 0 | } |
3043 | | } |
3044 | | |
3045 | | impl ReadArgs for AlternateSubst<'_> { |
3046 | | type Args = (); |
3047 | | } |
3048 | | |
3049 | | impl<'a> FontRead<'a> for AlternateSubst<'a> { |
3050 | | #[inline] |
3051 | 28.8k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3052 | 28.8k | let format: u16 = data.read_at(0usize)?; |
3053 | 28.4k | match format { |
3054 | 2.23k | AlternateSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
3055 | 1.49k | AlternateSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
3056 | 24.7k | other => Err(ReadError::InvalidFormat(other.into())), |
3057 | | } |
3058 | 28.8k | } <read_fonts::tables::gsub::AlternateSubst as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 3051 | 28.8k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 3052 | 28.8k | let format: u16 = data.read_at(0usize)?; | 3053 | 28.4k | match format { | 3054 | 2.23k | AlternateSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 3055 | 1.49k | AlternateSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 3056 | 24.7k | other => Err(ReadError::InvalidFormat(other.into())), | 3057 | | } | 3058 | 28.8k | } |
Unexecuted instantiation: <read_fonts::tables::gsub::AlternateSubst as read_fonts::read::FontRead>::read_with_args |
3059 | | } |
3060 | | |
3061 | | impl<'a> MinByteRange<'a> for AlternateSubst<'a> { |
3062 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3063 | 0 | match self { |
3064 | 0 | Self::Format1(item) => item.min_byte_range(), |
3065 | 0 | Self::Format2(item) => item.min_byte_range(), |
3066 | | } |
3067 | 0 | } |
3068 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
3069 | 0 | match self { |
3070 | 0 | Self::Format1(item) => item.min_table_bytes(), |
3071 | 0 | Self::Format2(item) => item.min_table_bytes(), |
3072 | | } |
3073 | 0 | } |
3074 | | } |
3075 | | |
3076 | | /// LigatureSubst (ISO/IEC 14496-22:2026). |
3077 | | #[derive(Clone)] |
3078 | | pub enum LigatureSubst<'a> { |
3079 | | Format1(LigatureSubstFormat1<'a>), |
3080 | | Format2(LigatureSubstFormat2<'a>), |
3081 | | } |
3082 | | |
3083 | | impl Default for LigatureSubst<'_> { |
3084 | 0 | fn default() -> Self { |
3085 | 0 | Self::Format1(Default::default()) |
3086 | 0 | } |
3087 | | } |
3088 | | |
3089 | | impl<'a> LigatureSubst<'a> { |
3090 | | ///Return the `FontData` used to resolve offsets for this table. |
3091 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
3092 | 0 | match self { |
3093 | 0 | Self::Format1(item) => item.offset_data(), |
3094 | 0 | Self::Format2(item) => item.offset_data(), |
3095 | | } |
3096 | 0 | } |
3097 | | |
3098 | | /// Format identifier: format = 1 |
3099 | 0 | pub fn subst_format(&self) -> u16 { |
3100 | 0 | match self { |
3101 | 0 | Self::Format1(item) => item.subst_format(), |
3102 | 0 | Self::Format2(item) => item.subst_format(), |
3103 | | } |
3104 | 0 | } |
3105 | | } |
3106 | | |
3107 | | impl ReadArgs for LigatureSubst<'_> { |
3108 | | type Args = (); |
3109 | | } |
3110 | | |
3111 | | impl<'a> FontRead<'a> for LigatureSubst<'a> { |
3112 | | #[inline] |
3113 | 258k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3114 | 258k | let format: u16 = data.read_at(0usize)?; |
3115 | 257k | match format { |
3116 | 16.1k | LigatureSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
3117 | 11.5k | LigatureSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
3118 | 230k | other => Err(ReadError::InvalidFormat(other.into())), |
3119 | | } |
3120 | 258k | } <read_fonts::tables::gsub::LigatureSubst as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 3113 | 258k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 3114 | 258k | let format: u16 = data.read_at(0usize)?; | 3115 | 257k | match format { | 3116 | 16.1k | LigatureSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 3117 | 11.5k | LigatureSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 3118 | 230k | other => Err(ReadError::InvalidFormat(other.into())), | 3119 | | } | 3120 | 258k | } |
Unexecuted instantiation: <read_fonts::tables::gsub::LigatureSubst as read_fonts::read::FontRead>::read_with_args |
3121 | | } |
3122 | | |
3123 | | impl<'a> MinByteRange<'a> for LigatureSubst<'a> { |
3124 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3125 | 0 | match self { |
3126 | 0 | Self::Format1(item) => item.min_byte_range(), |
3127 | 0 | Self::Format2(item) => item.min_byte_range(), |
3128 | | } |
3129 | 0 | } |
3130 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
3131 | 0 | match self { |
3132 | 0 | Self::Format1(item) => item.min_table_bytes(), |
3133 | 0 | Self::Format2(item) => item.min_table_bytes(), |
3134 | | } |
3135 | 0 | } |
3136 | | } |
3137 | | |
3138 | | /// ReverseChainSingleSubst (ISO/IEC 14496-22:2026). |
3139 | | #[derive(Clone)] |
3140 | | pub enum ReverseChainSingleSubst<'a> { |
3141 | | Format1(ReverseChainSingleSubstFormat1<'a>), |
3142 | | Format2(ReverseChainSingleSubstFormat2<'a>), |
3143 | | } |
3144 | | |
3145 | | impl Default for ReverseChainSingleSubst<'_> { |
3146 | 0 | fn default() -> Self { |
3147 | 0 | Self::Format1(Default::default()) |
3148 | 0 | } |
3149 | | } |
3150 | | |
3151 | | impl<'a> ReverseChainSingleSubst<'a> { |
3152 | | ///Return the `FontData` used to resolve offsets for this table. |
3153 | 0 | pub fn offset_data(&self) -> FontData<'a> { |
3154 | 0 | match self { |
3155 | 0 | Self::Format1(item) => item.offset_data(), |
3156 | 0 | Self::Format2(item) => item.offset_data(), |
3157 | | } |
3158 | 0 | } |
3159 | | |
3160 | | /// Format identifier: format = 1 |
3161 | 0 | pub fn subst_format(&self) -> u16 { |
3162 | 0 | match self { |
3163 | 0 | Self::Format1(item) => item.subst_format(), |
3164 | 0 | Self::Format2(item) => item.subst_format(), |
3165 | | } |
3166 | 0 | } |
3167 | | |
3168 | | /// Number of glyphs in the backtrack sequence. |
3169 | 0 | pub fn backtrack_glyph_count(&self) -> u16 { |
3170 | 0 | match self { |
3171 | 0 | Self::Format1(item) => item.backtrack_glyph_count(), |
3172 | 0 | Self::Format2(item) => item.backtrack_glyph_count(), |
3173 | | } |
3174 | 0 | } |
3175 | | |
3176 | | /// Number of glyphs in lookahead sequence. |
3177 | 0 | pub fn lookahead_glyph_count(&self) -> u16 { |
3178 | 0 | match self { |
3179 | 0 | Self::Format1(item) => item.lookahead_glyph_count(), |
3180 | 0 | Self::Format2(item) => item.lookahead_glyph_count(), |
3181 | | } |
3182 | 0 | } |
3183 | | } |
3184 | | |
3185 | | impl ReadArgs for ReverseChainSingleSubst<'_> { |
3186 | | type Args = (); |
3187 | | } |
3188 | | |
3189 | | impl<'a> FontRead<'a> for ReverseChainSingleSubst<'a> { |
3190 | | #[inline] |
3191 | 205k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3192 | 205k | let format: u16 = data.read_at(0usize)?; |
3193 | 204k | match format { |
3194 | 12.1k | ReverseChainSingleSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), |
3195 | 6.76k | ReverseChainSingleSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), |
3196 | 185k | other => Err(ReadError::InvalidFormat(other.into())), |
3197 | | } |
3198 | 205k | } <read_fonts::tables::gsub::ReverseChainSingleSubst as read_fonts::read::FontRead>::read_with_args Line | Count | Source | 3191 | 205k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { | 3192 | 205k | let format: u16 = data.read_at(0usize)?; | 3193 | 204k | match format { | 3194 | 12.1k | ReverseChainSingleSubstFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)), | 3195 | 6.76k | ReverseChainSingleSubstFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)), | 3196 | 185k | other => Err(ReadError::InvalidFormat(other.into())), | 3197 | | } | 3198 | 205k | } |
Unexecuted instantiation: <read_fonts::tables::gsub::ReverseChainSingleSubst as read_fonts::read::FontRead>::read_with_args |
3199 | | } |
3200 | | |
3201 | | impl<'a> MinByteRange<'a> for ReverseChainSingleSubst<'a> { |
3202 | 0 | fn min_byte_range(&self) -> Range<usize> { |
3203 | 0 | match self { |
3204 | 0 | Self::Format1(item) => item.min_byte_range(), |
3205 | 0 | Self::Format2(item) => item.min_byte_range(), |
3206 | | } |
3207 | 0 | } |
3208 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
3209 | 0 | match self { |
3210 | 0 | Self::Format1(item) => item.min_table_bytes(), |
3211 | 0 | Self::Format2(item) => item.min_table_bytes(), |
3212 | | } |
3213 | 0 | } |
3214 | | } |