write_fonts/generated/
generated_meta.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// THIS FILE IS AUTOGENERATED.
// Any changes to this file will be overwritten.
// For more information about how codegen works, see font-codegen/README.md

#[allow(unused_imports)]
use crate::codegen_prelude::*;

/// [`meta`](https://docs.microsoft.com/en-us/typography/opentype/spec/meta)
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Meta {
    /// Array of data map records.
    pub data_maps: Vec<DataMapRecord>,
}

impl Meta {
    /// Construct a new `Meta`
    pub fn new(data_maps: Vec<DataMapRecord>) -> Self {
        Self {
            data_maps: data_maps.into_iter().map(Into::into).collect(),
        }
    }
}

impl FontWrite for Meta {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        (1 as u32).write_into(writer);
        (0 as u32).write_into(writer);
        (0 as u32).write_into(writer);
        (u32::try_from(array_len(&self.data_maps)).unwrap()).write_into(writer);
        self.data_maps.write_into(writer);
    }
    fn table_type(&self) -> TableType {
        TableType::TopLevel(Meta::TAG)
    }
}

impl Validate for Meta {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("Meta", |ctx| {
            ctx.in_field("data_maps", |ctx| {
                if self.data_maps.len() > (u32::MAX as usize) {
                    ctx.report("array exceeds max length");
                }
                self.data_maps.validate_impl(ctx);
            });
        })
    }
}

impl TopLevelTable for Meta {
    const TAG: Tag = Tag::new(b"meta");
}

impl<'a> FromObjRef<read_fonts::tables::meta::Meta<'a>> for Meta {
    fn from_obj_ref(obj: &read_fonts::tables::meta::Meta<'a>, _: FontData) -> Self {
        let offset_data = obj.offset_data();
        Meta {
            data_maps: obj.data_maps().to_owned_obj(offset_data),
        }
    }
}

#[allow(clippy::needless_lifetimes)]
impl<'a> FromTableRef<read_fonts::tables::meta::Meta<'a>> for Meta {}

impl<'a> FontRead<'a> for Meta {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::tables::meta::Meta as FontRead>::read(data).map(|x| x.to_owned_table())
    }
}

///  <https://learn.microsoft.com/en-us/typography/opentype/spec/meta#table-formats>
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DataMapRecord {
    /// A tag indicating the type of metadata.
    pub tag: Tag,
    /// Offset in bytes from the beginning of the metadata table to the data for this tag.
    pub data: OffsetMarker<Metadata, WIDTH_32>,
}

impl DataMapRecord {
    /// Construct a new `DataMapRecord`
    pub fn new(tag: Tag, data: Metadata) -> Self {
        Self {
            tag,
            data: data.into(),
        }
    }
}

impl FontWrite for DataMapRecord {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        self.tag.write_into(writer);
        self.data.write_into(writer);
        (self.compute_data_len() as u32).write_into(writer);
    }
    fn table_type(&self) -> TableType {
        TableType::Named("DataMapRecord")
    }
}

impl Validate for DataMapRecord {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("DataMapRecord", |ctx| {
            ctx.in_field("data", |ctx| {
                self.validate_data_type(ctx);
            });
        })
    }
}