use crate::platform::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct Font {
pub family: String,
pub style: Style,
pub weight: Weight,
pub stretch: Stretch,
}
#[derive(Debug, Copy, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum Style {
#[default]
Normal,
Italic,
}
impl Style {
pub const fn value_for_italic(self) -> f32 {
match self {
Style::Normal => 0.0,
Style::Italic => 1.0,
}
}
}
#[derive(
Debug, Copy, Clone, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[serde(rename_all = "kebab-case")]
pub enum Weight {
Thin,
ExtraLight,
Light,
SemiLight,
#[default]
Normal,
Medium,
SemiBold,
Bold,
ExtraBold,
Black,
ExtraBlack,
}
impl Weight {
pub const fn value(self) -> f32 {
match self {
Weight::Thin => 100.0,
Weight::ExtraLight => 200.0,
Weight::Light => 300.0,
Weight::SemiLight => 350.0,
Weight::Normal => 400.0,
Weight::Medium => 500.0,
Weight::SemiBold => 600.0,
Weight::Bold => 700.0,
Weight::ExtraBold => 800.0,
Weight::Black => 900.0,
Weight::ExtraBlack => 950.0,
}
}
}
#[derive(Debug, Copy, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "kebab-case")]
pub enum Stretch {
UltraCondensed,
ExtraCondensed,
Condensed,
SemiCondensed,
#[default]
Normal,
SemiExpanded,
Expanded,
ExtraExpanded,
UltraExpanded,
}
impl Stretch {
pub const fn percentage(self) -> f32 {
match self {
Stretch::UltraCondensed => 50.0,
Stretch::ExtraCondensed => 62.5,
Stretch::Condensed => 75.0,
Stretch::SemiCondensed => 87.5,
Stretch::Normal => 100.0,
Stretch::SemiExpanded => 112.5,
Stretch::Expanded => 125.0,
Stretch::ExtraExpanded => 150.0,
Stretch::UltraExpanded => 200.0,
}
}
pub const fn factor(self) -> f32 {
match self {
Stretch::UltraCondensed => 0.5,
Stretch::ExtraCondensed => 0.625,
Stretch::Condensed => 0.75,
Stretch::SemiCondensed => 0.875,
Stretch::Normal => 1.0,
Stretch::SemiExpanded => 1.125,
Stretch::Expanded => 1.25,
Stretch::ExtraExpanded => 1.5,
Stretch::UltraExpanded => 2.0,
}
}
}