/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 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
71 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
72 | | pub struct LongMetric { |
73 | | /// Advance width/height, in font design units. |
74 | | pub advance: u16, |
75 | | /// Glyph leading (left/top) side bearing, in font design units. |
76 | | pub side_bearing: i16, |
77 | | } |
78 | | |
79 | | impl LongMetric { |
80 | | /// Construct a new `LongMetric` |
81 | 0 | pub fn new(advance: u16, side_bearing: i16) -> Self { |
82 | 0 | Self { |
83 | 0 | advance, |
84 | 0 | side_bearing, |
85 | 0 | } |
86 | 0 | } |
87 | | } |
88 | | |
89 | | impl FontWrite for LongMetric { |
90 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
91 | 0 | self.advance.write_into(writer); |
92 | 0 | self.side_bearing.write_into(writer); |
93 | 0 | } |
94 | 0 | fn table_type(&self) -> TableType { |
95 | 0 | TableType::Named("LongMetric") |
96 | 0 | } |
97 | | } |
98 | | |
99 | | impl Validate for LongMetric { |
100 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
101 | | } |
102 | | |
103 | | impl FromObjRef<read_fonts::tables::hmtx::LongMetric> for LongMetric { |
104 | 0 | fn from_obj_ref(obj: &read_fonts::tables::hmtx::LongMetric, _: FontData) -> Self { |
105 | 0 | LongMetric { |
106 | 0 | advance: obj.advance(), |
107 | 0 | side_bearing: obj.side_bearing(), |
108 | 0 | } |
109 | 0 | } |
110 | | } |