/src/fontations/read-fonts/generated/generated_vorg.rs
Line | Count | Source (jump to first uncovered line) |
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 | | /// The [VORG (Vertical Origin)](https://docs.microsoft.com/en-us/typography/opentype/spec/vorg) table. |
9 | | #[derive(Debug, Clone, Copy)] |
10 | | #[doc(hidden)] |
11 | | pub struct VorgMarker { |
12 | | vert_origin_y_metrics_byte_len: usize, |
13 | | } |
14 | | |
15 | | impl VorgMarker { |
16 | 0 | pub fn version_byte_range(&self) -> Range<usize> { |
17 | 0 | let start = 0; |
18 | 0 | start..start + MajorMinor::RAW_BYTE_LEN |
19 | 0 | } |
20 | | |
21 | 0 | pub fn default_vert_origin_y_byte_range(&self) -> Range<usize> { |
22 | 0 | let start = self.version_byte_range().end; |
23 | 0 | start..start + i16::RAW_BYTE_LEN |
24 | 0 | } |
25 | | |
26 | 0 | pub fn num_vert_origin_y_metrics_byte_range(&self) -> Range<usize> { |
27 | 0 | let start = self.default_vert_origin_y_byte_range().end; |
28 | 0 | start..start + u16::RAW_BYTE_LEN |
29 | 0 | } |
30 | | |
31 | 0 | pub fn vert_origin_y_metrics_byte_range(&self) -> Range<usize> { |
32 | 0 | let start = self.num_vert_origin_y_metrics_byte_range().end; |
33 | 0 | start..start + self.vert_origin_y_metrics_byte_len |
34 | 0 | } |
35 | | } |
36 | | |
37 | | impl MinByteRange for VorgMarker { |
38 | 0 | fn min_byte_range(&self) -> Range<usize> { |
39 | 0 | 0..self.vert_origin_y_metrics_byte_range().end |
40 | 0 | } |
41 | | } |
42 | | |
43 | | impl TopLevelTable for Vorg<'_> { |
44 | | /// `VORG` |
45 | | const TAG: Tag = Tag::new(b"VORG"); |
46 | | } |
47 | | |
48 | | impl<'a> FontRead<'a> for Vorg<'a> { |
49 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
50 | 0 | let mut cursor = data.cursor(); |
51 | 0 | cursor.advance::<MajorMinor>(); |
52 | 0 | cursor.advance::<i16>(); |
53 | 0 | let num_vert_origin_y_metrics: u16 = cursor.read()?; |
54 | 0 | let vert_origin_y_metrics_byte_len = (num_vert_origin_y_metrics as usize) |
55 | 0 | .checked_mul(VertOriginYMetrics::RAW_BYTE_LEN) |
56 | 0 | .ok_or(ReadError::OutOfBounds)?; |
57 | 0 | cursor.advance_by(vert_origin_y_metrics_byte_len); |
58 | 0 | cursor.finish(VorgMarker { |
59 | 0 | vert_origin_y_metrics_byte_len, |
60 | 0 | }) |
61 | 0 | } |
62 | | } |
63 | | |
64 | | /// The [VORG (Vertical Origin)](https://docs.microsoft.com/en-us/typography/opentype/spec/vorg) table. |
65 | | pub type Vorg<'a> = TableRef<'a, VorgMarker>; |
66 | | |
67 | | #[allow(clippy::needless_lifetimes)] |
68 | | impl<'a> Vorg<'a> { |
69 | | /// Major/minor version number. Set to 1.0. |
70 | 0 | pub fn version(&self) -> MajorMinor { |
71 | 0 | let range = self.shape.version_byte_range(); |
72 | 0 | self.data.read_at(range.start).unwrap() |
73 | 0 | } |
74 | | |
75 | | /// The y coordinate of a glyph’s vertical origin, in the font’s design |
76 | | /// coordinate system, to be used if no entry is present for the glyph |
77 | | /// in the vertOriginYMetrics array. |
78 | 0 | pub fn default_vert_origin_y(&self) -> i16 { |
79 | 0 | let range = self.shape.default_vert_origin_y_byte_range(); |
80 | 0 | self.data.read_at(range.start).unwrap() |
81 | 0 | } |
82 | | |
83 | | /// Number of elements in the vertOriginYMetrics array. |
84 | 0 | pub fn num_vert_origin_y_metrics(&self) -> u16 { |
85 | 0 | let range = self.shape.num_vert_origin_y_metrics_byte_range(); |
86 | 0 | self.data.read_at(range.start).unwrap() |
87 | 0 | } |
88 | | |
89 | | /// Array of VertOriginYMetrics records, sorted by glyph ID. |
90 | 0 | pub fn vert_origin_y_metrics(&self) -> &'a [VertOriginYMetrics] { |
91 | 0 | let range = self.shape.vert_origin_y_metrics_byte_range(); |
92 | 0 | self.data.read_array(range).unwrap() |
93 | 0 | } |
94 | | } |
95 | | |
96 | | #[cfg(feature = "experimental_traverse")] |
97 | | impl<'a> SomeTable<'a> for Vorg<'a> { |
98 | | fn type_name(&self) -> &str { |
99 | | "Vorg" |
100 | | } |
101 | | fn get_field(&self, idx: usize) -> Option<Field<'a>> { |
102 | | match idx { |
103 | | 0usize => Some(Field::new("version", self.version())), |
104 | | 1usize => Some(Field::new( |
105 | | "default_vert_origin_y", |
106 | | self.default_vert_origin_y(), |
107 | | )), |
108 | | 2usize => Some(Field::new( |
109 | | "num_vert_origin_y_metrics", |
110 | | self.num_vert_origin_y_metrics(), |
111 | | )), |
112 | | 3usize => Some(Field::new( |
113 | | "vert_origin_y_metrics", |
114 | | traversal::FieldType::array_of_records( |
115 | | stringify!(VertOriginYMetrics), |
116 | | self.vert_origin_y_metrics(), |
117 | | self.offset_data(), |
118 | | ), |
119 | | )), |
120 | | _ => None, |
121 | | } |
122 | | } |
123 | | } |
124 | | |
125 | | #[cfg(feature = "experimental_traverse")] |
126 | | #[allow(clippy::needless_lifetimes)] |
127 | | impl<'a> std::fmt::Debug for Vorg<'a> { |
128 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
129 | | (self as &dyn SomeTable<'a>).fmt(f) |
130 | | } |
131 | | } |
132 | | |
133 | | /// Vertical origin Y metrics record. |
134 | 0 | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)] Unexecuted instantiation: read_fonts::tables::vorg::_::{closure#0}::check::assert_impl::<_> Unexecuted instantiation: read_fonts::tables::vorg::_::{closure#0}::check::assert_impl::<_> Unexecuted instantiation: read_fonts::tables::vorg::_::{closure#0} Unexecuted instantiation: read_fonts::tables::vorg::_::{closure#0} Unexecuted instantiation: read_fonts::tables::vorg::_::{closure#0}::check Unexecuted instantiation: read_fonts::tables::vorg::_::{closure#0}::check |
135 | | #[repr(C)] |
136 | | #[repr(packed)] |
137 | | pub struct VertOriginYMetrics { |
138 | | /// Glyph index. |
139 | | pub glyph_index: BigEndian<GlyphId16>, |
140 | | /// Y coordinate, in the font’s design coordinate system, of the glyph’s vertical origin. |
141 | | pub vert_origin_y: BigEndian<i16>, |
142 | | } |
143 | | |
144 | | impl VertOriginYMetrics { |
145 | | /// Glyph index. |
146 | 0 | pub fn glyph_index(&self) -> GlyphId16 { |
147 | 0 | self.glyph_index.get() |
148 | 0 | } |
149 | | |
150 | | /// Y coordinate, in the font’s design coordinate system, of the glyph’s vertical origin. |
151 | 0 | pub fn vert_origin_y(&self) -> i16 { |
152 | 0 | self.vert_origin_y.get() |
153 | 0 | } |
154 | | } |
155 | | |
156 | | impl FixedSize for VertOriginYMetrics { |
157 | | const RAW_BYTE_LEN: usize = GlyphId16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN; |
158 | | } |
159 | | |
160 | | #[cfg(feature = "experimental_traverse")] |
161 | | impl<'a> SomeRecord<'a> for VertOriginYMetrics { |
162 | | fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> { |
163 | | RecordResolver { |
164 | | name: "VertOriginYMetrics", |
165 | | get_field: Box::new(move |idx, _data| match idx { |
166 | | 0usize => Some(Field::new("glyph_index", self.glyph_index())), |
167 | | 1usize => Some(Field::new("vert_origin_y", self.vert_origin_y())), |
168 | | _ => None, |
169 | | }), |
170 | | data, |
171 | | } |
172 | | } |
173 | | } |