write_fonts/generated/
generated_name.rs1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct Name {
12 pub name_record: Vec<NameRecord>,
14 pub lang_tag_record: Option<Vec<LangTagRecord>>,
16}
17
18impl Name {
19 pub fn new(name_record: Vec<NameRecord>) -> Self {
21 Self {
22 name_record,
23 ..Default::default()
24 }
25 }
26}
27
28impl FontWrite for Name {
29 #[allow(clippy::unnecessary_cast)]
30 fn write_into(&self, writer: &mut TableWriter) {
31 let version = self.compute_version() as u16;
32 version.write_into(writer);
33 (u16::try_from(array_len(&self.name_record)).unwrap()).write_into(writer);
34 (self.compute_storage_offset() as u16).write_into(writer);
35 writer.adjust_offsets(self.compute_storage_offset() as u32, |writer| {
36 self.name_record.write_into(writer);
37 });
38 version
39 .compatible(1u16)
40 .then(|| (u16::try_from(array_len(&self.lang_tag_record)).unwrap()).write_into(writer));
41 writer.adjust_offsets(self.compute_storage_offset() as u32, |writer| {
42 version.compatible(1u16).then(|| {
43 self.lang_tag_record
44 .as_ref()
45 .expect("missing conditional field should have failed validation")
46 .write_into(writer)
47 });
48 });
49 }
50 fn table_type(&self) -> TableType {
51 TableType::TopLevel(Name::TAG)
52 }
53}
54
55impl Validate for Name {
56 fn validate_impl(&self, ctx: &mut ValidationCtx) {
57 ctx.in_table("Name", |ctx| {
58 let version: u16 = self.compute_version();
59 ctx.in_field("name_record", |ctx| {
60 if self.name_record.len() > (u16::MAX as usize) {
61 ctx.report("array exceeds max length");
62 }
63 self.check_sorted_and_unique_name_records(ctx);
64 });
65 ctx.in_field("lang_tag_record", |ctx| {
66 if version.compatible(1u16) && self.lang_tag_record.is_none() {
67 ctx.report(format!("field must be present for version {version}"));
68 }
69 if self.lang_tag_record.is_some()
70 && self.lang_tag_record.as_ref().unwrap().len() > (u16::MAX as usize)
71 {
72 ctx.report("array exceeds max length");
73 }
74 self.lang_tag_record.validate_impl(ctx);
75 });
76 })
77 }
78}
79
80impl TopLevelTable for Name {
81 const TAG: Tag = Tag::new(b"name");
82}
83
84impl<'a> FromObjRef<read_fonts::tables::name::Name<'a>> for Name {
85 fn from_obj_ref(obj: &read_fonts::tables::name::Name<'a>, _: FontData) -> Self {
86 let offset_data = obj.string_data();
87 Name {
88 name_record: obj.name_record().to_owned_obj(offset_data),
89 lang_tag_record: obj.lang_tag_record().to_owned_obj(offset_data),
90 }
91 }
92}
93
94#[allow(clippy::needless_lifetimes)]
95impl<'a> FromTableRef<read_fonts::tables::name::Name<'a>> for Name {}
96
97impl<'a> FontRead<'a> for Name {
98 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
99 <read_fonts::tables::name::Name as FontRead>::read(data).map(|x| x.to_owned_table())
100 }
101}
102
103#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
105#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
106pub struct LangTagRecord {
107 pub lang_tag: OffsetMarker<String>,
110}
111
112impl LangTagRecord {
113 #[allow(clippy::useless_conversion)]
115 pub fn new(lang_tag: OffsetMarker<String>) -> Self {
116 Self {
117 lang_tag: lang_tag.into(),
118 }
119 }
120}
121
122impl FontWrite for LangTagRecord {
123 #[allow(clippy::unnecessary_cast)]
124 fn write_into(&self, writer: &mut TableWriter) {
125 (self.compile_name_string()).write_into(writer);
126 }
127 fn table_type(&self) -> TableType {
128 TableType::Named("LangTagRecord")
129 }
130}
131
132impl Validate for LangTagRecord {
133 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
134}
135
136impl FromObjRef<read_fonts::tables::name::LangTagRecord> for LangTagRecord {
137 fn from_obj_ref(obj: &read_fonts::tables::name::LangTagRecord, offset_data: FontData) -> Self {
138 LangTagRecord {
139 lang_tag: obj.lang_tag(offset_data).to_owned_table(),
140 }
141 }
142}
143
144#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
146#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
147pub struct NameRecord {
148 pub platform_id: u16,
150 pub encoding_id: u16,
152 pub language_id: u16,
154 pub name_id: NameId,
156 pub string: OffsetMarker<String>,
158}
159
160impl NameRecord {
161 #[allow(clippy::useless_conversion)]
163 pub fn new(
164 platform_id: u16,
165 encoding_id: u16,
166 language_id: u16,
167 name_id: NameId,
168 string: OffsetMarker<String>,
169 ) -> Self {
170 Self {
171 platform_id,
172 encoding_id,
173 language_id,
174 name_id,
175 string: string.into(),
176 }
177 }
178}
179
180impl FontWrite for NameRecord {
181 #[allow(clippy::unnecessary_cast)]
182 fn write_into(&self, writer: &mut TableWriter) {
183 self.platform_id.write_into(writer);
184 self.encoding_id.write_into(writer);
185 self.language_id.write_into(writer);
186 self.name_id.write_into(writer);
187 (self.compile_name_string()).write_into(writer);
188 }
189 fn table_type(&self) -> TableType {
190 TableType::Named("NameRecord")
191 }
192}
193
194impl Validate for NameRecord {
195 fn validate_impl(&self, ctx: &mut ValidationCtx) {
196 ctx.in_table("NameRecord", |ctx| {
197 ctx.in_field("string", |ctx| {
198 self.validate_string_data(ctx);
199 });
200 })
201 }
202}
203
204impl FromObjRef<read_fonts::tables::name::NameRecord> for NameRecord {
205 fn from_obj_ref(obj: &read_fonts::tables::name::NameRecord, offset_data: FontData) -> Self {
206 NameRecord {
207 platform_id: obj.platform_id(),
208 encoding_id: obj.encoding_id(),
209 language_id: obj.language_id(),
210 name_id: obj.name_id(),
211 string: obj.string(offset_data).to_owned_table(),
212 }
213 }
214}