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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Font technologies for the `tech()` hint on a CSS `@font-face` `src`
//! descriptor.
/// A font technology, as named by the `tech()` hint of a CSS `@font-face`
/// `src` descriptor.
///
/// Displays as the CSS technology keyword used inside `tech(...)`
/// (`color-colrv1`, `features-opentype`, `variations`, ...).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FontTech {
/// Color bitmap data tables, CSS `color-cbdt`.
ColorCbdt,
/// Multi-colored glyphs via COLR version 0 table, CSS `color-colrv0`.
ColorColrV0,
/// Multi-colored glyphs via COLR version 1 table, CSS `color-colrv1`.
ColorColrV1,
/// Standard bitmap graphics tables, CSS `color-sbix`.
ColorSbix,
/// SVG multi-colored tables, CSS `color-svg`.
ColorSvg,
/// TrueType `morx` and `kerx` tables, CSS `features-aat`.
FeaturesAat,
/// Graphite features, namely `Silf`, `Glat`, `Gloc`, `Feat`, and `Sill`
/// tables, CSS `features-graphite`.
FeaturesGraphite,
/// OpenType `GSUB` and `GPOS` tables, CSS `features-opentype`.
FeaturesOpenType,
/// Incremental font loading, CSS `incremental`.
Incremental,
/// Font palettes by means of `font-palette` to select one of many color
/// palettes in the font, CSS `palettes`.
Palettes,
/// Font variations in TrueType and OpenType fonts to control the font axis,
/// weight, glyphs, etc., CSS `variations`.
Variations,
}
impl FontTech {
/// The CSS technology keyword for this technology, as written inside
/// `tech(...)`.
#[must_use]
pub const fn keyword(self) -> &'static str {
match self {
Self::ColorCbdt => "color-cbdt",
Self::ColorColrV0 => "color-colrv0",
Self::ColorColrV1 => "color-colrv1",
Self::ColorSbix => "color-sbix",
Self::ColorSvg => "color-svg",
Self::FeaturesAat => "features-aat",
Self::FeaturesGraphite => "features-graphite",
Self::FeaturesOpenType => "features-opentype",
Self::Incremental => "incremental",
Self::Palettes => "palettes",
Self::Variations => "variations",
}
}
/// The technology named by the given CSS `tech(...)` keyword, if the
/// keyword names a known technology.
#[must_use]
pub fn from_keyword(keyword: &str) -> Option<Self> {
Some(match keyword {
"color-cbdt" => Self::ColorCbdt,
"color-colrv0" => Self::ColorColrV0,
"color-colrv1" => Self::ColorColrV1,
"color-sbix" => Self::ColorSbix,
"color-svg" => Self::ColorSvg,
"features-aat" => Self::FeaturesAat,
"features-graphite" => Self::FeaturesGraphite,
"features-opentype" => Self::FeaturesOpenType,
"incremental" => Self::Incremental,
"palettes" => Self::Palettes,
"variations" => Self::Variations,
_ => return None,
})
}
/// Folds this technology into a running content hash.
pub(crate) const fn hash(
self,
h: topcoat_core::fnv1a::Fnv1a<u64>,
) -> topcoat_core::fnv1a::Fnv1a<u64> {
h.write(self.keyword().as_bytes())
}
}
impl std::fmt::Display for FontTech {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.keyword())
}
}