Coverage Report

Created: 2025-11-16 06:56

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