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.offset_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 let Some(data) = TableDataRef::new(data.as_bytes()) else {
34 return Err(ReadError::OutOfBounds);
35 };
36 Ok(Self { data })
37 }
38}
39
40#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42#[repr(C, packed)]
43#[doc(hidden)]
44pub struct SvgFixedHeader {
45 pub version: BigEndian<u16>,
46 pub svg_document_list_offset: BigEndian<Offset32>,
47 pub _reserved: BigEndian<u16>,
48}
49
50#[allow(clippy::absurd_extreme_comparisons)]
51const _: () = assert!(std::mem::size_of::<SvgFixedHeader>() <= Svg::MIN_SIZE);
52
53#[derive(Clone)]
55pub struct Svg<'a> {
56 data: TableDataRef<'a, SvgFixedHeader>,
57}
58
59#[allow(clippy::needless_lifetimes)]
60impl<'a> Svg<'a> {
61 pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
62 basic_table_impls!(impl_the_methods);
63
64 pub fn version(&self) -> u16 {
66 self.data.header().version.get()
67 }
68
69 pub fn svg_document_list_offset(&self) -> Offset32 {
72 self.data.header().svg_document_list_offset.get()
73 }
74
75 pub fn svg_document_list(&self) -> Result<SVGDocumentList<'a>, ReadError> {
77 let data = self.offset_data();
78 self.svg_document_list_offset().resolve(data)
79 }
80
81 pub fn version_byte_range(&self) -> Range<usize> {
82 let start = 0;
83 let end = start + u16::RAW_BYTE_LEN;
84 start..end
85 }
86
87 pub fn svg_document_list_offset_byte_range(&self) -> Range<usize> {
88 let start = self.version_byte_range().end;
89 let end = start + Offset32::RAW_BYTE_LEN;
90 start..end
91 }
92
93 pub fn _reserved_byte_range(&self) -> Range<usize> {
94 let start = self.svg_document_list_offset_byte_range().end;
95 let end = start + u16::RAW_BYTE_LEN;
96 start..end
97 }
98}
99
100const _: () = assert!(FontData::default_data_long_enough(Svg::MIN_SIZE));
101
102impl Default for Svg<'_> {
103 fn default() -> Self {
104 Self {
105 data: TableDataRef::new(FontData::default_table_data().as_bytes())
106 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
107 }
108 }
109}
110
111impl<'a> MinByteRange<'a> for SVGDocumentList<'a> {
112 fn min_byte_range(&self) -> Range<usize> {
113 0..self.document_records_byte_range().end
114 }
115 fn min_table_bytes(&self) -> &'a [u8] {
116 let range = self.min_byte_range();
117 self.offset_data().as_bytes().get(range).unwrap_or_default()
118 }
119}
120
121impl ReadArgs for SVGDocumentList<'_> {
122 type Args = ();
123}
124
125impl<'a> FontRead<'a> for SVGDocumentList<'a> {
126 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
127 #[allow(clippy::absurd_extreme_comparisons)]
128 if data.len() < Self::MIN_SIZE {
129 return Err(ReadError::OutOfBounds);
130 }
131 let Some(data) = TableDataRef::new(data.as_bytes()) else {
132 return Err(ReadError::OutOfBounds);
133 };
134 Ok(Self { data })
135 }
136}
137
138#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
140#[repr(C, packed)]
141#[doc(hidden)]
142pub struct SVGDocumentListFixedHeader {
143 pub num_entries: BigEndian<u16>,
144}
145
146#[allow(clippy::absurd_extreme_comparisons)]
147const _: () =
148 assert!(std::mem::size_of::<SVGDocumentListFixedHeader>() <= SVGDocumentList::MIN_SIZE);
149
150#[derive(Clone)]
152pub struct SVGDocumentList<'a> {
153 data: TableDataRef<'a, SVGDocumentListFixedHeader>,
154}
155
156#[allow(clippy::needless_lifetimes)]
157impl<'a> SVGDocumentList<'a> {
158 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
159 basic_table_impls!(impl_the_methods);
160
161 pub fn num_entries(&self) -> u16 {
163 self.data.header().num_entries.get()
164 }
165
166 pub fn document_records(&self) -> &'a [SVGDocumentRecord] {
168 let range = self.document_records_byte_range();
169 self.offset_data()
170 .read_array(range)
171 .ok()
172 .unwrap_or_default()
173 }
174
175 pub fn num_entries_byte_range(&self) -> Range<usize> {
176 let start = 0;
177 let end = start + u16::RAW_BYTE_LEN;
178 start..end
179 }
180
181 pub fn document_records_byte_range(&self) -> Range<usize> {
182 let num_entries = self.num_entries();
183 let start = self.num_entries_byte_range().end;
184 let end = start
185 + (transforms::to_usize(num_entries)).saturating_mul(SVGDocumentRecord::RAW_BYTE_LEN);
186 start..end
187 }
188}
189
190const _: () = assert!(FontData::default_data_long_enough(
191 SVGDocumentList::MIN_SIZE
192));
193
194impl Default for SVGDocumentList<'_> {
195 fn default() -> Self {
196 Self {
197 data: TableDataRef::new(FontData::default_table_data().as_bytes())
198 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
199 }
200 }
201}
202
203#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
205#[repr(C)]
206#[repr(packed)]
207pub struct SVGDocumentRecord {
208 pub start_glyph_id: BigEndian<GlyphId16>,
210 pub end_glyph_id: BigEndian<GlyphId16>,
212 pub svg_doc_offset: BigEndian<u32>,
215 pub svg_doc_length: BigEndian<u32>,
217}
218
219impl SVGDocumentRecord {
220 pub fn start_glyph_id(&self) -> GlyphId16 {
222 self.start_glyph_id.get()
223 }
224
225 pub fn end_glyph_id(&self) -> GlyphId16 {
227 self.end_glyph_id.get()
228 }
229
230 pub fn svg_doc_offset(&self) -> u32 {
233 self.svg_doc_offset.get()
234 }
235
236 pub fn svg_doc_length(&self) -> u32 {
238 self.svg_doc_length.get()
239 }
240}
241
242impl FixedSize for SVGDocumentRecord {
243 const RAW_BYTE_LEN: usize =
244 GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN;
245}