Skip to main content

write_fonts/generated/
generated_vmtx.rs

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)]
6use crate::codegen_prelude::*;
7
8/// The [vmtx (Vertical Metrics)](https://docs.microsoft.com/en-us/typography/opentype/spec/vmtx) table
9#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct Vmtx {
12    /// Paired advance height and top side bearing values for each
13    /// glyph. Records are indexed by glyph ID.
14    pub v_metrics: Vec<LongMetric>,
15    /// Top side bearings for glyph IDs greater than or equal to numberOfLongMetrics.
16    pub top_side_bearings: Vec<i16>,
17}
18
19impl Vmtx {
20    /// Construct a new `Vmtx`
21    pub fn new(v_metrics: Vec<LongMetric>, top_side_bearings: Vec<i16>) -> Self {
22        Self {
23            v_metrics,
24            top_side_bearings,
25        }
26    }
27}
28
29impl FontWrite for Vmtx {
30    fn write_into(&self, writer: &mut TableWriter) {
31        self.v_metrics.write_into(writer);
32        self.top_side_bearings.write_into(writer);
33    }
34    fn table_type(&self) -> TableType {
35        TableType::TopLevel(Vmtx::TAG)
36    }
37}
38
39impl Validate for Vmtx {
40    fn validate_impl(&self, ctx: &mut ValidationCtx) {
41        ctx.in_table("Vmtx", |ctx| {
42            ctx.in_field("v_metrics", |ctx| {
43                if self.v_metrics.len() > to_usize(u16::MAX) {
44                    ctx.report("array exceeds max length");
45                }
46                self.v_metrics.validate_impl(ctx);
47            });
48        })
49    }
50}
51
52impl TopLevelTable for Vmtx {
53    const TAG: Tag = Tag::new(b"vmtx");
54}
55
56impl<'a> FromObjRef<read_fonts::tables::vmtx::Vmtx<'a>> for Vmtx {
57    fn from_obj_ref(obj: &read_fonts::tables::vmtx::Vmtx<'a>, _: FontData) -> Self {
58        let offset_data = obj.offset_data();
59        Vmtx {
60            v_metrics: obj.v_metrics().to_owned_obj(offset_data),
61            top_side_bearings: obj.top_side_bearings().to_owned_obj(offset_data),
62        }
63    }
64}
65
66#[allow(clippy::needless_lifetimes)]
67impl<'a> FromTableRef<read_fonts::tables::vmtx::Vmtx<'a>> for Vmtx {}
68
69/// VMTX vertical metrics (ISO/IEC 14496-22:2026, 5.6.14).
70#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
71#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
72pub struct VmtxExtended {
73    pub v_metrics: Vec<LongMetric>,
74    pub top_side_bearings: Vec<i16>,
75}
76
77impl VmtxExtended {
78    /// Construct a new `VmtxExtended`
79    pub fn new(v_metrics: Vec<LongMetric>, top_side_bearings: Vec<i16>) -> Self {
80        Self {
81            v_metrics,
82            top_side_bearings,
83        }
84    }
85}
86
87impl FontWrite for VmtxExtended {
88    fn write_into(&self, writer: &mut TableWriter) {
89        self.v_metrics.write_into(writer);
90        self.top_side_bearings.write_into(writer);
91    }
92    fn table_type(&self) -> TableType {
93        TableType::TopLevel(VmtxExtended::TAG)
94    }
95}
96
97impl Validate for VmtxExtended {
98    fn validate_impl(&self, ctx: &mut ValidationCtx) {
99        ctx.in_table("VmtxExtended", |ctx| {
100            ctx.in_field("v_metrics", |ctx| {
101                if self.v_metrics.len() > to_usize(u32::MAX) {
102                    ctx.report("array exceeds max length");
103                }
104                self.v_metrics.validate_impl(ctx);
105            });
106        })
107    }
108}
109
110impl TopLevelTable for VmtxExtended {
111    const TAG: Tag = Tag::new(b"VMTX");
112}
113
114impl<'a> FromObjRef<read_fonts::tables::vmtx::VmtxExtended<'a>> for VmtxExtended {
115    fn from_obj_ref(obj: &read_fonts::tables::vmtx::VmtxExtended<'a>, _: FontData) -> Self {
116        let offset_data = obj.offset_data();
117        VmtxExtended {
118            v_metrics: obj.v_metrics().to_owned_obj(offset_data),
119            top_side_bearings: obj.top_side_bearings().to_owned_obj(offset_data),
120        }
121    }
122}
123
124#[allow(clippy::needless_lifetimes)]
125impl<'a> FromTableRef<read_fonts::tables::vmtx::VmtxExtended<'a>> for VmtxExtended {}