Skip to main content

write_fonts/generated/
generated_meta.rs

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)]
6use crate::codegen_prelude::*;
7
8/// [`meta`](https://docs.microsoft.com/en-us/typography/opentype/spec/meta)
9#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct Meta {
12    /// Array of data map records.
13    pub data_maps: Vec<DataMapRecord>,
14}
15
16impl Meta {
17    /// Construct a new `Meta`
18    pub fn new(data_maps: Vec<DataMapRecord>) -> Self {
19        Self { data_maps }
20    }
21}
22
23impl FontWrite for Meta {
24    #[allow(clippy::unnecessary_cast)]
25    fn write_into(&self, writer: &mut TableWriter) {
26        (1 as u32).write_into(writer);
27        (0 as u32).write_into(writer);
28        (0 as u32).write_into(writer);
29        (u32::try_from(array_len(&self.data_maps)).unwrap()).write_into(writer);
30        self.data_maps.write_into(writer);
31    }
32    fn table_type(&self) -> TableType {
33        TableType::TopLevel(Meta::TAG)
34    }
35}
36
37impl Validate for Meta {
38    fn validate_impl(&self, ctx: &mut ValidationCtx) {
39        ctx.in_table("Meta", |ctx| {
40            ctx.in_field("data_maps", |ctx| {
41                if self.data_maps.len() > to_usize(u32::MAX) {
42                    ctx.report("array exceeds max length");
43                }
44                self.data_maps.validate_impl(ctx);
45            });
46        })
47    }
48}
49
50impl TopLevelTable for Meta {
51    const TAG: Tag = Tag::new(b"meta");
52}
53
54impl<'a> FromObjRef<read_fonts::tables::meta::Meta<'a>> for Meta {
55    fn from_obj_ref(obj: &read_fonts::tables::meta::Meta<'a>, _: FontData) -> Self {
56        let offset_data = obj.offset_data();
57        Meta {
58            data_maps: obj.data_maps().to_owned_obj(offset_data),
59        }
60    }
61}
62
63#[allow(clippy::needless_lifetimes)]
64impl<'a> FromTableRef<read_fonts::tables::meta::Meta<'a>> for Meta {}
65
66impl ReadArgs for Meta {
67    type Args = ();
68}
69
70impl<'a> FontRead<'a> for Meta {
71    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
72        <read_fonts::tables::meta::Meta as FontRead>::read(data).map(|x| x.to_owned_table())
73    }
74}
75
76///  <https://learn.microsoft.com/en-us/typography/opentype/spec/meta#table-formats>
77#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
78#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
79pub struct DataMapRecord {
80    /// A tag indicating the type of metadata.
81    pub tag: Tag,
82    /// Offset in bytes from the beginning of the metadata table to the data for this tag.
83    pub data: OffsetMarker<Metadata, WIDTH_32>,
84}
85
86impl DataMapRecord {
87    /// Construct a new `DataMapRecord`
88    pub fn new(tag: Tag, data: Metadata) -> Self {
89        Self {
90            tag,
91            data: data.into(),
92        }
93    }
94}
95
96impl FontWrite for DataMapRecord {
97    #[allow(clippy::unnecessary_cast)]
98    fn write_into(&self, writer: &mut TableWriter) {
99        self.tag.write_into(writer);
100        self.data.write_into(writer);
101        (self.compute_data_len() as u32).write_into(writer);
102    }
103    fn table_type(&self) -> TableType {
104        TableType::Named("DataMapRecord")
105    }
106}
107
108impl Validate for DataMapRecord {
109    fn validate_impl(&self, ctx: &mut ValidationCtx) {
110        ctx.in_table("DataMapRecord", |ctx| {
111            ctx.in_field("data", |ctx| {
112                self.validate_data_type(ctx);
113            });
114        })
115    }
116}