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<'a> FontRead<'a> for Base {
81 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
82 <read_fonts::tables::base::Base as FontRead>::read(data).map(|x| x.to_owned_table())
83 }
84}
85
86#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
88#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89pub struct Axis {
90 pub base_tag_list: NullableOffsetMarker<BaseTagList>,
93 pub base_script_list: OffsetMarker<BaseScriptList>,
95}
96
97impl Axis {
98 pub fn new(base_tag_list: Option<BaseTagList>, base_script_list: BaseScriptList) -> Self {
100 Self {
101 base_tag_list: base_tag_list.into(),
102 base_script_list: base_script_list.into(),
103 }
104 }
105}
106
107impl FontWrite for Axis {
108 fn write_into(&self, writer: &mut TableWriter) {
109 self.base_tag_list.write_into(writer);
110 self.base_script_list.write_into(writer);
111 }
112 fn table_type(&self) -> TableType {
113 TableType::Named("Axis")
114 }
115}
116
117impl Validate for Axis {
118 fn validate_impl(&self, ctx: &mut ValidationCtx) {
119 ctx.in_table("Axis", |ctx| {
120 ctx.in_field("base_tag_list", |ctx| {
121 self.base_tag_list.validate_impl(ctx);
122 });
123 ctx.in_field("base_script_list", |ctx| {
124 self.base_script_list.validate_impl(ctx);
125 });
126 })
127 }
128}
129
130impl<'a> FromObjRef<read_fonts::tables::base::Axis<'a>> for Axis {
131 fn from_obj_ref(obj: &read_fonts::tables::base::Axis<'a>, _: FontData) -> Self {
132 Axis {
133 base_tag_list: obj.base_tag_list().to_owned_table(),
134 base_script_list: obj.base_script_list().to_owned_table(),
135 }
136 }
137}
138
139#[allow(clippy::needless_lifetimes)]
140impl<'a> FromTableRef<read_fonts::tables::base::Axis<'a>> for Axis {}
141
142impl<'a> FontRead<'a> for Axis {
143 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
144 <read_fonts::tables::base::Axis as FontRead>::read(data).map(|x| x.to_owned_table())
145 }
146}
147
148#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
150#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
151pub struct BaseTagList {
152 pub baseline_tags: Vec<Tag>,
155}
156
157impl BaseTagList {
158 pub fn new(baseline_tags: Vec<Tag>) -> Self {
160 Self { baseline_tags }
161 }
162}
163
164impl FontWrite for BaseTagList {
165 #[allow(clippy::unnecessary_cast)]
166 fn write_into(&self, writer: &mut TableWriter) {
167 (u16::try_from(array_len(&self.baseline_tags)).unwrap()).write_into(writer);
168 self.baseline_tags.write_into(writer);
169 }
170 fn table_type(&self) -> TableType {
171 TableType::Named("BaseTagList")
172 }
173}
174
175impl Validate for BaseTagList {
176 fn validate_impl(&self, ctx: &mut ValidationCtx) {
177 ctx.in_table("BaseTagList", |ctx| {
178 ctx.in_field("baseline_tags", |ctx| {
179 if self.baseline_tags.len() > (u16::MAX as usize) {
180 ctx.report("array exceeds max length");
181 }
182 });
183 })
184 }
185}
186
187impl<'a> FromObjRef<read_fonts::tables::base::BaseTagList<'a>> for BaseTagList {
188 fn from_obj_ref(obj: &read_fonts::tables::base::BaseTagList<'a>, _: FontData) -> Self {
189 let offset_data = obj.offset_data();
190 BaseTagList {
191 baseline_tags: obj.baseline_tags().to_owned_obj(offset_data),
192 }
193 }
194}
195
196#[allow(clippy::needless_lifetimes)]
197impl<'a> FromTableRef<read_fonts::tables::base::BaseTagList<'a>> for BaseTagList {}
198
199impl<'a> FontRead<'a> for BaseTagList {
200 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
201 <read_fonts::tables::base::BaseTagList as FontRead>::read(data).map(|x| x.to_owned_table())
202 }
203}
204
205#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
207#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
208pub struct BaseScriptList {
209 pub base_script_records: Vec<BaseScriptRecord>,
212}
213
214impl BaseScriptList {
215 pub fn new(base_script_records: Vec<BaseScriptRecord>) -> Self {
217 Self {
218 base_script_records,
219 }
220 }
221}
222
223impl FontWrite for BaseScriptList {
224 #[allow(clippy::unnecessary_cast)]
225 fn write_into(&self, writer: &mut TableWriter) {
226 (u16::try_from(array_len(&self.base_script_records)).unwrap()).write_into(writer);
227 self.base_script_records.write_into(writer);
228 }
229 fn table_type(&self) -> TableType {
230 TableType::Named("BaseScriptList")
231 }
232}
233
234impl Validate for BaseScriptList {
235 fn validate_impl(&self, ctx: &mut ValidationCtx) {
236 ctx.in_table("BaseScriptList", |ctx| {
237 ctx.in_field("base_script_records", |ctx| {
238 if self.base_script_records.len() > (u16::MAX as usize) {
239 ctx.report("array exceeds max length");
240 }
241 self.base_script_records.validate_impl(ctx);
242 });
243 })
244 }
245}
246
247impl<'a> FromObjRef<read_fonts::tables::base::BaseScriptList<'a>> for BaseScriptList {
248 fn from_obj_ref(obj: &read_fonts::tables::base::BaseScriptList<'a>, _: FontData) -> Self {
249 let offset_data = obj.offset_data();
250 BaseScriptList {
251 base_script_records: obj.base_script_records().to_owned_obj(offset_data),
252 }
253 }
254}
255
256#[allow(clippy::needless_lifetimes)]
257impl<'a> FromTableRef<read_fonts::tables::base::BaseScriptList<'a>> for BaseScriptList {}
258
259impl<'a> FontRead<'a> for BaseScriptList {
260 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
261 <read_fonts::tables::base::BaseScriptList as FontRead>::read(data)
262 .map(|x| x.to_owned_table())
263 }
264}
265
266#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
268#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
269pub struct BaseScriptRecord {
270 pub base_script_tag: Tag,
272 pub base_script: OffsetMarker<BaseScript>,
274}
275
276impl BaseScriptRecord {
277 pub fn new(base_script_tag: Tag, base_script: BaseScript) -> Self {
279 Self {
280 base_script_tag,
281 base_script: base_script.into(),
282 }
283 }
284}
285
286impl FontWrite for BaseScriptRecord {
287 fn write_into(&self, writer: &mut TableWriter) {
288 self.base_script_tag.write_into(writer);
289 self.base_script.write_into(writer);
290 }
291 fn table_type(&self) -> TableType {
292 TableType::Named("BaseScriptRecord")
293 }
294}
295
296impl Validate for BaseScriptRecord {
297 fn validate_impl(&self, ctx: &mut ValidationCtx) {
298 ctx.in_table("BaseScriptRecord", |ctx| {
299 ctx.in_field("base_script", |ctx| {
300 self.base_script.validate_impl(ctx);
301 });
302 })
303 }
304}
305
306impl FromObjRef<read_fonts::tables::base::BaseScriptRecord> for BaseScriptRecord {
307 fn from_obj_ref(
308 obj: &read_fonts::tables::base::BaseScriptRecord,
309 offset_data: FontData,
310 ) -> Self {
311 BaseScriptRecord {
312 base_script_tag: obj.base_script_tag(),
313 base_script: obj.base_script(offset_data).to_owned_table(),
314 }
315 }
316}
317
318#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
320#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
321pub struct BaseScript {
322 pub base_values: NullableOffsetMarker<BaseValues>,
324 pub default_min_max: NullableOffsetMarker<MinMax>,
326 pub base_lang_sys_records: Vec<BaseLangSysRecord>,
329}
330
331impl BaseScript {
332 pub fn new(
334 base_values: Option<BaseValues>,
335 default_min_max: Option<MinMax>,
336 base_lang_sys_records: Vec<BaseLangSysRecord>,
337 ) -> Self {
338 Self {
339 base_values: base_values.into(),
340 default_min_max: default_min_max.into(),
341 base_lang_sys_records,
342 }
343 }
344}
345
346impl FontWrite for BaseScript {
347 #[allow(clippy::unnecessary_cast)]
348 fn write_into(&self, writer: &mut TableWriter) {
349 self.base_values.write_into(writer);
350 self.default_min_max.write_into(writer);
351 (u16::try_from(array_len(&self.base_lang_sys_records)).unwrap()).write_into(writer);
352 self.base_lang_sys_records.write_into(writer);
353 }
354 fn table_type(&self) -> TableType {
355 TableType::Named("BaseScript")
356 }
357}
358
359impl Validate for BaseScript {
360 fn validate_impl(&self, ctx: &mut ValidationCtx) {
361 ctx.in_table("BaseScript", |ctx| {
362 ctx.in_field("base_values", |ctx| {
363 self.base_values.validate_impl(ctx);
364 });
365 ctx.in_field("default_min_max", |ctx| {
366 self.default_min_max.validate_impl(ctx);
367 });
368 ctx.in_field("base_lang_sys_records", |ctx| {
369 if self.base_lang_sys_records.len() > (u16::MAX as usize) {
370 ctx.report("array exceeds max length");
371 }
372 self.base_lang_sys_records.validate_impl(ctx);
373 });
374 })
375 }
376}
377
378impl<'a> FromObjRef<read_fonts::tables::base::BaseScript<'a>> for BaseScript {
379 fn from_obj_ref(obj: &read_fonts::tables::base::BaseScript<'a>, _: FontData) -> Self {
380 let offset_data = obj.offset_data();
381 BaseScript {
382 base_values: obj.base_values().to_owned_table(),
383 default_min_max: obj.default_min_max().to_owned_table(),
384 base_lang_sys_records: obj.base_lang_sys_records().to_owned_obj(offset_data),
385 }
386 }
387}
388
389#[allow(clippy::needless_lifetimes)]
390impl<'a> FromTableRef<read_fonts::tables::base::BaseScript<'a>> for BaseScript {}
391
392impl<'a> FontRead<'a> for BaseScript {
393 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
394 <read_fonts::tables::base::BaseScript as FontRead>::read(data).map(|x| x.to_owned_table())
395 }
396}
397
398#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
400#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
401pub struct BaseLangSysRecord {
402 pub base_lang_sys_tag: Tag,
404 pub min_max: OffsetMarker<MinMax>,
406}
407
408impl BaseLangSysRecord {
409 pub fn new(base_lang_sys_tag: Tag, min_max: MinMax) -> Self {
411 Self {
412 base_lang_sys_tag,
413 min_max: min_max.into(),
414 }
415 }
416}
417
418impl FontWrite for BaseLangSysRecord {
419 fn write_into(&self, writer: &mut TableWriter) {
420 self.base_lang_sys_tag.write_into(writer);
421 self.min_max.write_into(writer);
422 }
423 fn table_type(&self) -> TableType {
424 TableType::Named("BaseLangSysRecord")
425 }
426}
427
428impl Validate for BaseLangSysRecord {
429 fn validate_impl(&self, ctx: &mut ValidationCtx) {
430 ctx.in_table("BaseLangSysRecord", |ctx| {
431 ctx.in_field("min_max", |ctx| {
432 self.min_max.validate_impl(ctx);
433 });
434 })
435 }
436}
437
438impl FromObjRef<read_fonts::tables::base::BaseLangSysRecord> for BaseLangSysRecord {
439 fn from_obj_ref(
440 obj: &read_fonts::tables::base::BaseLangSysRecord,
441 offset_data: FontData,
442 ) -> Self {
443 BaseLangSysRecord {
444 base_lang_sys_tag: obj.base_lang_sys_tag(),
445 min_max: obj.min_max(offset_data).to_owned_table(),
446 }
447 }
448}
449
450#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
452#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
453pub struct BaseValues {
454 pub default_baseline_index: u16,
458 pub base_coords: Vec<OffsetMarker<BaseCoord>>,
462}
463
464impl BaseValues {
465 pub fn new(default_baseline_index: u16, base_coords: Vec<BaseCoord>) -> Self {
467 Self {
468 default_baseline_index,
469 base_coords: base_coords.into_iter().map(Into::into).collect(),
470 }
471 }
472}
473
474impl FontWrite for BaseValues {
475 #[allow(clippy::unnecessary_cast)]
476 fn write_into(&self, writer: &mut TableWriter) {
477 self.default_baseline_index.write_into(writer);
478 (u16::try_from(array_len(&self.base_coords)).unwrap()).write_into(writer);
479 self.base_coords.write_into(writer);
480 }
481 fn table_type(&self) -> TableType {
482 TableType::Named("BaseValues")
483 }
484}
485
486impl Validate for BaseValues {
487 fn validate_impl(&self, ctx: &mut ValidationCtx) {
488 ctx.in_table("BaseValues", |ctx| {
489 ctx.in_field("base_coords", |ctx| {
490 if self.base_coords.len() > (u16::MAX as usize) {
491 ctx.report("array exceeds max length");
492 }
493 self.base_coords.validate_impl(ctx);
494 });
495 })
496 }
497}
498
499impl<'a> FromObjRef<read_fonts::tables::base::BaseValues<'a>> for BaseValues {
500 fn from_obj_ref(obj: &read_fonts::tables::base::BaseValues<'a>, _: FontData) -> Self {
501 BaseValues {
502 default_baseline_index: obj.default_baseline_index(),
503 base_coords: obj.base_coords().to_owned_table(),
504 }
505 }
506}
507
508#[allow(clippy::needless_lifetimes)]
509impl<'a> FromTableRef<read_fonts::tables::base::BaseValues<'a>> for BaseValues {}
510
511impl<'a> FontRead<'a> for BaseValues {
512 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
513 <read_fonts::tables::base::BaseValues as FontRead>::read(data).map(|x| x.to_owned_table())
514 }
515}
516
517#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
519#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
520pub struct MinMax {
521 pub min_coord: NullableOffsetMarker<BaseCoord>,
524 pub max_coord: NullableOffsetMarker<BaseCoord>,
527 pub feat_min_max_records: Vec<FeatMinMaxRecord>,
530}
531
532impl MinMax {
533 pub fn new(
535 min_coord: Option<BaseCoord>,
536 max_coord: Option<BaseCoord>,
537 feat_min_max_records: Vec<FeatMinMaxRecord>,
538 ) -> Self {
539 Self {
540 min_coord: min_coord.into(),
541 max_coord: max_coord.into(),
542 feat_min_max_records,
543 }
544 }
545}
546
547impl FontWrite for MinMax {
548 #[allow(clippy::unnecessary_cast)]
549 fn write_into(&self, writer: &mut TableWriter) {
550 self.min_coord.write_into(writer);
551 self.max_coord.write_into(writer);
552 (u16::try_from(array_len(&self.feat_min_max_records)).unwrap()).write_into(writer);
553 self.feat_min_max_records.write_into(writer);
554 }
555 fn table_type(&self) -> TableType {
556 TableType::Named("MinMax")
557 }
558}
559
560impl Validate for MinMax {
561 fn validate_impl(&self, ctx: &mut ValidationCtx) {
562 ctx.in_table("MinMax", |ctx| {
563 ctx.in_field("min_coord", |ctx| {
564 self.min_coord.validate_impl(ctx);
565 });
566 ctx.in_field("max_coord", |ctx| {
567 self.max_coord.validate_impl(ctx);
568 });
569 ctx.in_field("feat_min_max_records", |ctx| {
570 if self.feat_min_max_records.len() > (u16::MAX as usize) {
571 ctx.report("array exceeds max length");
572 }
573 self.feat_min_max_records.validate_impl(ctx);
574 });
575 })
576 }
577}
578
579impl<'a> FromObjRef<read_fonts::tables::base::MinMax<'a>> for MinMax {
580 fn from_obj_ref(obj: &read_fonts::tables::base::MinMax<'a>, _: FontData) -> Self {
581 let offset_data = obj.offset_data();
582 MinMax {
583 min_coord: obj.min_coord().to_owned_table(),
584 max_coord: obj.max_coord().to_owned_table(),
585 feat_min_max_records: obj.feat_min_max_records().to_owned_obj(offset_data),
586 }
587 }
588}
589
590#[allow(clippy::needless_lifetimes)]
591impl<'a> FromTableRef<read_fonts::tables::base::MinMax<'a>> for MinMax {}
592
593impl<'a> FontRead<'a> for MinMax {
594 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
595 <read_fonts::tables::base::MinMax as FontRead>::read(data).map(|x| x.to_owned_table())
596 }
597}
598
599#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
601#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
602pub struct FeatMinMaxRecord {
603 pub feature_table_tag: Tag,
606 pub min_coord: NullableOffsetMarker<BaseCoord>,
609 pub max_coord: NullableOffsetMarker<BaseCoord>,
612}
613
614impl FeatMinMaxRecord {
615 pub fn new(
617 feature_table_tag: Tag,
618 min_coord: Option<BaseCoord>,
619 max_coord: Option<BaseCoord>,
620 ) -> Self {
621 Self {
622 feature_table_tag,
623 min_coord: min_coord.into(),
624 max_coord: max_coord.into(),
625 }
626 }
627}
628
629impl FontWrite for FeatMinMaxRecord {
630 fn write_into(&self, writer: &mut TableWriter) {
631 self.feature_table_tag.write_into(writer);
632 self.min_coord.write_into(writer);
633 self.max_coord.write_into(writer);
634 }
635 fn table_type(&self) -> TableType {
636 TableType::Named("FeatMinMaxRecord")
637 }
638}
639
640impl Validate for FeatMinMaxRecord {
641 fn validate_impl(&self, ctx: &mut ValidationCtx) {
642 ctx.in_table("FeatMinMaxRecord", |ctx| {
643 ctx.in_field("min_coord", |ctx| {
644 self.min_coord.validate_impl(ctx);
645 });
646 ctx.in_field("max_coord", |ctx| {
647 self.max_coord.validate_impl(ctx);
648 });
649 })
650 }
651}
652
653impl FromObjRef<read_fonts::tables::base::FeatMinMaxRecord> for FeatMinMaxRecord {
654 fn from_obj_ref(
655 obj: &read_fonts::tables::base::FeatMinMaxRecord,
656 offset_data: FontData,
657 ) -> Self {
658 FeatMinMaxRecord {
659 feature_table_tag: obj.feature_table_tag(),
660 min_coord: obj.min_coord(offset_data).to_owned_table(),
661 max_coord: obj.max_coord(offset_data).to_owned_table(),
662 }
663 }
664}
665
666#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
667#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
668pub enum BaseCoord {
669 Format1(BaseCoordFormat1),
670 Format2(BaseCoordFormat2),
671 Format3(BaseCoordFormat3),
672}
673
674impl BaseCoord {
675 pub fn format_1(coordinate: i16) -> Self {
677 Self::Format1(BaseCoordFormat1::new(coordinate))
678 }
679
680 pub fn format_2(coordinate: i16, reference_glyph: u16, base_coord_point: u16) -> Self {
682 Self::Format2(BaseCoordFormat2::new(
683 coordinate,
684 reference_glyph,
685 base_coord_point,
686 ))
687 }
688
689 pub fn format_3(coordinate: i16, device: Option<DeviceOrVariationIndex>) -> Self {
691 Self::Format3(BaseCoordFormat3::new(coordinate, device))
692 }
693}
694
695impl Default for BaseCoord {
696 fn default() -> Self {
697 Self::Format1(Default::default())
698 }
699}
700
701impl FontWrite for BaseCoord {
702 fn write_into(&self, writer: &mut TableWriter) {
703 match self {
704 Self::Format1(item) => item.write_into(writer),
705 Self::Format2(item) => item.write_into(writer),
706 Self::Format3(item) => item.write_into(writer),
707 }
708 }
709 fn table_type(&self) -> TableType {
710 match self {
711 Self::Format1(item) => item.table_type(),
712 Self::Format2(item) => item.table_type(),
713 Self::Format3(item) => item.table_type(),
714 }
715 }
716}
717
718impl Validate for BaseCoord {
719 fn validate_impl(&self, ctx: &mut ValidationCtx) {
720 match self {
721 Self::Format1(item) => item.validate_impl(ctx),
722 Self::Format2(item) => item.validate_impl(ctx),
723 Self::Format3(item) => item.validate_impl(ctx),
724 }
725 }
726}
727
728impl FromObjRef<read_fonts::tables::base::BaseCoord<'_>> for BaseCoord {
729 fn from_obj_ref(obj: &read_fonts::tables::base::BaseCoord, _: FontData) -> Self {
730 use read_fonts::tables::base::BaseCoord as ObjRefType;
731 match obj {
732 ObjRefType::Format1(item) => BaseCoord::Format1(item.to_owned_table()),
733 ObjRefType::Format2(item) => BaseCoord::Format2(item.to_owned_table()),
734 ObjRefType::Format3(item) => BaseCoord::Format3(item.to_owned_table()),
735 }
736 }
737}
738
739impl FromTableRef<read_fonts::tables::base::BaseCoord<'_>> for BaseCoord {}
740
741impl<'a> FontRead<'a> for BaseCoord {
742 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
743 <read_fonts::tables::base::BaseCoord as FontRead>::read(data).map(|x| x.to_owned_table())
744 }
745}
746
747impl From<BaseCoordFormat1> for BaseCoord {
748 fn from(src: BaseCoordFormat1) -> BaseCoord {
749 BaseCoord::Format1(src)
750 }
751}
752
753impl From<BaseCoordFormat2> for BaseCoord {
754 fn from(src: BaseCoordFormat2) -> BaseCoord {
755 BaseCoord::Format2(src)
756 }
757}
758
759impl From<BaseCoordFormat3> for BaseCoord {
760 fn from(src: BaseCoordFormat3) -> BaseCoord {
761 BaseCoord::Format3(src)
762 }
763}
764
765#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
767#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
768pub struct BaseCoordFormat1 {
769 pub coordinate: i16,
771}
772
773impl BaseCoordFormat1 {
774 pub fn new(coordinate: i16) -> Self {
776 Self { coordinate }
777 }
778}
779
780impl FontWrite for BaseCoordFormat1 {
781 #[allow(clippy::unnecessary_cast)]
782 fn write_into(&self, writer: &mut TableWriter) {
783 (1 as u16).write_into(writer);
784 self.coordinate.write_into(writer);
785 }
786 fn table_type(&self) -> TableType {
787 TableType::Named("BaseCoordFormat1")
788 }
789}
790
791impl Validate for BaseCoordFormat1 {
792 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
793}
794
795impl<'a> FromObjRef<read_fonts::tables::base::BaseCoordFormat1<'a>> for BaseCoordFormat1 {
796 fn from_obj_ref(obj: &read_fonts::tables::base::BaseCoordFormat1<'a>, _: FontData) -> Self {
797 BaseCoordFormat1 {
798 coordinate: obj.coordinate(),
799 }
800 }
801}
802
803#[allow(clippy::needless_lifetimes)]
804impl<'a> FromTableRef<read_fonts::tables::base::BaseCoordFormat1<'a>> for BaseCoordFormat1 {}
805
806impl<'a> FontRead<'a> for BaseCoordFormat1 {
807 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
808 <read_fonts::tables::base::BaseCoordFormat1 as FontRead>::read(data)
809 .map(|x| x.to_owned_table())
810 }
811}
812
813#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
815#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
816pub struct BaseCoordFormat2 {
817 pub coordinate: i16,
819 pub reference_glyph: u16,
821 pub base_coord_point: u16,
823}
824
825impl BaseCoordFormat2 {
826 pub fn new(coordinate: i16, reference_glyph: u16, base_coord_point: u16) -> Self {
828 Self {
829 coordinate,
830 reference_glyph,
831 base_coord_point,
832 }
833 }
834}
835
836impl FontWrite for BaseCoordFormat2 {
837 #[allow(clippy::unnecessary_cast)]
838 fn write_into(&self, writer: &mut TableWriter) {
839 (2 as u16).write_into(writer);
840 self.coordinate.write_into(writer);
841 self.reference_glyph.write_into(writer);
842 self.base_coord_point.write_into(writer);
843 }
844 fn table_type(&self) -> TableType {
845 TableType::Named("BaseCoordFormat2")
846 }
847}
848
849impl Validate for BaseCoordFormat2 {
850 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
851}
852
853impl<'a> FromObjRef<read_fonts::tables::base::BaseCoordFormat2<'a>> for BaseCoordFormat2 {
854 fn from_obj_ref(obj: &read_fonts::tables::base::BaseCoordFormat2<'a>, _: FontData) -> Self {
855 BaseCoordFormat2 {
856 coordinate: obj.coordinate(),
857 reference_glyph: obj.reference_glyph(),
858 base_coord_point: obj.base_coord_point(),
859 }
860 }
861}
862
863#[allow(clippy::needless_lifetimes)]
864impl<'a> FromTableRef<read_fonts::tables::base::BaseCoordFormat2<'a>> for BaseCoordFormat2 {}
865
866impl<'a> FontRead<'a> for BaseCoordFormat2 {
867 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
868 <read_fonts::tables::base::BaseCoordFormat2 as FontRead>::read(data)
869 .map(|x| x.to_owned_table())
870 }
871}
872
873#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
875#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
876pub struct BaseCoordFormat3 {
877 pub coordinate: i16,
879 pub device: NullableOffsetMarker<DeviceOrVariationIndex>,
883}
884
885impl BaseCoordFormat3 {
886 pub fn new(coordinate: i16, device: Option<DeviceOrVariationIndex>) -> Self {
888 Self {
889 coordinate,
890 device: device.into(),
891 }
892 }
893}
894
895impl FontWrite for BaseCoordFormat3 {
896 #[allow(clippy::unnecessary_cast)]
897 fn write_into(&self, writer: &mut TableWriter) {
898 (3 as u16).write_into(writer);
899 self.coordinate.write_into(writer);
900 self.device.write_into(writer);
901 }
902 fn table_type(&self) -> TableType {
903 TableType::Named("BaseCoordFormat3")
904 }
905}
906
907impl Validate for BaseCoordFormat3 {
908 fn validate_impl(&self, ctx: &mut ValidationCtx) {
909 ctx.in_table("BaseCoordFormat3", |ctx| {
910 ctx.in_field("device", |ctx| {
911 self.device.validate_impl(ctx);
912 });
913 })
914 }
915}
916
917impl<'a> FromObjRef<read_fonts::tables::base::BaseCoordFormat3<'a>> for BaseCoordFormat3 {
918 fn from_obj_ref(obj: &read_fonts::tables::base::BaseCoordFormat3<'a>, _: FontData) -> Self {
919 BaseCoordFormat3 {
920 coordinate: obj.coordinate(),
921 device: obj.device().to_owned_table(),
922 }
923 }
924}
925
926#[allow(clippy::needless_lifetimes)]
927impl<'a> FromTableRef<read_fonts::tables::base::BaseCoordFormat3<'a>> for BaseCoordFormat3 {}
928
929impl<'a> FontRead<'a> for BaseCoordFormat3 {
930 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
931 <read_fonts::tables::base::BaseCoordFormat3 as FontRead>::read(data)
932 .map(|x| x.to_owned_table())
933 }
934}