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
//! Vertical origin table.
use super::parse_prelude::*;
/// Tag for the `VORG` table.
pub const VORG: Tag = Tag::new(b"VORG");
/// Glyph identifier and Y coordinate of the vertical origin.
#[derive(Copy, Clone, Debug)]
pub struct VyMetric {
pub gid: GlyphId,
pub y: FWord,
}
impl ReadData for VyMetric {
unsafe fn read_data_unchecked(buf: &[u8], offset: usize) -> Self {
Self {
gid: u16::read_data_unchecked(buf, offset),
y: i16::read_data_unchecked(buf, offset + 2),
}
}
}
/// Vertical origin table.
///
/// <https://docs.microsoft.com/en-us/typography/opentype/spec/vorg>
#[derive(Copy, Clone)]
pub struct Vorg<'a>(Buffer<'a>);
impl<'a> Vorg<'a> {
/// Creates a new vertical origin table from a byte slice containing the
/// table data.
pub fn new(data: &'a [u8]) -> Self {
Self(Buffer::new(data))
}
/// Returns the major version.
pub fn major_version(&self) -> u16 {
self.0.read(0).unwrap_or(0)
}
/// Returns the minor version.
pub fn minor_version(&self) -> u16 {
self.0.read(2).unwrap_or(0)
}
/// Returns the Y coordinate of a glyph’s vertical origin, in font units, to be used
/// if no entry is present.
pub fn default_vymetric(&self) -> FWord {
self.0.read(4).unwrap_or(0)
}
/// Returns a list of Y coordinates of a glyph's vertical origin, sorted by
/// glyph identifier.
pub fn vymetrics(&self) -> Slice<'a, VyMetric> {
self.0.read_slice16(8).unwrap_or_default()
}
}