/src/fontations/read-fonts/generated/generated_meta.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 | | /// [`meta`](https://docs.microsoft.com/en-us/typography/opentype/spec/meta) |
9 | | #[derive(Debug, Clone, Copy)] |
10 | | #[doc(hidden)] |
11 | | pub struct MetaMarker { |
12 | | data_maps_byte_len: usize, |
13 | | } |
14 | | |
15 | | impl MetaMarker { |
16 | 0 | pub fn version_byte_range(&self) -> Range<usize> { |
17 | 0 | let start = 0; |
18 | 0 | start..start + u32::RAW_BYTE_LEN |
19 | 0 | } |
20 | | |
21 | 0 | pub fn flags_byte_range(&self) -> Range<usize> { |
22 | 0 | let start = self.version_byte_range().end; |
23 | 0 | start..start + u32::RAW_BYTE_LEN |
24 | 0 | } |
25 | | |
26 | 0 | pub fn reserved_byte_range(&self) -> Range<usize> { |
27 | 0 | let start = self.flags_byte_range().end; |
28 | 0 | start..start + u32::RAW_BYTE_LEN |
29 | 0 | } |
30 | | |
31 | 0 | pub fn data_maps_count_byte_range(&self) -> Range<usize> { |
32 | 0 | let start = self.reserved_byte_range().end; |
33 | 0 | start..start + u32::RAW_BYTE_LEN |
34 | 0 | } |
35 | | |
36 | 0 | pub fn data_maps_byte_range(&self) -> Range<usize> { |
37 | 0 | let start = self.data_maps_count_byte_range().end; |
38 | 0 | start..start + self.data_maps_byte_len |
39 | 0 | } |
40 | | } |
41 | | |
42 | | impl MinByteRange for MetaMarker { |
43 | 0 | fn min_byte_range(&self) -> Range<usize> { |
44 | 0 | 0..self.data_maps_byte_range().end |
45 | 0 | } |
46 | | } |
47 | | |
48 | | impl TopLevelTable for Meta<'_> { |
49 | | /// `meta` |
50 | | const TAG: Tag = Tag::new(b"meta"); |
51 | | } |
52 | | |
53 | | impl<'a> FontRead<'a> for Meta<'a> { |
54 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
55 | 0 | let mut cursor = data.cursor(); |
56 | 0 | cursor.advance::<u32>(); |
57 | 0 | cursor.advance::<u32>(); |
58 | 0 | cursor.advance::<u32>(); |
59 | 0 | let data_maps_count: u32 = cursor.read()?; |
60 | 0 | let data_maps_byte_len = (data_maps_count as usize) |
61 | 0 | .checked_mul(DataMapRecord::RAW_BYTE_LEN) |
62 | 0 | .ok_or(ReadError::OutOfBounds)?; |
63 | 0 | cursor.advance_by(data_maps_byte_len); |
64 | 0 | cursor.finish(MetaMarker { data_maps_byte_len }) |
65 | 0 | } |
66 | | } |
67 | | |
68 | | /// [`meta`](https://docs.microsoft.com/en-us/typography/opentype/spec/meta) |
69 | | pub type Meta<'a> = TableRef<'a, MetaMarker>; |
70 | | |
71 | | #[allow(clippy::needless_lifetimes)] |
72 | | impl<'a> Meta<'a> { |
73 | | /// Version number of the metadata table — set to 1. |
74 | 0 | pub fn version(&self) -> u32 { |
75 | 0 | let range = self.shape.version_byte_range(); |
76 | 0 | self.data.read_at(range.start).unwrap() |
77 | 0 | } |
78 | | |
79 | | /// Flags — currently unused; set to 0. |
80 | 0 | pub fn flags(&self) -> u32 { |
81 | 0 | let range = self.shape.flags_byte_range(); |
82 | 0 | self.data.read_at(range.start).unwrap() |
83 | 0 | } |
84 | | |
85 | | /// The number of data maps in the table. |
86 | 0 | pub fn data_maps_count(&self) -> u32 { |
87 | 0 | let range = self.shape.data_maps_count_byte_range(); |
88 | 0 | self.data.read_at(range.start).unwrap() |
89 | 0 | } |
90 | | |
91 | | /// Array of data map records. |
92 | 0 | pub fn data_maps(&self) -> &'a [DataMapRecord] { |
93 | 0 | let range = self.shape.data_maps_byte_range(); |
94 | 0 | self.data.read_array(range).unwrap() |
95 | 0 | } |
96 | | } |
97 | | |
98 | | #[cfg(feature = "experimental_traverse")] |
99 | | impl<'a> SomeTable<'a> for Meta<'a> { |
100 | | fn type_name(&self) -> &str { |
101 | | "Meta" |
102 | | } |
103 | | fn get_field(&self, idx: usize) -> Option<Field<'a>> { |
104 | | match idx { |
105 | | 0usize => Some(Field::new("version", self.version())), |
106 | | 1usize => Some(Field::new("flags", self.flags())), |
107 | | 2usize => Some(Field::new("data_maps_count", self.data_maps_count())), |
108 | | 3usize => Some(Field::new( |
109 | | "data_maps", |
110 | | traversal::FieldType::array_of_records( |
111 | | stringify!(DataMapRecord), |
112 | | self.data_maps(), |
113 | | self.offset_data(), |
114 | | ), |
115 | | )), |
116 | | _ => None, |
117 | | } |
118 | | } |
119 | | } |
120 | | |
121 | | #[cfg(feature = "experimental_traverse")] |
122 | | #[allow(clippy::needless_lifetimes)] |
123 | | impl<'a> std::fmt::Debug for Meta<'a> { |
124 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
125 | | (self as &dyn SomeTable<'a>).fmt(f) |
126 | | } |
127 | | } |
128 | | |
129 | | /// <https://learn.microsoft.com/en-us/typography/opentype/spec/meta#table-formats> |
130 | | #[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)] |
131 | | #[repr(C)] |
132 | | #[repr(packed)] |
133 | | pub struct DataMapRecord { |
134 | | /// A tag indicating the type of metadata. |
135 | | pub tag: BigEndian<Tag>, |
136 | | /// Offset in bytes from the beginning of the metadata table to the data for this tag. |
137 | | pub data_offset: BigEndian<Offset32>, |
138 | | /// Length of the data, in bytes. The data is not required to be padded to any byte boundary. |
139 | | pub data_length: BigEndian<u32>, |
140 | | } |
141 | | |
142 | | impl DataMapRecord { |
143 | | /// A tag indicating the type of metadata. |
144 | 0 | pub fn tag(&self) -> Tag { |
145 | 0 | self.tag.get() |
146 | 0 | } |
147 | | |
148 | | /// Offset in bytes from the beginning of the metadata table to the data for this tag. |
149 | 0 | pub fn data_offset(&self) -> Offset32 { |
150 | 0 | self.data_offset.get() |
151 | 0 | } |
152 | | |
153 | | /// Offset in bytes from the beginning of the metadata table to the data for this tag. |
154 | | /// |
155 | | /// The `data` argument should be retrieved from the parent table |
156 | | /// By calling its `offset_data` method. |
157 | 0 | pub fn data<'a>(&self, data: FontData<'a>) -> Result<Metadata<'a>, ReadError> { |
158 | 0 | let args = (self.tag(), self.data_length()); |
159 | 0 | self.data_offset().resolve_with_args(data, &args) |
160 | 0 | } |
161 | | |
162 | | /// Length of the data, in bytes. The data is not required to be padded to any byte boundary. |
163 | 0 | pub fn data_length(&self) -> u32 { |
164 | 0 | self.data_length.get() |
165 | 0 | } |
166 | | } |
167 | | |
168 | | impl FixedSize for DataMapRecord { |
169 | | const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN; |
170 | | } |
171 | | |
172 | | #[cfg(feature = "experimental_traverse")] |
173 | | impl<'a> SomeRecord<'a> for DataMapRecord { |
174 | | fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> { |
175 | | RecordResolver { |
176 | | name: "DataMapRecord", |
177 | | get_field: Box::new(move |idx, _data| match idx { |
178 | | 0usize => Some(Field::new("tag", self.tag())), |
179 | | 1usize => Some(Field::new("data_offset", traversal::FieldType::Unknown)), |
180 | | 2usize => Some(Field::new("data_length", self.data_length())), |
181 | | _ => None, |
182 | | }), |
183 | | data, |
184 | | } |
185 | | } |
186 | | } |