Coverage Report

Created: 2026-11-11 07:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fontations/read-fonts/generated/generated_vorg.rs
Line
Count
Source
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)]
6
use crate::codegen_prelude::*;
7
8
impl<'a> MinByteRange<'a> for Vorg<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.vert_origin_y_metrics_byte_range().end
11
0
    }
12
0
    fn min_table_bytes(&self) -> &'a [u8] {
13
0
        let range = self.min_byte_range();
14
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
15
0
    }
16
}
17
18
impl TopLevelTable for Vorg<'_> {
19
    /// `VORG`
20
    const TAG: Tag = Tag::new(b"VORG");
21
}
22
23
impl ReadArgs for Vorg<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Vorg<'a> {
28
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
0
        if data.len() < Self::MIN_SIZE {
31
0
            return Err(ReadError::OutOfBounds);
32
0
        }
33
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
0
        Ok(Self { data })
37
0
    }
38
}
39
40
/// The fields at the start of the table, which are read directly.
41
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42
#[repr(C, packed)]
43
#[doc(hidden)]
44
pub struct VorgFixedHeader {
45
    pub version: BigEndian<MajorMinor>,
46
    pub default_vert_origin_y: BigEndian<i16>,
47
    pub num_vert_origin_y_metrics: BigEndian<u16>,
48
}
49
50
#[allow(clippy::absurd_extreme_comparisons)]
51
const _: () = assert!(std::mem::size_of::<VorgFixedHeader>() <= Vorg::MIN_SIZE);
52
53
/// The [VORG (Vertical Origin)](https://docs.microsoft.com/en-us/typography/opentype/spec/vorg) table.
54
#[derive(Clone)]
55
pub struct Vorg<'a> {
56
    data: TableDataRef<'a, VorgFixedHeader>,
57
}
58
59
#[allow(clippy::needless_lifetimes)]
60
impl<'a> Vorg<'a> {
61
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN + i16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
62
    basic_table_impls!(impl_the_methods);
63
64
    /// Major/minor version number. Set to 1.0.
65
0
    pub fn version(&self) -> MajorMinor {
66
0
        self.data.header().version.get()
67
0
    }
68
69
    /// The y coordinate of a glyph’s vertical origin, in the font’s design
70
    /// coordinate system, to be used if no entry is present for the glyph
71
    /// in the vertOriginYMetrics array.
72
0
    pub fn default_vert_origin_y(&self) -> i16 {
73
0
        self.data.header().default_vert_origin_y.get()
74
0
    }
75
76
    /// Number of elements in the vertOriginYMetrics array.
77
0
    pub fn num_vert_origin_y_metrics(&self) -> u16 {
78
0
        self.data.header().num_vert_origin_y_metrics.get()
79
0
    }
80
81
    /// Array of VertOriginYMetrics records, sorted by glyph ID.
82
0
    pub fn vert_origin_y_metrics(&self) -> &'a [VertOriginYMetrics] {
83
0
        let range = self.vert_origin_y_metrics_byte_range();
84
0
        self.offset_data()
85
0
            .read_array(range)
86
0
            .ok()
87
0
            .unwrap_or_default()
88
0
    }
89
90
0
    pub fn version_byte_range(&self) -> Range<usize> {
91
0
        let start = 0usize;
92
0
        let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
93
0
        start..end
94
0
    }
95
96
0
    pub fn default_vert_origin_y_byte_range(&self) -> Range<usize> {
97
0
        let start = self.version_byte_range().end;
98
0
        let end = start.saturating_add(i16::RAW_BYTE_LEN);
99
0
        start..end
100
0
    }
101
102
0
    pub fn num_vert_origin_y_metrics_byte_range(&self) -> Range<usize> {
103
0
        let start = self.default_vert_origin_y_byte_range().end;
104
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
105
0
        start..end
106
0
    }
107
108
0
    pub fn vert_origin_y_metrics_byte_range(&self) -> Range<usize> {
109
0
        let num_vert_origin_y_metrics = self.num_vert_origin_y_metrics();
110
0
        let start = self.num_vert_origin_y_metrics_byte_range().end;
111
0
        let end = start.saturating_add(
112
0
            (transforms::to_usize(num_vert_origin_y_metrics))
113
0
                .saturating_mul(VertOriginYMetrics::RAW_BYTE_LEN),
114
        );
115
0
        start..end
116
0
    }
117
}
118
119
const _: () = assert!(FontData::default_data_long_enough(Vorg::MIN_SIZE));
120
121
impl Default for Vorg<'_> {
122
0
    fn default() -> Self {
123
        Self {
124
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
125
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
126
        }
127
0
    }
128
}
129
130
/// Vertical origin Y metrics record.
131
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
132
#[repr(C)]
133
#[repr(packed)]
134
pub struct VertOriginYMetrics {
135
    /// Glyph index.
136
    pub glyph_index: BigEndian<GlyphId16>,
137
    /// Y coordinate, in the font’s design coordinate system, of the glyph’s vertical origin.
138
    pub vert_origin_y: BigEndian<i16>,
139
}
140
141
impl VertOriginYMetrics {
142
    /// Glyph index.
143
0
    pub fn glyph_index(&self) -> GlyphId16 {
144
0
        self.glyph_index.get()
145
0
    }
146
147
    /// Y coordinate, in the font’s design coordinate system, of the glyph’s vertical origin.
148
0
    pub fn vert_origin_y(&self) -> i16 {
149
0
        self.vert_origin_y.get()
150
0
    }
151
}
152
153
impl FixedSize for VertOriginYMetrics {
154
    const RAW_BYTE_LEN: usize = GlyphId16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN;
155
}