diff options
author | 2023-03-30 00:56:00 +0200 | |
---|---|---|
committer | 2023-03-30 00:56:00 +0200 | |
commit | 707de9d788dc3c49d4ac57a19afac1bb938b78d9 (patch) | |
tree | a1f38efa232742f375afae751d433276a83f7e49 /wgpu/src/text.rs | |
parent | 472fbdf1875e82bc89ac0bbd4b2ff09cae1d9620 (diff) | |
download | iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.tar.gz iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.tar.bz2 iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.zip |
Introduce support for `Font` attributes
Diffstat (limited to 'wgpu/src/text.rs')
-rw-r--r-- | wgpu/src/text.rs | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index ac116f69..b0b7a198 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -1,6 +1,7 @@ use crate::core::alignment; +use crate::core::font::{self, Font}; use crate::core::text::Hit; -use crate::core::{Font, Point, Rectangle, Size}; +use crate::core::{Point, Rectangle, Size}; use crate::layer::Text; use rustc_hash::{FxHashMap, FxHashSet}; @@ -262,14 +263,28 @@ impl Pipeline { } } -fn to_family(font: Font) -> glyphon::Family<'static> { - match font { - Font::Name(name) => glyphon::Family::Name(name), - Font::SansSerif => glyphon::Family::SansSerif, - Font::Serif => glyphon::Family::Serif, - Font::Cursive => glyphon::Family::Cursive, - Font::Fantasy => glyphon::Family::Fantasy, - Font::Monospace => glyphon::Family::Monospace, +fn to_family(family: font::Family) -> glyphon::Family<'static> { + match family { + font::Family::Name(name) => glyphon::Family::Name(name), + font::Family::SansSerif => glyphon::Family::SansSerif, + font::Family::Serif => glyphon::Family::Serif, + font::Family::Cursive => glyphon::Family::Cursive, + font::Family::Fantasy => glyphon::Family::Fantasy, + font::Family::Monospace => glyphon::Family::Monospace, + } +} + +fn to_weight(weight: font::Weight) -> glyphon::Weight { + match weight { + font::Weight::Thin => glyphon::Weight::THIN, + font::Weight::ExtraLight => glyphon::Weight::EXTRA_LIGHT, + font::Weight::Light => glyphon::Weight::LIGHT, + font::Weight::Normal => glyphon::Weight::NORMAL, + font::Weight::Medium => glyphon::Weight::MEDIUM, + font::Weight::Semibold => glyphon::Weight::SEMIBOLD, + font::Weight::Bold => glyphon::Weight::BOLD, + font::Weight::ExtraBold => glyphon::Weight::EXTRA_BOLD, + font::Weight::Black => glyphon::Weight::BLACK, } } @@ -328,8 +343,15 @@ impl Cache { font_system, key.content, glyphon::Attrs::new() - .family(to_family(key.font)) - .monospaced(matches!(key.font, Font::Monospace)), + .family(to_family(key.font.family)) + .weight(to_weight(key.font.weight)) + .monospaced( + key.font.monospaced + || matches!( + key.font.family, + font::Family::Monospace + ), + ), ); let _ = entry.insert(buffer); |