Skip to main content

freya_core/style/
font_slant.rs

1use freya_engine::prelude::Slant as SkSlant;
2
3/// Slant (style) of a font.
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)]
6pub enum FontSlant {
7    /// Regular, non-slanted text. This is the default.
8    #[default]
9    Upright = 0,
10    /// Italic text, using the font's dedicated italic glyphs.
11    Italic = 1,
12    /// Oblique text, a slanted version of the upright glyphs.
13    Oblique = 2,
14}
15
16impl FontSlant {
17    pub fn pretty(&self) -> String {
18        match self {
19            Self::Upright => "Upright".to_string(),
20            Self::Italic => "Italic".to_string(),
21            Self::Oblique => "Oblique".to_string(),
22        }
23    }
24}
25
26impl From<FontSlant> for SkSlant {
27    fn from(value: FontSlant) -> Self {
28        match value {
29            FontSlant::Italic => SkSlant::Italic,
30            FontSlant::Oblique => SkSlant::Oblique,
31            FontSlant::Upright => SkSlant::Upright,
32        }
33    }
34}