1
//! `gdef` font table utilities.
2
//!
3
//! <https://docs.microsoft.com/en-us/typography/opentype/spec/gdef>
4

            
5
use crate::layout::GDEFTable;
6

            
7
pub const GLYPH_CLASS_NONE: u16 = 0;
8
pub const GLYPH_CLASS_BASE: u16 = 1;
9
pub const GLYPH_CLASS_LIGATURE: u16 = 2;
10
pub const GLYPH_CLASS_MARK: u16 = 3;
11
pub const GLYPH_CLASS_COMPONENT: u16 = 4;
12

            
13
215892
pub fn gdef_is_mark(opt_gdef_table: Option<&GDEFTable>, glyph_index: u16) -> bool {
14
215892
    glyph_class(opt_gdef_table, glyph_index) == GLYPH_CLASS_MARK
15
215892
}
16

            
17
582822
pub fn glyph_class(opt_gdef_table: Option<&GDEFTable>, glyph: u16) -> u16 {
18
582822
    opt_gdef_table
19
582822
        .and_then(|gdef| gdef.opt_glyph_classdef.as_ref())
20
582822
        .map(|glyph_classdef| glyph_classdef.glyph_class_value(glyph))
21
582822
        .unwrap_or(GLYPH_CLASS_NONE)
22
582822
}
23

            
24
337230
pub fn mark_attach_class(opt_gdef_table: Option<&GDEFTable>, glyph: u16) -> u16 {
25
337230
    opt_gdef_table
26
337230
        .and_then(|gdef| gdef.opt_mark_attach_classdef.as_ref())
27
337230
        .map(|mark_attach_classdef| mark_attach_classdef.glyph_class_value(glyph))
28
337230
        .unwrap_or(GLYPH_CLASS_NONE)
29
337230
}
30

            
31
pub fn glyph_is_mark_in_set(opt_gdef_table: Option<&GDEFTable>, glyph: u16, index: usize) -> bool {
32
    gdef_is_mark(opt_gdef_table, glyph)
33
        && opt_gdef_table
34
            .and_then(|gdef| gdef.opt_mark_glyph_sets.as_ref())
35
            .and_then(|mark_glyph_sets| mark_glyph_sets.get(index))
36
            .is_some_and(|mark_set| mark_set.glyph_coverage_value(glyph).is_some())
37
}