/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.46.0/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.offset_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 ReadArgs for Svg<'_> { |
24 | | type Args = (); |
25 | | } |
26 | | |
27 | | impl<'a> FontRead<'a> for Svg<'a> { |
28 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
29 | | #[allow(clippy::absurd_extreme_comparisons)] |
30 | 0 | if data.len() < Self::MIN_SIZE { |
31 | 0 | return Err(ReadError::OutOfBounds); |
32 | 0 | } |
33 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
34 | 0 | return Err(ReadError::OutOfBounds); |
35 | | }; |
36 | 0 | Ok(Self { data }) |
37 | 0 | } |
38 | | } |
39 | | |
40 | | /// The fields at the start of the table, which are read directly. |
41 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
42 | | #[repr(C, packed)] |
43 | | #[doc(hidden)] |
44 | | pub 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)] |
51 | | const _: () = assert!(std::mem::size_of::<SvgFixedHeader>() <= Svg::MIN_SIZE); |
52 | | |
53 | | /// The [SVG](https://learn.microsoft.com/en-us/typography/opentype/spec/svg) table |
54 | | #[derive(Clone)] |
55 | | pub struct Svg<'a> { |
56 | | data: TableDataRef<'a, SvgFixedHeader>, |
57 | | } |
58 | | |
59 | | #[allow(clippy::needless_lifetimes)] |
60 | | impl<'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 | | /// Table version (starting at 0). Set to 0. |
65 | 0 | pub fn version(&self) -> u16 { |
66 | 0 | self.data.header().version.get() |
67 | 0 | } |
68 | | |
69 | | /// Offset to the SVGDocumentList, from the start of the SVG table. |
70 | | /// Must be non-zero. |
71 | 0 | pub fn svg_document_list_offset(&self) -> Offset32 { |
72 | 0 | self.data.header().svg_document_list_offset.get() |
73 | 0 | } |
74 | | |
75 | | /// Attempt to resolve [`svg_document_list_offset`][Self::svg_document_list_offset]. |
76 | 0 | pub fn svg_document_list(&self) -> Result<SVGDocumentList<'a>, ReadError> { |
77 | 0 | let data = self.offset_data(); |
78 | 0 | self.svg_document_list_offset().resolve(data) |
79 | 0 | } |
80 | | |
81 | 0 | pub fn version_byte_range(&self) -> Range<usize> { |
82 | 0 | let start = 0; |
83 | 0 | let end = start + u16::RAW_BYTE_LEN; |
84 | 0 | start..end |
85 | 0 | } |
86 | | |
87 | 0 | pub fn svg_document_list_offset_byte_range(&self) -> Range<usize> { |
88 | 0 | let start = self.version_byte_range().end; |
89 | 0 | let end = start + Offset32::RAW_BYTE_LEN; |
90 | 0 | start..end |
91 | 0 | } |
92 | | |
93 | 0 | pub fn _reserved_byte_range(&self) -> Range<usize> { |
94 | 0 | let start = self.svg_document_list_offset_byte_range().end; |
95 | 0 | let end = start + u16::RAW_BYTE_LEN; |
96 | 0 | start..end |
97 | 0 | } |
98 | | } |
99 | | |
100 | | const _: () = assert!(FontData::default_data_long_enough(Svg::MIN_SIZE)); |
101 | | |
102 | | impl Default for Svg<'_> { |
103 | 0 | fn default() -> Self { |
104 | | Self { |
105 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
106 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
107 | | } |
108 | 0 | } |
109 | | } |
110 | | |
111 | | impl<'a> MinByteRange<'a> for SVGDocumentList<'a> { |
112 | 0 | fn min_byte_range(&self) -> Range<usize> { |
113 | 0 | 0..self.document_records_byte_range().end |
114 | 0 | } |
115 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
116 | 0 | let range = self.min_byte_range(); |
117 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
118 | 0 | } |
119 | | } |
120 | | |
121 | | impl ReadArgs for SVGDocumentList<'_> { |
122 | | type Args = (); |
123 | | } |
124 | | |
125 | | impl<'a> FontRead<'a> for SVGDocumentList<'a> { |
126 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
127 | | #[allow(clippy::absurd_extreme_comparisons)] |
128 | 0 | if data.len() < Self::MIN_SIZE { |
129 | 0 | return Err(ReadError::OutOfBounds); |
130 | 0 | } |
131 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
132 | 0 | return Err(ReadError::OutOfBounds); |
133 | | }; |
134 | 0 | Ok(Self { data }) |
135 | 0 | } |
136 | | } |
137 | | |
138 | | /// The fields at the start of the table, which are read directly. |
139 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
140 | | #[repr(C, packed)] |
141 | | #[doc(hidden)] |
142 | | pub struct SVGDocumentListFixedHeader { |
143 | | pub num_entries: BigEndian<u16>, |
144 | | } |
145 | | |
146 | | #[allow(clippy::absurd_extreme_comparisons)] |
147 | | const _: () = |
148 | | assert!(std::mem::size_of::<SVGDocumentListFixedHeader>() <= SVGDocumentList::MIN_SIZE); |
149 | | |
150 | | /// [SVGDocumentList](https://learn.microsoft.com/en-us/typography/opentype/spec/svg) |
151 | | #[derive(Clone)] |
152 | | pub struct SVGDocumentList<'a> { |
153 | | data: TableDataRef<'a, SVGDocumentListFixedHeader>, |
154 | | } |
155 | | |
156 | | #[allow(clippy::needless_lifetimes)] |
157 | | impl<'a> SVGDocumentList<'a> { |
158 | | pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN; |
159 | | basic_table_impls!(impl_the_methods); |
160 | | |
161 | | /// Number of SVGDocumentRecords. Must be non-zero. |
162 | 0 | pub fn num_entries(&self) -> u16 { |
163 | 0 | self.data.header().num_entries.get() |
164 | 0 | } |
165 | | |
166 | | /// Array of SVGDocumentRecords. |
167 | 0 | pub fn document_records(&self) -> &'a [SVGDocumentRecord] { |
168 | 0 | let range = self.document_records_byte_range(); |
169 | 0 | self.offset_data() |
170 | 0 | .read_array(range) |
171 | 0 | .ok() |
172 | 0 | .unwrap_or_default() |
173 | 0 | } |
174 | | |
175 | 0 | pub fn num_entries_byte_range(&self) -> Range<usize> { |
176 | 0 | let start = 0; |
177 | 0 | let end = start + u16::RAW_BYTE_LEN; |
178 | 0 | start..end |
179 | 0 | } |
180 | | |
181 | 0 | pub fn document_records_byte_range(&self) -> Range<usize> { |
182 | 0 | let num_entries = self.num_entries(); |
183 | 0 | let start = self.num_entries_byte_range().end; |
184 | 0 | let end = start |
185 | 0 | + (transforms::to_usize(num_entries)).saturating_mul(SVGDocumentRecord::RAW_BYTE_LEN); |
186 | 0 | start..end |
187 | 0 | } |
188 | | } |
189 | | |
190 | | const _: () = assert!(FontData::default_data_long_enough( |
191 | | SVGDocumentList::MIN_SIZE |
192 | | )); |
193 | | |
194 | | impl Default for SVGDocumentList<'_> { |
195 | 0 | fn default() -> Self { |
196 | | Self { |
197 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
198 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
199 | | } |
200 | 0 | } |
201 | | } |
202 | | |
203 | | /// [SVGDocumentRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/svg) |
204 | | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)] |
205 | | #[repr(C)] |
206 | | #[repr(packed)] |
207 | | pub struct SVGDocumentRecord { |
208 | | /// The first glyph ID for the range covered by this record. |
209 | | pub start_glyph_id: BigEndian<GlyphId16>, |
210 | | /// The last glyph ID for the range covered by this record. |
211 | | pub end_glyph_id: BigEndian<GlyphId16>, |
212 | | /// Offset from the beginning of the SVGDocumentList to an SVG |
213 | | /// document. Must be non-zero. |
214 | | pub svg_doc_offset: BigEndian<u32>, |
215 | | /// Length of the SVG document data. Must be non-zero. |
216 | | pub svg_doc_length: BigEndian<u32>, |
217 | | } |
218 | | |
219 | | impl SVGDocumentRecord { |
220 | | /// The first glyph ID for the range covered by this record. |
221 | 0 | pub fn start_glyph_id(&self) -> GlyphId16 { |
222 | 0 | self.start_glyph_id.get() |
223 | 0 | } |
224 | | |
225 | | /// The last glyph ID for the range covered by this record. |
226 | 0 | pub fn end_glyph_id(&self) -> GlyphId16 { |
227 | 0 | self.end_glyph_id.get() |
228 | 0 | } |
229 | | |
230 | | /// Offset from the beginning of the SVGDocumentList to an SVG |
231 | | /// document. Must be non-zero. |
232 | 0 | pub fn svg_doc_offset(&self) -> u32 { |
233 | 0 | self.svg_doc_offset.get() |
234 | 0 | } |
235 | | |
236 | | /// Length of the SVG document data. Must be non-zero. |
237 | 0 | pub fn svg_doc_length(&self) -> u32 { |
238 | 0 | self.svg_doc_length.get() |
239 | 0 | } |
240 | | } |
241 | | |
242 | | impl 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 | | } |