1//! Load and use fonts.
2use std::hash::Hash;
34/// A font.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
6pub struct Font {
7/// The [`Family`] of the [`Font`].
8pub family: Family,
9/// The [`Weight`] of the [`Font`].
10pub weight: Weight,
11/// The [`Stretch`] of the [`Font`].
12pub stretch: Stretch,
13/// The [`Style`] of the [`Font`].
14pub style: Style,
15}
1617impl Font {
18/// A non-monospaced sans-serif font with normal [`Weight`].
19pub const DEFAULT: Font = Font {
20 family: Family::SansSerif,
21 weight: Weight::Normal,
22 stretch: Stretch::Normal,
23 style: Style::Normal,
24 };
2526/// A monospaced font with normal [`Weight`].
27pub const MONOSPACE: Font = Font {
28 family: Family::Monospace,
29 ..Self::DEFAULT
30 };
3132/// Creates a non-monospaced [`Font`] with the given [`Family::Name`] and
33 /// normal [`Weight`].
34pub const fn with_name(name: &'static str) -> Self {
35 Font {
36 family: Family::Name(name),
37 ..Self::DEFAULT
38 }
39 }
40}
4142/// A font family.
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
44pub enum Family {
45/// The name of a font family of choice.
46Name(&'static str),
4748/// Serif fonts represent the formal text style for a script.
49Serif,
5051/// Glyphs in sans-serif fonts, as the term is used in CSS, are generally low
52 /// contrast and have stroke endings that are plain — without any flaring,
53 /// cross stroke, or other ornamentation.
54#[default]
55SansSerif,
5657/// Glyphs in cursive fonts generally use a more informal script style, and
58 /// the result looks more like handwritten pen or brush writing than printed
59 /// letterwork.
60Cursive,
6162/// Fantasy fonts are primarily decorative or expressive fonts that contain
63 /// decorative or expressive representations of characters.
64Fantasy,
6566/// The sole criterion of a monospace font is that all glyphs have the same
67 /// fixed width.
68Monospace,
69}
7071/// The weight of some text.
72#[allow(missing_docs)]
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
74#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
75pub enum Weight {
76 Thin,
77 ExtraLight,
78 Light,
79#[default]
80Normal,
81 Medium,
82 Semibold,
83 Bold,
84 ExtraBold,
85 Black,
86}
8788/// The width of some text.
89#[allow(missing_docs)]
90#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
91#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
92pub enum Stretch {
93 UltraCondensed,
94 ExtraCondensed,
95 Condensed,
96 SemiCondensed,
97#[default]
98Normal,
99 SemiExpanded,
100 Expanded,
101 ExtraExpanded,
102 UltraExpanded,
103}
104105/// The style of some text.
106#[allow(missing_docs)]
107#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
108#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
109pub enum Style {
110#[default]
111Normal,
112 Italic,
113 Oblique,
114}