1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
// THIS FILE IS AUTOGENERATED.
// Any changes to this file will be overwritten.
// For more information about how codegen works, see font-codegen/README.md

#[allow(unused_imports)]
use crate::codegen_prelude::*;

pub use read_fonts::tables::variations::EntryFormat;

/// [TupleVariationHeader](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#tuplevariationheader)
#[derive(Clone, Debug, Default)]
pub struct TupleVariationHeader {
    /// The size in bytes of the serialized data for this tuple
    /// variation table.
    pub variation_data_size: u16,
    /// A packed field. The high 4 bits are flags (see below). The low
    /// 12 bits are an index into a shared tuple records array.
    pub tuple_index: TupleIndex,
    /// Peak tuple record for this tuple variation table — optional,
    /// determined by flags in the tupleIndex value.  Note that this
    /// must always be included in the 'cvar' table.
    pub peak_tuple: Vec<F2Dot14>,
    /// Intermediate start tuple record for this tuple variation table
    /// — optional, determined by flags in the tupleIndex value.
    pub intermediate_start_tuple: Vec<F2Dot14>,
    /// Intermediate end tuple record for this tuple variation table
    /// — optional, determined by flags in the tupleIndex value.
    pub intermediate_end_tuple: Vec<F2Dot14>,
}

impl FontWrite for TupleVariationHeader {
    fn write_into(&self, writer: &mut TableWriter) {
        self.variation_data_size.write_into(writer);
        self.tuple_index.write_into(writer);
        self.peak_tuple.write_into(writer);
        self.intermediate_start_tuple.write_into(writer);
        self.intermediate_end_tuple.write_into(writer);
    }
    fn name(&self) -> &'static str {
        "TupleVariationHeader"
    }
}

impl Validate for TupleVariationHeader {
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
}

impl<'a> FromObjRef<read_fonts::tables::variations::TupleVariationHeader<'a>>
    for TupleVariationHeader
{
    fn from_obj_ref(
        obj: &read_fonts::tables::variations::TupleVariationHeader<'a>,
        _: FontData,
    ) -> Self {
        let offset_data = obj.offset_data();
        TupleVariationHeader {
            variation_data_size: obj.variation_data_size(),
            tuple_index: obj.tuple_index(),
            peak_tuple: obj.peak_tuple().to_owned_obj(offset_data),
            intermediate_start_tuple: obj.intermediate_start_tuple().to_owned_obj(offset_data),
            intermediate_end_tuple: obj.intermediate_end_tuple().to_owned_obj(offset_data),
        }
    }
}

impl<'a> FromTableRef<read_fonts::tables::variations::TupleVariationHeader<'a>>
    for TupleVariationHeader
{
}

/// A [Tuple Record](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#tuple-records)
///
/// The tuple variation store formats reference regions within the font’s
/// variation space using tuple records. A tuple record identifies a position
/// in terms of normalized coordinates, which use F2DOT14 values.
#[derive(Clone, Debug, Default, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct Tuple {
    /// Coordinate array specifying a position within the font’s variation space.
    ///
    /// The number of elements must match the axisCount specified in the
    /// 'fvar' table.
    pub values: Vec<F2Dot14>,
}

impl Tuple {
    /// Construct a new `Tuple`
    pub fn new(values: Vec<F2Dot14>) -> Self {
        Self {
            values: values.into_iter().map(Into::into).collect(),
        }
    }
}

impl FontWrite for Tuple {
    fn write_into(&self, writer: &mut TableWriter) {
        self.values.write_into(writer);
    }
    fn name(&self) -> &'static str {
        "Tuple"
    }
}

impl Validate for Tuple {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("Tuple", |ctx| {
            ctx.in_field("values", |ctx| {
                if self.values.len() > (u16::MAX as usize) {
                    ctx.report("array exceeds max length");
                }
            });
        })
    }
}

impl FromObjRef<read_fonts::tables::variations::Tuple<'_>> for Tuple {
    fn from_obj_ref(obj: &read_fonts::tables::variations::Tuple, offset_data: FontData) -> Self {
        Tuple {
            values: obj.values().to_owned_obj(offset_data),
        }
    }
}

/// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table format 0
#[derive(Clone, Debug, Default)]
pub struct DeltaSetIndexMapFormat0 {
    /// A packed field that describes the compressed representation of
    /// delta-set indices. See details below.
    pub entry_format: EntryFormat,
    /// The number of mapping entries.
    pub map_count: u16,
    /// The delta-set index mapping data. See details below.
    pub map_data: Vec<u8>,
}

impl DeltaSetIndexMapFormat0 {
    /// Construct a new `DeltaSetIndexMapFormat0`
    pub fn new(entry_format: EntryFormat, map_count: u16, map_data: Vec<u8>) -> Self {
        Self {
            entry_format,
            map_count,
            map_data: map_data.into_iter().map(Into::into).collect(),
        }
    }
}

impl FontWrite for DeltaSetIndexMapFormat0 {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        (0 as u8).write_into(writer);
        self.entry_format.write_into(writer);
        self.map_count.write_into(writer);
        self.map_data.write_into(writer);
    }
    fn name(&self) -> &'static str {
        "DeltaSetIndexMapFormat0"
    }
}

impl Validate for DeltaSetIndexMapFormat0 {
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
}

impl<'a> FromObjRef<read_fonts::tables::variations::DeltaSetIndexMapFormat0<'a>>
    for DeltaSetIndexMapFormat0
{
    fn from_obj_ref(
        obj: &read_fonts::tables::variations::DeltaSetIndexMapFormat0<'a>,
        _: FontData,
    ) -> Self {
        let offset_data = obj.offset_data();
        DeltaSetIndexMapFormat0 {
            entry_format: obj.entry_format(),
            map_count: obj.map_count(),
            map_data: obj.map_data().to_owned_obj(offset_data),
        }
    }
}

impl<'a> FromTableRef<read_fonts::tables::variations::DeltaSetIndexMapFormat0<'a>>
    for DeltaSetIndexMapFormat0
{
}

impl<'a> FontRead<'a> for DeltaSetIndexMapFormat0 {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::tables::variations::DeltaSetIndexMapFormat0 as FontRead>::read(data)
            .map(|x| x.to_owned_table())
    }
}

/// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table format 1
#[derive(Clone, Debug, Default)]
pub struct DeltaSetIndexMapFormat1 {
    /// A packed field that describes the compressed representation of
    /// delta-set indices. See details below.
    pub entry_format: EntryFormat,
    /// The number of mapping entries.
    pub map_count: u32,
    /// The delta-set index mapping data. See details below.
    pub map_data: Vec<u8>,
}

impl DeltaSetIndexMapFormat1 {
    /// Construct a new `DeltaSetIndexMapFormat1`
    pub fn new(entry_format: EntryFormat, map_count: u32, map_data: Vec<u8>) -> Self {
        Self {
            entry_format,
            map_count,
            map_data: map_data.into_iter().map(Into::into).collect(),
        }
    }
}

impl FontWrite for DeltaSetIndexMapFormat1 {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        (1 as u8).write_into(writer);
        self.entry_format.write_into(writer);
        self.map_count.write_into(writer);
        self.map_data.write_into(writer);
    }
    fn name(&self) -> &'static str {
        "DeltaSetIndexMapFormat1"
    }
}

impl Validate for DeltaSetIndexMapFormat1 {
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
}

impl<'a> FromObjRef<read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>>
    for DeltaSetIndexMapFormat1
{
    fn from_obj_ref(
        obj: &read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>,
        _: FontData,
    ) -> Self {
        let offset_data = obj.offset_data();
        DeltaSetIndexMapFormat1 {
            entry_format: obj.entry_format(),
            map_count: obj.map_count(),
            map_data: obj.map_data().to_owned_obj(offset_data),
        }
    }
}

impl<'a> FromTableRef<read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>>
    for DeltaSetIndexMapFormat1
{
}

impl<'a> FontRead<'a> for DeltaSetIndexMapFormat1 {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::tables::variations::DeltaSetIndexMapFormat1 as FontRead>::read(data)
            .map(|x| x.to_owned_table())
    }
}

/// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table
#[derive(Clone, Debug)]
pub enum DeltaSetIndexMap {
    Format0(DeltaSetIndexMapFormat0),
    Format1(DeltaSetIndexMapFormat1),
}

impl DeltaSetIndexMap {
    /// Construct a new `DeltaSetIndexMapFormat0` subtable
    pub fn format_0(entry_format: EntryFormat, map_count: u16, map_data: Vec<u8>) -> Self {
        Self::Format0(DeltaSetIndexMapFormat0::new(
            entry_format,
            map_count,
            map_data,
        ))
    }

    /// Construct a new `DeltaSetIndexMapFormat1` subtable
    pub fn format_1(entry_format: EntryFormat, map_count: u32, map_data: Vec<u8>) -> Self {
        Self::Format1(DeltaSetIndexMapFormat1::new(
            entry_format,
            map_count,
            map_data,
        ))
    }
}

impl Default for DeltaSetIndexMap {
    fn default() -> Self {
        Self::Format0(Default::default())
    }
}

impl FontWrite for DeltaSetIndexMap {
    fn write_into(&self, writer: &mut TableWriter) {
        match self {
            Self::Format0(item) => item.write_into(writer),
            Self::Format1(item) => item.write_into(writer),
        }
    }
    fn name(&self) -> &'static str {
        match self {
            Self::Format0(_) => "DeltaSetIndexMap.Format0",
            Self::Format1(_) => "DeltaSetIndexMap.Format1",
        }
    }
}

impl Validate for DeltaSetIndexMap {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        match self {
            Self::Format0(item) => item.validate_impl(ctx),
            Self::Format1(item) => item.validate_impl(ctx),
        }
    }
}

impl FromObjRef<read_fonts::tables::variations::DeltaSetIndexMap<'_>> for DeltaSetIndexMap {
    fn from_obj_ref(obj: &read_fonts::tables::variations::DeltaSetIndexMap, _: FontData) -> Self {
        use read_fonts::tables::variations::DeltaSetIndexMap as ObjRefType;
        match obj {
            ObjRefType::Format0(item) => DeltaSetIndexMap::Format0(item.to_owned_table()),
            ObjRefType::Format1(item) => DeltaSetIndexMap::Format1(item.to_owned_table()),
        }
    }
}

impl FromTableRef<read_fonts::tables::variations::DeltaSetIndexMap<'_>> for DeltaSetIndexMap {}

impl<'a> FontRead<'a> for DeltaSetIndexMap {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::tables::variations::DeltaSetIndexMap as FontRead>::read(data)
            .map(|x| x.to_owned_table())
    }
}

impl FontWrite for EntryFormat {
    fn write_into(&self, writer: &mut TableWriter) {
        writer.write_slice(&self.bits().to_be_bytes())
    }
}

/// The [VariationRegionList](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) table
#[derive(Clone, Debug, Default)]
pub struct VariationRegionList {
    /// Array of variation regions.
    pub variation_regions: Vec<VariationRegion>,
}

impl VariationRegionList {
    /// Construct a new `VariationRegionList`
    pub fn new(variation_regions: Vec<VariationRegion>) -> Self {
        Self { variation_regions }
    }
}

impl FontWrite for VariationRegionList {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        (self.compute_axis_count() as u16).write_into(writer);
        (array_len(&self.variation_regions).unwrap() as u16).write_into(writer);
        self.variation_regions.write_into(writer);
    }
    fn name(&self) -> &'static str {
        "VariationRegionList"
    }
}

impl Validate for VariationRegionList {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("VariationRegionList", |ctx| {
            ctx.in_field("variation_regions", |ctx| {
                if self.variation_regions.len() > (u16::MAX as usize) {
                    ctx.report("array exceeds max length");
                }
                self.variation_regions.validate_impl(ctx);
            });
        })
    }
}

impl<'a> FromObjRef<read_fonts::tables::variations::VariationRegionList<'a>>
    for VariationRegionList
{
    fn from_obj_ref(
        obj: &read_fonts::tables::variations::VariationRegionList<'a>,
        _: FontData,
    ) -> Self {
        let offset_data = obj.offset_data();
        VariationRegionList {
            variation_regions: obj
                .variation_regions()
                .iter()
                .filter_map(|x| x.map(|x| FromObjRef::from_obj_ref(&x, offset_data)).ok())
                .collect(),
        }
    }
}

impl<'a> FromTableRef<read_fonts::tables::variations::VariationRegionList<'a>>
    for VariationRegionList
{
}

impl<'a> FontRead<'a> for VariationRegionList {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::tables::variations::VariationRegionList as FontRead>::read(data)
            .map(|x| x.to_owned_table())
    }
}

/// The [VariationRegion](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) record
#[derive(Clone, Debug, Default)]
pub struct VariationRegion {
    /// Array of region axis coordinates records, in the order of axes
    /// given in the 'fvar' table.
    pub region_axes: Vec<RegionAxisCoordinates>,
}

impl VariationRegion {
    /// Construct a new `VariationRegion`
    pub fn new(region_axes: Vec<RegionAxisCoordinates>) -> Self {
        Self {
            region_axes: region_axes.into_iter().map(Into::into).collect(),
        }
    }
}

impl FontWrite for VariationRegion {
    fn write_into(&self, writer: &mut TableWriter) {
        self.region_axes.write_into(writer);
    }
    fn name(&self) -> &'static str {
        "VariationRegion"
    }
}

impl Validate for VariationRegion {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("VariationRegion", |ctx| {
            ctx.in_field("region_axes", |ctx| {
                if self.region_axes.len() > (u16::MAX as usize) {
                    ctx.report("array exceeds max length");
                }
                self.region_axes.validate_impl(ctx);
            });
        })
    }
}

impl FromObjRef<read_fonts::tables::variations::VariationRegion<'_>> for VariationRegion {
    fn from_obj_ref(
        obj: &read_fonts::tables::variations::VariationRegion,
        offset_data: FontData,
    ) -> Self {
        VariationRegion {
            region_axes: obj.region_axes().to_owned_obj(offset_data),
        }
    }
}

/// The [RegionAxisCoordinates](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) record
#[derive(Clone, Debug, Default)]
pub struct RegionAxisCoordinates {
    /// The region start coordinate value for the current axis.
    pub start_coord: F2Dot14,
    /// The region peak coordinate value for the current axis.
    pub peak_coord: F2Dot14,
    /// The region end coordinate value for the current axis.
    pub end_coord: F2Dot14,
}

impl RegionAxisCoordinates {
    /// Construct a new `RegionAxisCoordinates`
    pub fn new(start_coord: F2Dot14, peak_coord: F2Dot14, end_coord: F2Dot14) -> Self {
        Self {
            start_coord,
            peak_coord,
            end_coord,
        }
    }
}

impl FontWrite for RegionAxisCoordinates {
    fn write_into(&self, writer: &mut TableWriter) {
        self.start_coord.write_into(writer);
        self.peak_coord.write_into(writer);
        self.end_coord.write_into(writer);
    }
    fn name(&self) -> &'static str {
        "RegionAxisCoordinates"
    }
}

impl Validate for RegionAxisCoordinates {
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
}

impl FromObjRef<read_fonts::tables::variations::RegionAxisCoordinates> for RegionAxisCoordinates {
    fn from_obj_ref(
        obj: &read_fonts::tables::variations::RegionAxisCoordinates,
        _: FontData,
    ) -> Self {
        RegionAxisCoordinates {
            start_coord: obj.start_coord(),
            peak_coord: obj.peak_coord(),
            end_coord: obj.end_coord(),
        }
    }
}

/// The [ItemVariationStore](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#item-variation-store-header-and-item-variation-data-subtables) table
#[derive(Clone, Debug, Default)]
pub struct ItemVariationStore {
    /// Format— set to 1
    pub format: u16,
    /// Offset in bytes from the start of the item variation store to
    /// the variation region list.
    pub variation_region_list: OffsetMarker<VariationRegionList, WIDTH_32>,
    /// Offsets in bytes from the start of the item variation store to
    /// each item variation data subtable.
    pub item_variation_datas: Vec<NullableOffsetMarker<ItemVariationData, WIDTH_32>>,
}

impl ItemVariationStore {
    /// Construct a new `ItemVariationStore`
    pub fn new(
        format: u16,
        variation_region_list: VariationRegionList,
        item_variation_datas: Vec<Option<ItemVariationData>>,
    ) -> Self {
        Self {
            format,
            variation_region_list: variation_region_list.into(),
            item_variation_datas: item_variation_datas.into_iter().map(Into::into).collect(),
        }
    }
}

impl FontWrite for ItemVariationStore {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        self.format.write_into(writer);
        self.variation_region_list.write_into(writer);
        (array_len(&self.item_variation_datas).unwrap() as u16).write_into(writer);
        self.item_variation_datas.write_into(writer);
    }
    fn name(&self) -> &'static str {
        "ItemVariationStore"
    }
}

impl Validate for ItemVariationStore {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("ItemVariationStore", |ctx| {
            ctx.in_field("variation_region_list", |ctx| {
                self.variation_region_list.validate_impl(ctx);
            });
            ctx.in_field("item_variation_datas", |ctx| {
                if self.item_variation_datas.len() > (u16::MAX as usize) {
                    ctx.report("array exceeds max length");
                }
                self.item_variation_datas.validate_impl(ctx);
            });
        })
    }
}

impl<'a> FromObjRef<read_fonts::tables::variations::ItemVariationStore<'a>> for ItemVariationStore {
    fn from_obj_ref(
        obj: &read_fonts::tables::variations::ItemVariationStore<'a>,
        _: FontData,
    ) -> Self {
        ItemVariationStore {
            format: obj.format(),
            variation_region_list: obj.variation_region_list().to_owned_table(),
            item_variation_datas: obj
                .item_variation_datas()
                .map(|x| x.to_owned_table())
                .collect(),
        }
    }
}

impl<'a> FromTableRef<read_fonts::tables::variations::ItemVariationStore<'a>>
    for ItemVariationStore
{
}

impl<'a> FontRead<'a> for ItemVariationStore {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::tables::variations::ItemVariationStore as FontRead>::read(data)
            .map(|x| x.to_owned_table())
    }
}

/// The [ItemVariationData](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#item-variation-store-header-and-item-variation-data-subtables) subtable
#[derive(Clone, Debug, Default)]
pub struct ItemVariationData {
    /// The number of delta sets for distinct items.
    pub item_count: u16,
    /// A packed field: the high bit is a flag—see details below.
    pub word_delta_count: u16,
    /// Array of indices into the variation region list for the regions
    /// referenced by this item variation data table.
    pub region_indexes: Vec<u16>,
    /// Delta-set rows.
    pub delta_sets: Vec<u8>,
}

impl ItemVariationData {
    /// Construct a new `ItemVariationData`
    pub fn new(
        item_count: u16,
        word_delta_count: u16,
        region_indexes: Vec<u16>,
        delta_sets: Vec<u8>,
    ) -> Self {
        Self {
            item_count,
            word_delta_count,
            region_indexes: region_indexes.into_iter().map(Into::into).collect(),
            delta_sets: delta_sets.into_iter().map(Into::into).collect(),
        }
    }
}

impl FontWrite for ItemVariationData {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        self.item_count.write_into(writer);
        self.word_delta_count.write_into(writer);
        (array_len(&self.region_indexes).unwrap() as u16).write_into(writer);
        self.region_indexes.write_into(writer);
        self.delta_sets.write_into(writer);
    }
    fn name(&self) -> &'static str {
        "ItemVariationData"
    }
}

impl Validate for ItemVariationData {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("ItemVariationData", |ctx| {
            ctx.in_field("region_indexes", |ctx| {
                if self.region_indexes.len() > (u16::MAX as usize) {
                    ctx.report("array exceeds max length");
                }
            });
        })
    }
}

impl<'a> FromObjRef<read_fonts::tables::variations::ItemVariationData<'a>> for ItemVariationData {
    fn from_obj_ref(
        obj: &read_fonts::tables::variations::ItemVariationData<'a>,
        _: FontData,
    ) -> Self {
        let offset_data = obj.offset_data();
        ItemVariationData {
            item_count: obj.item_count(),
            word_delta_count: obj.word_delta_count(),
            region_indexes: obj.region_indexes().to_owned_obj(offset_data),
            delta_sets: obj.delta_sets().to_owned_obj(offset_data),
        }
    }
}

impl<'a> FromTableRef<read_fonts::tables::variations::ItemVariationData<'a>> for ItemVariationData {}

impl<'a> FontRead<'a> for ItemVariationData {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::tables::variations::ItemVariationData as FontRead>::read(data)
            .map(|x| x.to_owned_table())
    }
}