freya_core/style/
font_feature.rs1use std::borrow::Cow;
2
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[derive(Debug, PartialEq, Eq, Clone, Hash)]
10pub struct FontFeature {
11 pub name: Cow<'static, str>,
12 pub value: i32,
13}
14
15impl FontFeature {
16 pub const fn new(name: &'static str, value: i32) -> Self {
17 FontFeature {
18 name: Cow::Borrowed(name),
19 value,
20 }
21 }
22
23 pub const TABULAR_NUMBERS: Self = Self::new("tnum", 1);
25 pub const SMALL_CAPS: Self = Self::new("smcp", 1);
27 pub const SLASHED_ZERO: Self = Self::new("zero", 1);
29 pub const FRACTIONS: Self = Self::new("frac", 1);
31 pub const NO_LIGATURES: Self = Self::new("liga", 0);
33}
34
35impl From<&'static str> for FontFeature {
36 fn from(name: &'static str) -> Self {
37 Self::new(name, 1)
38 }
39}
40
41impl<T: Into<Cow<'static, str>>> From<(T, i32)> for FontFeature {
42 fn from((name, value): (T, i32)) -> Self {
43 FontFeature {
44 name: name.into(),
45 value,
46 }
47 }
48}