1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use postscript::{self, compact1::FontSet};
use truetype::tables::{
    CharacterMapping, FontHeader, GlyphData, GlyphMapping, HorizontalHeader, HorizontalMetrics,
    MaximumProfile, Names, PostScript, WindowsMetrics,
};
use truetype::{self, Tag};

use crate::tables::{
    ColorPalettes, FontVariations, GlyphDefinition, GlyphPositioning, GlyphSubstitution,
};

/// A type representing a font table.
pub trait Table {
    #[doc(hidden)]
    fn tag() -> Tag;
}

macro_rules! implement {
    ($($tag:expr => $type:ident,)+) => {
        $(impl Table for $type {
            #[inline]
            fn tag() -> Tag {
                Tag(*$tag)
            }
        })+
    };
}

implement! {
    b"CFF " => FontSet,
    b"CPAL" => ColorPalettes,
    b"GDEF" => GlyphDefinition,
    b"GPOS" => GlyphPositioning,
    b"GSUB" => GlyphSubstitution,
    b"OS/2" => WindowsMetrics,
    b"cmap" => CharacterMapping,
    b"fvar" => FontVariations,
    b"glyf" => GlyphData,
    b"head" => FontHeader,
    b"hhea" => HorizontalHeader,
    b"hmtx" => HorizontalMetrics,
    b"loca" => GlyphMapping,
    b"maxp" => MaximumProfile,
    b"name" => Names,
    b"post" => PostScript,
}