write_fonts/generated/
generated_dsig.rs1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8pub use read_fonts::tables::dsig::PermissionFlags;
9
10#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct Dsig {
14 pub flags: PermissionFlags,
16 pub signature_records: Vec<SignatureRecord>,
18}
19
20impl Dsig {
21 pub fn new(flags: PermissionFlags, signature_records: Vec<SignatureRecord>) -> Self {
23 Self {
24 flags,
25 signature_records,
26 }
27 }
28}
29
30impl FontWrite for Dsig {
31 #[allow(clippy::unnecessary_cast)]
32 fn write_into(&self, writer: &mut TableWriter) {
33 (1 as u32).write_into(writer);
34 (u16::try_from(array_len(&self.signature_records)).unwrap()).write_into(writer);
35 self.flags.write_into(writer);
36 self.signature_records.write_into(writer);
37 }
38 fn table_type(&self) -> TableType {
39 TableType::TopLevel(Dsig::TAG)
40 }
41}
42
43impl Validate for Dsig {
44 fn validate_impl(&self, ctx: &mut ValidationCtx) {
45 ctx.in_table("Dsig", |ctx| {
46 ctx.in_field("signature_records", |ctx| {
47 if self.signature_records.len() > (u16::MAX as usize) {
48 ctx.report("array exceeds max length");
49 }
50 self.signature_records.validate_impl(ctx);
51 });
52 })
53 }
54}
55
56impl TopLevelTable for Dsig {
57 const TAG: Tag = Tag::new(b"DSIG");
58}
59
60impl<'a> FromObjRef<read_fonts::tables::dsig::Dsig<'a>> for Dsig {
61 fn from_obj_ref(obj: &read_fonts::tables::dsig::Dsig<'a>, _: FontData) -> Self {
62 let offset_data = obj.offset_data();
63 Dsig {
64 flags: obj.flags(),
65 signature_records: obj.signature_records().to_owned_obj(offset_data),
66 }
67 }
68}
69
70#[allow(clippy::needless_lifetimes)]
71impl<'a> FromTableRef<read_fonts::tables::dsig::Dsig<'a>> for Dsig {}
72
73impl<'a> FontRead<'a> for Dsig {
74 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
75 <read_fonts::tables::dsig::Dsig as FontRead>::read(data).map(|x| x.to_owned_table())
76 }
77}
78
79impl FontWrite for PermissionFlags {
80 fn write_into(&self, writer: &mut TableWriter) {
81 writer.write_slice(&self.bits().to_be_bytes())
82 }
83}
84
85#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
87#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
88pub struct SignatureRecord {
89 pub signature_block: OffsetMarker<SignatureBlockFormat1, WIDTH_32>,
91}
92
93impl SignatureRecord {
94 pub fn new(signature_block: SignatureBlockFormat1) -> Self {
96 Self {
97 signature_block: signature_block.into(),
98 }
99 }
100}
101
102impl FontWrite for SignatureRecord {
103 #[allow(clippy::unnecessary_cast)]
104 fn write_into(&self, writer: &mut TableWriter) {
105 (1 as u32).write_into(writer);
106 (self.compute_signature_block_len() as u32).write_into(writer);
107 self.signature_block.write_into(writer);
108 }
109 fn table_type(&self) -> TableType {
110 TableType::Named("SignatureRecord")
111 }
112}
113
114impl Validate for SignatureRecord {
115 fn validate_impl(&self, ctx: &mut ValidationCtx) {
116 ctx.in_table("SignatureRecord", |ctx| {
117 ctx.in_field("signature_block", |ctx| {
118 self.signature_block.validate_impl(ctx);
119 });
120 })
121 }
122}
123
124impl FromObjRef<read_fonts::tables::dsig::SignatureRecord> for SignatureRecord {
125 fn from_obj_ref(
126 obj: &read_fonts::tables::dsig::SignatureRecord,
127 offset_data: FontData,
128 ) -> Self {
129 SignatureRecord {
130 signature_block: obj.signature_block(offset_data).to_owned_table(),
131 }
132 }
133}
134
135#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
137#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
138pub struct SignatureBlockFormat1 {
139 pub signature: Vec<u8>,
141}
142
143impl SignatureBlockFormat1 {
144 pub fn new(signature: Vec<u8>) -> Self {
146 Self { signature }
147 }
148}
149
150impl FontWrite for SignatureBlockFormat1 {
151 #[allow(clippy::unnecessary_cast)]
152 fn write_into(&self, writer: &mut TableWriter) {
153 (0 as u16).write_into(writer);
154 (0 as u16).write_into(writer);
155 (u32::try_from(array_len(&self.signature)).unwrap()).write_into(writer);
156 self.signature.write_into(writer);
157 }
158 fn table_type(&self) -> TableType {
159 TableType::Named("SignatureBlockFormat1")
160 }
161}
162
163impl Validate for SignatureBlockFormat1 {
164 fn validate_impl(&self, ctx: &mut ValidationCtx) {
165 ctx.in_table("SignatureBlockFormat1", |ctx| {
166 ctx.in_field("signature", |ctx| {
167 if self.signature.len() > (u32::MAX as usize) {
168 ctx.report("array exceeds max length");
169 }
170 });
171 })
172 }
173}
174
175impl<'a> FromObjRef<read_fonts::tables::dsig::SignatureBlockFormat1<'a>> for SignatureBlockFormat1 {
176 fn from_obj_ref(
177 obj: &read_fonts::tables::dsig::SignatureBlockFormat1<'a>,
178 _: FontData,
179 ) -> Self {
180 let offset_data = obj.offset_data();
181 SignatureBlockFormat1 {
182 signature: obj.signature().to_owned_obj(offset_data),
183 }
184 }
185}
186
187#[allow(clippy::needless_lifetimes)]
188impl<'a> FromTableRef<read_fonts::tables::dsig::SignatureBlockFormat1<'a>>
189 for SignatureBlockFormat1
190{
191}
192
193impl<'a> FontRead<'a> for SignatureBlockFormat1 {
194 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
195 <read_fonts::tables::dsig::SignatureBlockFormat1 as FontRead>::read(data)
196 .map(|x| x.to_owned_table())
197 }
198}