Overhaul Font type to allow font family selection

This commit is contained in:
Héctor Ramón Jiménez 2023-02-04 07:33:33 +01:00
parent a7580e0696
commit b29de28d1f
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
25 changed files with 147 additions and 256 deletions

View file

@ -1,40 +1,29 @@
use std::hash::{Hash, Hasher};
use std::hash::Hash;
/// A font.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Font {
/// The default font.
///
/// This is normally a font configured in a renderer or loaded from the
/// system.
Default,
/// The name of a font family of choice.
Name(&'static str),
/// An external font.
External {
/// The name of the external font
name: &'static str,
/// Serif fonts represent the formal text style for a script.
Serif,
/// The bytes of the external font
bytes: &'static [u8],
},
}
impl Default for Font {
fn default() -> Font {
Font::Default
}
}
impl Hash for Font {
fn hash<H: Hasher>(&self, hasher: &mut H) {
match self {
Self::Default => {
0.hash(hasher);
}
Self::External { name, .. } => {
1.hash(hasher);
name.hash(hasher);
}
}
}
/// Glyphs in sans-serif fonts, as the term is used in CSS, are generally low
/// contrast and have stroke endings that are plain — without any flaring,
/// cross stroke, or other ornamentation.
SansSerif,
/// Glyphs in cursive fonts generally use a more informal script style, and
/// the result looks more like handwritten pen or brush writing than printed
/// letterwork.
Cursive,
/// Fantasy fonts are primarily decorative or expressive fonts that contain
/// decorative or expressive representations of characters.
Fantasy,
/// The sole criterion of a monospace font is that all glyphs have the same
/// fixed width.
Monospace,
}