/src/fontations/write-fonts/generated/generated_hmtx.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 | | /// The [hmtx (Horizontal Metrics)](https://docs.microsoft.com/en-us/typography/opentype/spec/hmtx) table |
9 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
10 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
11 | | pub struct Hmtx { |
12 | | /// Paired advance width/height and left/top side bearing values for each |
13 | | /// glyph. Records are indexed by glyph ID. |
14 | | pub h_metrics: Vec<LongMetric>, |
15 | | /// Leading (left/top) side bearings for glyph IDs greater than or equal to |
16 | | /// numberOfLongMetrics. |
17 | | pub left_side_bearings: Vec<i16>, |
18 | | } |
19 | | |
20 | | impl Hmtx { |
21 | | /// Construct a new `Hmtx` |
22 | 0 | pub fn new(h_metrics: Vec<LongMetric>, left_side_bearings: Vec<i16>) -> Self { |
23 | 0 | Self { |
24 | 0 | h_metrics, |
25 | 0 | left_side_bearings, |
26 | 0 | } |
27 | 0 | } |
28 | | } |
29 | | |
30 | | impl FontWrite for Hmtx { |
31 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
32 | 0 | self.h_metrics.write_into(writer); |
33 | 0 | self.left_side_bearings.write_into(writer); |
34 | 0 | } |
35 | 0 | fn table_type(&self) -> TableType { |
36 | 0 | TableType::TopLevel(Hmtx::TAG) |
37 | 0 | } |
38 | | } |
39 | | |
40 | | impl Validate for Hmtx { |
41 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
42 | 0 | ctx.in_table("Hmtx", |ctx| { |
43 | 0 | ctx.in_field("h_metrics", |ctx| { |
44 | 0 | if self.h_metrics.len() > to_usize(u16::MAX) { |
45 | 0 | ctx.report("array exceeds max length"); |
46 | 0 | } |
47 | 0 | self.h_metrics.validate_impl(ctx); |
48 | 0 | }); |
49 | 0 | }) |
50 | 0 | } |
51 | | } |
52 | | |
53 | | impl TopLevelTable for Hmtx { |
54 | | const TAG: Tag = Tag::new(b"hmtx"); |
55 | | } |
56 | | |
57 | | impl<'a> FromObjRef<read_fonts::tables::hmtx::Hmtx<'a>> for Hmtx { |
58 | 0 | fn from_obj_ref(obj: &read_fonts::tables::hmtx::Hmtx<'a>, _: FontData) -> Self { |
59 | 0 | let offset_data = obj.offset_data(); |
60 | 0 | Hmtx { |
61 | 0 | h_metrics: obj.h_metrics().to_owned_obj(offset_data), |
62 | 0 | left_side_bearings: obj.left_side_bearings().to_owned_obj(offset_data), |
63 | 0 | } |
64 | 0 | } |
65 | | } |
66 | | |
67 | | #[allow(clippy::needless_lifetimes)] |
68 | | impl<'a> FromTableRef<read_fonts::tables::hmtx::Hmtx<'a>> for Hmtx {} |
69 | | |
70 | | /// HMTX horizontal metrics (ISO/IEC 14496-22:2026, 5.1.11). |
71 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
72 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
73 | | pub struct HmtxExtended { |
74 | | pub h_metrics: Vec<LongMetric>, |
75 | | pub left_side_bearings: Vec<i16>, |
76 | | } |
77 | | |
78 | | impl HmtxExtended { |
79 | | /// Construct a new `HmtxExtended` |
80 | 0 | pub fn new(h_metrics: Vec<LongMetric>, left_side_bearings: Vec<i16>) -> Self { |
81 | 0 | Self { |
82 | 0 | h_metrics, |
83 | 0 | left_side_bearings, |
84 | 0 | } |
85 | 0 | } |
86 | | } |
87 | | |
88 | | impl FontWrite for HmtxExtended { |
89 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
90 | 0 | self.h_metrics.write_into(writer); |
91 | 0 | self.left_side_bearings.write_into(writer); |
92 | 0 | } |
93 | 0 | fn table_type(&self) -> TableType { |
94 | 0 | TableType::TopLevel(HmtxExtended::TAG) |
95 | 0 | } |
96 | | } |
97 | | |
98 | | impl Validate for HmtxExtended { |
99 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
100 | 0 | ctx.in_table("HmtxExtended", |ctx| { |
101 | 0 | ctx.in_field("h_metrics", |ctx| { |
102 | 0 | if self.h_metrics.len() > to_usize(u32::MAX) { |
103 | 0 | ctx.report("array exceeds max length"); |
104 | 0 | } |
105 | 0 | self.h_metrics.validate_impl(ctx); |
106 | 0 | }); |
107 | 0 | }) |
108 | 0 | } |
109 | | } |
110 | | |
111 | | impl TopLevelTable for HmtxExtended { |
112 | | const TAG: Tag = Tag::new(b"HMTX"); |
113 | | } |
114 | | |
115 | | impl<'a> FromObjRef<read_fonts::tables::hmtx::HmtxExtended<'a>> for HmtxExtended { |
116 | 0 | fn from_obj_ref(obj: &read_fonts::tables::hmtx::HmtxExtended<'a>, _: FontData) -> Self { |
117 | 0 | let offset_data = obj.offset_data(); |
118 | 0 | HmtxExtended { |
119 | 0 | h_metrics: obj.h_metrics().to_owned_obj(offset_data), |
120 | 0 | left_side_bearings: obj.left_side_bearings().to_owned_obj(offset_data), |
121 | 0 | } |
122 | 0 | } |
123 | | } |
124 | | |
125 | | #[allow(clippy::needless_lifetimes)] |
126 | | impl<'a> FromTableRef<read_fonts::tables::hmtx::HmtxExtended<'a>> for HmtxExtended {} |
127 | | |
128 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
129 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
130 | | pub struct LongMetric { |
131 | | /// Advance width/height, in font design units. |
132 | | pub advance: u16, |
133 | | /// Glyph leading (left/top) side bearing, in font design units. |
134 | | pub side_bearing: i16, |
135 | | } |
136 | | |
137 | | impl LongMetric { |
138 | | /// Construct a new `LongMetric` |
139 | 0 | pub fn new(advance: u16, side_bearing: i16) -> Self { |
140 | 0 | Self { |
141 | 0 | advance, |
142 | 0 | side_bearing, |
143 | 0 | } |
144 | 0 | } |
145 | | } |
146 | | |
147 | | impl FontWrite for LongMetric { |
148 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
149 | 0 | self.advance.write_into(writer); |
150 | 0 | self.side_bearing.write_into(writer); |
151 | 0 | } |
152 | 0 | fn table_type(&self) -> TableType { |
153 | 0 | TableType::Named("LongMetric") |
154 | 0 | } |
155 | | } |
156 | | |
157 | | impl Validate for LongMetric { |
158 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
159 | | } |
160 | | |
161 | | impl FromObjRef<read_fonts::tables::hmtx::LongMetric> for LongMetric { |
162 | 0 | fn from_obj_ref(obj: &read_fonts::tables::hmtx::LongMetric, _: FontData) -> Self { |
163 | 0 | LongMetric { |
164 | 0 | advance: obj.advance(), |
165 | 0 | side_bearing: obj.side_bearing(), |
166 | 0 | } |
167 | 0 | } |
168 | | } |