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() > (u32::MAX as usize) {
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<'a> FontRead<'a> for Meta {
67    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
68        <read_fonts::tables::meta::Meta as FontRead>::read(data).map(|x| x.to_owned_table())
69    }
70}
71
72///  <https://learn.microsoft.com/en-us/typography/opentype/spec/meta#table-formats>
73#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
74#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
75pub struct DataMapRecord {
76    /// A tag indicating the type of metadata.
77    pub tag: Tag,
78    /// Offset in bytes from the beginning of the metadata table to the data for this tag.
79    pub data: OffsetMarker<Metadata, WIDTH_32>,
80}
81
82impl DataMapRecord {
83    /// Construct a new `DataMapRecord`
84    pub fn new(tag: Tag, data: Metadata) -> Self {
85        Self {
86            tag,
87            data: data.into(),
88        }
89    }
90}
91
92impl FontWrite for DataMapRecord {
93    #[allow(clippy::unnecessary_cast)]
94    fn write_into(&self, writer: &mut TableWriter) {
95        self.tag.write_into(writer);
96        self.data.write_into(writer);
97        (self.compute_data_len() as u32).write_into(writer);
98    }
99    fn table_type(&self) -> TableType {
100        TableType::Named("DataMapRecord")
101    }
102}
103
104impl Validate for DataMapRecord {
105    fn validate_impl(&self, ctx: &mut ValidationCtx) {
106        ctx.in_table("DataMapRecord", |ctx| {
107            ctx.in_field("data", |ctx| {
108                self.validate_data_type(ctx);
109            });
110        })
111    }
112}