summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar lufte <javier@lufte.net>2023-08-18 18:46:22 -0300
committerLibravatar lufte <javier@lufte.net>2023-08-18 18:46:22 -0300
commite86363837d8e3a6241a90cb5b895034f07106059 (patch)
tree24852327d51460f8feec47cfe96c4f84604a14e3
parentcb8b70bec3e8bbf809e7d8ffc559adb712f45e14 (diff)
downloadiced-e86363837d8e3a6241a90cb5b895034f07106059.tar.gz
iced-e86363837d8e3a6241a90cb5b895034f07106059.tar.bz2
iced-e86363837d8e3a6241a90cb5b895034f07106059.zip
Make the style attribute available on Font
-rw-r--r--core/src/font.rs13
-rw-r--r--tiny_skia/src/text.rs11
-rw-r--r--wgpu/src/text.rs11
3 files changed, 33 insertions, 2 deletions
diff --git a/core/src/font.rs b/core/src/font.rs
index bb425fd6..7f647847 100644
--- a/core/src/font.rs
+++ b/core/src/font.rs
@@ -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,
}
@@ -20,6 +22,7 @@ impl Font {
family: Family::SansSerif,
weight: Weight::Normal,
stretch: Stretch::Normal,
+ style: Style::Normal,
monospaced: false,
};
@@ -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,
+}
diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs
index 15f25740..08fde4bf 100644
--- a/tiny_skia/src/text.rs
+++ b/tiny_skia/src/text.rs
@@ -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,
@@ -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),
);
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index ef910c39..fb13545d 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -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,
@@ -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),
);