Coverage Report

Created: 2026-07-25 07:50

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() > to_usize(u16::MAX) {
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 ReadArgs for DeltaSetIndexMapFormat0 {
188
    type Args = ();
189
}
190
191
impl<'a> FontRead<'a> for DeltaSetIndexMapFormat0 {
192
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
193
0
        <read_fonts::tables::variations::DeltaSetIndexMapFormat0 as FontRead>::read(data)
194
0
            .map(|x| x.to_owned_table())
195
0
    }
196
}
197
198
/// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table format 1
199
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
200
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
201
pub struct DeltaSetIndexMapFormat1 {
202
    /// A packed field that describes the compressed representation of
203
    /// delta-set indices. See details below.
204
    pub entry_format: EntryFormat,
205
    /// The number of mapping entries.
206
    pub map_count: u32,
207
    /// The delta-set index mapping data. See details below.
208
    pub map_data: Vec<u8>,
209
}
210
211
impl DeltaSetIndexMapFormat1 {
212
    /// Construct a new `DeltaSetIndexMapFormat1`
213
0
    pub fn new(entry_format: EntryFormat, map_count: u32, map_data: Vec<u8>) -> Self {
214
0
        Self {
215
0
            entry_format,
216
0
            map_count,
217
0
            map_data,
218
0
        }
219
0
    }
220
}
221
222
impl FontWrite for DeltaSetIndexMapFormat1 {
223
    #[allow(clippy::unnecessary_cast)]
224
0
    fn write_into(&self, writer: &mut TableWriter) {
225
0
        (1 as u8).write_into(writer);
226
0
        self.entry_format.write_into(writer);
227
0
        self.map_count.write_into(writer);
228
0
        self.map_data.write_into(writer);
229
0
    }
230
0
    fn table_type(&self) -> TableType {
231
0
        TableType::Named("DeltaSetIndexMapFormat1")
232
0
    }
233
}
234
235
impl Validate for DeltaSetIndexMapFormat1 {
236
0
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
237
}
238
239
impl<'a> FromObjRef<read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>>
240
    for DeltaSetIndexMapFormat1
241
{
242
0
    fn from_obj_ref(
243
0
        obj: &read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>,
244
0
        _: FontData,
245
0
    ) -> Self {
246
0
        let offset_data = obj.offset_data();
247
0
        DeltaSetIndexMapFormat1 {
248
0
            entry_format: obj.entry_format(),
249
0
            map_count: obj.map_count(),
250
0
            map_data: obj.map_data().to_owned_obj(offset_data),
251
0
        }
252
0
    }
253
}
254
255
#[allow(clippy::needless_lifetimes)]
256
impl<'a> FromTableRef<read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>>
257
    for DeltaSetIndexMapFormat1
258
{
259
}
260
261
impl ReadArgs for DeltaSetIndexMapFormat1 {
262
    type Args = ();
263
}
264
265
impl<'a> FontRead<'a> for DeltaSetIndexMapFormat1 {
266
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
267
0
        <read_fonts::tables::variations::DeltaSetIndexMapFormat1 as FontRead>::read(data)
268
0
            .map(|x| x.to_owned_table())
269
0
    }
270
}
271
272
/// The [DeltaSetIndexMap](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#associating-target-items-to-variation-data) table
273
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
274
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
275
pub enum DeltaSetIndexMap {
276
    Format0(DeltaSetIndexMapFormat0),
277
    Format1(DeltaSetIndexMapFormat1),
278
}
279
280
impl DeltaSetIndexMap {
281
    /// Construct a new `DeltaSetIndexMapFormat0` subtable
282
0
    pub fn format_0(entry_format: EntryFormat, map_count: u16, map_data: Vec<u8>) -> Self {
283
0
        Self::Format0(DeltaSetIndexMapFormat0::new(
284
0
            entry_format,
285
0
            map_count,
286
0
            map_data,
287
0
        ))
288
0
    }
289
290
    /// Construct a new `DeltaSetIndexMapFormat1` subtable
291
0
    pub fn format_1(entry_format: EntryFormat, map_count: u32, map_data: Vec<u8>) -> Self {
292
0
        Self::Format1(DeltaSetIndexMapFormat1::new(
293
0
            entry_format,
294
0
            map_count,
295
0
            map_data,
296
0
        ))
297
0
    }
298
}
299
300
impl Default for DeltaSetIndexMap {
301
0
    fn default() -> Self {
302
0
        Self::Format0(Default::default())
303
0
    }
304
}
305
306
impl FontWrite for DeltaSetIndexMap {
307
0
    fn write_into(&self, writer: &mut TableWriter) {
308
0
        match self {
309
0
            Self::Format0(item) => item.write_into(writer),
310
0
            Self::Format1(item) => item.write_into(writer),
311
        }
312
0
    }
313
0
    fn table_type(&self) -> TableType {
314
0
        match self {
315
0
            Self::Format0(item) => item.table_type(),
316
0
            Self::Format1(item) => item.table_type(),
317
        }
318
0
    }
319
}
320
321
impl Validate for DeltaSetIndexMap {
322
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
323
0
        match self {
324
0
            Self::Format0(item) => item.validate_impl(ctx),
325
0
            Self::Format1(item) => item.validate_impl(ctx),
326
        }
327
0
    }
328
}
329
330
impl FromObjRef<read_fonts::tables::variations::DeltaSetIndexMap<'_>> for DeltaSetIndexMap {
331
0
    fn from_obj_ref(obj: &read_fonts::tables::variations::DeltaSetIndexMap, _: FontData) -> Self {
332
        use read_fonts::tables::variations::DeltaSetIndexMap as ObjRefType;
333
0
        match obj {
334
0
            ObjRefType::Format0(item) => DeltaSetIndexMap::Format0(item.to_owned_table()),
335
0
            ObjRefType::Format1(item) => DeltaSetIndexMap::Format1(item.to_owned_table()),
336
        }
337
0
    }
338
}
339
340
impl FromTableRef<read_fonts::tables::variations::DeltaSetIndexMap<'_>> for DeltaSetIndexMap {}
341
342
impl ReadArgs for DeltaSetIndexMap {
343
    type Args = ();
344
}
345
346
impl<'a> FontRead<'a> for DeltaSetIndexMap {
347
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
348
0
        <read_fonts::tables::variations::DeltaSetIndexMap as FontRead>::read(data)
349
0
            .map(|x| x.to_owned_table())
350
0
    }
351
}
352
353
impl From<DeltaSetIndexMapFormat0> for DeltaSetIndexMap {
354
0
    fn from(src: DeltaSetIndexMapFormat0) -> DeltaSetIndexMap {
355
0
        DeltaSetIndexMap::Format0(src)
356
0
    }
357
}
358
359
impl From<DeltaSetIndexMapFormat1> for DeltaSetIndexMap {
360
0
    fn from(src: DeltaSetIndexMapFormat1) -> DeltaSetIndexMap {
361
0
        DeltaSetIndexMap::Format1(src)
362
0
    }
363
}
364
365
impl FontWrite for EntryFormat {
366
0
    fn write_into(&self, writer: &mut TableWriter) {
367
0
        writer.write_slice(&self.bits().to_be_bytes())
368
0
    }
369
}
370
371
/// The [VariationRegionList](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) table
372
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
373
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
374
pub struct VariationRegionList {
375
    /// The number of variation axes for this font. This must be the
376
    /// same number as axisCount in the 'fvar' table.
377
    pub axis_count: u16,
378
    /// Array of variation regions.
379
    pub variation_regions: Vec<VariationRegion>,
380
}
381
382
impl VariationRegionList {
383
    /// Construct a new `VariationRegionList`
384
0
    pub fn new(axis_count: u16, variation_regions: Vec<VariationRegion>) -> Self {
385
0
        Self {
386
0
            axis_count,
387
0
            variation_regions,
388
0
        }
389
0
    }
390
}
391
392
impl FontWrite for VariationRegionList {
393
    #[allow(clippy::unnecessary_cast)]
394
0
    fn write_into(&self, writer: &mut TableWriter) {
395
0
        self.axis_count.write_into(writer);
396
0
        (u16::try_from(array_len(&self.variation_regions)).unwrap()).write_into(writer);
397
0
        self.variation_regions.write_into(writer);
398
0
    }
399
0
    fn table_type(&self) -> TableType {
400
0
        TableType::Named("VariationRegionList")
401
0
    }
402
}
403
404
impl Validate for VariationRegionList {
405
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
406
0
        ctx.in_table("VariationRegionList", |ctx| {
407
0
            ctx.in_field("variation_regions", |ctx| {
408
0
                if self.variation_regions.len() > to_usize(u16::MAX) {
409
0
                    ctx.report("array exceeds max length");
410
0
                }
411
0
                self.variation_regions.validate_impl(ctx);
412
0
            });
413
0
        })
414
0
    }
415
}
416
417
impl<'a> FromObjRef<read_fonts::tables::variations::VariationRegionList<'a>>
418
    for VariationRegionList
419
{
420
0
    fn from_obj_ref(
421
0
        obj: &read_fonts::tables::variations::VariationRegionList<'a>,
422
0
        _: FontData,
423
0
    ) -> Self {
424
0
        let offset_data = obj.offset_data();
425
        VariationRegionList {
426
0
            axis_count: obj.axis_count(),
427
0
            variation_regions: obj
428
0
                .variation_regions()
429
0
                .iter()
430
0
                .filter_map(|x| x.map(|x| FromObjRef::from_obj_ref(&x, offset_data)).ok())
431
0
                .collect(),
432
        }
433
0
    }
434
}
435
436
#[allow(clippy::needless_lifetimes)]
437
impl<'a> FromTableRef<read_fonts::tables::variations::VariationRegionList<'a>>
438
    for VariationRegionList
439
{
440
}
441
442
impl ReadArgs for VariationRegionList {
443
    type Args = ();
444
}
445
446
impl<'a> FontRead<'a> for VariationRegionList {
447
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
448
0
        <read_fonts::tables::variations::VariationRegionList as FontRead>::read(data)
449
0
            .map(|x| x.to_owned_table())
450
0
    }
451
}
452
453
/// The [VariationRegion](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) record
454
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
455
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
456
pub struct VariationRegion {
457
    /// Array of region axis coordinates records, in the order of axes
458
    /// given in the 'fvar' table.
459
    pub region_axes: Vec<RegionAxisCoordinates>,
460
}
461
462
impl VariationRegion {
463
    /// Construct a new `VariationRegion`
464
0
    pub fn new(region_axes: Vec<RegionAxisCoordinates>) -> Self {
465
0
        Self { region_axes }
466
0
    }
467
}
468
469
impl FontWrite for VariationRegion {
470
0
    fn write_into(&self, writer: &mut TableWriter) {
471
0
        self.region_axes.write_into(writer);
472
0
    }
473
0
    fn table_type(&self) -> TableType {
474
0
        TableType::Named("VariationRegion")
475
0
    }
476
}
477
478
impl Validate for VariationRegion {
479
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
480
0
        ctx.in_table("VariationRegion", |ctx| {
481
0
            ctx.in_field("region_axes", |ctx| {
482
0
                if self.region_axes.len() > to_usize(u16::MAX) {
483
0
                    ctx.report("array exceeds max length");
484
0
                }
485
0
                self.region_axes.validate_impl(ctx);
486
0
            });
487
0
        })
488
0
    }
489
}
490
491
impl FromObjRef<read_fonts::tables::variations::VariationRegion<'_>> for VariationRegion {
492
0
    fn from_obj_ref(
493
0
        obj: &read_fonts::tables::variations::VariationRegion,
494
0
        offset_data: FontData,
495
0
    ) -> Self {
496
0
        VariationRegion {
497
0
            region_axes: obj.region_axes().to_owned_obj(offset_data),
498
0
        }
499
0
    }
500
}
501
502
/// The [RegionAxisCoordinates](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#variation-regions) record
503
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
504
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
505
pub struct RegionAxisCoordinates {
506
    /// The region start coordinate value for the current axis.
507
    pub start_coord: F2Dot14,
508
    /// The region peak coordinate value for the current axis.
509
    pub peak_coord: F2Dot14,
510
    /// The region end coordinate value for the current axis.
511
    pub end_coord: F2Dot14,
512
}
513
514
impl RegionAxisCoordinates {
515
    /// Construct a new `RegionAxisCoordinates`
516
0
    pub fn new(start_coord: F2Dot14, peak_coord: F2Dot14, end_coord: F2Dot14) -> Self {
517
0
        Self {
518
0
            start_coord,
519
0
            peak_coord,
520
0
            end_coord,
521
0
        }
522
0
    }
523
}
524
525
impl FontWrite for RegionAxisCoordinates {
526
0
    fn write_into(&self, writer: &mut TableWriter) {
527
0
        self.start_coord.write_into(writer);
528
0
        self.peak_coord.write_into(writer);
529
0
        self.end_coord.write_into(writer);
530
0
    }
531
0
    fn table_type(&self) -> TableType {
532
0
        TableType::Named("RegionAxisCoordinates")
533
0
    }
534
}
535
536
impl Validate for RegionAxisCoordinates {
537
0
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
538
}
539
540
impl FromObjRef<read_fonts::tables::variations::RegionAxisCoordinates> for RegionAxisCoordinates {
541
0
    fn from_obj_ref(
542
0
        obj: &read_fonts::tables::variations::RegionAxisCoordinates,
543
0
        _: FontData,
544
0
    ) -> Self {
545
0
        RegionAxisCoordinates {
546
0
            start_coord: obj.start_coord(),
547
0
            peak_coord: obj.peak_coord(),
548
0
            end_coord: obj.end_coord(),
549
0
        }
550
0
    }
551
}
552
553
/// The [ItemVariationStore](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#item-variation-store-header-and-item-variation-data-subtables) table
554
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
555
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
556
pub struct ItemVariationStore {
557
    /// Offset in bytes from the start of the item variation store to
558
    /// the variation region list.
559
    pub variation_region_list: OffsetMarker<VariationRegionList, WIDTH_32>,
560
    /// Offsets in bytes from the start of the item variation store to
561
    /// each item variation data subtable.
562
    pub item_variation_data: Vec<NullableOffsetMarker<ItemVariationData, WIDTH_32>>,
563
}
564
565
impl ItemVariationStore {
566
    /// Construct a new `ItemVariationStore`
567
0
    pub fn new(
568
0
        variation_region_list: VariationRegionList,
569
0
        item_variation_data: Vec<Option<ItemVariationData>>,
570
0
    ) -> Self {
571
0
        Self {
572
0
            variation_region_list: variation_region_list.into(),
573
0
            item_variation_data: item_variation_data.into_iter().map(Into::into).collect(),
574
0
        }
575
0
    }
576
}
577
578
impl FontWrite for ItemVariationStore {
579
    #[allow(clippy::unnecessary_cast)]
580
0
    fn write_into(&self, writer: &mut TableWriter) {
581
0
        (1 as u16).write_into(writer);
582
0
        self.variation_region_list.write_into(writer);
583
0
        (u16::try_from(array_len(&self.item_variation_data)).unwrap()).write_into(writer);
584
0
        self.item_variation_data.write_into(writer);
585
0
    }
586
0
    fn table_type(&self) -> TableType {
587
0
        TableType::Named("ItemVariationStore")
588
0
    }
589
}
590
591
impl Validate for ItemVariationStore {
592
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
593
0
        ctx.in_table("ItemVariationStore", |ctx| {
594
0
            ctx.in_field("variation_region_list", |ctx| {
595
0
                self.variation_region_list.validate_impl(ctx);
596
0
            });
597
0
            ctx.in_field("item_variation_data", |ctx| {
598
0
                if self.item_variation_data.len() > to_usize(u16::MAX) {
599
0
                    ctx.report("array exceeds max length");
600
0
                }
601
0
                self.item_variation_data.validate_impl(ctx);
602
0
            });
603
0
        })
604
0
    }
605
}
606
607
impl<'a> FromObjRef<read_fonts::tables::variations::ItemVariationStore<'a>> for ItemVariationStore {
608
0
    fn from_obj_ref(
609
0
        obj: &read_fonts::tables::variations::ItemVariationStore<'a>,
610
0
        _: FontData,
611
0
    ) -> Self {
612
0
        ItemVariationStore {
613
0
            variation_region_list: obj.variation_region_list().to_owned_table(),
614
0
            item_variation_data: obj.item_variation_data().to_owned_table(),
615
0
        }
616
0
    }
617
}
618
619
#[allow(clippy::needless_lifetimes)]
620
impl<'a> FromTableRef<read_fonts::tables::variations::ItemVariationStore<'a>>
621
    for ItemVariationStore
622
{
623
}
624
625
impl ReadArgs for ItemVariationStore {
626
    type Args = ();
627
}
628
629
impl<'a> FontRead<'a> for ItemVariationStore {
630
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
631
0
        <read_fonts::tables::variations::ItemVariationStore as FontRead>::read(data)
632
0
            .map(|x| x.to_owned_table())
633
0
    }
634
}
635
636
/// The [ItemVariationData](https://learn.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#item-variation-store-header-and-item-variation-data-subtables) subtable
637
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
638
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
639
pub struct ItemVariationData {
640
    /// The number of delta sets for distinct items.
641
    pub item_count: u16,
642
    /// A packed field: the high bit is a flag—see details below.
643
    pub word_delta_count: u16,
644
    /// Array of indices into the variation region list for the regions
645
    /// referenced by this item variation data table.
646
    pub region_indexes: Vec<u16>,
647
    /// Delta-set rows.
648
    pub delta_sets: Vec<u8>,
649
}
650
651
impl ItemVariationData {
652
    /// Construct a new `ItemVariationData`
653
0
    pub fn new(
654
0
        item_count: u16,
655
0
        word_delta_count: u16,
656
0
        region_indexes: Vec<u16>,
657
0
        delta_sets: Vec<u8>,
658
0
    ) -> Self {
659
0
        Self {
660
0
            item_count,
661
0
            word_delta_count,
662
0
            region_indexes,
663
0
            delta_sets,
664
0
        }
665
0
    }
666
}
667
668
impl FontWrite for ItemVariationData {
669
    #[allow(clippy::unnecessary_cast)]
670
0
    fn write_into(&self, writer: &mut TableWriter) {
671
0
        self.item_count.write_into(writer);
672
0
        self.word_delta_count.write_into(writer);
673
0
        (u16::try_from(array_len(&self.region_indexes)).unwrap()).write_into(writer);
674
0
        self.region_indexes.write_into(writer);
675
0
        self.delta_sets.write_into(writer);
676
0
    }
677
0
    fn table_type(&self) -> TableType {
678
0
        TableType::Named("ItemVariationData")
679
0
    }
680
}
681
682
impl Validate for ItemVariationData {
683
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
684
0
        ctx.in_table("ItemVariationData", |ctx| {
685
0
            ctx.in_field("region_indexes", |ctx| {
686
0
                if self.region_indexes.len() > to_usize(u16::MAX) {
687
0
                    ctx.report("array exceeds max length");
688
0
                }
689
0
            });
690
0
        })
691
0
    }
692
}
693
694
impl<'a> FromObjRef<read_fonts::tables::variations::ItemVariationData<'a>> for ItemVariationData {
695
0
    fn from_obj_ref(
696
0
        obj: &read_fonts::tables::variations::ItemVariationData<'a>,
697
0
        _: FontData,
698
0
    ) -> Self {
699
0
        let offset_data = obj.offset_data();
700
0
        ItemVariationData {
701
0
            item_count: obj.item_count(),
702
0
            word_delta_count: obj.word_delta_count(),
703
0
            region_indexes: obj.region_indexes().to_owned_obj(offset_data),
704
0
            delta_sets: obj.delta_sets().to_owned_obj(offset_data),
705
0
        }
706
0
    }
707
}
708
709
#[allow(clippy::needless_lifetimes)]
710
impl<'a> FromTableRef<read_fonts::tables::variations::ItemVariationData<'a>> for ItemVariationData {}
711
712
impl ReadArgs for ItemVariationData {
713
    type Args = ();
714
}
715
716
impl<'a> FontRead<'a> for ItemVariationData {
717
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
718
0
        <read_fonts::tables::variations::ItemVariationData as FontRead>::read(data)
719
0
            .map(|x| x.to_owned_table())
720
0
    }
721
}