1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8pub use read_fonts::tables::gdef::GlyphClassDef;
9
10#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct Gdef {
14 pub glyph_class_def: NullableOffsetMarker<ClassDef>,
17 pub attach_list: NullableOffsetMarker<AttachList>,
20 pub lig_caret_list: NullableOffsetMarker<LigCaretList>,
23 pub mark_attach_class_def: NullableOffsetMarker<ClassDef>,
26 pub mark_glyph_sets_def: NullableOffsetMarker<MarkGlyphSets>,
29 pub item_var_store: NullableOffsetMarker<ItemVariationStore, WIDTH_32>,
32 pub glyph_class_def2: NullableOffsetMarker<ClassDef, WIDTH_32>,
34 pub attach_list2: NullableOffsetMarker<AttachList, WIDTH_32>,
36 pub lig_caret_list2: NullableOffsetMarker<LigCaretList2, WIDTH_32>,
38 pub mark_attach_class_def2: NullableOffsetMarker<ClassDef, WIDTH_32>,
40 pub mark_glyph_sets_def2: NullableOffsetMarker<MarkGlyphSets, WIDTH_32>,
42}
43
44impl Gdef {
45 pub fn new(
47 glyph_class_def: Option<ClassDef>,
48 attach_list: Option<AttachList>,
49 lig_caret_list: Option<LigCaretList>,
50 mark_attach_class_def: Option<ClassDef>,
51 ) -> Self {
52 Self {
53 glyph_class_def: glyph_class_def.into(),
54 attach_list: attach_list.into(),
55 lig_caret_list: lig_caret_list.into(),
56 mark_attach_class_def: mark_attach_class_def.into(),
57 ..Default::default()
58 }
59 }
60}
61
62impl FontWrite for Gdef {
63 #[allow(clippy::unnecessary_cast)]
64 fn write_into(&self, writer: &mut TableWriter) {
65 let version = self.compute_version() as MajorMinor;
66 version.write_into(writer);
67 self.glyph_class_def.write_into(writer);
68 self.attach_list.write_into(writer);
69 self.lig_caret_list.write_into(writer);
70 self.mark_attach_class_def.write_into(writer);
71 version
72 .compatible((1u16, 2u16))
73 .then(|| self.mark_glyph_sets_def.write_into(writer));
74 version
75 .compatible((1u16, 3u16))
76 .then(|| self.item_var_store.write_into(writer));
77 version
78 .compatible((1u16, 4u16))
79 .then(|| self.glyph_class_def2.write_into(writer));
80 version
81 .compatible((1u16, 4u16))
82 .then(|| self.attach_list2.write_into(writer));
83 version
84 .compatible((1u16, 4u16))
85 .then(|| self.lig_caret_list2.write_into(writer));
86 version
87 .compatible((1u16, 4u16))
88 .then(|| self.mark_attach_class_def2.write_into(writer));
89 version
90 .compatible((1u16, 4u16))
91 .then(|| self.mark_glyph_sets_def2.write_into(writer));
92 }
93 fn table_type(&self) -> TableType {
94 TableType::TopLevel(Gdef::TAG)
95 }
96}
97
98impl Validate for Gdef {
99 fn validate_impl(&self, ctx: &mut ValidationCtx) {
100 ctx.in_table("Gdef", |ctx| {
101 ctx.in_field("glyph_class_def", |ctx| {
102 self.glyph_class_def.validate_impl(ctx);
103 });
104 ctx.in_field("attach_list", |ctx| {
105 self.attach_list.validate_impl(ctx);
106 });
107 ctx.in_field("lig_caret_list", |ctx| {
108 self.lig_caret_list.validate_impl(ctx);
109 });
110 ctx.in_field("mark_attach_class_def", |ctx| {
111 self.mark_attach_class_def.validate_impl(ctx);
112 });
113 ctx.in_field("mark_glyph_sets_def", |ctx| {
114 self.mark_glyph_sets_def.validate_impl(ctx);
115 });
116 ctx.in_field("item_var_store", |ctx| {
117 self.item_var_store.validate_impl(ctx);
118 });
119 ctx.in_field("glyph_class_def2", |ctx| {
120 self.glyph_class_def2.validate_impl(ctx);
121 });
122 ctx.in_field("attach_list2", |ctx| {
123 self.attach_list2.validate_impl(ctx);
124 });
125 ctx.in_field("lig_caret_list2", |ctx| {
126 self.lig_caret_list2.validate_impl(ctx);
127 });
128 ctx.in_field("mark_attach_class_def2", |ctx| {
129 self.mark_attach_class_def2.validate_impl(ctx);
130 });
131 ctx.in_field("mark_glyph_sets_def2", |ctx| {
132 self.mark_glyph_sets_def2.validate_impl(ctx);
133 });
134 })
135 }
136}
137
138impl TopLevelTable for Gdef {
139 const TAG: Tag = Tag::new(b"GDEF");
140}
141
142impl<'a> FromObjRef<read_fonts::tables::gdef::Gdef<'a>> for Gdef {
143 fn from_obj_ref(obj: &read_fonts::tables::gdef::Gdef<'a>, _: FontData) -> Self {
144 Gdef {
145 glyph_class_def: obj.original_glyph_class_def().to_owned_table(),
146 attach_list: obj.original_attach_list().to_owned_table(),
147 lig_caret_list: obj.original_lig_caret_list().to_owned_table(),
148 mark_attach_class_def: obj.original_mark_attach_class_def().to_owned_table(),
149 mark_glyph_sets_def: obj.original_mark_glyph_sets_def().to_owned_table(),
150 item_var_store: obj.item_var_store().to_owned_table(),
151 glyph_class_def2: obj.glyph_class_def2().to_owned_table(),
152 attach_list2: obj.attach_list2().to_owned_table(),
153 lig_caret_list2: obj.lig_caret_list2().to_owned_table(),
154 mark_attach_class_def2: obj.mark_attach_class_def2().to_owned_table(),
155 mark_glyph_sets_def2: obj.mark_glyph_sets_def2().to_owned_table(),
156 }
157 }
158}
159
160#[allow(clippy::needless_lifetimes)]
161impl<'a> FromTableRef<read_fonts::tables::gdef::Gdef<'a>> for Gdef {}
162
163impl ReadArgs for Gdef {
164 type Args = ();
165}
166
167impl<'a> FontRead<'a> for Gdef {
168 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
169 <read_fonts::tables::gdef::Gdef as FontRead>::read(data).map(|x| x.to_owned_table())
170 }
171}
172
173impl FontWrite for GlyphClassDef {
174 fn write_into(&self, writer: &mut TableWriter) {
175 let val = *self as u16;
176 writer.write_slice(&val.to_be_bytes())
177 }
178}
179
180#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
182#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
183pub struct AttachList {
184 pub coverage: OffsetMarker<CoverageTable>,
186 pub attach_points: Vec<OffsetMarker<AttachPoint>>,
189}
190
191impl AttachList {
192 pub fn new(coverage: CoverageTable, attach_points: Vec<AttachPoint>) -> Self {
194 Self {
195 coverage: coverage.into(),
196 attach_points: attach_points.into_iter().map(Into::into).collect(),
197 }
198 }
199}
200
201impl FontWrite for AttachList {
202 #[allow(clippy::unnecessary_cast)]
203 fn write_into(&self, writer: &mut TableWriter) {
204 self.coverage.write_into(writer);
205 (u16::try_from(array_len(&self.attach_points)).unwrap()).write_into(writer);
206 self.attach_points.write_into(writer);
207 }
208 fn table_type(&self) -> TableType {
209 TableType::Named("AttachList")
210 }
211}
212
213impl Validate for AttachList {
214 fn validate_impl(&self, ctx: &mut ValidationCtx) {
215 ctx.in_table("AttachList", |ctx| {
216 ctx.in_field("coverage", |ctx| {
217 self.coverage.validate_impl(ctx);
218 });
219 ctx.in_field("attach_points", |ctx| {
220 if self.attach_points.len() > to_usize(u16::MAX) {
221 ctx.report("array exceeds max length");
222 }
223 self.attach_points.validate_impl(ctx);
224 });
225 })
226 }
227}
228
229impl<'a> FromObjRef<read_fonts::tables::gdef::AttachList<'a>> for AttachList {
230 fn from_obj_ref(obj: &read_fonts::tables::gdef::AttachList<'a>, _: FontData) -> Self {
231 AttachList {
232 coverage: obj.coverage().to_owned_table(),
233 attach_points: obj.attach_points().to_owned_table(),
234 }
235 }
236}
237
238#[allow(clippy::needless_lifetimes)]
239impl<'a> FromTableRef<read_fonts::tables::gdef::AttachList<'a>> for AttachList {}
240
241impl ReadArgs for AttachList {
242 type Args = ();
243}
244
245impl<'a> FontRead<'a> for AttachList {
246 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
247 <read_fonts::tables::gdef::AttachList as FontRead>::read(data).map(|x| x.to_owned_table())
248 }
249}
250
251#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
253#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
254pub struct AttachPoint {
255 pub point_indices: Vec<u16>,
257}
258
259impl AttachPoint {
260 pub fn new(point_indices: Vec<u16>) -> Self {
262 Self { point_indices }
263 }
264}
265
266impl FontWrite for AttachPoint {
267 #[allow(clippy::unnecessary_cast)]
268 fn write_into(&self, writer: &mut TableWriter) {
269 (u16::try_from(array_len(&self.point_indices)).unwrap()).write_into(writer);
270 self.point_indices.write_into(writer);
271 }
272 fn table_type(&self) -> TableType {
273 TableType::Named("AttachPoint")
274 }
275}
276
277impl Validate for AttachPoint {
278 fn validate_impl(&self, ctx: &mut ValidationCtx) {
279 ctx.in_table("AttachPoint", |ctx| {
280 ctx.in_field("point_indices", |ctx| {
281 if self.point_indices.len() > to_usize(u16::MAX) {
282 ctx.report("array exceeds max length");
283 }
284 });
285 })
286 }
287}
288
289impl<'a> FromObjRef<read_fonts::tables::gdef::AttachPoint<'a>> for AttachPoint {
290 fn from_obj_ref(obj: &read_fonts::tables::gdef::AttachPoint<'a>, _: FontData) -> Self {
291 let offset_data = obj.offset_data();
292 AttachPoint {
293 point_indices: obj.point_indices().to_owned_obj(offset_data),
294 }
295 }
296}
297
298#[allow(clippy::needless_lifetimes)]
299impl<'a> FromTableRef<read_fonts::tables::gdef::AttachPoint<'a>> for AttachPoint {}
300
301impl ReadArgs for AttachPoint {
302 type Args = ();
303}
304
305impl<'a> FontRead<'a> for AttachPoint {
306 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
307 <read_fonts::tables::gdef::AttachPoint as FontRead>::read(data).map(|x| x.to_owned_table())
308 }
309}
310
311#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
313#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
314pub struct LigCaretList {
315 pub coverage: OffsetMarker<CoverageTable>,
317 pub lig_glyphs: Vec<OffsetMarker<LigGlyph>>,
320}
321
322impl LigCaretList {
323 pub fn new(coverage: CoverageTable, lig_glyphs: Vec<LigGlyph>) -> Self {
325 Self {
326 coverage: coverage.into(),
327 lig_glyphs: lig_glyphs.into_iter().map(Into::into).collect(),
328 }
329 }
330}
331
332impl FontWrite for LigCaretList {
333 #[allow(clippy::unnecessary_cast)]
334 fn write_into(&self, writer: &mut TableWriter) {
335 self.coverage.write_into(writer);
336 (u16::try_from(array_len(&self.lig_glyphs)).unwrap()).write_into(writer);
337 self.lig_glyphs.write_into(writer);
338 }
339 fn table_type(&self) -> TableType {
340 TableType::Named("LigCaretList")
341 }
342}
343
344impl Validate for LigCaretList {
345 fn validate_impl(&self, ctx: &mut ValidationCtx) {
346 ctx.in_table("LigCaretList", |ctx| {
347 ctx.in_field("coverage", |ctx| {
348 self.coverage.validate_impl(ctx);
349 });
350 ctx.in_field("lig_glyphs", |ctx| {
351 if self.lig_glyphs.len() > to_usize(u16::MAX) {
352 ctx.report("array exceeds max length");
353 }
354 self.lig_glyphs.validate_impl(ctx);
355 });
356 })
357 }
358}
359
360impl<'a> FromObjRef<read_fonts::tables::gdef::LigCaretList<'a>> for LigCaretList {
361 fn from_obj_ref(obj: &read_fonts::tables::gdef::LigCaretList<'a>, _: FontData) -> Self {
362 LigCaretList {
363 coverage: obj.coverage().to_owned_table(),
364 lig_glyphs: obj.lig_glyphs().to_owned_table(),
365 }
366 }
367}
368
369#[allow(clippy::needless_lifetimes)]
370impl<'a> FromTableRef<read_fonts::tables::gdef::LigCaretList<'a>> for LigCaretList {}
371
372impl ReadArgs for LigCaretList {
373 type Args = ();
374}
375
376impl<'a> FontRead<'a> for LigCaretList {
377 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
378 <read_fonts::tables::gdef::LigCaretList as FontRead>::read(data).map(|x| x.to_owned_table())
379 }
380}
381
382#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
384#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
385pub struct LigGlyph {
386 pub caret_values: Vec<OffsetMarker<CaretValue>>,
389}
390
391impl LigGlyph {
392 pub fn new(caret_values: Vec<CaretValue>) -> Self {
394 Self {
395 caret_values: caret_values.into_iter().map(Into::into).collect(),
396 }
397 }
398}
399
400impl FontWrite for LigGlyph {
401 #[allow(clippy::unnecessary_cast)]
402 fn write_into(&self, writer: &mut TableWriter) {
403 (u16::try_from(array_len(&self.caret_values)).unwrap()).write_into(writer);
404 self.caret_values.write_into(writer);
405 }
406 fn table_type(&self) -> TableType {
407 TableType::Named("LigGlyph")
408 }
409}
410
411impl Validate for LigGlyph {
412 fn validate_impl(&self, ctx: &mut ValidationCtx) {
413 ctx.in_table("LigGlyph", |ctx| {
414 ctx.in_field("caret_values", |ctx| {
415 if self.caret_values.len() > to_usize(u16::MAX) {
416 ctx.report("array exceeds max length");
417 }
418 self.caret_values.validate_impl(ctx);
419 });
420 })
421 }
422}
423
424impl<'a> FromObjRef<read_fonts::tables::gdef::LigGlyph<'a>> for LigGlyph {
425 fn from_obj_ref(obj: &read_fonts::tables::gdef::LigGlyph<'a>, _: FontData) -> Self {
426 LigGlyph {
427 caret_values: obj.caret_values().to_owned_table(),
428 }
429 }
430}
431
432#[allow(clippy::needless_lifetimes)]
433impl<'a> FromTableRef<read_fonts::tables::gdef::LigGlyph<'a>> for LigGlyph {}
434
435impl ReadArgs for LigGlyph {
436 type Args = ();
437}
438
439impl<'a> FontRead<'a> for LigGlyph {
440 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
441 <read_fonts::tables::gdef::LigGlyph as FontRead>::read(data).map(|x| x.to_owned_table())
442 }
443}
444
445#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
447#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
448pub enum CaretValue {
449 Format1(CaretValueFormat1),
450 Format2(CaretValueFormat2),
451 Format3(CaretValueFormat3),
452}
453
454impl CaretValue {
455 pub fn format_1(coordinate: i16) -> Self {
457 Self::Format1(CaretValueFormat1::new(coordinate))
458 }
459
460 pub fn format_2(caret_value_point_index: u16) -> Self {
462 Self::Format2(CaretValueFormat2::new(caret_value_point_index))
463 }
464
465 pub fn format_3(coordinate: i16, device: DeviceOrVariationIndex) -> Self {
467 Self::Format3(CaretValueFormat3::new(coordinate, device))
468 }
469}
470
471impl Default for CaretValue {
472 fn default() -> Self {
473 Self::Format1(Default::default())
474 }
475}
476
477impl FontWrite for CaretValue {
478 fn write_into(&self, writer: &mut TableWriter) {
479 match self {
480 Self::Format1(item) => item.write_into(writer),
481 Self::Format2(item) => item.write_into(writer),
482 Self::Format3(item) => item.write_into(writer),
483 }
484 }
485 fn table_type(&self) -> TableType {
486 match self {
487 Self::Format1(item) => item.table_type(),
488 Self::Format2(item) => item.table_type(),
489 Self::Format3(item) => item.table_type(),
490 }
491 }
492}
493
494impl Validate for CaretValue {
495 fn validate_impl(&self, ctx: &mut ValidationCtx) {
496 match self {
497 Self::Format1(item) => item.validate_impl(ctx),
498 Self::Format2(item) => item.validate_impl(ctx),
499 Self::Format3(item) => item.validate_impl(ctx),
500 }
501 }
502}
503
504impl FromObjRef<read_fonts::tables::gdef::CaretValue<'_>> for CaretValue {
505 fn from_obj_ref(obj: &read_fonts::tables::gdef::CaretValue, _: FontData) -> Self {
506 use read_fonts::tables::gdef::CaretValue as ObjRefType;
507 match obj {
508 ObjRefType::Format1(item) => CaretValue::Format1(item.to_owned_table()),
509 ObjRefType::Format2(item) => CaretValue::Format2(item.to_owned_table()),
510 ObjRefType::Format3(item) => CaretValue::Format3(item.to_owned_table()),
511 }
512 }
513}
514
515impl FromTableRef<read_fonts::tables::gdef::CaretValue<'_>> for CaretValue {}
516
517impl ReadArgs for CaretValue {
518 type Args = ();
519}
520
521impl<'a> FontRead<'a> for CaretValue {
522 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
523 <read_fonts::tables::gdef::CaretValue as FontRead>::read(data).map(|x| x.to_owned_table())
524 }
525}
526
527impl From<CaretValueFormat1> for CaretValue {
528 fn from(src: CaretValueFormat1) -> CaretValue {
529 CaretValue::Format1(src)
530 }
531}
532
533impl From<CaretValueFormat2> for CaretValue {
534 fn from(src: CaretValueFormat2) -> CaretValue {
535 CaretValue::Format2(src)
536 }
537}
538
539impl From<CaretValueFormat3> for CaretValue {
540 fn from(src: CaretValueFormat3) -> CaretValue {
541 CaretValue::Format3(src)
542 }
543}
544
545#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
547#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
548pub struct CaretValueFormat1 {
549 pub coordinate: i16,
551}
552
553impl CaretValueFormat1 {
554 pub fn new(coordinate: i16) -> Self {
556 Self { coordinate }
557 }
558}
559
560impl FontWrite for CaretValueFormat1 {
561 #[allow(clippy::unnecessary_cast)]
562 fn write_into(&self, writer: &mut TableWriter) {
563 (1 as u16).write_into(writer);
564 self.coordinate.write_into(writer);
565 }
566 fn table_type(&self) -> TableType {
567 TableType::Named("CaretValueFormat1")
568 }
569}
570
571impl Validate for CaretValueFormat1 {
572 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
573}
574
575impl<'a> FromObjRef<read_fonts::tables::gdef::CaretValueFormat1<'a>> for CaretValueFormat1 {
576 fn from_obj_ref(obj: &read_fonts::tables::gdef::CaretValueFormat1<'a>, _: FontData) -> Self {
577 CaretValueFormat1 {
578 coordinate: obj.coordinate(),
579 }
580 }
581}
582
583#[allow(clippy::needless_lifetimes)]
584impl<'a> FromTableRef<read_fonts::tables::gdef::CaretValueFormat1<'a>> for CaretValueFormat1 {}
585
586impl ReadArgs for CaretValueFormat1 {
587 type Args = ();
588}
589
590impl<'a> FontRead<'a> for CaretValueFormat1 {
591 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
592 <read_fonts::tables::gdef::CaretValueFormat1 as FontRead>::read(data)
593 .map(|x| x.to_owned_table())
594 }
595}
596
597#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
599#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
600pub struct CaretValueFormat2 {
601 pub caret_value_point_index: u16,
603}
604
605impl CaretValueFormat2 {
606 pub fn new(caret_value_point_index: u16) -> Self {
608 Self {
609 caret_value_point_index,
610 }
611 }
612}
613
614impl FontWrite for CaretValueFormat2 {
615 #[allow(clippy::unnecessary_cast)]
616 fn write_into(&self, writer: &mut TableWriter) {
617 (2 as u16).write_into(writer);
618 self.caret_value_point_index.write_into(writer);
619 }
620 fn table_type(&self) -> TableType {
621 TableType::Named("CaretValueFormat2")
622 }
623}
624
625impl Validate for CaretValueFormat2 {
626 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
627}
628
629impl<'a> FromObjRef<read_fonts::tables::gdef::CaretValueFormat2<'a>> for CaretValueFormat2 {
630 fn from_obj_ref(obj: &read_fonts::tables::gdef::CaretValueFormat2<'a>, _: FontData) -> Self {
631 CaretValueFormat2 {
632 caret_value_point_index: obj.caret_value_point_index(),
633 }
634 }
635}
636
637#[allow(clippy::needless_lifetimes)]
638impl<'a> FromTableRef<read_fonts::tables::gdef::CaretValueFormat2<'a>> for CaretValueFormat2 {}
639
640impl ReadArgs for CaretValueFormat2 {
641 type Args = ();
642}
643
644impl<'a> FontRead<'a> for CaretValueFormat2 {
645 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
646 <read_fonts::tables::gdef::CaretValueFormat2 as FontRead>::read(data)
647 .map(|x| x.to_owned_table())
648 }
649}
650
651#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
653#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
654pub struct CaretValueFormat3 {
655 pub coordinate: i16,
657 pub device: OffsetMarker<DeviceOrVariationIndex>,
661}
662
663impl CaretValueFormat3 {
664 pub fn new(coordinate: i16, device: DeviceOrVariationIndex) -> Self {
666 Self {
667 coordinate,
668 device: device.into(),
669 }
670 }
671}
672
673impl FontWrite for CaretValueFormat3 {
674 #[allow(clippy::unnecessary_cast)]
675 fn write_into(&self, writer: &mut TableWriter) {
676 (3 as u16).write_into(writer);
677 self.coordinate.write_into(writer);
678 self.device.write_into(writer);
679 }
680 fn table_type(&self) -> TableType {
681 TableType::Named("CaretValueFormat3")
682 }
683}
684
685impl Validate for CaretValueFormat3 {
686 fn validate_impl(&self, ctx: &mut ValidationCtx) {
687 ctx.in_table("CaretValueFormat3", |ctx| {
688 ctx.in_field("device", |ctx| {
689 self.device.validate_impl(ctx);
690 });
691 })
692 }
693}
694
695impl<'a> FromObjRef<read_fonts::tables::gdef::CaretValueFormat3<'a>> for CaretValueFormat3 {
696 fn from_obj_ref(obj: &read_fonts::tables::gdef::CaretValueFormat3<'a>, _: FontData) -> Self {
697 CaretValueFormat3 {
698 coordinate: obj.coordinate(),
699 device: obj.device().to_owned_table(),
700 }
701 }
702}
703
704#[allow(clippy::needless_lifetimes)]
705impl<'a> FromTableRef<read_fonts::tables::gdef::CaretValueFormat3<'a>> for CaretValueFormat3 {}
706
707impl ReadArgs for CaretValueFormat3 {
708 type Args = ();
709}
710
711impl<'a> FontRead<'a> for CaretValueFormat3 {
712 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
713 <read_fonts::tables::gdef::CaretValueFormat3 as FontRead>::read(data)
714 .map(|x| x.to_owned_table())
715 }
716}
717
718#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
720#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
721pub struct MarkGlyphSets {
722 pub coverages: Vec<OffsetMarker<CoverageTable, WIDTH_32>>,
725}
726
727impl MarkGlyphSets {
728 pub fn new(coverages: Vec<CoverageTable>) -> Self {
730 Self {
731 coverages: coverages.into_iter().map(Into::into).collect(),
732 }
733 }
734}
735
736impl FontWrite for MarkGlyphSets {
737 #[allow(clippy::unnecessary_cast)]
738 fn write_into(&self, writer: &mut TableWriter) {
739 (1 as u16).write_into(writer);
740 (u16::try_from(array_len(&self.coverages)).unwrap()).write_into(writer);
741 self.coverages.write_into(writer);
742 }
743 fn table_type(&self) -> TableType {
744 TableType::Named("MarkGlyphSets")
745 }
746}
747
748impl Validate for MarkGlyphSets {
749 fn validate_impl(&self, ctx: &mut ValidationCtx) {
750 ctx.in_table("MarkGlyphSets", |ctx| {
751 ctx.in_field("coverages", |ctx| {
752 if self.coverages.len() > to_usize(u16::MAX) {
753 ctx.report("array exceeds max length");
754 }
755 self.coverages.validate_impl(ctx);
756 });
757 })
758 }
759}
760
761impl<'a> FromObjRef<read_fonts::tables::gdef::MarkGlyphSets<'a>> for MarkGlyphSets {
762 fn from_obj_ref(obj: &read_fonts::tables::gdef::MarkGlyphSets<'a>, _: FontData) -> Self {
763 MarkGlyphSets {
764 coverages: obj.coverages().to_owned_table(),
765 }
766 }
767}
768
769#[allow(clippy::needless_lifetimes)]
770impl<'a> FromTableRef<read_fonts::tables::gdef::MarkGlyphSets<'a>> for MarkGlyphSets {}
771
772impl ReadArgs for MarkGlyphSets {
773 type Args = ();
774}
775
776impl<'a> FontRead<'a> for MarkGlyphSets {
777 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
778 <read_fonts::tables::gdef::MarkGlyphSets as FontRead>::read(data)
779 .map(|x| x.to_owned_table())
780 }
781}
782
783#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
785#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
786pub struct LigCaretList2 {
787 pub coverage: OffsetMarker<CoverageTable, WIDTH_32>,
789 pub lig_glyphs: Vec<OffsetMarker<LigGlyph, WIDTH_24>>,
792}
793
794impl LigCaretList2 {
795 pub fn new(coverage: CoverageTable, lig_glyphs: Vec<LigGlyph>) -> Self {
797 Self {
798 coverage: coverage.into(),
799 lig_glyphs: lig_glyphs.into_iter().map(Into::into).collect(),
800 }
801 }
802}
803
804impl FontWrite for LigCaretList2 {
805 #[allow(clippy::unnecessary_cast)]
806 fn write_into(&self, writer: &mut TableWriter) {
807 self.coverage.write_into(writer);
808 (Uint24::try_from(array_len(&self.lig_glyphs)).unwrap()).write_into(writer);
809 self.lig_glyphs.write_into(writer);
810 }
811 fn table_type(&self) -> TableType {
812 TableType::Named("LigCaretList2")
813 }
814}
815
816impl Validate for LigCaretList2 {
817 fn validate_impl(&self, ctx: &mut ValidationCtx) {
818 ctx.in_table("LigCaretList2", |ctx| {
819 ctx.in_field("coverage", |ctx| {
820 self.coverage.validate_impl(ctx);
821 });
822 ctx.in_field("lig_glyphs", |ctx| {
823 if self.lig_glyphs.len() > to_usize(Uint24::MAX) {
824 ctx.report("array exceeds max length");
825 }
826 self.lig_glyphs.validate_impl(ctx);
827 });
828 })
829 }
830}
831
832impl<'a> FromObjRef<read_fonts::tables::gdef::LigCaretList2<'a>> for LigCaretList2 {
833 fn from_obj_ref(obj: &read_fonts::tables::gdef::LigCaretList2<'a>, _: FontData) -> Self {
834 LigCaretList2 {
835 coverage: obj.coverage().to_owned_table(),
836 lig_glyphs: obj.lig_glyphs().to_owned_table(),
837 }
838 }
839}
840
841#[allow(clippy::needless_lifetimes)]
842impl<'a> FromTableRef<read_fonts::tables::gdef::LigCaretList2<'a>> for LigCaretList2 {}
843
844impl ReadArgs for LigCaretList2 {
845 type Args = ();
846}
847
848impl<'a> FontRead<'a> for LigCaretList2 {
849 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
850 <read_fonts::tables::gdef::LigCaretList2 as FontRead>::read(data)
851 .map(|x| x.to_owned_table())
852 }
853}