Coverage Report

Created: 2025-07-23 06:50

/src/fontations/write-fonts/generated/generated_avar.rs
Line
Count
Source (jump to first uncovered line)
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 [avar (Axis Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/avar) table
9
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11
pub struct Avar {
12
    /// The segment maps array — one segment map for each axis, in the order of axes specified in the 'fvar' table.
13
    pub axis_segment_maps: Vec<SegmentMaps>,
14
    /// Offset to DeltaSetIndexMap table (may be NULL).
15
    pub axis_index_map: NullableOffsetMarker<DeltaSetIndexMap, WIDTH_32>,
16
    /// Offset to ItemVariationStore (may be NULL).
17
    pub var_store: NullableOffsetMarker<ItemVariationStore, WIDTH_32>,
18
}
19
20
impl Avar {
21
    /// Construct a new `Avar`
22
0
    pub fn new(axis_segment_maps: Vec<SegmentMaps>) -> Self {
23
0
        Self {
24
0
            axis_segment_maps,
25
0
            ..Default::default()
26
0
        }
27
0
    }
28
}
29
30
impl FontWrite for Avar {
31
    #[allow(clippy::unnecessary_cast)]
32
0
    fn write_into(&self, writer: &mut TableWriter) {
33
0
        let version = self.compute_version() as MajorMinor;
34
0
        version.write_into(writer);
35
0
        (0 as u16).write_into(writer);
36
0
        (u16::try_from(array_len(&self.axis_segment_maps)).unwrap()).write_into(writer);
37
0
        self.axis_segment_maps.write_into(writer);
38
0
        version
39
0
            .compatible((2u16, 0u16))
40
0
            .then(|| self.axis_index_map.write_into(writer));
41
0
        version
42
0
            .compatible((2u16, 0u16))
43
0
            .then(|| self.var_store.write_into(writer));
44
0
    }
45
0
    fn table_type(&self) -> TableType {
46
0
        TableType::TopLevel(Avar::TAG)
47
0
    }
48
}
49
50
impl Validate for Avar {
51
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
52
0
        ctx.in_table("Avar", |ctx| {
53
0
            ctx.in_field("axis_segment_maps", |ctx| {
54
0
                if self.axis_segment_maps.len() > (u16::MAX as usize) {
55
0
                    ctx.report("array exceeds max length");
56
0
                }
57
0
                self.axis_segment_maps.validate_impl(ctx);
58
0
            });
59
0
            ctx.in_field("axis_index_map", |ctx| {
60
0
                self.axis_index_map.validate_impl(ctx);
61
0
            });
62
0
            ctx.in_field("var_store", |ctx| {
63
0
                self.var_store.validate_impl(ctx);
64
0
            });
65
0
        })
66
0
    }
67
}
68
69
impl TopLevelTable for Avar {
70
    const TAG: Tag = Tag::new(b"avar");
71
}
72
73
impl<'a> FromObjRef<read_fonts::tables::avar::Avar<'a>> for Avar {
74
0
    fn from_obj_ref(obj: &read_fonts::tables::avar::Avar<'a>, _: FontData) -> Self {
75
0
        let offset_data = obj.offset_data();
76
0
        Avar {
77
0
            axis_segment_maps: obj
78
0
                .axis_segment_maps()
79
0
                .iter()
80
0
                .filter_map(|x| x.map(|x| FromObjRef::from_obj_ref(&x, offset_data)).ok())
81
0
                .collect(),
82
0
            axis_index_map: obj.axis_index_map().to_owned_table(),
83
0
            var_store: obj.var_store().to_owned_table(),
84
0
        }
85
0
    }
86
}
87
88
#[allow(clippy::needless_lifetimes)]
89
impl<'a> FromTableRef<read_fonts::tables::avar::Avar<'a>> for Avar {}
90
91
impl<'a> FontRead<'a> for Avar {
92
0
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
93
0
        <read_fonts::tables::avar::Avar as FontRead>::read(data).map(|x| x.to_owned_table())
94
0
    }
95
}
96
97
/// [SegmentMaps](https://learn.microsoft.com/en-us/typography/opentype/spec/avar#table-formats) record
98
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
99
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
100
pub struct SegmentMaps {
101
    /// The array of axis value map records for this axis.
102
    pub axis_value_maps: Vec<AxisValueMap>,
103
}
104
105
impl SegmentMaps {
106
    /// Construct a new `SegmentMaps`
107
0
    pub fn new(axis_value_maps: Vec<AxisValueMap>) -> Self {
108
0
        Self { axis_value_maps }
109
0
    }
110
}
111
112
impl FontWrite for SegmentMaps {
113
    #[allow(clippy::unnecessary_cast)]
114
0
    fn write_into(&self, writer: &mut TableWriter) {
115
0
        (u16::try_from(array_len(&self.axis_value_maps)).unwrap()).write_into(writer);
116
0
        self.axis_value_maps.write_into(writer);
117
0
    }
118
0
    fn table_type(&self) -> TableType {
119
0
        TableType::Named("SegmentMaps")
120
0
    }
121
}
122
123
impl Validate for SegmentMaps {
124
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
125
0
        ctx.in_table("SegmentMaps", |ctx| {
126
0
            ctx.in_field("axis_value_maps", |ctx| {
127
0
                if self.axis_value_maps.len() > (u16::MAX as usize) {
128
0
                    ctx.report("array exceeds max length");
129
0
                }
130
0
                self.axis_value_maps.validate_impl(ctx);
131
0
            });
132
0
        })
133
0
    }
134
}
135
136
impl FromObjRef<read_fonts::tables::avar::SegmentMaps<'_>> for SegmentMaps {
137
0
    fn from_obj_ref(obj: &read_fonts::tables::avar::SegmentMaps, offset_data: FontData) -> Self {
138
0
        SegmentMaps {
139
0
            axis_value_maps: obj.axis_value_maps().to_owned_obj(offset_data),
140
0
        }
141
0
    }
142
}
143
144
/// [AxisValueMap](https://learn.microsoft.com/en-us/typography/opentype/spec/avar#table-formats) record
145
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
146
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
147
pub struct AxisValueMap {
148
    /// A normalized coordinate value obtained using default normalization.
149
    pub from_coordinate: F2Dot14,
150
    /// The modified, normalized coordinate value.
151
    pub to_coordinate: F2Dot14,
152
}
153
154
impl AxisValueMap {
155
    /// Construct a new `AxisValueMap`
156
0
    pub fn new(from_coordinate: F2Dot14, to_coordinate: F2Dot14) -> Self {
157
0
        Self {
158
0
            from_coordinate,
159
0
            to_coordinate,
160
0
        }
161
0
    }
162
}
163
164
impl FontWrite for AxisValueMap {
165
0
    fn write_into(&self, writer: &mut TableWriter) {
166
0
        self.from_coordinate.write_into(writer);
167
0
        self.to_coordinate.write_into(writer);
168
0
    }
169
0
    fn table_type(&self) -> TableType {
170
0
        TableType::Named("AxisValueMap")
171
0
    }
172
}
173
174
impl Validate for AxisValueMap {
175
0
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
176
}
177
178
impl FromObjRef<read_fonts::tables::avar::AxisValueMap> for AxisValueMap {
179
0
    fn from_obj_ref(obj: &read_fonts::tables::avar::AxisValueMap, _: FontData) -> Self {
180
0
        AxisValueMap {
181
0
            from_coordinate: obj.from_coordinate(),
182
0
            to_coordinate: obj.to_coordinate(),
183
0
        }
184
0
    }
185
}