/src/fontations/write-fonts/generated/generated_gdef.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 | | pub use read_fonts::tables::gdef::GlyphClassDef; |
9 | | |
10 | | /// [GDEF](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#gdef-header) 1.0 |
11 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
12 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
13 | | pub struct Gdef { |
14 | | /// Offset to class definition table for glyph type, from beginning |
15 | | /// of GDEF header (may be NULL) |
16 | | pub glyph_class_def: NullableOffsetMarker<ClassDef>, |
17 | | /// Offset to attachment point list table, from beginning of GDEF |
18 | | /// header (may be NULL) |
19 | | pub attach_list: NullableOffsetMarker<AttachList>, |
20 | | /// Offset to ligature caret list table, from beginning of GDEF |
21 | | /// header (may be NULL) |
22 | | pub lig_caret_list: NullableOffsetMarker<LigCaretList>, |
23 | | /// Offset to class definition table for mark attachment type, from |
24 | | /// beginning of GDEF header (may be NULL) |
25 | | pub mark_attach_class_def: NullableOffsetMarker<ClassDef>, |
26 | | /// Offset to the table of mark glyph set definitions, from |
27 | | /// beginning of GDEF header (may be NULL) |
28 | | pub mark_glyph_sets_def: NullableOffsetMarker<MarkGlyphSets>, |
29 | | /// Offset to the Item Variation Store table, from beginning of |
30 | | /// GDEF header (may be NULL) |
31 | | pub item_var_store: NullableOffsetMarker<ItemVariationStore, WIDTH_32>, |
32 | | } |
33 | | |
34 | | impl Gdef { |
35 | | /// Construct a new `Gdef` |
36 | 0 | pub fn new( |
37 | 0 | glyph_class_def: Option<ClassDef>, |
38 | 0 | attach_list: Option<AttachList>, |
39 | 0 | lig_caret_list: Option<LigCaretList>, |
40 | 0 | mark_attach_class_def: Option<ClassDef>, |
41 | 0 | ) -> Self { |
42 | 0 | Self { |
43 | 0 | glyph_class_def: glyph_class_def.into(), |
44 | 0 | attach_list: attach_list.into(), |
45 | 0 | lig_caret_list: lig_caret_list.into(), |
46 | 0 | mark_attach_class_def: mark_attach_class_def.into(), |
47 | 0 | ..Default::default() |
48 | 0 | } |
49 | 0 | } |
50 | | } |
51 | | |
52 | | impl FontWrite for Gdef { |
53 | | #[allow(clippy::unnecessary_cast)] |
54 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
55 | 0 | let version = self.compute_version() as MajorMinor; |
56 | 0 | version.write_into(writer); |
57 | 0 | self.glyph_class_def.write_into(writer); |
58 | 0 | self.attach_list.write_into(writer); |
59 | 0 | self.lig_caret_list.write_into(writer); |
60 | 0 | self.mark_attach_class_def.write_into(writer); |
61 | 0 | version |
62 | 0 | .compatible((1u16, 2u16)) |
63 | 0 | .then(|| self.mark_glyph_sets_def.write_into(writer)); |
64 | 0 | version |
65 | 0 | .compatible((1u16, 3u16)) |
66 | 0 | .then(|| self.item_var_store.write_into(writer)); |
67 | 0 | } |
68 | 0 | fn table_type(&self) -> TableType { |
69 | 0 | TableType::TopLevel(Gdef::TAG) |
70 | 0 | } |
71 | | } |
72 | | |
73 | | impl Validate for Gdef { |
74 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
75 | 0 | ctx.in_table("Gdef", |ctx| { |
76 | 0 | ctx.in_field("glyph_class_def", |ctx| { |
77 | 0 | self.glyph_class_def.validate_impl(ctx); |
78 | 0 | }); |
79 | 0 | ctx.in_field("attach_list", |ctx| { |
80 | 0 | self.attach_list.validate_impl(ctx); |
81 | 0 | }); |
82 | 0 | ctx.in_field("lig_caret_list", |ctx| { |
83 | 0 | self.lig_caret_list.validate_impl(ctx); |
84 | 0 | }); |
85 | 0 | ctx.in_field("mark_attach_class_def", |ctx| { |
86 | 0 | self.mark_attach_class_def.validate_impl(ctx); |
87 | 0 | }); |
88 | 0 | ctx.in_field("mark_glyph_sets_def", |ctx| { |
89 | 0 | self.mark_glyph_sets_def.validate_impl(ctx); |
90 | 0 | }); |
91 | 0 | ctx.in_field("item_var_store", |ctx| { |
92 | 0 | self.item_var_store.validate_impl(ctx); |
93 | 0 | }); |
94 | 0 | }) |
95 | 0 | } |
96 | | } |
97 | | |
98 | | impl TopLevelTable for Gdef { |
99 | | const TAG: Tag = Tag::new(b"GDEF"); |
100 | | } |
101 | | |
102 | | impl<'a> FromObjRef<read_fonts::tables::gdef::Gdef<'a>> for Gdef { |
103 | 0 | fn from_obj_ref(obj: &read_fonts::tables::gdef::Gdef<'a>, _: FontData) -> Self { |
104 | 0 | Gdef { |
105 | 0 | glyph_class_def: obj.glyph_class_def().to_owned_table(), |
106 | 0 | attach_list: obj.attach_list().to_owned_table(), |
107 | 0 | lig_caret_list: obj.lig_caret_list().to_owned_table(), |
108 | 0 | mark_attach_class_def: obj.mark_attach_class_def().to_owned_table(), |
109 | 0 | mark_glyph_sets_def: obj.mark_glyph_sets_def().to_owned_table(), |
110 | 0 | item_var_store: obj.item_var_store().to_owned_table(), |
111 | 0 | } |
112 | 0 | } |
113 | | } |
114 | | |
115 | | #[allow(clippy::needless_lifetimes)] |
116 | | impl<'a> FromTableRef<read_fonts::tables::gdef::Gdef<'a>> for Gdef {} |
117 | | |
118 | | impl ReadArgs for Gdef { |
119 | | type Args = (); |
120 | | } |
121 | | |
122 | | impl<'a> FontRead<'a> for Gdef { |
123 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
124 | 0 | <read_fonts::tables::gdef::Gdef as FontRead>::read(data).map(|x| x.to_owned_table()) |
125 | 0 | } |
126 | | } |
127 | | |
128 | | impl FontWrite for GlyphClassDef { |
129 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
130 | 0 | let val = *self as u16; |
131 | 0 | writer.write_slice(&val.to_be_bytes()) |
132 | 0 | } |
133 | | } |
134 | | |
135 | | /// [Attachment Point List Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#attachment-point-list-table) |
136 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
137 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
138 | | pub struct AttachList { |
139 | | /// Offset to Coverage table - from beginning of AttachList table |
140 | | pub coverage: OffsetMarker<CoverageTable>, |
141 | | /// Array of offsets to AttachPoint tables-from beginning of |
142 | | /// AttachList table-in Coverage Index order |
143 | | pub attach_points: Vec<OffsetMarker<AttachPoint>>, |
144 | | } |
145 | | |
146 | | impl AttachList { |
147 | | /// Construct a new `AttachList` |
148 | 0 | pub fn new(coverage: CoverageTable, attach_points: Vec<AttachPoint>) -> Self { |
149 | 0 | Self { |
150 | 0 | coverage: coverage.into(), |
151 | 0 | attach_points: attach_points.into_iter().map(Into::into).collect(), |
152 | 0 | } |
153 | 0 | } |
154 | | } |
155 | | |
156 | | impl FontWrite for AttachList { |
157 | | #[allow(clippy::unnecessary_cast)] |
158 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
159 | 0 | self.coverage.write_into(writer); |
160 | 0 | (u16::try_from(array_len(&self.attach_points)).unwrap()).write_into(writer); |
161 | 0 | self.attach_points.write_into(writer); |
162 | 0 | } |
163 | 0 | fn table_type(&self) -> TableType { |
164 | 0 | TableType::Named("AttachList") |
165 | 0 | } |
166 | | } |
167 | | |
168 | | impl Validate for AttachList { |
169 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
170 | 0 | ctx.in_table("AttachList", |ctx| { |
171 | 0 | ctx.in_field("coverage", |ctx| { |
172 | 0 | self.coverage.validate_impl(ctx); |
173 | 0 | }); |
174 | 0 | ctx.in_field("attach_points", |ctx| { |
175 | 0 | if self.attach_points.len() > to_usize(u16::MAX) { |
176 | 0 | ctx.report("array exceeds max length"); |
177 | 0 | } |
178 | 0 | self.attach_points.validate_impl(ctx); |
179 | 0 | }); |
180 | 0 | }) |
181 | 0 | } |
182 | | } |
183 | | |
184 | | impl<'a> FromObjRef<read_fonts::tables::gdef::AttachList<'a>> for AttachList { |
185 | 0 | fn from_obj_ref(obj: &read_fonts::tables::gdef::AttachList<'a>, _: FontData) -> Self { |
186 | 0 | AttachList { |
187 | 0 | coverage: obj.coverage().to_owned_table(), |
188 | 0 | attach_points: obj.attach_points().to_owned_table(), |
189 | 0 | } |
190 | 0 | } |
191 | | } |
192 | | |
193 | | #[allow(clippy::needless_lifetimes)] |
194 | | impl<'a> FromTableRef<read_fonts::tables::gdef::AttachList<'a>> for AttachList {} |
195 | | |
196 | | impl ReadArgs for AttachList { |
197 | | type Args = (); |
198 | | } |
199 | | |
200 | | impl<'a> FontRead<'a> for AttachList { |
201 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
202 | 0 | <read_fonts::tables::gdef::AttachList as FontRead>::read(data).map(|x| x.to_owned_table()) |
203 | 0 | } |
204 | | } |
205 | | |
206 | | /// Part of [AttachList] |
207 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
208 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
209 | | pub struct AttachPoint { |
210 | | /// Array of contour point indices -in increasing numerical order |
211 | | pub point_indices: Vec<u16>, |
212 | | } |
213 | | |
214 | | impl AttachPoint { |
215 | | /// Construct a new `AttachPoint` |
216 | 0 | pub fn new(point_indices: Vec<u16>) -> Self { |
217 | 0 | Self { point_indices } |
218 | 0 | } |
219 | | } |
220 | | |
221 | | impl FontWrite for AttachPoint { |
222 | | #[allow(clippy::unnecessary_cast)] |
223 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
224 | 0 | (u16::try_from(array_len(&self.point_indices)).unwrap()).write_into(writer); |
225 | 0 | self.point_indices.write_into(writer); |
226 | 0 | } |
227 | 0 | fn table_type(&self) -> TableType { |
228 | 0 | TableType::Named("AttachPoint") |
229 | 0 | } |
230 | | } |
231 | | |
232 | | impl Validate for AttachPoint { |
233 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
234 | 0 | ctx.in_table("AttachPoint", |ctx| { |
235 | 0 | ctx.in_field("point_indices", |ctx| { |
236 | 0 | if self.point_indices.len() > to_usize(u16::MAX) { |
237 | 0 | ctx.report("array exceeds max length"); |
238 | 0 | } |
239 | 0 | }); |
240 | 0 | }) |
241 | 0 | } |
242 | | } |
243 | | |
244 | | impl<'a> FromObjRef<read_fonts::tables::gdef::AttachPoint<'a>> for AttachPoint { |
245 | 0 | fn from_obj_ref(obj: &read_fonts::tables::gdef::AttachPoint<'a>, _: FontData) -> Self { |
246 | 0 | let offset_data = obj.offset_data(); |
247 | 0 | AttachPoint { |
248 | 0 | point_indices: obj.point_indices().to_owned_obj(offset_data), |
249 | 0 | } |
250 | 0 | } |
251 | | } |
252 | | |
253 | | #[allow(clippy::needless_lifetimes)] |
254 | | impl<'a> FromTableRef<read_fonts::tables::gdef::AttachPoint<'a>> for AttachPoint {} |
255 | | |
256 | | impl ReadArgs for AttachPoint { |
257 | | type Args = (); |
258 | | } |
259 | | |
260 | | impl<'a> FontRead<'a> for AttachPoint { |
261 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
262 | 0 | <read_fonts::tables::gdef::AttachPoint as FontRead>::read(data).map(|x| x.to_owned_table()) |
263 | 0 | } |
264 | | } |
265 | | |
266 | | /// [Ligature Caret List Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#ligature-caret-list-table) |
267 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
268 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
269 | | pub struct LigCaretList { |
270 | | /// Offset to Coverage table - from beginning of LigCaretList table |
271 | | pub coverage: OffsetMarker<CoverageTable>, |
272 | | /// Array of offsets to LigGlyph tables, from beginning of |
273 | | /// LigCaretList table —in Coverage Index order |
274 | | pub lig_glyphs: Vec<OffsetMarker<LigGlyph>>, |
275 | | } |
276 | | |
277 | | impl LigCaretList { |
278 | | /// Construct a new `LigCaretList` |
279 | 0 | pub fn new(coverage: CoverageTable, lig_glyphs: Vec<LigGlyph>) -> Self { |
280 | 0 | Self { |
281 | 0 | coverage: coverage.into(), |
282 | 0 | lig_glyphs: lig_glyphs.into_iter().map(Into::into).collect(), |
283 | 0 | } |
284 | 0 | } |
285 | | } |
286 | | |
287 | | impl FontWrite for LigCaretList { |
288 | | #[allow(clippy::unnecessary_cast)] |
289 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
290 | 0 | self.coverage.write_into(writer); |
291 | 0 | (u16::try_from(array_len(&self.lig_glyphs)).unwrap()).write_into(writer); |
292 | 0 | self.lig_glyphs.write_into(writer); |
293 | 0 | } |
294 | 0 | fn table_type(&self) -> TableType { |
295 | 0 | TableType::Named("LigCaretList") |
296 | 0 | } |
297 | | } |
298 | | |
299 | | impl Validate for LigCaretList { |
300 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
301 | 0 | ctx.in_table("LigCaretList", |ctx| { |
302 | 0 | ctx.in_field("coverage", |ctx| { |
303 | 0 | self.coverage.validate_impl(ctx); |
304 | 0 | }); |
305 | 0 | ctx.in_field("lig_glyphs", |ctx| { |
306 | 0 | if self.lig_glyphs.len() > to_usize(u16::MAX) { |
307 | 0 | ctx.report("array exceeds max length"); |
308 | 0 | } |
309 | 0 | self.lig_glyphs.validate_impl(ctx); |
310 | 0 | }); |
311 | 0 | }) |
312 | 0 | } |
313 | | } |
314 | | |
315 | | impl<'a> FromObjRef<read_fonts::tables::gdef::LigCaretList<'a>> for LigCaretList { |
316 | 0 | fn from_obj_ref(obj: &read_fonts::tables::gdef::LigCaretList<'a>, _: FontData) -> Self { |
317 | 0 | LigCaretList { |
318 | 0 | coverage: obj.coverage().to_owned_table(), |
319 | 0 | lig_glyphs: obj.lig_glyphs().to_owned_table(), |
320 | 0 | } |
321 | 0 | } |
322 | | } |
323 | | |
324 | | #[allow(clippy::needless_lifetimes)] |
325 | | impl<'a> FromTableRef<read_fonts::tables::gdef::LigCaretList<'a>> for LigCaretList {} |
326 | | |
327 | | impl ReadArgs for LigCaretList { |
328 | | type Args = (); |
329 | | } |
330 | | |
331 | | impl<'a> FontRead<'a> for LigCaretList { |
332 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
333 | 0 | <read_fonts::tables::gdef::LigCaretList as FontRead>::read(data).map(|x| x.to_owned_table()) |
334 | 0 | } |
335 | | } |
336 | | |
337 | | /// [Ligature Glyph Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#ligature-glyph-table) |
338 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
339 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
340 | | pub struct LigGlyph { |
341 | | /// Array of offsets to CaretValue tables, from beginning of |
342 | | /// LigGlyph table — in increasing coordinate order |
343 | | pub caret_values: Vec<OffsetMarker<CaretValue>>, |
344 | | } |
345 | | |
346 | | impl LigGlyph { |
347 | | /// Construct a new `LigGlyph` |
348 | 0 | pub fn new(caret_values: Vec<CaretValue>) -> Self { |
349 | 0 | Self { |
350 | 0 | caret_values: caret_values.into_iter().map(Into::into).collect(), |
351 | 0 | } |
352 | 0 | } |
353 | | } |
354 | | |
355 | | impl FontWrite for LigGlyph { |
356 | | #[allow(clippy::unnecessary_cast)] |
357 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
358 | 0 | (u16::try_from(array_len(&self.caret_values)).unwrap()).write_into(writer); |
359 | 0 | self.caret_values.write_into(writer); |
360 | 0 | } |
361 | 0 | fn table_type(&self) -> TableType { |
362 | 0 | TableType::Named("LigGlyph") |
363 | 0 | } |
364 | | } |
365 | | |
366 | | impl Validate for LigGlyph { |
367 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
368 | 0 | ctx.in_table("LigGlyph", |ctx| { |
369 | 0 | ctx.in_field("caret_values", |ctx| { |
370 | 0 | if self.caret_values.len() > to_usize(u16::MAX) { |
371 | 0 | ctx.report("array exceeds max length"); |
372 | 0 | } |
373 | 0 | self.caret_values.validate_impl(ctx); |
374 | 0 | }); |
375 | 0 | }) |
376 | 0 | } |
377 | | } |
378 | | |
379 | | impl<'a> FromObjRef<read_fonts::tables::gdef::LigGlyph<'a>> for LigGlyph { |
380 | 0 | fn from_obj_ref(obj: &read_fonts::tables::gdef::LigGlyph<'a>, _: FontData) -> Self { |
381 | 0 | LigGlyph { |
382 | 0 | caret_values: obj.caret_values().to_owned_table(), |
383 | 0 | } |
384 | 0 | } |
385 | | } |
386 | | |
387 | | #[allow(clippy::needless_lifetimes)] |
388 | | impl<'a> FromTableRef<read_fonts::tables::gdef::LigGlyph<'a>> for LigGlyph {} |
389 | | |
390 | | impl ReadArgs for LigGlyph { |
391 | | type Args = (); |
392 | | } |
393 | | |
394 | | impl<'a> FontRead<'a> for LigGlyph { |
395 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
396 | 0 | <read_fonts::tables::gdef::LigGlyph as FontRead>::read(data).map(|x| x.to_owned_table()) |
397 | 0 | } |
398 | | } |
399 | | |
400 | | /// [Caret Value Tables](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#caret-value-tables) |
401 | | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] |
402 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
403 | | pub enum CaretValue { |
404 | | Format1(CaretValueFormat1), |
405 | | Format2(CaretValueFormat2), |
406 | | Format3(CaretValueFormat3), |
407 | | } |
408 | | |
409 | | impl CaretValue { |
410 | | /// Construct a new `CaretValueFormat1` subtable |
411 | 0 | pub fn format_1(coordinate: i16) -> Self { |
412 | 0 | Self::Format1(CaretValueFormat1::new(coordinate)) |
413 | 0 | } |
414 | | |
415 | | /// Construct a new `CaretValueFormat2` subtable |
416 | 0 | pub fn format_2(caret_value_point_index: u16) -> Self { |
417 | 0 | Self::Format2(CaretValueFormat2::new(caret_value_point_index)) |
418 | 0 | } |
419 | | |
420 | | /// Construct a new `CaretValueFormat3` subtable |
421 | 0 | pub fn format_3(coordinate: i16, device: DeviceOrVariationIndex) -> Self { |
422 | 0 | Self::Format3(CaretValueFormat3::new(coordinate, device)) |
423 | 0 | } |
424 | | } |
425 | | |
426 | | impl Default for CaretValue { |
427 | 0 | fn default() -> Self { |
428 | 0 | Self::Format1(Default::default()) |
429 | 0 | } |
430 | | } |
431 | | |
432 | | impl FontWrite for CaretValue { |
433 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
434 | 0 | match self { |
435 | 0 | Self::Format1(item) => item.write_into(writer), |
436 | 0 | Self::Format2(item) => item.write_into(writer), |
437 | 0 | Self::Format3(item) => item.write_into(writer), |
438 | | } |
439 | 0 | } |
440 | 0 | fn table_type(&self) -> TableType { |
441 | 0 | match self { |
442 | 0 | Self::Format1(item) => item.table_type(), |
443 | 0 | Self::Format2(item) => item.table_type(), |
444 | 0 | Self::Format3(item) => item.table_type(), |
445 | | } |
446 | 0 | } |
447 | | } |
448 | | |
449 | | impl Validate for CaretValue { |
450 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
451 | 0 | match self { |
452 | 0 | Self::Format1(item) => item.validate_impl(ctx), |
453 | 0 | Self::Format2(item) => item.validate_impl(ctx), |
454 | 0 | Self::Format3(item) => item.validate_impl(ctx), |
455 | | } |
456 | 0 | } |
457 | | } |
458 | | |
459 | | impl FromObjRef<read_fonts::tables::gdef::CaretValue<'_>> for CaretValue { |
460 | 0 | fn from_obj_ref(obj: &read_fonts::tables::gdef::CaretValue, _: FontData) -> Self { |
461 | | use read_fonts::tables::gdef::CaretValue as ObjRefType; |
462 | 0 | match obj { |
463 | 0 | ObjRefType::Format1(item) => CaretValue::Format1(item.to_owned_table()), |
464 | 0 | ObjRefType::Format2(item) => CaretValue::Format2(item.to_owned_table()), |
465 | 0 | ObjRefType::Format3(item) => CaretValue::Format3(item.to_owned_table()), |
466 | | } |
467 | 0 | } |
468 | | } |
469 | | |
470 | | impl FromTableRef<read_fonts::tables::gdef::CaretValue<'_>> for CaretValue {} |
471 | | |
472 | | impl ReadArgs for CaretValue { |
473 | | type Args = (); |
474 | | } |
475 | | |
476 | | impl<'a> FontRead<'a> for CaretValue { |
477 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
478 | 0 | <read_fonts::tables::gdef::CaretValue as FontRead>::read(data).map(|x| x.to_owned_table()) |
479 | 0 | } |
480 | | } |
481 | | |
482 | | impl From<CaretValueFormat1> for CaretValue { |
483 | 0 | fn from(src: CaretValueFormat1) -> CaretValue { |
484 | 0 | CaretValue::Format1(src) |
485 | 0 | } |
486 | | } |
487 | | |
488 | | impl From<CaretValueFormat2> for CaretValue { |
489 | 0 | fn from(src: CaretValueFormat2) -> CaretValue { |
490 | 0 | CaretValue::Format2(src) |
491 | 0 | } |
492 | | } |
493 | | |
494 | | impl From<CaretValueFormat3> for CaretValue { |
495 | 0 | fn from(src: CaretValueFormat3) -> CaretValue { |
496 | 0 | CaretValue::Format3(src) |
497 | 0 | } |
498 | | } |
499 | | |
500 | | /// [CaretValue Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#caretvalue-format-1) |
501 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
502 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
503 | | pub struct CaretValueFormat1 { |
504 | | /// X or Y value, in design units |
505 | | pub coordinate: i16, |
506 | | } |
507 | | |
508 | | impl CaretValueFormat1 { |
509 | | /// Construct a new `CaretValueFormat1` |
510 | 0 | pub fn new(coordinate: i16) -> Self { |
511 | 0 | Self { coordinate } |
512 | 0 | } |
513 | | } |
514 | | |
515 | | impl FontWrite for CaretValueFormat1 { |
516 | | #[allow(clippy::unnecessary_cast)] |
517 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
518 | 0 | (1 as u16).write_into(writer); |
519 | 0 | self.coordinate.write_into(writer); |
520 | 0 | } |
521 | 0 | fn table_type(&self) -> TableType { |
522 | 0 | TableType::Named("CaretValueFormat1") |
523 | 0 | } |
524 | | } |
525 | | |
526 | | impl Validate for CaretValueFormat1 { |
527 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
528 | | } |
529 | | |
530 | | impl<'a> FromObjRef<read_fonts::tables::gdef::CaretValueFormat1<'a>> for CaretValueFormat1 { |
531 | 0 | fn from_obj_ref(obj: &read_fonts::tables::gdef::CaretValueFormat1<'a>, _: FontData) -> Self { |
532 | 0 | CaretValueFormat1 { |
533 | 0 | coordinate: obj.coordinate(), |
534 | 0 | } |
535 | 0 | } |
536 | | } |
537 | | |
538 | | #[allow(clippy::needless_lifetimes)] |
539 | | impl<'a> FromTableRef<read_fonts::tables::gdef::CaretValueFormat1<'a>> for CaretValueFormat1 {} |
540 | | |
541 | | impl ReadArgs for CaretValueFormat1 { |
542 | | type Args = (); |
543 | | } |
544 | | |
545 | | impl<'a> FontRead<'a> for CaretValueFormat1 { |
546 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
547 | 0 | <read_fonts::tables::gdef::CaretValueFormat1 as FontRead>::read(data) |
548 | 0 | .map(|x| x.to_owned_table()) |
549 | 0 | } |
550 | | } |
551 | | |
552 | | /// [CaretValue Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#caretvalue-format-2) |
553 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
554 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
555 | | pub struct CaretValueFormat2 { |
556 | | /// Contour point index on glyph |
557 | | pub caret_value_point_index: u16, |
558 | | } |
559 | | |
560 | | impl CaretValueFormat2 { |
561 | | /// Construct a new `CaretValueFormat2` |
562 | 0 | pub fn new(caret_value_point_index: u16) -> Self { |
563 | 0 | Self { |
564 | 0 | caret_value_point_index, |
565 | 0 | } |
566 | 0 | } |
567 | | } |
568 | | |
569 | | impl FontWrite for CaretValueFormat2 { |
570 | | #[allow(clippy::unnecessary_cast)] |
571 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
572 | 0 | (2 as u16).write_into(writer); |
573 | 0 | self.caret_value_point_index.write_into(writer); |
574 | 0 | } |
575 | 0 | fn table_type(&self) -> TableType { |
576 | 0 | TableType::Named("CaretValueFormat2") |
577 | 0 | } |
578 | | } |
579 | | |
580 | | impl Validate for CaretValueFormat2 { |
581 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
582 | | } |
583 | | |
584 | | impl<'a> FromObjRef<read_fonts::tables::gdef::CaretValueFormat2<'a>> for CaretValueFormat2 { |
585 | 0 | fn from_obj_ref(obj: &read_fonts::tables::gdef::CaretValueFormat2<'a>, _: FontData) -> Self { |
586 | 0 | CaretValueFormat2 { |
587 | 0 | caret_value_point_index: obj.caret_value_point_index(), |
588 | 0 | } |
589 | 0 | } |
590 | | } |
591 | | |
592 | | #[allow(clippy::needless_lifetimes)] |
593 | | impl<'a> FromTableRef<read_fonts::tables::gdef::CaretValueFormat2<'a>> for CaretValueFormat2 {} |
594 | | |
595 | | impl ReadArgs for CaretValueFormat2 { |
596 | | type Args = (); |
597 | | } |
598 | | |
599 | | impl<'a> FontRead<'a> for CaretValueFormat2 { |
600 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
601 | 0 | <read_fonts::tables::gdef::CaretValueFormat2 as FontRead>::read(data) |
602 | 0 | .map(|x| x.to_owned_table()) |
603 | 0 | } |
604 | | } |
605 | | |
606 | | /// [CaretValue Format 3](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#caretvalue-format-3) |
607 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
608 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
609 | | pub struct CaretValueFormat3 { |
610 | | /// X or Y value, in design units |
611 | | pub coordinate: i16, |
612 | | /// Offset to Device table (non-variable font) / Variation Index |
613 | | /// table (variable font) for X or Y value-from beginning of |
614 | | /// CaretValue table |
615 | | pub device: OffsetMarker<DeviceOrVariationIndex>, |
616 | | } |
617 | | |
618 | | impl CaretValueFormat3 { |
619 | | /// Construct a new `CaretValueFormat3` |
620 | 0 | pub fn new(coordinate: i16, device: DeviceOrVariationIndex) -> Self { |
621 | 0 | Self { |
622 | 0 | coordinate, |
623 | 0 | device: device.into(), |
624 | 0 | } |
625 | 0 | } |
626 | | } |
627 | | |
628 | | impl FontWrite for CaretValueFormat3 { |
629 | | #[allow(clippy::unnecessary_cast)] |
630 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
631 | 0 | (3 as u16).write_into(writer); |
632 | 0 | self.coordinate.write_into(writer); |
633 | 0 | self.device.write_into(writer); |
634 | 0 | } |
635 | 0 | fn table_type(&self) -> TableType { |
636 | 0 | TableType::Named("CaretValueFormat3") |
637 | 0 | } |
638 | | } |
639 | | |
640 | | impl Validate for CaretValueFormat3 { |
641 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
642 | 0 | ctx.in_table("CaretValueFormat3", |ctx| { |
643 | 0 | ctx.in_field("device", |ctx| { |
644 | 0 | self.device.validate_impl(ctx); |
645 | 0 | }); |
646 | 0 | }) |
647 | 0 | } |
648 | | } |
649 | | |
650 | | impl<'a> FromObjRef<read_fonts::tables::gdef::CaretValueFormat3<'a>> for CaretValueFormat3 { |
651 | 0 | fn from_obj_ref(obj: &read_fonts::tables::gdef::CaretValueFormat3<'a>, _: FontData) -> Self { |
652 | 0 | CaretValueFormat3 { |
653 | 0 | coordinate: obj.coordinate(), |
654 | 0 | device: obj.device().to_owned_table(), |
655 | 0 | } |
656 | 0 | } |
657 | | } |
658 | | |
659 | | #[allow(clippy::needless_lifetimes)] |
660 | | impl<'a> FromTableRef<read_fonts::tables::gdef::CaretValueFormat3<'a>> for CaretValueFormat3 {} |
661 | | |
662 | | impl ReadArgs for CaretValueFormat3 { |
663 | | type Args = (); |
664 | | } |
665 | | |
666 | | impl<'a> FontRead<'a> for CaretValueFormat3 { |
667 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
668 | 0 | <read_fonts::tables::gdef::CaretValueFormat3 as FontRead>::read(data) |
669 | 0 | .map(|x| x.to_owned_table()) |
670 | 0 | } |
671 | | } |
672 | | |
673 | | /// [Mark Glyph Sets Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#mark-glyph-sets-table) |
674 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
675 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
676 | | pub struct MarkGlyphSets { |
677 | | /// Array of offsets to mark glyph set coverage tables, from the |
678 | | /// start of the MarkGlyphSets table. |
679 | | pub coverages: Vec<OffsetMarker<CoverageTable, WIDTH_32>>, |
680 | | } |
681 | | |
682 | | impl MarkGlyphSets { |
683 | | /// Construct a new `MarkGlyphSets` |
684 | 0 | pub fn new(coverages: Vec<CoverageTable>) -> Self { |
685 | 0 | Self { |
686 | 0 | coverages: coverages.into_iter().map(Into::into).collect(), |
687 | 0 | } |
688 | 0 | } |
689 | | } |
690 | | |
691 | | impl FontWrite for MarkGlyphSets { |
692 | | #[allow(clippy::unnecessary_cast)] |
693 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
694 | 0 | (1 as u16).write_into(writer); |
695 | 0 | (u16::try_from(array_len(&self.coverages)).unwrap()).write_into(writer); |
696 | 0 | self.coverages.write_into(writer); |
697 | 0 | } |
698 | 0 | fn table_type(&self) -> TableType { |
699 | 0 | TableType::Named("MarkGlyphSets") |
700 | 0 | } |
701 | | } |
702 | | |
703 | | impl Validate for MarkGlyphSets { |
704 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
705 | 0 | ctx.in_table("MarkGlyphSets", |ctx| { |
706 | 0 | ctx.in_field("coverages", |ctx| { |
707 | 0 | if self.coverages.len() > to_usize(u16::MAX) { |
708 | 0 | ctx.report("array exceeds max length"); |
709 | 0 | } |
710 | 0 | self.coverages.validate_impl(ctx); |
711 | 0 | }); |
712 | 0 | }) |
713 | 0 | } |
714 | | } |
715 | | |
716 | | impl<'a> FromObjRef<read_fonts::tables::gdef::MarkGlyphSets<'a>> for MarkGlyphSets { |
717 | 0 | fn from_obj_ref(obj: &read_fonts::tables::gdef::MarkGlyphSets<'a>, _: FontData) -> Self { |
718 | 0 | MarkGlyphSets { |
719 | 0 | coverages: obj.coverages().to_owned_table(), |
720 | 0 | } |
721 | 0 | } |
722 | | } |
723 | | |
724 | | #[allow(clippy::needless_lifetimes)] |
725 | | impl<'a> FromTableRef<read_fonts::tables::gdef::MarkGlyphSets<'a>> for MarkGlyphSets {} |
726 | | |
727 | | impl ReadArgs for MarkGlyphSets { |
728 | | type Args = (); |
729 | | } |
730 | | |
731 | | impl<'a> FontRead<'a> for MarkGlyphSets { |
732 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
733 | 0 | <read_fonts::tables::gdef::MarkGlyphSets as FontRead>::read(data) |
734 | 0 | .map(|x| x.to_owned_table()) |
735 | 0 | } |
736 | | } |