write_fonts/tables/
avar.rs

1//! The [avar](https://learn.microsoft.com/en-us/typography/opentype/spec/avar) table
2
3use super::variations::{DeltaSetIndexMap, ItemVariationStore};
4
5include!("../../generated/generated_avar.rs");
6
7impl SegmentMaps {
8    /// Returns true if all the axis value maps are identity maps.
9    pub fn is_identity(&self) -> bool {
10        self.axis_value_maps
11            .iter()
12            .all(|av| av.from_coordinate == av.to_coordinate)
13    }
14}
15
16impl Avar {
17    fn compute_version(&self) -> MajorMinor {
18        if self.axis_index_map.is_some() || self.var_store.is_some() {
19            MajorMinor::VERSION_2_0
20        } else {
21            MajorMinor::VERSION_1_0
22        }
23    }
24}
25
26#[cfg(test)]
27mod tests {
28
29    use super::*;
30    use font_types::F2Dot14;
31
32    #[test]
33    fn test_is_identity() {
34        let mut segment_maps = SegmentMaps::default();
35
36        assert!(segment_maps.is_identity());
37
38        segment_maps.axis_value_maps.push(AxisValueMap {
39            from_coordinate: F2Dot14::from_f32(-1.0),
40            to_coordinate: F2Dot14::from_f32(-1.0),
41        });
42
43        assert!(segment_maps.is_identity());
44
45        segment_maps.axis_value_maps.push(AxisValueMap {
46            from_coordinate: F2Dot14::from_f32(0.0),
47            to_coordinate: F2Dot14::from_f32(0.0),
48        });
49        segment_maps.axis_value_maps.push(AxisValueMap {
50            from_coordinate: F2Dot14::from_f32(0.3),
51            to_coordinate: F2Dot14::from_f32(0.6),
52        });
53        segment_maps.axis_value_maps.push(AxisValueMap {
54            from_coordinate: F2Dot14::from_f32(1.0),
55            to_coordinate: F2Dot14::from_f32(1.0),
56        });
57
58        assert!(!segment_maps.is_identity());
59    }
60}