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() > to_usize(u16::MAX) {
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 ReadArgs for Cff2Header {
88    type Args = ();
89}
90
91impl<'a> FontRead<'a> for Cff2Header {
92    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
93        <read_fonts::ps::cff::v2::Cff2Header as FontRead>::read(data).map(|x| x.to_owned_table())
94    }
95}
96
97/// An array of variable-sized objects in a `CFF2` table.
98#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
99#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
100pub struct Index {
101    /// Number of objects stored in INDEX.
102    pub count: u32,
103    /// Object array element size.
104    pub off_size: u8,
105    /// Bytes containing `count + 1` offsets each of `off_size`.
106    pub offsets: Vec<u8>,
107    /// Array containing the object data.
108    pub data: Vec<u8>,
109}
110
111impl Index {
112    /// Construct a new `Index`
113    pub fn new(count: u32, off_size: u8, offsets: Vec<u8>, data: Vec<u8>) -> Self {
114        Self {
115            count,
116            off_size,
117            offsets,
118            data,
119        }
120    }
121}
122
123impl FontWrite for Index {
124    fn write_into(&self, writer: &mut TableWriter) {
125        self.count.write_into(writer);
126        self.off_size.write_into(writer);
127        self.offsets.write_into(writer);
128        self.data.write_into(writer);
129    }
130    fn table_type(&self) -> TableType {
131        TableType::Named("Index")
132    }
133}
134
135impl Validate for Index {
136    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
137}
138
139impl<'a> FromObjRef<read_fonts::ps::cff::v2::Index<'a>> for Index {
140    fn from_obj_ref(obj: &read_fonts::ps::cff::v2::Index<'a>, _: FontData) -> Self {
141        let offset_data = obj.offset_data();
142        Index {
143            count: obj.count(),
144            off_size: obj.off_size(),
145            offsets: obj.offsets().to_owned_obj(offset_data),
146            data: obj.data().to_owned_obj(offset_data),
147        }
148    }
149}
150
151#[allow(clippy::needless_lifetimes)]
152impl<'a> FromTableRef<read_fonts::ps::cff::v2::Index<'a>> for Index {}
153
154impl ReadArgs for Index {
155    type Args = ();
156}
157
158impl<'a> FontRead<'a> for Index {
159    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
160        <read_fonts::ps::cff::v2::Index as FontRead>::read(data).map(|x| x.to_owned_table())
161    }
162}