Coverage Report

Created: 2025-09-27 07:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fontations/read-fonts/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
/// The [SVG](https://learn.microsoft.com/en-us/typography/opentype/spec/svg) table
9
#[derive(Debug, Clone, Copy)]
10
#[doc(hidden)]
11
pub struct SvgMarker {}
12
13
impl SvgMarker {
14
0
    pub fn version_byte_range(&self) -> Range<usize> {
15
0
        let start = 0;
16
0
        start..start + u16::RAW_BYTE_LEN
17
0
    }
18
19
0
    pub fn svg_document_list_offset_byte_range(&self) -> Range<usize> {
20
0
        let start = self.version_byte_range().end;
21
0
        start..start + Offset32::RAW_BYTE_LEN
22
0
    }
23
24
0
    pub fn _reserved_byte_range(&self) -> Range<usize> {
25
0
        let start = self.svg_document_list_offset_byte_range().end;
26
0
        start..start + u16::RAW_BYTE_LEN
27
0
    }
28
}
29
30
impl MinByteRange for SvgMarker {
31
0
    fn min_byte_range(&self) -> Range<usize> {
32
0
        0..self._reserved_byte_range().end
33
0
    }
34
}
35
36
impl TopLevelTable for Svg<'_> {
37
    /// `SVG `
38
    const TAG: Tag = Tag::new(b"SVG ");
39
}
40
41
impl<'a> FontRead<'a> for Svg<'a> {
42
0
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
43
0
        let mut cursor = data.cursor();
44
0
        cursor.advance::<u16>();
45
0
        cursor.advance::<Offset32>();
46
0
        cursor.advance::<u16>();
47
0
        cursor.finish(SvgMarker {})
48
0
    }
49
}
50
51
/// The [SVG](https://learn.microsoft.com/en-us/typography/opentype/spec/svg) table
52
pub type Svg<'a> = TableRef<'a, SvgMarker>;
53
54
#[allow(clippy::needless_lifetimes)]
55
impl<'a> Svg<'a> {
56
    /// Table version (starting at 0). Set to 0.
57
0
    pub fn version(&self) -> u16 {
58
0
        let range = self.shape.version_byte_range();
59
0
        self.data.read_at(range.start).unwrap()
60
0
    }
61
62
    /// Offset to the SVGDocumentList, from the start of the SVG table.
63
    /// Must be non-zero.
64
0
    pub fn svg_document_list_offset(&self) -> Offset32 {
65
0
        let range = self.shape.svg_document_list_offset_byte_range();
66
0
        self.data.read_at(range.start).unwrap()
67
0
    }
68
69
    /// Attempt to resolve [`svg_document_list_offset`][Self::svg_document_list_offset].
70
0
    pub fn svg_document_list(&self) -> Result<SVGDocumentList<'a>, ReadError> {
71
0
        let data = self.data;
72
0
        self.svg_document_list_offset().resolve(data)
73
0
    }
74
}
75
76
#[cfg(feature = "experimental_traverse")]
77
impl<'a> SomeTable<'a> for Svg<'a> {
78
    fn type_name(&self) -> &str {
79
        "Svg"
80
    }
81
    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
82
        match idx {
83
            0usize => Some(Field::new("version", self.version())),
84
            1usize => Some(Field::new(
85
                "svg_document_list_offset",
86
                FieldType::offset(self.svg_document_list_offset(), self.svg_document_list()),
87
            )),
88
            _ => None,
89
        }
90
    }
91
}
92
93
#[cfg(feature = "experimental_traverse")]
94
#[allow(clippy::needless_lifetimes)]
95
impl<'a> std::fmt::Debug for Svg<'a> {
96
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97
        (self as &dyn SomeTable<'a>).fmt(f)
98
    }
99
}
100
101
/// [SVGDocumentList](https://learn.microsoft.com/en-us/typography/opentype/spec/svg)
102
#[derive(Debug, Clone, Copy)]
103
#[doc(hidden)]
104
pub struct SVGDocumentListMarker {
105
    document_records_byte_len: usize,
106
}
107
108
impl SVGDocumentListMarker {
109
0
    pub fn num_entries_byte_range(&self) -> Range<usize> {
110
0
        let start = 0;
111
0
        start..start + u16::RAW_BYTE_LEN
112
0
    }
113
114
0
    pub fn document_records_byte_range(&self) -> Range<usize> {
115
0
        let start = self.num_entries_byte_range().end;
116
0
        start..start + self.document_records_byte_len
117
0
    }
118
}
119
120
impl MinByteRange for SVGDocumentListMarker {
121
0
    fn min_byte_range(&self) -> Range<usize> {
122
0
        0..self.document_records_byte_range().end
123
0
    }
124
}
125
126
impl<'a> FontRead<'a> for SVGDocumentList<'a> {
127
0
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
128
0
        let mut cursor = data.cursor();
129
0
        let num_entries: u16 = cursor.read()?;
130
0
        let document_records_byte_len = (num_entries as usize)
131
0
            .checked_mul(SVGDocumentRecord::RAW_BYTE_LEN)
132
0
            .ok_or(ReadError::OutOfBounds)?;
133
0
        cursor.advance_by(document_records_byte_len);
134
0
        cursor.finish(SVGDocumentListMarker {
135
0
            document_records_byte_len,
136
0
        })
137
0
    }
138
}
139
140
/// [SVGDocumentList](https://learn.microsoft.com/en-us/typography/opentype/spec/svg)
141
pub type SVGDocumentList<'a> = TableRef<'a, SVGDocumentListMarker>;
142
143
#[allow(clippy::needless_lifetimes)]
144
impl<'a> SVGDocumentList<'a> {
145
    /// Number of SVGDocumentRecords. Must be non-zero.
146
0
    pub fn num_entries(&self) -> u16 {
147
0
        let range = self.shape.num_entries_byte_range();
148
0
        self.data.read_at(range.start).unwrap()
149
0
    }
150
151
    /// Array of SVGDocumentRecords.
152
0
    pub fn document_records(&self) -> &'a [SVGDocumentRecord] {
153
0
        let range = self.shape.document_records_byte_range();
154
0
        self.data.read_array(range).unwrap()
155
0
    }
156
}
157
158
#[cfg(feature = "experimental_traverse")]
159
impl<'a> SomeTable<'a> for SVGDocumentList<'a> {
160
    fn type_name(&self) -> &str {
161
        "SVGDocumentList"
162
    }
163
    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
164
        match idx {
165
            0usize => Some(Field::new("num_entries", self.num_entries())),
166
            1usize => Some(Field::new(
167
                "document_records",
168
                traversal::FieldType::array_of_records(
169
                    stringify!(SVGDocumentRecord),
170
                    self.document_records(),
171
                    self.offset_data(),
172
                ),
173
            )),
174
            _ => None,
175
        }
176
    }
177
}
178
179
#[cfg(feature = "experimental_traverse")]
180
#[allow(clippy::needless_lifetimes)]
181
impl<'a> std::fmt::Debug for SVGDocumentList<'a> {
182
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
183
        (self as &dyn SomeTable<'a>).fmt(f)
184
    }
185
}
186
187
/// [SVGDocumentRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/svg)
188
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
189
#[repr(C)]
190
#[repr(packed)]
191
pub struct SVGDocumentRecord {
192
    /// The first glyph ID for the range covered by this record.
193
    pub start_glyph_id: BigEndian<GlyphId16>,
194
    /// The last glyph ID for the range covered by this record.
195
    pub end_glyph_id: BigEndian<GlyphId16>,
196
    /// Offset from the beginning of the SVGDocumentList to an SVG
197
    /// document. Must be non-zero.
198
    pub svg_doc_offset: BigEndian<u32>,
199
    /// Length of the SVG document data. Must be non-zero.
200
    pub svg_doc_length: BigEndian<u32>,
201
}
202
203
impl SVGDocumentRecord {
204
    /// The first glyph ID for the range covered by this record.
205
0
    pub fn start_glyph_id(&self) -> GlyphId16 {
206
0
        self.start_glyph_id.get()
207
0
    }
208
209
    /// The last glyph ID for the range covered by this record.
210
0
    pub fn end_glyph_id(&self) -> GlyphId16 {
211
0
        self.end_glyph_id.get()
212
0
    }
213
214
    /// Offset from the beginning of the SVGDocumentList to an SVG
215
    /// document. Must be non-zero.
216
0
    pub fn svg_doc_offset(&self) -> u32 {
217
0
        self.svg_doc_offset.get()
218
0
    }
219
220
    /// Length of the SVG document data. Must be non-zero.
221
0
    pub fn svg_doc_length(&self) -> u32 {
222
0
        self.svg_doc_length.get()
223
0
    }
224
}
225
226
impl FixedSize for SVGDocumentRecord {
227
    const RAW_BYTE_LEN: usize =
228
        GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN;
229
}
230
231
#[cfg(feature = "experimental_traverse")]
232
impl<'a> SomeRecord<'a> for SVGDocumentRecord {
233
    fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
234
        RecordResolver {
235
            name: "SVGDocumentRecord",
236
            get_field: Box::new(move |idx, _data| match idx {
237
                0usize => Some(Field::new("start_glyph_id", self.start_glyph_id())),
238
                1usize => Some(Field::new("end_glyph_id", self.end_glyph_id())),
239
                2usize => Some(Field::new("svg_doc_offset", self.svg_doc_offset())),
240
                3usize => Some(Field::new("svg_doc_length", self.svg_doc_length())),
241
                _ => None,
242
            }),
243
            data,
244
        }
245
    }
246
}