Coverage Report

Created: 2026-04-01 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fontations/write-fonts/src/tables/gdef.rs
Line
Count
Source
1
//! the [GDEF] table
2
//!
3
//! [GDEF]: https://docs.microsoft.com/en-us/typography/opentype/spec/gdef
4
5
use types::MajorMinor;
6
7
use crate::tables::layout::VariationIndex;
8
9
use super::{
10
    layout::{ClassDef, CoverageTable, DeviceOrVariationIndex},
11
    variations::{
12
        common_builder::RemapVarStore, ivs_builder::VariationIndexRemapping, ItemVariationStore,
13
    },
14
};
15
16
include!("../../generated/generated_gdef.rs");
17
18
impl Gdef {
19
0
    fn compute_version(&self) -> MajorMinor {
20
0
        if self.item_var_store.is_some() {
21
0
            MajorMinor::VERSION_1_3
22
0
        } else if self.mark_glyph_sets_def.is_some() {
23
0
            MajorMinor::VERSION_1_2
24
        } else {
25
0
            MajorMinor::VERSION_1_0
26
        }
27
0
    }
28
}
29
30
impl RemapVarStore<VariationIndex> for Gdef {
31
0
    fn remap_variation_indices(&mut self, key_map: &VariationIndexRemapping) {
32
0
        if let Some(ligs) = self.lig_caret_list.as_mut() {
33
0
            ligs.remap_variation_indices(key_map);
34
0
        }
35
0
    }
36
}
37
38
impl RemapVarStore<VariationIndex> for LigCaretList {
39
0
    fn remap_variation_indices(&mut self, key_map: &VariationIndexRemapping) {
40
0
        self.lig_glyphs.iter_mut().for_each(|lig| {
41
0
            lig.caret_values
42
0
                .iter_mut()
43
0
                .for_each(|caret| caret.remap_variation_indices(key_map))
44
0
        })
45
0
    }
46
}
47
48
impl RemapVarStore<VariationIndex> for CaretValue {
49
0
    fn remap_variation_indices(&mut self, key_map: &VariationIndexRemapping) {
50
0
        if let CaretValue::Format3(table) = self {
51
0
            table.remap_variation_indices(key_map)
52
0
        }
53
0
    }
54
}
55
56
impl RemapVarStore<VariationIndex> for CaretValueFormat3 {
57
0
    fn remap_variation_indices(&mut self, key_map: &VariationIndexRemapping) {
58
0
        self.device.remap_variation_indices(key_map)
59
0
    }
60
}
61
62
#[cfg(test)]
63
mod tests {
64
    use super::*;
65
66
    #[test]
67
    fn var_store_without_glyph_sets() {
68
        // this should compile, and version should be 1.3
69
        let gdef = Gdef {
70
            item_var_store: ItemVariationStore::default().into(),
71
            ..Default::default()
72
        };
73
74
        assert_eq!(gdef.compute_version(), MajorMinor::VERSION_1_3);
75
        let _dumped = crate::write::dump_table(&gdef).unwrap();
76
        let data = FontData::new(&_dumped);
77
        let loaded = read_fonts::tables::gdef::Gdef::read(data).unwrap();
78
79
        assert_eq!(loaded.version(), MajorMinor::VERSION_1_3);
80
        assert!(!loaded.item_var_store_offset().unwrap().is_null());
81
    }
82
}