Merge pull request #2041 from lufte/issue-2040

Make the style attribute available on Font
This commit is contained in:
Héctor Ramón 2023-08-20 14:22:46 +02:00 committed by GitHub
commit 3bea1f703c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 2 deletions

View file

@ -10,6 +10,8 @@ pub struct Font {
pub weight: Weight, pub weight: Weight,
/// The [`Stretch`] of the [`Font`]. /// The [`Stretch`] of the [`Font`].
pub stretch: Stretch, pub stretch: Stretch,
/// The [`Style`] of the [`Font`].
pub style: Style,
/// Whether if the [`Font`] is monospaced or not. /// Whether if the [`Font`] is monospaced or not.
pub monospaced: bool, pub monospaced: bool,
} }
@ -20,6 +22,7 @@ impl Font {
family: Family::SansSerif, family: Family::SansSerif,
weight: Weight::Normal, weight: Weight::Normal,
stretch: Stretch::Normal, stretch: Stretch::Normal,
style: Style::Normal,
monospaced: false, monospaced: false,
}; };
@ -100,3 +103,13 @@ pub enum Stretch {
ExtraExpanded, ExtraExpanded,
UltraExpanded, UltraExpanded,
} }
/// The style of some text.
#[allow(missing_docs)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Style {
#[default]
Normal,
Italic,
Oblique,
}

View file

@ -233,6 +233,14 @@ fn to_stretch(stretch: font::Stretch) -> cosmic_text::Stretch {
} }
} }
fn to_style(style: font::Style) -> cosmic_text::Style {
match style {
font::Style::Normal => cosmic_text::Style::Normal,
font::Style::Italic => cosmic_text::Style::Italic,
font::Style::Oblique => cosmic_text::Style::Oblique,
}
}
fn to_shaping(shaping: Shaping) -> cosmic_text::Shaping { fn to_shaping(shaping: Shaping) -> cosmic_text::Shaping {
match shaping { match shaping {
Shaping::Basic => cosmic_text::Shaping::Basic, Shaping::Basic => cosmic_text::Shaping::Basic,
@ -411,7 +419,8 @@ impl Cache {
cosmic_text::Attrs::new() cosmic_text::Attrs::new()
.family(to_family(key.font.family)) .family(to_family(key.font.family))
.weight(to_weight(key.font.weight)) .weight(to_weight(key.font.weight))
.stretch(to_stretch(key.font.stretch)), .stretch(to_stretch(key.font.stretch))
.style(to_style(key.font.style)),
to_shaping(key.shaping), to_shaping(key.shaping),
); );

View file

@ -339,6 +339,14 @@ fn to_stretch(stretch: font::Stretch) -> glyphon::Stretch {
} }
} }
fn to_style(style: font::Style) -> glyphon::Style {
match style {
font::Style::Normal => glyphon::Style::Normal,
font::Style::Italic => glyphon::Style::Italic,
font::Style::Oblique => glyphon::Style::Oblique,
}
}
fn to_shaping(shaping: Shaping) -> glyphon::Shaping { fn to_shaping(shaping: Shaping) -> glyphon::Shaping {
match shaping { match shaping {
Shaping::Basic => glyphon::Shaping::Basic, Shaping::Basic => glyphon::Shaping::Basic,
@ -420,7 +428,8 @@ impl Cache {
glyphon::Attrs::new() glyphon::Attrs::new()
.family(to_family(key.font.family)) .family(to_family(key.font.family))
.weight(to_weight(key.font.weight)) .weight(to_weight(key.font.weight))
.stretch(to_stretch(key.font.stretch)), .stretch(to_stretch(key.font.stretch))
.style(to_style(key.font.style)),
to_shaping(key.shaping), to_shaping(key.shaping),
); );