Coverage Report

Created: 2025-12-31 07:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fontations/write-fonts/generated/generated_variations.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
pub use read_fonts::tables::variations::EntryFormat;
9
10
/// [TupleVariationHeader](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#tuplevariationheader)
11
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
12
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13
pub struct TupleVariationHeader {
14
    /// The size in bytes of the serialized data for this tuple
15
    /// variation table.
16
    pub variation_data_size: u16,
17
    /// A packed field. The high 4 bits are flags (see below). The low
18
    /// 12 bits are an index into a shared tuple records array.
19
    pub tuple_index: TupleIndex,
20
    /// Peak tuple record for this tuple variation table — optional,
21
    /// determined by flags in the tupleIndex value.  Note that this
22
    /// must always be included in the 'cvar' table.
23
    pub peak_tuple: Vec<F2Dot14>,
24
    /// Intermediate start tuple record for this tuple variation table
25
    /// — optional, determined by flags in the tupleIndex value.
26
    pub intermediate_start_tuple: Vec<F2Dot14>,
27
    /// Intermediate end tuple record for this tuple variation table
28
    /// — optional, determined by flags in the tupleIndex value.
29
    pub intermediate_end_tuple: Vec<F2Dot14>,
30
}
31
32
impl FontWrite for TupleVariationHeader {
33
0
    fn write_into(&self, writer: &mut TableWriter) {
34
0
        self.variation_data_size.write_into(writer);
35
0
        self.tuple_index.write_into(writer);
36
0
        self.peak_tuple.write_into(writer);
37
0
        self.intermediate_start_tuple.write_into(writer);
38
0
        self.intermediate_end_tuple.write_into(writer);
39
0
    }
40
0
    fn table_type(&self) -> TableType {
41
0
        TableType::Named("TupleVariationHeader")
42
0
    }
43
}
44
45
impl Validate for TupleVariationHeader {
46
0
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
47
}
48
49
impl<'a> FromObjRef<read_fonts::tables::variations::TupleVariationHeader<'a>>
50
    for TupleVariationHeader
51
{
52
0
    fn from_obj_ref(
53
0
        obj: &read_fonts::tables::variations::TupleVariationHeader<'a>,
54
0
        _: FontData,
55
0
    ) -> Self {
56
0
        let offset_data = obj.offset_data();
57
0
        TupleVariationHeader {
58
0
            variation_data_size: obj.variation_data_size(),
59
0
            tuple_index: obj.tuple_index(),
60
0
            peak_tuple: obj.peak_tuple().to_owned_obj(offset_data),
61
0
            intermediate_start_tuple: obj.intermediate_start_tuple().to_owned_obj(offset_data),
62
0
            intermediate_end_tuple: obj.intermediate_end_tuple().to_owned_obj(offset_data),
63
0
        }
64
0
    }
65
}
66
67
#[allow(clippy::needless_lifetimes)]
68
impl<'a> FromTableRef<read_fonts::tables::variations::TupleVariationHeader<'a>>
69
    for TupleVariationHeader
70
{
71
}
72
73
/// A [Tuple Record](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#tuple-records)
74
///
75
/// The tuple variation store formats reference regions within the font’s
76
/// variation space using tuple records. A tuple record identifies a position
77
/// in terms of normalized coordinates, which use F2DOT14 values.
78
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
79
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80
pub struct Tuple {
81
    /// Coordinate array specifying a position within the font’s variation space.
82
    ///
83
    /// The number of elements must match the axisCount specified in the
84
    /// 'fvar' table.
85
    pub values: Vec<F2Dot14>,
86
}
87
88
impl Tuple {
89
    /// Construct a new `Tuple`
90
0
    pub fn new(values: Vec<F2Dot14>) -> Self {
91
0
        Self { values }
92
0
    }
93
}
94
95
impl FontWrite for Tuple {
96
0
    fn write_into(&self, writer: &mut TableWriter) {
97
0
        self.values.write_into(writer);
98
0
    }
99
0
    fn table_type(&self) -> TableType {
100
0
        TableType::Named("Tuple")
101
0
    }
102
}
103
104
impl Validate for Tuple {
105
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
106
0
        ctx.in_table("Tuple", |ctx| {
107
0
            ctx.in_field("values", |ctx| {
108
0
                if self.values.len() > (u16::MAX as usize) {
109
0
                    ctx.report("array exceeds max length");
110
0
                }
111
0
            });
112
0
        })
113
0
    }
114
}
115
116
impl FromObjRef<read_fonts::tables::variations::Tuple<'_>> for Tuple {
117
0
    fn from_obj_ref(obj: &read_fonts::tables::variations::Tuple, offset_data: FontData) -> Self {
118
0
        Tuple {
119
0
            values: obj.values().to_owned_obj(offset_data),
120
0
        }
121
0
    }
122
}
123
124
/// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table format 0
125
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
126
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
127
pub struct DeltaSetIndexMapFormat0 {
128
    /// A packed field that describes the compressed representation of
129
    /// delta-set indices. See details below.
130
    pub entry_format: EntryFormat,
131
    /// The number of mapping entries.
132
    pub map_count: u16,
133
    /// The delta-set index mapping data. See details below.
134
    pub map_data: Vec<u8>,
135
}
136
137
impl DeltaSetIndexMapFormat0 {
138
    /// Construct a new `DeltaSetIndexMapFormat0`
139
0
    pub fn new(entry_format: EntryFormat, map_count: u16, map_data: Vec<u8>) -> Self {
140
0
        Self {
141
0
            entry_format,
142
0
            map_count,
143
0
            map_data,
144
0
        }
145
0
    }
146
}
147
148
impl FontWrite for DeltaSetIndexMapFormat0 {
149
    #[allow(clippy::unnecessary_cast)]
150
0
    fn write_into(&self, writer: &mut TableWriter) {
151
0
        (0 as u8).write_into(writer);
152
0
        self.entry_format.write_into(writer);
153
0
        self.map_count.write_into(writer);
154
0
        self.map_data.write_into(writer);
155
0
    }
156
0
    fn table_type(&self) -> TableType {
157
0
        TableType::Named("DeltaSetIndexMapFormat0")
158
0
    }
159
}
160
161
impl Validate for DeltaSetIndexMapFormat0 {
162
0
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
163
}
164
165
impl<'a> FromObjRef<read_fonts::tables::variations::DeltaSetIndexMapFormat0<'a>>
166
    for DeltaSetIndexMapFormat0
167
{
168
0
    fn from_obj_ref(
169
0
        obj: &read_fonts::tables::variations::DeltaSetIndexMapFormat0<'a>,
170
0
        _: FontData,
171
0
    ) -> Self {
172
0
        let offset_data = obj.offset_data();
173
0
        DeltaSetIndexMapFormat0 {
174
0
            entry_format: obj.entry_format(),
175
0
            map_count: obj.map_count(),
176
0
            map_data: obj.map_data().to_owned_obj(offset_data),
177
0
        }
178
0
    }
179
}
180
181
#[allow(clippy::needless_lifetimes)]
182
impl<'a> FromTableRef<read_fonts::tables::variations::DeltaSetIndexMapFormat0<'a>>
183
    for DeltaSetIndexMapFormat0
184
{
185
}
186
187
impl<'a> FontRead<'a> for DeltaSetIndexMapFormat0 {
188
0
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
189
0
        <read_fonts::tables::variations::DeltaSetIndexMapFormat0 as FontRead>::read(data)
190
0
            .map(|x| x.to_owned_table())
191
0
    }
192
}
193
194
/// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table format 1
195
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
196
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
197
pub struct DeltaSetIndexMapFormat1 {
198
    /// A packed field that describes the compressed representation of
199
    /// delta-set indices. See details below.
200
    pub entry_format: EntryFormat,
201
    /// The number of mapping entries.
202
    pub map_count: u32,
203
    /// The delta-set index mapping data. See details below.
204
    pub map_data: Vec<u8>,
205
}
206
207
impl DeltaSetIndexMapFormat1 {
208
    /// Construct a new `DeltaSetIndexMapFormat1`
209
0
    pub fn new(entry_format: EntryFormat, map_count: u32, map_data: Vec<u8>) -> Self {
210
0
        Self {
211
0
            entry_format,
212
0
            map_count,
213
0
            map_data,
214
0
        }
215
0
    }
216
}
217
218
impl FontWrite for DeltaSetIndexMapFormat1 {
219
    #[allow(clippy::unnecessary_cast)]
220
0
    fn write_into(&self, writer: &mut TableWriter) {
221
0
        (1 as u8).write_into(writer);
222
0
        self.entry_format.write_into(writer);
223
0
        self.map_count.write_into(writer);
224
0
        self.map_data.write_into(writer);
225
0
    }
226
0
    fn table_type(&self) -> TableType {
227
0
        TableType::Named("DeltaSetIndexMapFormat1")
228
0
    }
229
}
230
231
impl Validate for DeltaSetIndexMapFormat1 {
232
0
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
233
}
234
235
impl<'a> FromObjRef<read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>>
236
    for DeltaSetIndexMapFormat1
237
{
238
0
    fn from_obj_ref(
239
0
        obj: &read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>,
240
0
        _: FontData,
241
0
    ) -> Self {
242
0
        let offset_data = obj.offset_data();
243
0
        DeltaSetIndexMapFormat1 {
244
0
            entry_format: obj.entry_format(),
245
0
            map_count: obj.map_count(),
246
0
            map_data: obj.map_data().to_owned_obj(offset_data),
247
0
        }
248
0
    }
249
}
250
251
#[allow(clippy::needless_lifetimes)]
252
impl<'a> FromTableRef<read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>>
253
    for DeltaSetIndexMapFormat1
254
{
255
}
256
257
impl<'a> FontRead<'a> for DeltaSetIndexMapFormat1 {
258
0
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
259
0
        <read_fonts::tables::variations::DeltaSetIndexMapFormat1 as FontRead>::read(data)
260
0
            .map(|x| x.to_owned_table())
261
0
    }
262
}
263
264
/// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table
265
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
266
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
267
pub enum DeltaSetIndexMap {
268
    Format0(DeltaSetIndexMapFormat0),
269
    Format1(DeltaSetIndexMapFormat1),
270
}
271
272
impl DeltaSetIndexMap {
273
    /// Construct a new `DeltaSetIndexMapFormat0` subtable
274
0
    pub fn format_0(entry_format: EntryFormat, map_count: u16, map_data: Vec<u8>) -> Self {
275
0
        Self::Format0(DeltaSetIndexMapFormat0::new(
276
0
            entry_format,
277
0
            map_count,
278
0
            map_data,
279
0
        ))
280
0
    }
281
282
    /// Construct a new `DeltaSetIndexMapFormat1` subtable
283
0
    pub fn format_1(entry_format: EntryFormat, map_count: u32, map_data: Vec<u8>) -> Self {
284
0
        Self::Format1(DeltaSetIndexMapFormat1::new(
285
0
            entry_format,
286
0
            map_count,
287
0
            map_data,
288
0
        ))
289
0
    }
290
}
291
292
impl Default for DeltaSetIndexMap {
293
0
    fn default() -> Self {
294
0
        Self::Format0(Default::default())
295
0
    }
296
}
297
298
impl FontWrite for DeltaSetIndexMap {
299
0
    fn write_into(&self, writer: &mut TableWriter) {
300
0
        match self {
301
0
            Self::Format0(item) => item.write_into(writer),
302
0
            Self::Format1(item) => item.write_into(writer),
303
        }
304
0
    }
305
0
    fn table_type(&self) -> TableType {
306
0
        match self {
307
0
            Self::Format0(item) => item.table_type(),
308
0
            Self::Format1(item) => item.table_type(),
309
        }
310
0
    }
311
}
312
313
impl Validate for DeltaSetIndexMap {
314
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
315
0
        match self {
316
0
            Self::Format0(item) => item.validate_impl(ctx),
317
0
            Self::Format1(item) => item.validate_impl(ctx),
318
        }
319
0
    }
320
}
321
322
impl FromObjRef<read_fonts::tables::variations::DeltaSetIndexMap<'_>> for DeltaSetIndexMap {
323
0
    fn from_obj_ref(obj: &read_fonts::tables::variations::DeltaSetIndexMap, _: FontData) -> Self {
324
        use read_fonts::tables::variations::DeltaSetIndexMap as ObjRefType;
325
0
        match obj {
326
0
            ObjRefType::Format0(item) => DeltaSetIndexMap::Format0(item.to_owned_table()),
327
0
            ObjRefType::Format1(item) => DeltaSetIndexMap::Format1(item.to_owned_table()),
328
        }
329
0
    }
330
}
331
332
impl FromTableRef<read_fonts::tables::variations::DeltaSetIndexMap<'_>> for DeltaSetIndexMap {}
333
334
impl<'a> FontRead<'a> for DeltaSetIndexMap {
335
0
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
336
0
        <read_fonts::tables::variations::DeltaSetIndexMap as FontRead>::read(data)
337
0
            .map(|x| x.to_owned_table())
338
0
    }
339
}
340
341
impl From<DeltaSetIndexMapFormat0> for DeltaSetIndexMap {
342
0
    fn from(src: DeltaSetIndexMapFormat0) -> DeltaSetIndexMap {
343
0
        DeltaSetIndexMap::Format0(src)
344
0
    }
345
}
346
347
impl From<DeltaSetIndexMapFormat1> for DeltaSetIndexMap {
348
0
    fn from(src: DeltaSetIndexMapFormat1) -> DeltaSetIndexMap {
349
0
        DeltaSetIndexMap::Format1(src)
350
0
    }
351
}
352
353
impl FontWrite for EntryFormat {
354
0
    fn write_into(&self, writer: &mut TableWriter) {
355
0
        writer.write_slice(&self.bits().to_be_bytes())
356
0
    }
357
}
358
359
/// The [VariationRegionList](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) table
360
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
361
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
362
pub struct VariationRegionList {
363
    /// The number of variation axes for this font. This must be the
364
    /// same number as axisCount in the 'fvar' table.
365
    pub axis_count: u16,
366
    /// Array of variation regions.
367
    pub variation_regions: Vec<VariationRegion>,
368
}
369
370
impl VariationRegionList {
371
    /// Construct a new `VariationRegionList`
372
0
    pub fn new(axis_count: u16, variation_regions: Vec<VariationRegion>) -> Self {
373
0
        Self {
374
0
            axis_count,
375
0
            variation_regions,
376
0
        }
377
0
    }
378
}
379
380
impl FontWrite for VariationRegionList {
381
    #[allow(clippy::unnecessary_cast)]
382
0
    fn write_into(&self, writer: &mut TableWriter) {
383
0
        self.axis_count.write_into(writer);
384
0
        (u16::try_from(array_len(&self.variation_regions)).unwrap()).write_into(writer);
385
0
        self.variation_regions.write_into(writer);
386
0
    }
387
0
    fn table_type(&self) -> TableType {
388
0
        TableType::Named("VariationRegionList")
389
0
    }
390
}
391
392
impl Validate for VariationRegionList {
393
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
394
0
        ctx.in_table("VariationRegionList", |ctx| {
395
0
            ctx.in_field("variation_regions", |ctx| {
396
0
                if self.variation_regions.len() > (u16::MAX as usize) {
397
0
                    ctx.report("array exceeds max length");
398
0
                }
399
0
                self.variation_regions.validate_impl(ctx);
400
0
            });
401
0
        })
402
0
    }
403
}
404
405
impl<'a> FromObjRef<read_fonts::tables::variations::VariationRegionList<'a>>
406
    for VariationRegionList
407
{
408
0
    fn from_obj_ref(
409
0
        obj: &read_fonts::tables::variations::VariationRegionList<'a>,
410
0
        _: FontData,
411
0
    ) -> Self {
412
0
        let offset_data = obj.offset_data();
413
        VariationRegionList {
414
0
            axis_count: obj.axis_count(),
415
0
            variation_regions: obj
416
0
                .variation_regions()
417
0
                .iter()
418
0
                .filter_map(|x| x.map(|x| FromObjRef::from_obj_ref(&x, offset_data)).ok())
419
0
                .collect(),
420
        }
421
0
    }
422
}
423
424
#[allow(clippy::needless_lifetimes)]
425
impl<'a> FromTableRef<read_fonts::tables::variations::VariationRegionList<'a>>
426
    for VariationRegionList
427
{
428
}
429
430
impl<'a> FontRead<'a> for VariationRegionList {
431
0
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
432
0
        <read_fonts::tables::variations::VariationRegionList as FontRead>::read(data)
433
0
            .map(|x| x.to_owned_table())
434
0
    }
435
}
436
437
/// The [VariationRegion](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) record
438
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
439
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
440
pub struct VariationRegion {
441
    /// Array of region axis coordinates records, in the order of axes
442
    /// given in the 'fvar' table.
443
    pub region_axes: Vec<RegionAxisCoordinates>,
444
}
445
446
impl VariationRegion {
447
    /// Construct a new `VariationRegion`
448
0
    pub fn new(region_axes: Vec<RegionAxisCoordinates>) -> Self {
449
0
        Self { region_axes }
450
0
    }
451
}
452
453
impl FontWrite for VariationRegion {
454
0
    fn write_into(&self, writer: &mut TableWriter) {
455
0
        self.region_axes.write_into(writer);
456
0
    }
457
0
    fn table_type(&self) -> TableType {
458
0
        TableType::Named("VariationRegion")
459
0
    }
460
}
461
462
impl Validate for VariationRegion {
463
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
464
0
        ctx.in_table("VariationRegion", |ctx| {
465
0
            ctx.in_field("region_axes", |ctx| {
466
0
                if self.region_axes.len() > (u16::MAX as usize) {
467
0
                    ctx.report("array exceeds max length");
468
0
                }
469
0
                self.region_axes.validate_impl(ctx);
470
0
            });
471
0
        })
472
0
    }
473
}
474
475
impl FromObjRef<read_fonts::tables::variations::VariationRegion<'_>> for VariationRegion {
476
0
    fn from_obj_ref(
477
0
        obj: &read_fonts::tables::variations::VariationRegion,
478
0
        offset_data: FontData,
479
0
    ) -> Self {
480
0
        VariationRegion {
481
0
            region_axes: obj.region_axes().to_owned_obj(offset_data),
482
0
        }
483
0
    }
484
}
485
486
/// The [RegionAxisCoordinates](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) record
487
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
488
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
489
pub struct RegionAxisCoordinates {
490
    /// The region start coordinate value for the current axis.
491
    pub start_coord: F2Dot14,
492
    /// The region peak coordinate value for the current axis.
493
    pub peak_coord: F2Dot14,
494
    /// The region end coordinate value for the current axis.
495
    pub end_coord: F2Dot14,
496
}
497
498
impl RegionAxisCoordinates {
499
    /// Construct a new `RegionAxisCoordinates`
500
0
    pub fn new(start_coord: F2Dot14, peak_coord: F2Dot14, end_coord: F2Dot14) -> Self {
501
0
        Self {
502
0
            start_coord,
503
0
            peak_coord,
504
0
            end_coord,
505
0
        }
506
0
    }
507
}
508
509
impl FontWrite for RegionAxisCoordinates {
510
0
    fn write_into(&self, writer: &mut TableWriter) {
511
0
        self.start_coord.write_into(writer);
512
0
        self.peak_coord.write_into(writer);
513
0
        self.end_coord.write_into(writer);
514
0
    }
515
0
    fn table_type(&self) -> TableType {
516
0
        TableType::Named("RegionAxisCoordinates")
517
0
    }
518
}
519
520
impl Validate for RegionAxisCoordinates {
521
0
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
522
}
523
524
impl FromObjRef<read_fonts::tables::variations::RegionAxisCoordinates> for RegionAxisCoordinates {
525
0
    fn from_obj_ref(
526
0
        obj: &read_fonts::tables::variations::RegionAxisCoordinates,
527
0
        _: FontData,
528
0
    ) -> Self {
529
0
        RegionAxisCoordinates {
530
0
            start_coord: obj.start_coord(),
531
0
            peak_coord: obj.peak_coord(),
532
0
            end_coord: obj.end_coord(),
533
0
        }
534
0
    }
535
}
536
537
/// The [ItemVariationStore](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#item-variation-store-header-and-item-variation-data-subtables) table
538
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
539
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
540
pub struct ItemVariationStore {
541
    /// Offset in bytes from the start of the item variation store to
542
    /// the variation region list.
543
    pub variation_region_list: OffsetMarker<VariationRegionList, WIDTH_32>,
544
    /// Offsets in bytes from the start of the item variation store to
545
    /// each item variation data subtable.
546
    pub item_variation_data: Vec<NullableOffsetMarker<ItemVariationData, WIDTH_32>>,
547
}
548
549
impl ItemVariationStore {
550
    /// Construct a new `ItemVariationStore`
551
0
    pub fn new(
552
0
        variation_region_list: VariationRegionList,
553
0
        item_variation_data: Vec<Option<ItemVariationData>>,
554
0
    ) -> Self {
555
0
        Self {
556
0
            variation_region_list: variation_region_list.into(),
557
0
            item_variation_data: item_variation_data.into_iter().map(Into::into).collect(),
558
0
        }
559
0
    }
560
}
561
562
impl FontWrite for ItemVariationStore {
563
    #[allow(clippy::unnecessary_cast)]
564
0
    fn write_into(&self, writer: &mut TableWriter) {
565
0
        (1 as u16).write_into(writer);
566
0
        self.variation_region_list.write_into(writer);
567
0
        (u16::try_from(array_len(&self.item_variation_data)).unwrap()).write_into(writer);
568
0
        self.item_variation_data.write_into(writer);
569
0
    }
570
0
    fn table_type(&self) -> TableType {
571
0
        TableType::Named("ItemVariationStore")
572
0
    }
573
}
574
575
impl Validate for ItemVariationStore {
576
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
577
0
        ctx.in_table("ItemVariationStore", |ctx| {
578
0
            ctx.in_field("variation_region_list", |ctx| {
579
0
                self.variation_region_list.validate_impl(ctx);
580
0
            });
581
0
            ctx.in_field("item_variation_data", |ctx| {
582
0
                if self.item_variation_data.len() > (u16::MAX as usize) {
583
0
                    ctx.report("array exceeds max length");
584
0
                }
585
0
                self.item_variation_data.validate_impl(ctx);
586
0
            });
587
0
        })
588
0
    }
589
}
590
591
impl<'a> FromObjRef<read_fonts::tables::variations::ItemVariationStore<'a>> for ItemVariationStore {
592
0
    fn from_obj_ref(
593
0
        obj: &read_fonts::tables::variations::ItemVariationStore<'a>,
594
0
        _: FontData,
595
0
    ) -> Self {
596
0
        ItemVariationStore {
597
0
            variation_region_list: obj.variation_region_list().to_owned_table(),
598
0
            item_variation_data: obj.item_variation_data().to_owned_table(),
599
0
        }
600
0
    }
601
}
602
603
#[allow(clippy::needless_lifetimes)]
604
impl<'a> FromTableRef<read_fonts::tables::variations::ItemVariationStore<'a>>
605
    for ItemVariationStore
606
{
607
}
608
609
impl<'a> FontRead<'a> for ItemVariationStore {
610
0
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
611
0
        <read_fonts::tables::variations::ItemVariationStore as FontRead>::read(data)
612
0
            .map(|x| x.to_owned_table())
613
0
    }
614
}
615
616
/// The [ItemVariationData](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#item-variation-store-header-and-item-variation-data-subtables) subtable
617
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
618
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
619
pub struct ItemVariationData {
620
    /// The number of delta sets for distinct items.
621
    pub item_count: u16,
622
    /// A packed field: the high bit is a flag—see details below.
623
    pub word_delta_count: u16,
624
    /// Array of indices into the variation region list for the regions
625
    /// referenced by this item variation data table.
626
    pub region_indexes: Vec<u16>,
627
    /// Delta-set rows.
628
    pub delta_sets: Vec<u8>,
629
}
630
631
impl ItemVariationData {
632
    /// Construct a new `ItemVariationData`
633
0
    pub fn new(
634
0
        item_count: u16,
635
0
        word_delta_count: u16,
636
0
        region_indexes: Vec<u16>,
637
0
        delta_sets: Vec<u8>,
638
0
    ) -> Self {
639
0
        Self {
640
0
            item_count,
641
0
            word_delta_count,
642
0
            region_indexes,
643
0
            delta_sets,
644
0
        }
645
0
    }
646
}
647
648
impl FontWrite for ItemVariationData {
649
    #[allow(clippy::unnecessary_cast)]
650
0
    fn write_into(&self, writer: &mut TableWriter) {
651
0
        self.item_count.write_into(writer);
652
0
        self.word_delta_count.write_into(writer);
653
0
        (u16::try_from(array_len(&self.region_indexes)).unwrap()).write_into(writer);
654
0
        self.region_indexes.write_into(writer);
655
0
        self.delta_sets.write_into(writer);
656
0
    }
657
0
    fn table_type(&self) -> TableType {
658
0
        TableType::Named("ItemVariationData")
659
0
    }
660
}
661
662
impl Validate for ItemVariationData {
663
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
664
0
        ctx.in_table("ItemVariationData", |ctx| {
665
0
            ctx.in_field("region_indexes", |ctx| {
666
0
                if self.region_indexes.len() > (u16::MAX as usize) {
667
0
                    ctx.report("array exceeds max length");
668
0
                }
669
0
            });
670
0
        })
671
0
    }
672
}
673
674
impl<'a> FromObjRef<read_fonts::tables::variations::ItemVariationData<'a>> for ItemVariationData {
675
0
    fn from_obj_ref(
676
0
        obj: &read_fonts::tables::variations::ItemVariationData<'a>,
677
0
        _: FontData,
678
0
    ) -> Self {
679
0
        let offset_data = obj.offset_data();
680
0
        ItemVariationData {
681
0
            item_count: obj.item_count(),
682
0
            word_delta_count: obj.word_delta_count(),
683
0
            region_indexes: obj.region_indexes().to_owned_obj(offset_data),
684
0
            delta_sets: obj.delta_sets().to_owned_obj(offset_data),
685
0
        }
686
0
    }
687
}
688
689
#[allow(clippy::needless_lifetimes)]
690
impl<'a> FromTableRef<read_fonts::tables::variations::ItemVariationData<'a>> for ItemVariationData {}
691
692
impl<'a> FontRead<'a> for ItemVariationData {
693
0
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
694
0
        <read_fonts::tables::variations::ItemVariationData as FontRead>::read(data)
695
0
            .map(|x| x.to_owned_table())
696
0
    }
697
}