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
}
}