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