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() > (u16::MAX as usize) {
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 {}