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
#[allow(unused_imports)]
use crate::codegen_prelude::*;
#[derive(Clone, Debug, Default)]
pub struct Hmtx {
pub h_metrics: Vec<LongMetric>,
pub left_side_bearings: Vec<i16>,
}
impl Hmtx {
pub fn new(h_metrics: Vec<LongMetric>, left_side_bearings: Vec<i16>) -> Self {
Self {
h_metrics: h_metrics.into_iter().map(Into::into).collect(),
left_side_bearings: left_side_bearings.into_iter().map(Into::into).collect(),
}
}
}
impl FontWrite for Hmtx {
fn write_into(&self, writer: &mut TableWriter) {
self.h_metrics.write_into(writer);
self.left_side_bearings.write_into(writer);
}
}
impl Validate for Hmtx {
fn validate_impl(&self, ctx: &mut ValidationCtx) {
ctx.in_table("Hmtx", |ctx| {
ctx.in_field("h_metrics", |ctx| {
if self.h_metrics.len() > (u16::MAX as usize) {
ctx.report("array exceeds max length");
}
self.h_metrics.validate_impl(ctx);
});
})
}
}
impl TopLevelTable for Hmtx {
const TAG: Tag = Tag::new(b"hmtx");
}
impl<'a> FromObjRef<read_fonts::tables::hmtx::Hmtx<'a>> for Hmtx {
fn from_obj_ref(obj: &read_fonts::tables::hmtx::Hmtx<'a>, _: FontData) -> Self {
let offset_data = obj.offset_data();
Hmtx {
h_metrics: obj.h_metrics().to_owned_obj(offset_data),
left_side_bearings: obj.left_side_bearings().to_owned_obj(offset_data),
}
}
}
impl<'a> FromTableRef<read_fonts::tables::hmtx::Hmtx<'a>> for Hmtx {}
#[derive(Clone, Debug, Default)]
pub struct LongMetric {
pub advance: u16,
pub side_bearing: i16,
}
impl LongMetric {
pub fn new(advance: u16, side_bearing: i16) -> Self {
Self {
advance,
side_bearing,
}
}
}
impl FontWrite for LongMetric {
fn write_into(&self, writer: &mut TableWriter) {
self.advance.write_into(writer);
self.side_bearing.write_into(writer);
}
}
impl Validate for LongMetric {
fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
}
impl FromObjRef<read_fonts::tables::hmtx::LongMetric> for LongMetric {
fn from_obj_ref(obj: &read_fonts::tables::hmtx::LongMetric, _: FontData) -> Self {
LongMetric {
advance: obj.advance(),
side_bearing: obj.side_bearing(),
}
}
}