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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct FontFamily(FontFamilyInner);
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[doc(hidden)]
#[non_exhaustive]
pub enum FontFamilyInner {
Serif,
SansSerif,
Monospace,
SystemUi,
Named(Arc<str>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FontWeight(u16);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FontStyle {
Regular,
Italic,
}
impl FontFamily {
pub const SANS_SERIF: FontFamily = FontFamily(FontFamilyInner::SansSerif);
pub const SERIF: FontFamily = FontFamily(FontFamilyInner::Serif);
pub const SYSTEM_UI: FontFamily = FontFamily(FontFamilyInner::SystemUi);
pub const MONOSPACE: FontFamily = FontFamily(FontFamilyInner::Monospace);
pub fn new_unchecked(s: impl Into<Arc<str>>) -> Self {
FontFamily(FontFamilyInner::Named(s.into()))
}
pub fn name(&self) -> &str {
match &self.0 {
FontFamilyInner::Serif => "serif",
FontFamilyInner::SansSerif => "sans-serif",
FontFamilyInner::SystemUi => "system-ui",
FontFamilyInner::Monospace => "monospace",
FontFamilyInner::Named(s) => &s,
}
}
pub fn is_generic(&self) -> bool {
!matches!(self.0, FontFamilyInner::Named(_))
}
#[doc(hidden)]
pub fn inner(&self) -> &FontFamilyInner {
&self.0
}
}
impl FontWeight {
pub const THIN: FontWeight = FontWeight(100);
pub const HAIRLINE: FontWeight = FontWeight::THIN;
pub const EXTRA_LIGHT: FontWeight = FontWeight(200);
pub const LIGHT: FontWeight = FontWeight(300);
pub const REGULAR: FontWeight = FontWeight(400);
pub const NORMAL: FontWeight = FontWeight::REGULAR;
pub const MEDIUM: FontWeight = FontWeight(500);
pub const SEMI_BOLD: FontWeight = FontWeight(600);
pub const BOLD: FontWeight = FontWeight(700);
pub const EXTRA_BOLD: FontWeight = FontWeight(800);
pub const BLACK: FontWeight = FontWeight(900);
pub const HEAVY: FontWeight = FontWeight::BLACK;
pub const EXTRA_BLACK: FontWeight = FontWeight(950);
pub fn new(raw: u16) -> FontWeight {
let raw = raw.min(1000).max(1);
FontWeight(raw)
}
pub const fn to_raw(self) -> u16 {
self.0
}
}
impl Default for FontFamily {
fn default() -> Self {
FontFamily::SYSTEM_UI
}
}
impl Default for FontWeight {
fn default() -> Self {
FontWeight::REGULAR
}
}
impl Default for FontStyle {
fn default() -> Self {
FontStyle::Regular
}
}