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