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
// THIS FILE IS AUTOGENERATED.
// Any changes to this file will be overwritten.
// For more information about how codegen works, see font-codegen/README.md

#[allow(unused_imports)]
use crate::codegen_prelude::*;

/// The [vmtx (Vertical Metrics)](https://docs.microsoft.com/en-us/typography/opentype/spec/vmtx) table
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Vmtx {
    /// Paired advance height and top side bearing values for each
    /// glyph. Records are indexed by glyph ID.
    pub v_metrics: Vec<LongMetric>,
    /// Top side bearings for glyph IDs greater than or equal to numberOfLongMetrics.
    pub top_side_bearings: Vec<i16>,
}

impl Vmtx {
    /// Construct a new `Vmtx`
    pub fn new(v_metrics: Vec<LongMetric>, top_side_bearings: Vec<i16>) -> Self {
        Self {
            v_metrics: v_metrics.into_iter().map(Into::into).collect(),
            top_side_bearings: top_side_bearings.into_iter().map(Into::into).collect(),
        }
    }
}

impl FontWrite for Vmtx {
    fn write_into(&self, writer: &mut TableWriter) {
        self.v_metrics.write_into(writer);
        self.top_side_bearings.write_into(writer);
    }
    fn table_type(&self) -> TableType {
        TableType::TopLevel(Vmtx::TAG)
    }
}

impl Validate for Vmtx {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("Vmtx", |ctx| {
            ctx.in_field("v_metrics", |ctx| {
                if self.v_metrics.len() > (u16::MAX as usize) {
                    ctx.report("array exceeds max length");
                }
                self.v_metrics.validate_impl(ctx);
            });
        })
    }
}

impl TopLevelTable for Vmtx {
    const TAG: Tag = Tag::new(b"vmtx");
}

impl<'a> FromObjRef<read_fonts::tables::vmtx::Vmtx<'a>> for Vmtx {
    fn from_obj_ref(obj: &read_fonts::tables::vmtx::Vmtx<'a>, _: FontData) -> Self {
        let offset_data = obj.offset_data();
        Vmtx {
            v_metrics: obj.v_metrics().to_owned_obj(offset_data),
            top_side_bearings: obj.top_side_bearings().to_owned_obj(offset_data),
        }
    }
}

impl<'a> FromTableRef<read_fonts::tables::vmtx::Vmtx<'a>> for Vmtx {}