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() > to_usize(u16::MAX) {
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() > to_usize(u16::MAX)
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 ReadArgs for Name {
98 type Args = ();
99}
100
101impl<'a> FontRead<'a> for Name {
102 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
103 <read_fonts::tables::name::Name as FontRead>::read(data).map(|x| x.to_owned_table())
104 }
105}
106
107#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
109#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
110pub struct LangTagRecord {
111 pub lang_tag: OffsetMarker<String>,
114}
115
116impl LangTagRecord {
117 #[allow(clippy::useless_conversion)]
119 pub fn new(lang_tag: OffsetMarker<String>) -> Self {
120 Self {
121 lang_tag: lang_tag.into(),
122 }
123 }
124}
125
126impl FontWrite for LangTagRecord {
127 #[allow(clippy::unnecessary_cast)]
128 fn write_into(&self, writer: &mut TableWriter) {
129 (self.compile_name_string()).write_into(writer);
130 }
131 fn table_type(&self) -> TableType {
132 TableType::Named("LangTagRecord")
133 }
134}
135
136impl Validate for LangTagRecord {
137 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
138}
139
140impl FromObjRef<read_fonts::tables::name::LangTagRecord> for LangTagRecord {
141 fn from_obj_ref(obj: &read_fonts::tables::name::LangTagRecord, offset_data: FontData) -> Self {
142 LangTagRecord {
143 lang_tag: obj.lang_tag(offset_data).to_owned_table(),
144 }
145 }
146}
147
148#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
150#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
151pub struct NameRecord {
152 pub platform_id: u16,
154 pub encoding_id: u16,
156 pub language_id: u16,
158 pub name_id: NameId,
160 pub string: OffsetMarker<String>,
162}
163
164impl NameRecord {
165 #[allow(clippy::useless_conversion)]
167 pub fn new(
168 platform_id: u16,
169 encoding_id: u16,
170 language_id: u16,
171 name_id: NameId,
172 string: OffsetMarker<String>,
173 ) -> Self {
174 Self {
175 platform_id,
176 encoding_id,
177 language_id,
178 name_id,
179 string: string.into(),
180 }
181 }
182}
183
184impl FontWrite for NameRecord {
185 #[allow(clippy::unnecessary_cast)]
186 fn write_into(&self, writer: &mut TableWriter) {
187 self.platform_id.write_into(writer);
188 self.encoding_id.write_into(writer);
189 self.language_id.write_into(writer);
190 self.name_id.write_into(writer);
191 (self.compile_name_string()).write_into(writer);
192 }
193 fn table_type(&self) -> TableType {
194 TableType::Named("NameRecord")
195 }
196}
197
198impl Validate for NameRecord {
199 fn validate_impl(&self, ctx: &mut ValidationCtx) {
200 ctx.in_table("NameRecord", |ctx| {
201 ctx.in_field("string", |ctx| {
202 self.validate_string_data(ctx);
203 });
204 })
205 }
206}
207
208impl FromObjRef<read_fonts::tables::name::NameRecord> for NameRecord {
209 fn from_obj_ref(obj: &read_fonts::tables::name::NameRecord, offset_data: FontData) -> Self {
210 NameRecord {
211 platform_id: obj.platform_id(),
212 encoding_id: obj.encoding_id(),
213 language_id: obj.language_id(),
214 name_id: obj.name_id(),
215 string: obj.string(offset_data).to_owned_table(),
216 }
217 }
218}