/src/fontations/read-fonts/generated/generated_svg.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 Svg<'a> { |
9 | 0 | fn min_byte_range(&self) -> Range<usize> { |
10 | 0 | 0..self._reserved_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.data.as_bytes().get(range).unwrap_or_default() |
15 | 0 | } |
16 | | } |
17 | | |
18 | | impl TopLevelTable for Svg<'_> { |
19 | | /// `SVG ` |
20 | | const TAG: Tag = Tag::new(b"SVG "); |
21 | | } |
22 | | |
23 | | impl<'a> FontRead<'a> for Svg<'a> { |
24 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
25 | | #[allow(clippy::absurd_extreme_comparisons)] |
26 | 0 | if data.len() < Self::MIN_SIZE { |
27 | 0 | return Err(ReadError::OutOfBounds); |
28 | 0 | } |
29 | 0 | Ok(Self { data }) |
30 | 0 | } |
31 | | } |
32 | | |
33 | | /// The [SVG](https://learn.microsoft.com/en-us/typography/opentype/spec/svg) table |
34 | | #[derive(Clone)] |
35 | | pub struct Svg<'a> { |
36 | | data: FontData<'a>, |
37 | | } |
38 | | |
39 | | #[allow(clippy::needless_lifetimes)] |
40 | | impl<'a> Svg<'a> { |
41 | | pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + u16::RAW_BYTE_LEN); |
42 | | basic_table_impls!(impl_the_methods); |
43 | | |
44 | | /// Table version (starting at 0). Set to 0. |
45 | 0 | pub fn version(&self) -> u16 { |
46 | 0 | let range = self.version_byte_range(); |
47 | 0 | self.data.read_at(range.start).ok().unwrap() |
48 | 0 | } |
49 | | |
50 | | /// Offset to the SVGDocumentList, from the start of the SVG table. |
51 | | /// Must be non-zero. |
52 | 0 | pub fn svg_document_list_offset(&self) -> Offset32 { |
53 | 0 | let range = self.svg_document_list_offset_byte_range(); |
54 | 0 | self.data.read_at(range.start).ok().unwrap() |
55 | 0 | } |
56 | | |
57 | | /// Attempt to resolve [`svg_document_list_offset`][Self::svg_document_list_offset]. |
58 | 0 | pub fn svg_document_list(&self) -> Result<SVGDocumentList<'a>, ReadError> { |
59 | 0 | let data = self.data; |
60 | 0 | self.svg_document_list_offset().resolve(data) |
61 | 0 | } |
62 | | |
63 | 0 | pub fn version_byte_range(&self) -> Range<usize> { |
64 | 0 | let start = 0; |
65 | 0 | start..start + u16::RAW_BYTE_LEN |
66 | 0 | } |
67 | | |
68 | 0 | pub fn svg_document_list_offset_byte_range(&self) -> Range<usize> { |
69 | 0 | let start = self.version_byte_range().end; |
70 | 0 | start..start + Offset32::RAW_BYTE_LEN |
71 | 0 | } |
72 | | |
73 | 0 | pub fn _reserved_byte_range(&self) -> Range<usize> { |
74 | 0 | let start = self.svg_document_list_offset_byte_range().end; |
75 | 0 | start..start + u16::RAW_BYTE_LEN |
76 | 0 | } |
77 | | } |
78 | | |
79 | | #[cfg(feature = "experimental_traverse")] |
80 | | impl<'a> SomeTable<'a> for Svg<'a> { |
81 | | fn type_name(&self) -> &str { |
82 | | "Svg" |
83 | | } |
84 | | fn get_field(&self, idx: usize) -> Option<Field<'a>> { |
85 | | match idx { |
86 | | 0usize => Some(Field::new("version", self.version())), |
87 | | 1usize => Some(Field::new( |
88 | | "svg_document_list_offset", |
89 | | FieldType::offset(self.svg_document_list_offset(), self.svg_document_list()), |
90 | | )), |
91 | | _ => None, |
92 | | } |
93 | | } |
94 | | } |
95 | | |
96 | | #[cfg(feature = "experimental_traverse")] |
97 | | #[allow(clippy::needless_lifetimes)] |
98 | | impl<'a> std::fmt::Debug for Svg<'a> { |
99 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
100 | | (self as &dyn SomeTable<'a>).fmt(f) |
101 | | } |
102 | | } |
103 | | |
104 | | impl<'a> MinByteRange<'a> for SVGDocumentList<'a> { |
105 | 0 | fn min_byte_range(&self) -> Range<usize> { |
106 | 0 | 0..self.document_records_byte_range().end |
107 | 0 | } |
108 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
109 | 0 | let range = self.min_byte_range(); |
110 | 0 | self.data.as_bytes().get(range).unwrap_or_default() |
111 | 0 | } |
112 | | } |
113 | | |
114 | | impl<'a> FontRead<'a> for SVGDocumentList<'a> { |
115 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
116 | | #[allow(clippy::absurd_extreme_comparisons)] |
117 | 0 | if data.len() < Self::MIN_SIZE { |
118 | 0 | return Err(ReadError::OutOfBounds); |
119 | 0 | } |
120 | 0 | Ok(Self { data }) |
121 | 0 | } |
122 | | } |
123 | | |
124 | | /// [SVGDocumentList](https://learn.microsoft.com/en-us/typography/opentype/spec/svg) |
125 | | #[derive(Clone)] |
126 | | pub struct SVGDocumentList<'a> { |
127 | | data: FontData<'a>, |
128 | | } |
129 | | |
130 | | #[allow(clippy::needless_lifetimes)] |
131 | | impl<'a> SVGDocumentList<'a> { |
132 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
133 | | basic_table_impls!(impl_the_methods); |
134 | | |
135 | | /// Number of SVGDocumentRecords. Must be non-zero. |
136 | 0 | pub fn num_entries(&self) -> u16 { |
137 | 0 | let range = self.num_entries_byte_range(); |
138 | 0 | self.data.read_at(range.start).ok().unwrap() |
139 | 0 | } |
140 | | |
141 | | /// Array of SVGDocumentRecords. |
142 | 0 | pub fn document_records(&self) -> &'a [SVGDocumentRecord] { |
143 | 0 | let range = self.document_records_byte_range(); |
144 | 0 | self.data.read_array(range).ok().unwrap_or_default() |
145 | 0 | } |
146 | | |
147 | 0 | pub fn num_entries_byte_range(&self) -> Range<usize> { |
148 | 0 | let start = 0; |
149 | 0 | start..start + u16::RAW_BYTE_LEN |
150 | 0 | } |
151 | | |
152 | 0 | pub fn document_records_byte_range(&self) -> Range<usize> { |
153 | 0 | let num_entries = self.num_entries(); |
154 | 0 | let start = self.num_entries_byte_range().end; |
155 | 0 | start..start + (num_entries as usize).saturating_mul(SVGDocumentRecord::RAW_BYTE_LEN) |
156 | 0 | } |
157 | | } |
158 | | |
159 | | #[cfg(feature = "experimental_traverse")] |
160 | | impl<'a> SomeTable<'a> for SVGDocumentList<'a> { |
161 | | fn type_name(&self) -> &str { |
162 | | "SVGDocumentList" |
163 | | } |
164 | | fn get_field(&self, idx: usize) -> Option<Field<'a>> { |
165 | | match idx { |
166 | | 0usize => Some(Field::new("num_entries", self.num_entries())), |
167 | | 1usize => Some(Field::new( |
168 | | "document_records", |
169 | | traversal::FieldType::array_of_records( |
170 | | stringify!(SVGDocumentRecord), |
171 | | self.document_records(), |
172 | | self.offset_data(), |
173 | | ), |
174 | | )), |
175 | | _ => None, |
176 | | } |
177 | | } |
178 | | } |
179 | | |
180 | | #[cfg(feature = "experimental_traverse")] |
181 | | #[allow(clippy::needless_lifetimes)] |
182 | | impl<'a> std::fmt::Debug for SVGDocumentList<'a> { |
183 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
184 | | (self as &dyn SomeTable<'a>).fmt(f) |
185 | | } |
186 | | } |
187 | | |
188 | | /// [SVGDocumentRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/svg) |
189 | | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)] |
190 | | #[repr(C)] |
191 | | #[repr(packed)] |
192 | | pub struct SVGDocumentRecord { |
193 | | /// The first glyph ID for the range covered by this record. |
194 | | pub start_glyph_id: BigEndian<GlyphId16>, |
195 | | /// The last glyph ID for the range covered by this record. |
196 | | pub end_glyph_id: BigEndian<GlyphId16>, |
197 | | /// Offset from the beginning of the SVGDocumentList to an SVG |
198 | | /// document. Must be non-zero. |
199 | | pub svg_doc_offset: BigEndian<u32>, |
200 | | /// Length of the SVG document data. Must be non-zero. |
201 | | pub svg_doc_length: BigEndian<u32>, |
202 | | } |
203 | | |
204 | | impl SVGDocumentRecord { |
205 | | /// The first glyph ID for the range covered by this record. |
206 | 0 | pub fn start_glyph_id(&self) -> GlyphId16 { |
207 | 0 | self.start_glyph_id.get() |
208 | 0 | } |
209 | | |
210 | | /// The last glyph ID for the range covered by this record. |
211 | 0 | pub fn end_glyph_id(&self) -> GlyphId16 { |
212 | 0 | self.end_glyph_id.get() |
213 | 0 | } |
214 | | |
215 | | /// Offset from the beginning of the SVGDocumentList to an SVG |
216 | | /// document. Must be non-zero. |
217 | 0 | pub fn svg_doc_offset(&self) -> u32 { |
218 | 0 | self.svg_doc_offset.get() |
219 | 0 | } |
220 | | |
221 | | /// Length of the SVG document data. Must be non-zero. |
222 | 0 | pub fn svg_doc_length(&self) -> u32 { |
223 | 0 | self.svg_doc_length.get() |
224 | 0 | } |
225 | | } |
226 | | |
227 | | impl FixedSize for SVGDocumentRecord { |
228 | | const RAW_BYTE_LEN: usize = |
229 | | GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN; |
230 | | } |
231 | | |
232 | | #[cfg(feature = "experimental_traverse")] |
233 | | impl<'a> SomeRecord<'a> for SVGDocumentRecord { |
234 | | fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> { |
235 | | RecordResolver { |
236 | | name: "SVGDocumentRecord", |
237 | | get_field: Box::new(move |idx, _data| match idx { |
238 | | 0usize => Some(Field::new("start_glyph_id", self.start_glyph_id())), |
239 | | 1usize => Some(Field::new("end_glyph_id", self.end_glyph_id())), |
240 | | 2usize => Some(Field::new("svg_doc_offset", self.svg_doc_offset())), |
241 | | 3usize => Some(Field::new("svg_doc_length", self.svg_doc_length())), |
242 | | _ => None, |
243 | | }), |
244 | | data, |
245 | | } |
246 | | } |
247 | | } |