1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#[allow(unused_imports)]
use crate::codegen_prelude::*;
#[derive(Clone, Debug)]
pub struct Post {
pub version: Version16Dot16,
pub italic_angle: Fixed,
pub underline_position: FWord,
pub underline_thickness: FWord,
pub is_fixed_pitch: u32,
pub min_mem_type42: u32,
pub max_mem_type42: u32,
pub min_mem_type1: u32,
pub max_mem_type1: u32,
pub num_glyphs: Option<u16>,
pub glyph_name_index: Option<Vec<u16>>,
pub string_data: Option<Vec<PString>>,
}
impl Default for Post {
fn default() -> Self {
Self {
version: Version16Dot16::VERSION_1_0,
italic_angle: Default::default(),
underline_position: Default::default(),
underline_thickness: Default::default(),
is_fixed_pitch: Default::default(),
min_mem_type42: Default::default(),
max_mem_type42: Default::default(),
min_mem_type1: Default::default(),
max_mem_type1: Default::default(),
num_glyphs: Default::default(),
glyph_name_index: Default::default(),
string_data: Default::default(),
}
}
}
impl Post {
#[allow(clippy::too_many_arguments)]
pub fn new(
italic_angle: Fixed,
underline_position: FWord,
underline_thickness: FWord,
is_fixed_pitch: u32,
min_mem_type42: u32,
max_mem_type42: u32,
min_mem_type1: u32,
max_mem_type1: u32,
) -> Self {
Self {
italic_angle,
underline_position,
underline_thickness,
is_fixed_pitch,
min_mem_type42,
max_mem_type42,
min_mem_type1,
max_mem_type1,
..Default::default()
}
}
}
impl FontWrite for Post {
fn write_into(&self, writer: &mut TableWriter) {
let version = self.version;
version.write_into(writer);
self.italic_angle.write_into(writer);
self.underline_position.write_into(writer);
self.underline_thickness.write_into(writer);
self.is_fixed_pitch.write_into(writer);
self.min_mem_type42.write_into(writer);
self.max_mem_type42.write_into(writer);
self.min_mem_type1.write_into(writer);
self.max_mem_type1.write_into(writer);
version.compatible((2, 0)).then(|| {
self.num_glyphs
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((2, 0)).then(|| {
self.glyph_name_index
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((2, 0)).then(|| {
self.string_data
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
}
}
impl Validate for Post {
fn validate_impl(&self, ctx: &mut ValidationCtx) {
ctx.in_table("Post", |ctx| {
let version = self.version;
ctx.in_field("num_glyphs", |ctx| {
if version.compatible((2, 0)) && self.num_glyphs.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("glyph_name_index", |ctx| {
if version.compatible((2, 0)) && self.glyph_name_index.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
if self.glyph_name_index.is_some()
&& self.glyph_name_index.as_ref().unwrap().len() > (u16::MAX as usize)
{
ctx.report("array exceeds max length");
}
});
})
}
}
impl TopLevelTable for Post {
const TAG: Tag = Tag::new(b"post");
}
impl<'a> FromObjRef<read_fonts::tables::post::Post<'a>> for Post {
fn from_obj_ref(obj: &read_fonts::tables::post::Post<'a>, _: FontData) -> Self {
let offset_data = obj.offset_data();
Post {
version: obj.version(),
italic_angle: obj.italic_angle(),
underline_position: obj.underline_position(),
underline_thickness: obj.underline_thickness(),
is_fixed_pitch: obj.is_fixed_pitch(),
min_mem_type42: obj.min_mem_type42(),
max_mem_type42: obj.max_mem_type42(),
min_mem_type1: obj.min_mem_type1(),
max_mem_type1: obj.max_mem_type1(),
num_glyphs: obj.num_glyphs(),
glyph_name_index: obj.glyph_name_index().to_owned_obj(offset_data),
string_data: obj.string_data().map(|obj| {
obj.iter()
.filter_map(|x| x.map(|x| FromObjRef::from_obj_ref(&x, offset_data)).ok())
.collect()
}),
}
}
}
impl<'a> FromTableRef<read_fonts::tables::post::Post<'a>> for Post {}
impl<'a> FontRead<'a> for Post {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
<read_fonts::tables::post::Post as FontRead>::read(data).map(|x| x.to_owned_table())
}
}