diff options
author | 2023-03-30 00:56:00 +0200 | |
---|---|---|
committer | 2023-03-30 00:56:00 +0200 | |
commit | 707de9d788dc3c49d4ac57a19afac1bb938b78d9 (patch) | |
tree | a1f38efa232742f375afae751d433276a83f7e49 /tiny_skia/src | |
parent | 472fbdf1875e82bc89ac0bbd4b2ff09cae1d9620 (diff) | |
download | iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.tar.gz iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.tar.bz2 iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.zip |
Introduce support for `Font` attributes
Diffstat (limited to 'tiny_skia/src')
-rw-r--r-- | tiny_skia/src/backend.rs | 4 | ||||
-rw-r--r-- | tiny_skia/src/settings.rs | 2 | ||||
-rw-r--r-- | tiny_skia/src/text.rs | 44 |
3 files changed, 36 insertions, 14 deletions
diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs index 271d026f..58076b84 100644 --- a/tiny_skia/src/backend.rs +++ b/tiny_skia/src/backend.rs @@ -72,7 +72,7 @@ impl Backend { height: f32::INFINITY, }, color: Color::BLACK, - font: Font::Monospace, + font: Font::MONOSPACE, horizontal_alignment: alignment::Horizontal::Left, vertical_alignment: alignment::Vertical::Top, }, @@ -492,7 +492,7 @@ impl iced_graphics::Backend for Backend { } impl backend::Text for Backend { - const ICON_FONT: Font = Font::Name("Iced-Icons"); + const ICON_FONT: Font = Font::with_name("Iced-Icons"); const CHECKMARK_ICON: char = '\u{f00c}'; const ARROW_DOWN_ICON: char = '\u{e800}'; diff --git a/tiny_skia/src/settings.rs b/tiny_skia/src/settings.rs index 9e4be0c4..abffbfe6 100644 --- a/tiny_skia/src/settings.rs +++ b/tiny_skia/src/settings.rs @@ -17,7 +17,7 @@ pub struct Settings { impl Default for Settings { fn default() -> Settings { Settings { - default_font: Font::SansSerif, + default_font: Font::default(), default_text_size: 16.0, } } diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs index 8391571c..c9bb9873 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/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::{Color, Font, Point, Rectangle, Size}; +use crate::core::{Color, Point, Rectangle, Size}; use rustc_hash::{FxHashMap, FxHashSet}; use std::borrow::Cow; @@ -183,14 +184,28 @@ impl Pipeline { } } -fn to_family(font: Font) -> cosmic_text::Family<'static> { - match font { - Font::Name(name) => cosmic_text::Family::Name(name), - Font::SansSerif => cosmic_text::Family::SansSerif, - Font::Serif => cosmic_text::Family::Serif, - Font::Cursive => cosmic_text::Family::Cursive, - Font::Fantasy => cosmic_text::Family::Fantasy, - Font::Monospace => cosmic_text::Family::Monospace, +fn to_family(family: font::Family) -> cosmic_text::Family<'static> { + match family { + font::Family::Name(name) => cosmic_text::Family::Name(name), + font::Family::SansSerif => cosmic_text::Family::SansSerif, + font::Family::Serif => cosmic_text::Family::Serif, + font::Family::Cursive => cosmic_text::Family::Cursive, + font::Family::Fantasy => cosmic_text::Family::Fantasy, + font::Family::Monospace => cosmic_text::Family::Monospace, + } +} + +fn to_weight(weight: font::Weight) -> cosmic_text::Weight { + match weight { + font::Weight::Thin => cosmic_text::Weight::THIN, + font::Weight::ExtraLight => cosmic_text::Weight::EXTRA_LIGHT, + font::Weight::Light => cosmic_text::Weight::LIGHT, + font::Weight::Normal => cosmic_text::Weight::NORMAL, + font::Weight::Medium => cosmic_text::Weight::MEDIUM, + font::Weight::Semibold => cosmic_text::Weight::SEMIBOLD, + font::Weight::Bold => cosmic_text::Weight::BOLD, + font::Weight::ExtraBold => cosmic_text::Weight::EXTRA_BOLD, + font::Weight::Black => cosmic_text::Weight::BLACK, } } @@ -354,8 +369,15 @@ impl Cache { font_system, key.content, cosmic_text::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); |