1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct Base {
12 pub horiz_axis: NullableOffsetMarker<Axis>,
14 pub vert_axis: NullableOffsetMarker<Axis>,
16 pub item_var_store: NullableOffsetMarker<ItemVariationStore, WIDTH_32>,
18}
19
20impl Base {
21 pub fn new(horiz_axis: Option<Axis>, vert_axis: Option<Axis>) -> Self {
23 Self {
24 horiz_axis: horiz_axis.into(),
25 vert_axis: vert_axis.into(),
26 ..Default::default()
27 }
28 }
29}
30
31impl FontWrite for Base {
32 #[allow(clippy::unnecessary_cast)]
33 fn write_into(&self, writer: &mut TableWriter) {
34 let version = self.compute_version() as MajorMinor;
35 version.write_into(writer);
36 self.horiz_axis.write_into(writer);
37 self.vert_axis.write_into(writer);
38 version
39 .compatible((1u16, 1u16))
40 .then(|| self.item_var_store.write_into(writer));
41 }
42 fn table_type(&self) -> TableType {
43 TableType::TopLevel(Base::TAG)
44 }
45}
46
47impl Validate for Base {
48 fn validate_impl(&self, ctx: &mut ValidationCtx) {
49 ctx.in_table("Base", |ctx| {
50 ctx.in_field("horiz_axis", |ctx| {
51 self.horiz_axis.validate_impl(ctx);
52 });
53 ctx.in_field("vert_axis", |ctx| {
54 self.vert_axis.validate_impl(ctx);
55 });
56 ctx.in_field("item_var_store", |ctx| {
57 self.item_var_store.validate_impl(ctx);
58 });
59 })
60 }
61}
62
63impl TopLevelTable for Base {
64 const TAG: Tag = Tag::new(b"BASE");
65}
66
67impl<'a> FromObjRef<read_fonts::tables::base::Base<'a>> for Base {
68 fn from_obj_ref(obj: &read_fonts::tables::base::Base<'a>, _: FontData) -> Self {
69 Base {
70 horiz_axis: obj.horiz_axis().to_owned_table(),
71 vert_axis: obj.vert_axis().to_owned_table(),
72 item_var_store: obj.item_var_store().to_owned_table(),
73 }
74 }
75}
76
77#[allow(clippy::needless_lifetimes)]
78impl<'a> FromTableRef<read_fonts::tables::base::Base<'a>> for Base {}
79
80impl ReadArgs for Base {
81 type Args = ();
82}
83
84impl<'a> FontRead<'a> for Base {
85 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
86 <read_fonts::tables::base::Base as FontRead>::read(data).map(|x| x.to_owned_table())
87 }
88}
89
90#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
92#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
93pub struct Axis {
94 pub base_tag_list: NullableOffsetMarker<BaseTagList>,
97 pub base_script_list: OffsetMarker<BaseScriptList>,
99}
100
101impl Axis {
102 pub fn new(base_tag_list: Option<BaseTagList>, base_script_list: BaseScriptList) -> Self {
104 Self {
105 base_tag_list: base_tag_list.into(),
106 base_script_list: base_script_list.into(),
107 }
108 }
109}
110
111impl FontWrite for Axis {
112 fn write_into(&self, writer: &mut TableWriter) {
113 self.base_tag_list.write_into(writer);
114 self.base_script_list.write_into(writer);
115 }
116 fn table_type(&self) -> TableType {
117 TableType::Named("Axis")
118 }
119}
120
121impl Validate for Axis {
122 fn validate_impl(&self, ctx: &mut ValidationCtx) {
123 ctx.in_table("Axis", |ctx| {
124 ctx.in_field("base_tag_list", |ctx| {
125 self.base_tag_list.validate_impl(ctx);
126 });
127 ctx.in_field("base_script_list", |ctx| {
128 self.base_script_list.validate_impl(ctx);
129 });
130 })
131 }
132}
133
134impl<'a> FromObjRef<read_fonts::tables::base::Axis<'a>> for Axis {
135 fn from_obj_ref(obj: &read_fonts::tables::base::Axis<'a>, _: FontData) -> Self {
136 Axis {
137 base_tag_list: obj.base_tag_list().to_owned_table(),
138 base_script_list: obj.base_script_list().to_owned_table(),
139 }
140 }
141}
142
143#[allow(clippy::needless_lifetimes)]
144impl<'a> FromTableRef<read_fonts::tables::base::Axis<'a>> for Axis {}
145
146impl ReadArgs for Axis {
147 type Args = ();
148}
149
150impl<'a> FontRead<'a> for Axis {
151 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
152 <read_fonts::tables::base::Axis as FontRead>::read(data).map(|x| x.to_owned_table())
153 }
154}
155
156#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
158#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
159pub struct BaseTagList {
160 pub baseline_tags: Vec<Tag>,
163}
164
165impl BaseTagList {
166 pub fn new(baseline_tags: Vec<Tag>) -> Self {
168 Self { baseline_tags }
169 }
170}
171
172impl FontWrite for BaseTagList {
173 #[allow(clippy::unnecessary_cast)]
174 fn write_into(&self, writer: &mut TableWriter) {
175 (u16::try_from(array_len(&self.baseline_tags)).unwrap()).write_into(writer);
176 self.baseline_tags.write_into(writer);
177 }
178 fn table_type(&self) -> TableType {
179 TableType::Named("BaseTagList")
180 }
181}
182
183impl Validate for BaseTagList {
184 fn validate_impl(&self, ctx: &mut ValidationCtx) {
185 ctx.in_table("BaseTagList", |ctx| {
186 ctx.in_field("baseline_tags", |ctx| {
187 if self.baseline_tags.len() > to_usize(u16::MAX) {
188 ctx.report("array exceeds max length");
189 }
190 });
191 })
192 }
193}
194
195impl<'a> FromObjRef<read_fonts::tables::base::BaseTagList<'a>> for BaseTagList {
196 fn from_obj_ref(obj: &read_fonts::tables::base::BaseTagList<'a>, _: FontData) -> Self {
197 let offset_data = obj.offset_data();
198 BaseTagList {
199 baseline_tags: obj.baseline_tags().to_owned_obj(offset_data),
200 }
201 }
202}
203
204#[allow(clippy::needless_lifetimes)]
205impl<'a> FromTableRef<read_fonts::tables::base::BaseTagList<'a>> for BaseTagList {}
206
207impl ReadArgs for BaseTagList {
208 type Args = ();
209}
210
211impl<'a> FontRead<'a> for BaseTagList {
212 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
213 <read_fonts::tables::base::BaseTagList as FontRead>::read(data).map(|x| x.to_owned_table())
214 }
215}
216
217#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
219#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
220pub struct BaseScriptList {
221 pub base_script_records: Vec<BaseScriptRecord>,
224}
225
226impl BaseScriptList {
227 pub fn new(base_script_records: Vec<BaseScriptRecord>) -> Self {
229 Self {
230 base_script_records,
231 }
232 }
233}
234
235impl FontWrite for BaseScriptList {
236 #[allow(clippy::unnecessary_cast)]
237 fn write_into(&self, writer: &mut TableWriter) {
238 (u16::try_from(array_len(&self.base_script_records)).unwrap()).write_into(writer);
239 self.base_script_records.write_into(writer);
240 }
241 fn table_type(&self) -> TableType {
242 TableType::Named("BaseScriptList")
243 }
244}
245
246impl Validate for BaseScriptList {
247 fn validate_impl(&self, ctx: &mut ValidationCtx) {
248 ctx.in_table("BaseScriptList", |ctx| {
249 ctx.in_field("base_script_records", |ctx| {
250 if self.base_script_records.len() > to_usize(u16::MAX) {
251 ctx.report("array exceeds max length");
252 }
253 self.base_script_records.validate_impl(ctx);
254 });
255 })
256 }
257}
258
259impl<'a> FromObjRef<read_fonts::tables::base::BaseScriptList<'a>> for BaseScriptList {
260 fn from_obj_ref(obj: &read_fonts::tables::base::BaseScriptList<'a>, _: FontData) -> Self {
261 let offset_data = obj.offset_data();
262 BaseScriptList {
263 base_script_records: obj.base_script_records().to_owned_obj(offset_data),
264 }
265 }
266}
267
268#[allow(clippy::needless_lifetimes)]
269impl<'a> FromTableRef<read_fonts::tables::base::BaseScriptList<'a>> for BaseScriptList {}
270
271impl ReadArgs for BaseScriptList {
272 type Args = ();
273}
274
275impl<'a> FontRead<'a> for BaseScriptList {
276 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
277 <read_fonts::tables::base::BaseScriptList as FontRead>::read(data)
278 .map(|x| x.to_owned_table())
279 }
280}
281
282#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
284#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
285pub struct BaseScriptRecord {
286 pub base_script_tag: Tag,
288 pub base_script: OffsetMarker<BaseScript>,
290}
291
292impl BaseScriptRecord {
293 pub fn new(base_script_tag: Tag, base_script: BaseScript) -> Self {
295 Self {
296 base_script_tag,
297 base_script: base_script.into(),
298 }
299 }
300}
301
302impl FontWrite for BaseScriptRecord {
303 fn write_into(&self, writer: &mut TableWriter) {
304 self.base_script_tag.write_into(writer);
305 self.base_script.write_into(writer);
306 }
307 fn table_type(&self) -> TableType {
308 TableType::Named("BaseScriptRecord")
309 }
310}
311
312impl Validate for BaseScriptRecord {
313 fn validate_impl(&self, ctx: &mut ValidationCtx) {
314 ctx.in_table("BaseScriptRecord", |ctx| {
315 ctx.in_field("base_script", |ctx| {
316 self.base_script.validate_impl(ctx);
317 });
318 })
319 }
320}
321
322impl FromObjRef<read_fonts::tables::base::BaseScriptRecord> for BaseScriptRecord {
323 fn from_obj_ref(
324 obj: &read_fonts::tables::base::BaseScriptRecord,
325 offset_data: FontData,
326 ) -> Self {
327 BaseScriptRecord {
328 base_script_tag: obj.base_script_tag(),
329 base_script: obj.base_script(offset_data).to_owned_table(),
330 }
331 }
332}
333
334#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
336#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
337pub struct BaseScript {
338 pub base_values: NullableOffsetMarker<BaseValues>,
340 pub default_min_max: NullableOffsetMarker<MinMax>,
342 pub base_lang_sys_records: Vec<BaseLangSysRecord>,
345}
346
347impl BaseScript {
348 pub fn new(
350 base_values: Option<BaseValues>,
351 default_min_max: Option<MinMax>,
352 base_lang_sys_records: Vec<BaseLangSysRecord>,
353 ) -> Self {
354 Self {
355 base_values: base_values.into(),
356 default_min_max: default_min_max.into(),
357 base_lang_sys_records,
358 }
359 }
360}
361
362impl FontWrite for BaseScript {
363 #[allow(clippy::unnecessary_cast)]
364 fn write_into(&self, writer: &mut TableWriter) {
365 self.base_values.write_into(writer);
366 self.default_min_max.write_into(writer);
367 (u16::try_from(array_len(&self.base_lang_sys_records)).unwrap()).write_into(writer);
368 self.base_lang_sys_records.write_into(writer);
369 }
370 fn table_type(&self) -> TableType {
371 TableType::Named("BaseScript")
372 }
373}
374
375impl Validate for BaseScript {
376 fn validate_impl(&self, ctx: &mut ValidationCtx) {
377 ctx.in_table("BaseScript", |ctx| {
378 ctx.in_field("base_values", |ctx| {
379 self.base_values.validate_impl(ctx);
380 });
381 ctx.in_field("default_min_max", |ctx| {
382 self.default_min_max.validate_impl(ctx);
383 });
384 ctx.in_field("base_lang_sys_records", |ctx| {
385 if self.base_lang_sys_records.len() > to_usize(u16::MAX) {
386 ctx.report("array exceeds max length");
387 }
388 self.base_lang_sys_records.validate_impl(ctx);
389 });
390 })
391 }
392}
393
394impl<'a> FromObjRef<read_fonts::tables::base::BaseScript<'a>> for BaseScript {
395 fn from_obj_ref(obj: &read_fonts::tables::base::BaseScript<'a>, _: FontData) -> Self {
396 let offset_data = obj.offset_data();
397 BaseScript {
398 base_values: obj.base_values().to_owned_table(),
399 default_min_max: obj.default_min_max().to_owned_table(),
400 base_lang_sys_records: obj.base_lang_sys_records().to_owned_obj(offset_data),
401 }
402 }
403}
404
405#[allow(clippy::needless_lifetimes)]
406impl<'a> FromTableRef<read_fonts::tables::base::BaseScript<'a>> for BaseScript {}
407
408impl ReadArgs for BaseScript {
409 type Args = ();
410}
411
412impl<'a> FontRead<'a> for BaseScript {
413 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
414 <read_fonts::tables::base::BaseScript as FontRead>::read(data).map(|x| x.to_owned_table())
415 }
416}
417
418#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
420#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
421pub struct BaseLangSysRecord {
422 pub base_lang_sys_tag: Tag,
424 pub min_max: OffsetMarker<MinMax>,
426}
427
428impl BaseLangSysRecord {
429 pub fn new(base_lang_sys_tag: Tag, min_max: MinMax) -> Self {
431 Self {
432 base_lang_sys_tag,
433 min_max: min_max.into(),
434 }
435 }
436}
437
438impl FontWrite for BaseLangSysRecord {
439 fn write_into(&self, writer: &mut TableWriter) {
440 self.base_lang_sys_tag.write_into(writer);
441 self.min_max.write_into(writer);
442 }
443 fn table_type(&self) -> TableType {
444 TableType::Named("BaseLangSysRecord")
445 }
446}
447
448impl Validate for BaseLangSysRecord {
449 fn validate_impl(&self, ctx: &mut ValidationCtx) {
450 ctx.in_table("BaseLangSysRecord", |ctx| {
451 ctx.in_field("min_max", |ctx| {
452 self.min_max.validate_impl(ctx);
453 });
454 })
455 }
456}
457
458impl FromObjRef<read_fonts::tables::base::BaseLangSysRecord> for BaseLangSysRecord {
459 fn from_obj_ref(
460 obj: &read_fonts::tables::base::BaseLangSysRecord,
461 offset_data: FontData,
462 ) -> Self {
463 BaseLangSysRecord {
464 base_lang_sys_tag: obj.base_lang_sys_tag(),
465 min_max: obj.min_max(offset_data).to_owned_table(),
466 }
467 }
468}
469
470#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
472#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
473pub struct BaseValues {
474 pub default_baseline_index: u16,
478 pub base_coords: Vec<OffsetMarker<BaseCoord>>,
482}
483
484impl BaseValues {
485 pub fn new(default_baseline_index: u16, base_coords: Vec<BaseCoord>) -> Self {
487 Self {
488 default_baseline_index,
489 base_coords: base_coords.into_iter().map(Into::into).collect(),
490 }
491 }
492}
493
494impl FontWrite for BaseValues {
495 #[allow(clippy::unnecessary_cast)]
496 fn write_into(&self, writer: &mut TableWriter) {
497 self.default_baseline_index.write_into(writer);
498 (u16::try_from(array_len(&self.base_coords)).unwrap()).write_into(writer);
499 self.base_coords.write_into(writer);
500 }
501 fn table_type(&self) -> TableType {
502 TableType::Named("BaseValues")
503 }
504}
505
506impl Validate for BaseValues {
507 fn validate_impl(&self, ctx: &mut ValidationCtx) {
508 ctx.in_table("BaseValues", |ctx| {
509 ctx.in_field("base_coords", |ctx| {
510 if self.base_coords.len() > to_usize(u16::MAX) {
511 ctx.report("array exceeds max length");
512 }
513 self.base_coords.validate_impl(ctx);
514 });
515 })
516 }
517}
518
519impl<'a> FromObjRef<read_fonts::tables::base::BaseValues<'a>> for BaseValues {
520 fn from_obj_ref(obj: &read_fonts::tables::base::BaseValues<'a>, _: FontData) -> Self {
521 BaseValues {
522 default_baseline_index: obj.default_baseline_index(),
523 base_coords: obj.base_coords().to_owned_table(),
524 }
525 }
526}
527
528#[allow(clippy::needless_lifetimes)]
529impl<'a> FromTableRef<read_fonts::tables::base::BaseValues<'a>> for BaseValues {}
530
531impl ReadArgs for BaseValues {
532 type Args = ();
533}
534
535impl<'a> FontRead<'a> for BaseValues {
536 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
537 <read_fonts::tables::base::BaseValues as FontRead>::read(data).map(|x| x.to_owned_table())
538 }
539}
540
541#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
543#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
544pub struct MinMax {
545 pub min_coord: NullableOffsetMarker<BaseCoord>,
548 pub max_coord: NullableOffsetMarker<BaseCoord>,
551 pub feat_min_max_records: Vec<FeatMinMaxRecord>,
554}
555
556impl MinMax {
557 pub fn new(
559 min_coord: Option<BaseCoord>,
560 max_coord: Option<BaseCoord>,
561 feat_min_max_records: Vec<FeatMinMaxRecord>,
562 ) -> Self {
563 Self {
564 min_coord: min_coord.into(),
565 max_coord: max_coord.into(),
566 feat_min_max_records,
567 }
568 }
569}
570
571impl FontWrite for MinMax {
572 #[allow(clippy::unnecessary_cast)]
573 fn write_into(&self, writer: &mut TableWriter) {
574 self.min_coord.write_into(writer);
575 self.max_coord.write_into(writer);
576 (u16::try_from(array_len(&self.feat_min_max_records)).unwrap()).write_into(writer);
577 self.feat_min_max_records.write_into(writer);
578 }
579 fn table_type(&self) -> TableType {
580 TableType::Named("MinMax")
581 }
582}
583
584impl Validate for MinMax {
585 fn validate_impl(&self, ctx: &mut ValidationCtx) {
586 ctx.in_table("MinMax", |ctx| {
587 ctx.in_field("min_coord", |ctx| {
588 self.min_coord.validate_impl(ctx);
589 });
590 ctx.in_field("max_coord", |ctx| {
591 self.max_coord.validate_impl(ctx);
592 });
593 ctx.in_field("feat_min_max_records", |ctx| {
594 if self.feat_min_max_records.len() > to_usize(u16::MAX) {
595 ctx.report("array exceeds max length");
596 }
597 self.feat_min_max_records.validate_impl(ctx);
598 });
599 })
600 }
601}
602
603impl<'a> FromObjRef<read_fonts::tables::base::MinMax<'a>> for MinMax {
604 fn from_obj_ref(obj: &read_fonts::tables::base::MinMax<'a>, _: FontData) -> Self {
605 let offset_data = obj.offset_data();
606 MinMax {
607 min_coord: obj.min_coord().to_owned_table(),
608 max_coord: obj.max_coord().to_owned_table(),
609 feat_min_max_records: obj.feat_min_max_records().to_owned_obj(offset_data),
610 }
611 }
612}
613
614#[allow(clippy::needless_lifetimes)]
615impl<'a> FromTableRef<read_fonts::tables::base::MinMax<'a>> for MinMax {}
616
617impl ReadArgs for MinMax {
618 type Args = ();
619}
620
621impl<'a> FontRead<'a> for MinMax {
622 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
623 <read_fonts::tables::base::MinMax as FontRead>::read(data).map(|x| x.to_owned_table())
624 }
625}
626
627#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
629#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
630pub struct FeatMinMaxRecord {
631 pub feature_table_tag: Tag,
634 pub min_coord: NullableOffsetMarker<BaseCoord>,
637 pub max_coord: NullableOffsetMarker<BaseCoord>,
640}
641
642impl FeatMinMaxRecord {
643 pub fn new(
645 feature_table_tag: Tag,
646 min_coord: Option<BaseCoord>,
647 max_coord: Option<BaseCoord>,
648 ) -> Self {
649 Self {
650 feature_table_tag,
651 min_coord: min_coord.into(),
652 max_coord: max_coord.into(),
653 }
654 }
655}
656
657impl FontWrite for FeatMinMaxRecord {
658 fn write_into(&self, writer: &mut TableWriter) {
659 self.feature_table_tag.write_into(writer);
660 self.min_coord.write_into(writer);
661 self.max_coord.write_into(writer);
662 }
663 fn table_type(&self) -> TableType {
664 TableType::Named("FeatMinMaxRecord")
665 }
666}
667
668impl Validate for FeatMinMaxRecord {
669 fn validate_impl(&self, ctx: &mut ValidationCtx) {
670 ctx.in_table("FeatMinMaxRecord", |ctx| {
671 ctx.in_field("min_coord", |ctx| {
672 self.min_coord.validate_impl(ctx);
673 });
674 ctx.in_field("max_coord", |ctx| {
675 self.max_coord.validate_impl(ctx);
676 });
677 })
678 }
679}
680
681impl FromObjRef<read_fonts::tables::base::FeatMinMaxRecord> for FeatMinMaxRecord {
682 fn from_obj_ref(
683 obj: &read_fonts::tables::base::FeatMinMaxRecord,
684 offset_data: FontData,
685 ) -> Self {
686 FeatMinMaxRecord {
687 feature_table_tag: obj.feature_table_tag(),
688 min_coord: obj.min_coord(offset_data).to_owned_table(),
689 max_coord: obj.max_coord(offset_data).to_owned_table(),
690 }
691 }
692}
693
694#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
695#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
696pub enum BaseCoord {
697 Format1(BaseCoordFormat1),
698 Format2(BaseCoordFormat2),
699 Format3(BaseCoordFormat3),
700}
701
702impl BaseCoord {
703 pub fn format_1(coordinate: i16) -> Self {
705 Self::Format1(BaseCoordFormat1::new(coordinate))
706 }
707
708 pub fn format_2(coordinate: i16, reference_glyph: u16, base_coord_point: u16) -> Self {
710 Self::Format2(BaseCoordFormat2::new(
711 coordinate,
712 reference_glyph,
713 base_coord_point,
714 ))
715 }
716
717 pub fn format_3(coordinate: i16, device: Option<DeviceOrVariationIndex>) -> Self {
719 Self::Format3(BaseCoordFormat3::new(coordinate, device))
720 }
721}
722
723impl Default for BaseCoord {
724 fn default() -> Self {
725 Self::Format1(Default::default())
726 }
727}
728
729impl FontWrite for BaseCoord {
730 fn write_into(&self, writer: &mut TableWriter) {
731 match self {
732 Self::Format1(item) => item.write_into(writer),
733 Self::Format2(item) => item.write_into(writer),
734 Self::Format3(item) => item.write_into(writer),
735 }
736 }
737 fn table_type(&self) -> TableType {
738 match self {
739 Self::Format1(item) => item.table_type(),
740 Self::Format2(item) => item.table_type(),
741 Self::Format3(item) => item.table_type(),
742 }
743 }
744}
745
746impl Validate for BaseCoord {
747 fn validate_impl(&self, ctx: &mut ValidationCtx) {
748 match self {
749 Self::Format1(item) => item.validate_impl(ctx),
750 Self::Format2(item) => item.validate_impl(ctx),
751 Self::Format3(item) => item.validate_impl(ctx),
752 }
753 }
754}
755
756impl FromObjRef<read_fonts::tables::base::BaseCoord<'_>> for BaseCoord {
757 fn from_obj_ref(obj: &read_fonts::tables::base::BaseCoord, _: FontData) -> Self {
758 use read_fonts::tables::base::BaseCoord as ObjRefType;
759 match obj {
760 ObjRefType::Format1(item) => BaseCoord::Format1(item.to_owned_table()),
761 ObjRefType::Format2(item) => BaseCoord::Format2(item.to_owned_table()),
762 ObjRefType::Format3(item) => BaseCoord::Format3(item.to_owned_table()),
763 }
764 }
765}
766
767impl FromTableRef<read_fonts::tables::base::BaseCoord<'_>> for BaseCoord {}
768
769impl ReadArgs for BaseCoord {
770 type Args = ();
771}
772
773impl<'a> FontRead<'a> for BaseCoord {
774 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
775 <read_fonts::tables::base::BaseCoord as FontRead>::read(data).map(|x| x.to_owned_table())
776 }
777}
778
779impl From<BaseCoordFormat1> for BaseCoord {
780 fn from(src: BaseCoordFormat1) -> BaseCoord {
781 BaseCoord::Format1(src)
782 }
783}
784
785impl From<BaseCoordFormat2> for BaseCoord {
786 fn from(src: BaseCoordFormat2) -> BaseCoord {
787 BaseCoord::Format2(src)
788 }
789}
790
791impl From<BaseCoordFormat3> for BaseCoord {
792 fn from(src: BaseCoordFormat3) -> BaseCoord {
793 BaseCoord::Format3(src)
794 }
795}
796
797#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
799#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
800pub struct BaseCoordFormat1 {
801 pub coordinate: i16,
803}
804
805impl BaseCoordFormat1 {
806 pub fn new(coordinate: i16) -> Self {
808 Self { coordinate }
809 }
810}
811
812impl FontWrite for BaseCoordFormat1 {
813 #[allow(clippy::unnecessary_cast)]
814 fn write_into(&self, writer: &mut TableWriter) {
815 (1 as u16).write_into(writer);
816 self.coordinate.write_into(writer);
817 }
818 fn table_type(&self) -> TableType {
819 TableType::Named("BaseCoordFormat1")
820 }
821}
822
823impl Validate for BaseCoordFormat1 {
824 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
825}
826
827impl<'a> FromObjRef<read_fonts::tables::base::BaseCoordFormat1<'a>> for BaseCoordFormat1 {
828 fn from_obj_ref(obj: &read_fonts::tables::base::BaseCoordFormat1<'a>, _: FontData) -> Self {
829 BaseCoordFormat1 {
830 coordinate: obj.coordinate(),
831 }
832 }
833}
834
835#[allow(clippy::needless_lifetimes)]
836impl<'a> FromTableRef<read_fonts::tables::base::BaseCoordFormat1<'a>> for BaseCoordFormat1 {}
837
838impl ReadArgs for BaseCoordFormat1 {
839 type Args = ();
840}
841
842impl<'a> FontRead<'a> for BaseCoordFormat1 {
843 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
844 <read_fonts::tables::base::BaseCoordFormat1 as FontRead>::read(data)
845 .map(|x| x.to_owned_table())
846 }
847}
848
849#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
851#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
852pub struct BaseCoordFormat2 {
853 pub coordinate: i16,
855 pub reference_glyph: u16,
857 pub base_coord_point: u16,
859}
860
861impl BaseCoordFormat2 {
862 pub fn new(coordinate: i16, reference_glyph: u16, base_coord_point: u16) -> Self {
864 Self {
865 coordinate,
866 reference_glyph,
867 base_coord_point,
868 }
869 }
870}
871
872impl FontWrite for BaseCoordFormat2 {
873 #[allow(clippy::unnecessary_cast)]
874 fn write_into(&self, writer: &mut TableWriter) {
875 (2 as u16).write_into(writer);
876 self.coordinate.write_into(writer);
877 self.reference_glyph.write_into(writer);
878 self.base_coord_point.write_into(writer);
879 }
880 fn table_type(&self) -> TableType {
881 TableType::Named("BaseCoordFormat2")
882 }
883}
884
885impl Validate for BaseCoordFormat2 {
886 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
887}
888
889impl<'a> FromObjRef<read_fonts::tables::base::BaseCoordFormat2<'a>> for BaseCoordFormat2 {
890 fn from_obj_ref(obj: &read_fonts::tables::base::BaseCoordFormat2<'a>, _: FontData) -> Self {
891 BaseCoordFormat2 {
892 coordinate: obj.coordinate(),
893 reference_glyph: obj.reference_glyph(),
894 base_coord_point: obj.base_coord_point(),
895 }
896 }
897}
898
899#[allow(clippy::needless_lifetimes)]
900impl<'a> FromTableRef<read_fonts::tables::base::BaseCoordFormat2<'a>> for BaseCoordFormat2 {}
901
902impl ReadArgs for BaseCoordFormat2 {
903 type Args = ();
904}
905
906impl<'a> FontRead<'a> for BaseCoordFormat2 {
907 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
908 <read_fonts::tables::base::BaseCoordFormat2 as FontRead>::read(data)
909 .map(|x| x.to_owned_table())
910 }
911}
912
913#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
915#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
916pub struct BaseCoordFormat3 {
917 pub coordinate: i16,
919 pub device: NullableOffsetMarker<DeviceOrVariationIndex>,
923}
924
925impl BaseCoordFormat3 {
926 pub fn new(coordinate: i16, device: Option<DeviceOrVariationIndex>) -> Self {
928 Self {
929 coordinate,
930 device: device.into(),
931 }
932 }
933}
934
935impl FontWrite for BaseCoordFormat3 {
936 #[allow(clippy::unnecessary_cast)]
937 fn write_into(&self, writer: &mut TableWriter) {
938 (3 as u16).write_into(writer);
939 self.coordinate.write_into(writer);
940 self.device.write_into(writer);
941 }
942 fn table_type(&self) -> TableType {
943 TableType::Named("BaseCoordFormat3")
944 }
945}
946
947impl Validate for BaseCoordFormat3 {
948 fn validate_impl(&self, ctx: &mut ValidationCtx) {
949 ctx.in_table("BaseCoordFormat3", |ctx| {
950 ctx.in_field("device", |ctx| {
951 self.device.validate_impl(ctx);
952 });
953 })
954 }
955}
956
957impl<'a> FromObjRef<read_fonts::tables::base::BaseCoordFormat3<'a>> for BaseCoordFormat3 {
958 fn from_obj_ref(obj: &read_fonts::tables::base::BaseCoordFormat3<'a>, _: FontData) -> Self {
959 BaseCoordFormat3 {
960 coordinate: obj.coordinate(),
961 device: obj.device().to_owned_table(),
962 }
963 }
964}
965
966#[allow(clippy::needless_lifetimes)]
967impl<'a> FromTableRef<read_fonts::tables::base::BaseCoordFormat3<'a>> for BaseCoordFormat3 {}
968
969impl ReadArgs for BaseCoordFormat3 {
970 type Args = ();
971}
972
973impl<'a> FontRead<'a> for BaseCoordFormat3 {
974 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
975 <read_fonts::tables::base::BaseCoordFormat3 as FontRead>::read(data)
976 .map(|x| x.to_owned_table())
977 }
978}