pinot/
vorg.rs

1//! Vertical origin table.
2
3use super::parse_prelude::*;
4
5/// Tag for the `VORG` table.
6pub const VORG: Tag = Tag::new(b"VORG");
7
8/// Glyph identifier and Y coordinate of the vertical origin.
9#[derive(Copy, Clone, Debug)]
10pub struct VyMetric {
11    pub gid: GlyphId,
12    pub y: FWord,
13}
14
15impl ReadData for VyMetric {
16    unsafe fn read_data_unchecked(buf: &[u8], offset: usize) -> Self {
17        Self {
18            gid: u16::read_data_unchecked(buf, offset),
19            y: i16::read_data_unchecked(buf, offset + 2),
20        }
21    }
22}
23
24/// Vertical origin table.
25///
26/// <https://docs.microsoft.com/en-us/typography/opentype/spec/vorg>
27#[derive(Copy, Clone)]
28pub struct Vorg<'a>(Buffer<'a>);
29
30impl<'a> Vorg<'a> {
31    /// Creates a new vertical origin table from a byte slice containing the
32    /// table data.
33    pub fn new(data: &'a [u8]) -> Self {
34        Self(Buffer::new(data))
35    }
36
37    /// Returns the major version.
38    pub fn major_version(&self) -> u16 {
39        self.0.read(0).unwrap_or(0)
40    }
41
42    /// Returns the minor version.
43    pub fn minor_version(&self) -> u16 {
44        self.0.read(2).unwrap_or(0)
45    }
46
47    /// Returns the Y coordinate of a glyph’s vertical origin, in font units, to be used
48    /// if no entry is present.
49    pub fn default_vymetric(&self) -> FWord {
50        self.0.read(4).unwrap_or(0)
51    }
52
53    /// Returns a list of Y coordinates of a glyph's vertical origin, sorted by
54    /// glyph identifier.
55    pub fn vymetrics(&self) -> Slice<'a, VyMetric> {
56        self.0.read_slice16(8).unwrap_or_default()
57    }
58}