Skip to main content

write_fonts/generated/
generated_cff2.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/// [Compact Font Format (CFF) version 2](https://learn.microsoft.com/en-us/typography/opentype/spec/cff2) table header
9#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct Cff2Header {
12    /// Header size (bytes).
13    pub header_size: u8,
14    /// Length of Top DICT structure in bytes.
15    pub top_dict_length: u16,
16    /// Padding bytes before the start of the Top DICT.
17    pub _padding: Vec<u8>,
18    /// Data containing the Top DICT.
19    pub top_dict_data: Vec<u8>,
20    /// Remaining table data.
21    pub trailing_data: Vec<u8>,
22}
23
24impl Cff2Header {
25    /// Construct a new `Cff2Header`
26    pub fn new(
27        header_size: u8,
28        top_dict_length: u16,
29        _padding: Vec<u8>,
30        top_dict_data: Vec<u8>,
31        trailing_data: Vec<u8>,
32    ) -> Self {
33        Self {
34            header_size,
35            top_dict_length,
36            _padding,
37            top_dict_data,
38            trailing_data,
39        }
40    }
41}
42
43impl FontWrite for Cff2Header {
44    #[allow(clippy::unnecessary_cast)]
45    fn write_into(&self, writer: &mut TableWriter) {
46        (2 as u8).write_into(writer);
47        (0 as u8).write_into(writer);
48        self.header_size.write_into(writer);
49        self.top_dict_length.write_into(writer);
50        self._padding.write_into(writer);
51        self.top_dict_data.write_into(writer);
52        self.trailing_data.write_into(writer);
53    }
54    fn table_type(&self) -> TableType {
55        TableType::Named("Cff2Header")
56    }
57}
58
59impl Validate for Cff2Header {
60    fn validate_impl(&self, ctx: &mut ValidationCtx) {
61        ctx.in_table("Cff2Header", |ctx| {
62            ctx.in_field("top_dict_data", |ctx| {
63                if self.top_dict_data.len() > (u16::MAX as usize) {
64                    ctx.report("array exceeds max length");
65                }
66            });
67        })
68    }
69}
70
71impl<'a> FromObjRef<read_fonts::ps::cff::v2::Cff2Header<'a>> for Cff2Header {
72    fn from_obj_ref(obj: &read_fonts::ps::cff::v2::Cff2Header<'a>, _: FontData) -> Self {
73        let offset_data = obj.offset_data();
74        Cff2Header {
75            header_size: obj.header_size(),
76            top_dict_length: obj.top_dict_length(),
77            _padding: obj._padding().to_owned_obj(offset_data),
78            top_dict_data: obj.top_dict_data().to_owned_obj(offset_data),
79            trailing_data: obj.trailing_data().to_owned_obj(offset_data),
80        }
81    }
82}
83
84#[allow(clippy::needless_lifetimes)]
85impl<'a> FromTableRef<read_fonts::ps::cff::v2::Cff2Header<'a>> for Cff2Header {}
86
87impl<'a> FontRead<'a> for Cff2Header {
88    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
89        <read_fonts::ps::cff::v2::Cff2Header as FontRead>::read(data).map(|x| x.to_owned_table())
90    }
91}
92
93/// An array of variable-sized objects in a `CFF2` table.
94#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
95#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
96pub struct Index {
97    /// Number of objects stored in INDEX.
98    pub count: u32,
99    /// Object array element size.
100    pub off_size: u8,
101    /// Bytes containing `count + 1` offsets each of `off_size`.
102    pub offsets: Vec<u8>,
103    /// Array containing the object data.
104    pub data: Vec<u8>,
105}
106
107impl Index {
108    /// Construct a new `Index`
109    pub fn new(count: u32, off_size: u8, offsets: Vec<u8>, data: Vec<u8>) -> Self {
110        Self {
111            count,
112            off_size,
113            offsets,
114            data,
115        }
116    }
117}
118
119impl FontWrite for Index {
120    fn write_into(&self, writer: &mut TableWriter) {
121        self.count.write_into(writer);
122        self.off_size.write_into(writer);
123        self.offsets.write_into(writer);
124        self.data.write_into(writer);
125    }
126    fn table_type(&self) -> TableType {
127        TableType::Named("Index")
128    }
129}
130
131impl Validate for Index {
132    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
133}
134
135impl<'a> FromObjRef<read_fonts::ps::cff::v2::Index<'a>> for Index {
136    fn from_obj_ref(obj: &read_fonts::ps::cff::v2::Index<'a>, _: FontData) -> Self {
137        let offset_data = obj.offset_data();
138        Index {
139            count: obj.count(),
140            off_size: obj.off_size(),
141            offsets: obj.offsets().to_owned_obj(offset_data),
142            data: obj.data().to_owned_obj(offset_data),
143        }
144    }
145}
146
147#[allow(clippy::needless_lifetimes)]
148impl<'a> FromTableRef<read_fonts::ps::cff::v2::Index<'a>> for Index {}
149
150impl<'a> FontRead<'a> for Index {
151    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
152        <read_fonts::ps::cff::v2::Index as FontRead>::read(data).map(|x| x.to_owned_table())
153    }
154}