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_avar.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 [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() > to_usize(u16::MAX) {
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
        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
        }
85
0
    }
86
}
87
88
#[allow(clippy::needless_lifetimes)]
89
impl<'a> FromTableRef<read_fonts::tables::avar::Avar<'a>> for Avar {}
90
91
impl ReadArgs for Avar {
92
    type Args = ();
93
}
94
95
impl<'a> FontRead<'a> for Avar {
96
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
97
0
        <read_fonts::tables::avar::Avar as FontRead>::read(data).map(|x| x.to_owned_table())
98
0
    }
99
}
100
101
/// [SegmentMaps](https://learn.microsoft.com/en-us/typography/opentype/spec/avar#table-formats) record
102
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
103
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
104
pub struct SegmentMaps {
105
    /// The array of axis value map records for this axis.
106
    pub axis_value_maps: Vec<AxisValueMap>,
107
}
108
109
impl SegmentMaps {
110
    /// Construct a new `SegmentMaps`
111
0
    pub fn new(axis_value_maps: Vec<AxisValueMap>) -> Self {
112
0
        Self { axis_value_maps }
113
0
    }
114
}
115
116
impl FontWrite for SegmentMaps {
117
    #[allow(clippy::unnecessary_cast)]
118
0
    fn write_into(&self, writer: &mut TableWriter) {
119
0
        (u16::try_from(array_len(&self.axis_value_maps)).unwrap()).write_into(writer);
120
0
        self.axis_value_maps.write_into(writer);
121
0
    }
122
0
    fn table_type(&self) -> TableType {
123
0
        TableType::Named("SegmentMaps")
124
0
    }
125
}
126
127
impl Validate for SegmentMaps {
128
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
129
0
        ctx.in_table("SegmentMaps", |ctx| {
130
0
            ctx.in_field("axis_value_maps", |ctx| {
131
0
                if self.axis_value_maps.len() > to_usize(u16::MAX) {
132
0
                    ctx.report("array exceeds max length");
133
0
                }
134
0
                self.axis_value_maps.validate_impl(ctx);
135
0
            });
136
0
        })
137
0
    }
138
}
139
140
impl FromObjRef<read_fonts::tables::avar::SegmentMaps<'_>> for SegmentMaps {
141
0
    fn from_obj_ref(obj: &read_fonts::tables::avar::SegmentMaps, offset_data: FontData) -> Self {
142
0
        SegmentMaps {
143
0
            axis_value_maps: obj.axis_value_maps().to_owned_obj(offset_data),
144
0
        }
145
0
    }
146
}
147
148
/// [AxisValueMap](https://learn.microsoft.com/en-us/typography/opentype/spec/avar#table-formats) record
149
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
150
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
151
pub struct AxisValueMap {
152
    /// A normalized coordinate value obtained using default normalization.
153
    pub from_coordinate: F2Dot14,
154
    /// The modified, normalized coordinate value.
155
    pub to_coordinate: F2Dot14,
156
}
157
158
impl AxisValueMap {
159
    /// Construct a new `AxisValueMap`
160
0
    pub fn new(from_coordinate: F2Dot14, to_coordinate: F2Dot14) -> Self {
161
0
        Self {
162
0
            from_coordinate,
163
0
            to_coordinate,
164
0
        }
165
0
    }
166
}
167
168
impl FontWrite for AxisValueMap {
169
0
    fn write_into(&self, writer: &mut TableWriter) {
170
0
        self.from_coordinate.write_into(writer);
171
0
        self.to_coordinate.write_into(writer);
172
0
    }
173
0
    fn table_type(&self) -> TableType {
174
0
        TableType::Named("AxisValueMap")
175
0
    }
176
}
177
178
impl Validate for AxisValueMap {
179
0
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
180
}
181
182
impl FromObjRef<read_fonts::tables::avar::AxisValueMap> for AxisValueMap {
183
0
    fn from_obj_ref(obj: &read_fonts::tables::avar::AxisValueMap, _: FontData) -> Self {
184
0
        AxisValueMap {
185
0
            from_coordinate: obj.from_coordinate(),
186
0
            to_coordinate: obj.to_coordinate(),
187
0
        }
188
0
    }
189
}