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
96impl<'a> MinByteRange<'a> for SVGDocumentList<'a> {
97 fn min_byte_range(&self) -> Range<usize> {
98 0..self.document_records_byte_range().end
99 }
100 fn min_table_bytes(&self) -> &'a [u8] {
101 let range = self.min_byte_range();
102 self.data.as_bytes().get(range).unwrap_or_default()
103 }
104}
105
106impl ReadArgs for SVGDocumentList<'_> {
107 type Args = ();
108}
109
110impl<'a> FontRead<'a> for SVGDocumentList<'a> {
111 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
112 #[allow(clippy::absurd_extreme_comparisons)]
113 if data.len() < Self::MIN_SIZE {
114 return Err(ReadError::OutOfBounds);
115 }
116 Ok(Self { data })
117 }
118}
119
120#[derive(Clone)]
122pub struct SVGDocumentList<'a> {
123 data: FontData<'a>,
124}
125
126#[allow(clippy::needless_lifetimes)]
127impl<'a> SVGDocumentList<'a> {
128 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
129 basic_table_impls!(impl_the_methods);
130
131 pub fn num_entries(&self) -> u16 {
133 let range = self.num_entries_byte_range();
134 self.data.read_at(range.start).ok().unwrap()
135 }
136
137 pub fn document_records(&self) -> &'a [SVGDocumentRecord] {
139 let range = self.document_records_byte_range();
140 self.data.read_array(range).ok().unwrap_or_default()
141 }
142
143 pub fn num_entries_byte_range(&self) -> Range<usize> {
144 let start = 0;
145 let end = start + u16::RAW_BYTE_LEN;
146 start..end
147 }
148
149 pub fn document_records_byte_range(&self) -> Range<usize> {
150 let num_entries = self.num_entries();
151 let start = self.num_entries_byte_range().end;
152 let end = start
153 + (transforms::to_usize(num_entries)).saturating_mul(SVGDocumentRecord::RAW_BYTE_LEN);
154 start..end
155 }
156}
157
158const _: () = assert!(FontData::default_data_long_enough(
159 SVGDocumentList::MIN_SIZE
160));
161
162impl Default for SVGDocumentList<'_> {
163 fn default() -> Self {
164 Self {
165 data: FontData::default_table_data(),
166 }
167 }
168}
169
170#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
172#[repr(C)]
173#[repr(packed)]
174pub struct SVGDocumentRecord {
175 pub start_glyph_id: BigEndian<GlyphId16>,
177 pub end_glyph_id: BigEndian<GlyphId16>,
179 pub svg_doc_offset: BigEndian<u32>,
182 pub svg_doc_length: BigEndian<u32>,
184}
185
186impl SVGDocumentRecord {
187 pub fn start_glyph_id(&self) -> GlyphId16 {
189 self.start_glyph_id.get()
190 }
191
192 pub fn end_glyph_id(&self) -> GlyphId16 {
194 self.end_glyph_id.get()
195 }
196
197 pub fn svg_doc_offset(&self) -> u32 {
200 self.svg_doc_offset.get()
201 }
202
203 pub fn svg_doc_length(&self) -> u32 {
205 self.svg_doc_length.get()
206 }
207}
208
209impl FixedSize for SVGDocumentRecord {
210 const RAW_BYTE_LEN: usize =
211 GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN;
212}