read_fonts/generated/
generated_svg.rs1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Svg<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self._reserved_byte_range().end
11 }
12 fn min_table_bytes(&self) -> &'a [u8] {
13 let range = self.min_byte_range();
14 self.data.as_bytes().get(range).unwrap_or_default()
15 }
16}
17
18impl TopLevelTable for Svg<'_> {
19 const TAG: Tag = Tag::new(b"SVG ");
21}
22
23impl<'a> FontRead<'a> for Svg<'a> {
24 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
25 #[allow(clippy::absurd_extreme_comparisons)]
26 if data.len() < Self::MIN_SIZE {
27 return Err(ReadError::OutOfBounds);
28 }
29 Ok(Self { data })
30 }
31}
32
33#[derive(Clone)]
35pub struct Svg<'a> {
36 data: FontData<'a>,
37}
38
39#[allow(clippy::needless_lifetimes)]
40impl<'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 pub fn version(&self) -> u16 {
46 let range = self.version_byte_range();
47 self.data.read_at(range.start).ok().unwrap()
48 }
49
50 pub fn svg_document_list_offset(&self) -> Offset32 {
53 let range = self.svg_document_list_offset_byte_range();
54 self.data.read_at(range.start).ok().unwrap()
55 }
56
57 pub fn svg_document_list(&self) -> Result<SVGDocumentList<'a>, ReadError> {
59 let data = self.data;
60 self.svg_document_list_offset().resolve(data)
61 }
62
63 pub fn version_byte_range(&self) -> Range<usize> {
64 let start = 0;
65 let end = start + u16::RAW_BYTE_LEN;
66 start..end
67 }
68
69 pub fn svg_document_list_offset_byte_range(&self) -> Range<usize> {
70 let start = self.version_byte_range().end;
71 let end = start + Offset32::RAW_BYTE_LEN;
72 start..end
73 }
74
75 pub fn _reserved_byte_range(&self) -> Range<usize> {
76 let start = self.svg_document_list_offset_byte_range().end;
77 let end = start + u16::RAW_BYTE_LEN;
78 start..end
79 }
80}
81
82const _: () = assert!(FontData::default_data_long_enough(Svg::MIN_SIZE));
83
84impl Default for Svg<'_> {
85 fn default() -> Self {
86 Self {
87 data: FontData::default_table_data(),
88 }
89 }
90}
91
92#[cfg(feature = "experimental_traverse")]
93impl<'a> SomeTable<'a> for Svg<'a> {
94 fn type_name(&self) -> &str {
95 "Svg"
96 }
97 fn get_field(&self, idx: usize) -> Option<Field<'a>> {
98 match idx {
99 0usize => Some(Field::new("version", self.version())),
100 1usize => Some(Field::new(
101 "svg_document_list_offset",
102 FieldType::offset(self.svg_document_list_offset(), self.svg_document_list()),
103 )),
104 _ => None,
105 }
106 }
107}
108
109#[cfg(feature = "experimental_traverse")]
110#[allow(clippy::needless_lifetimes)]
111impl<'a> std::fmt::Debug for Svg<'a> {
112 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113 (self as &dyn SomeTable<'a>).fmt(f)
114 }
115}
116
117impl<'a> MinByteRange<'a> for SVGDocumentList<'a> {
118 fn min_byte_range(&self) -> Range<usize> {
119 0..self.document_records_byte_range().end
120 }
121 fn min_table_bytes(&self) -> &'a [u8] {
122 let range = self.min_byte_range();
123 self.data.as_bytes().get(range).unwrap_or_default()
124 }
125}
126
127impl<'a> FontRead<'a> for SVGDocumentList<'a> {
128 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
129 #[allow(clippy::absurd_extreme_comparisons)]
130 if data.len() < Self::MIN_SIZE {
131 return Err(ReadError::OutOfBounds);
132 }
133 Ok(Self { data })
134 }
135}
136
137#[derive(Clone)]
139pub struct SVGDocumentList<'a> {
140 data: FontData<'a>,
141}
142
143#[allow(clippy::needless_lifetimes)]
144impl<'a> SVGDocumentList<'a> {
145 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
146 basic_table_impls!(impl_the_methods);
147
148 pub fn num_entries(&self) -> u16 {
150 let range = self.num_entries_byte_range();
151 self.data.read_at(range.start).ok().unwrap()
152 }
153
154 pub fn document_records(&self) -> &'a [SVGDocumentRecord] {
156 let range = self.document_records_byte_range();
157 self.data.read_array(range).ok().unwrap_or_default()
158 }
159
160 pub fn num_entries_byte_range(&self) -> Range<usize> {
161 let start = 0;
162 let end = start + u16::RAW_BYTE_LEN;
163 start..end
164 }
165
166 pub fn document_records_byte_range(&self) -> Range<usize> {
167 let num_entries = self.num_entries();
168 let start = self.num_entries_byte_range().end;
169 let end = start
170 + (transforms::to_usize(num_entries)).saturating_mul(SVGDocumentRecord::RAW_BYTE_LEN);
171 start..end
172 }
173}
174
175const _: () = assert!(FontData::default_data_long_enough(
176 SVGDocumentList::MIN_SIZE
177));
178
179impl Default for SVGDocumentList<'_> {
180 fn default() -> Self {
181 Self {
182 data: FontData::default_table_data(),
183 }
184 }
185}
186
187#[cfg(feature = "experimental_traverse")]
188impl<'a> SomeTable<'a> for SVGDocumentList<'a> {
189 fn type_name(&self) -> &str {
190 "SVGDocumentList"
191 }
192 fn get_field(&self, idx: usize) -> Option<Field<'a>> {
193 match idx {
194 0usize => Some(Field::new("num_entries", self.num_entries())),
195 1usize => Some(Field::new(
196 "document_records",
197 traversal::FieldType::array_of_records(
198 stringify!(SVGDocumentRecord),
199 self.document_records(),
200 self.offset_data(),
201 ),
202 )),
203 _ => None,
204 }
205 }
206}
207
208#[cfg(feature = "experimental_traverse")]
209#[allow(clippy::needless_lifetimes)]
210impl<'a> std::fmt::Debug for SVGDocumentList<'a> {
211 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
212 (self as &dyn SomeTable<'a>).fmt(f)
213 }
214}
215
216#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
218#[repr(C)]
219#[repr(packed)]
220pub struct SVGDocumentRecord {
221 pub start_glyph_id: BigEndian<GlyphId16>,
223 pub end_glyph_id: BigEndian<GlyphId16>,
225 pub svg_doc_offset: BigEndian<u32>,
228 pub svg_doc_length: BigEndian<u32>,
230}
231
232impl SVGDocumentRecord {
233 pub fn start_glyph_id(&self) -> GlyphId16 {
235 self.start_glyph_id.get()
236 }
237
238 pub fn end_glyph_id(&self) -> GlyphId16 {
240 self.end_glyph_id.get()
241 }
242
243 pub fn svg_doc_offset(&self) -> u32 {
246 self.svg_doc_offset.get()
247 }
248
249 pub fn svg_doc_length(&self) -> u32 {
251 self.svg_doc_length.get()
252 }
253}
254
255impl FixedSize for SVGDocumentRecord {
256 const RAW_BYTE_LEN: usize =
257 GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN;
258}
259
260#[cfg(feature = "experimental_traverse")]
261impl<'a> SomeRecord<'a> for SVGDocumentRecord {
262 fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
263 RecordResolver {
264 name: "SVGDocumentRecord",
265 get_field: Box::new(move |idx, _data| match idx {
266 0usize => Some(Field::new("start_glyph_id", self.start_glyph_id())),
267 1usize => Some(Field::new("end_glyph_id", self.end_glyph_id())),
268 2usize => Some(Field::new("svg_doc_offset", self.svg_doc_offset())),
269 3usize => Some(Field::new("svg_doc_length", self.svg_doc_length())),
270 _ => None,
271 }),
272 data,
273 }
274 }
275}