Skip to content

Commit

Permalink
Make the style attribute available on Font
Browse files Browse the repository at this point in the history
  • Loading branch information
lufte committed Aug 18, 2023
1 parent cb8b70b commit e863638
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
13 changes: 13 additions & 0 deletions core/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub struct Font {
pub weight: Weight,
/// The [`Stretch`] of the [`Font`].
pub stretch: Stretch,
/// The [`Style`] of the [`Font`].
pub style: Style,
/// Whether if the [`Font`] is monospaced or not.
pub monospaced: bool,
}
Expand All @@ -20,6 +22,7 @@ impl Font {
family: Family::SansSerif,
weight: Weight::Normal,
stretch: Stretch::Normal,
style: Style::Normal,
monospaced: false,
};

Expand Down Expand Up @@ -100,3 +103,13 @@ pub enum Stretch {
ExtraExpanded,
UltraExpanded,
}

/// The style of some text.
#[allow(missing_docs)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Style {
#[default]
Normal,
Italic,
Oblique,
}
11 changes: 10 additions & 1 deletion tiny_skia/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
match shaping {
Shaping::Basic => cosmic_text::Shaping::Basic,
Expand Down Expand Up @@ -411,7 +419,8 @@ impl Cache {
cosmic_text::Attrs::new()
.family(to_family(key.font.family))
.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),
);

Expand Down
11 changes: 10 additions & 1 deletion wgpu/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
match shaping {
Shaping::Basic => glyphon::Shaping::Basic,
Expand Down Expand Up @@ -420,7 +428,8 @@ impl Cache {
glyphon::Attrs::new()
.family(to_family(key.font.family))
.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),
);

Expand Down

0 comments on commit e863638

Please sign in to comment.