Introduce font::Stretch
This commit is contained in:
parent
707de9d788
commit
0b459c8e24
3 changed files with 49 additions and 0 deletions
|
|
@ -8,6 +8,8 @@ pub struct Font {
|
||||||
pub family: Family,
|
pub family: Family,
|
||||||
/// The [`Weight`] of the [`Font`].
|
/// The [`Weight`] of the [`Font`].
|
||||||
pub weight: Weight,
|
pub weight: Weight,
|
||||||
|
/// The [`Stretch`] of the [`Font`].
|
||||||
|
pub stretch: Stretch,
|
||||||
/// Whether if the [`Font`] is monospaced or not.
|
/// Whether if the [`Font`] is monospaced or not.
|
||||||
pub monospaced: bool,
|
pub monospaced: bool,
|
||||||
}
|
}
|
||||||
|
|
@ -17,6 +19,7 @@ impl Font {
|
||||||
pub const DEFAULT: Font = Font {
|
pub const DEFAULT: Font = Font {
|
||||||
family: Family::SansSerif,
|
family: Family::SansSerif,
|
||||||
weight: Weight::Normal,
|
weight: Weight::Normal,
|
||||||
|
stretch: Stretch::Normal,
|
||||||
monospaced: false,
|
monospaced: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -81,3 +84,19 @@ pub enum Weight {
|
||||||
ExtraBold,
|
ExtraBold,
|
||||||
Black,
|
Black,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The width of some text.
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
|
||||||
|
pub enum Stretch {
|
||||||
|
UltraCondensed,
|
||||||
|
ExtraCondensed,
|
||||||
|
Condensed,
|
||||||
|
SemiCondensed,
|
||||||
|
#[default]
|
||||||
|
Normal,
|
||||||
|
SemiExpanded,
|
||||||
|
Expanded,
|
||||||
|
ExtraExpanded,
|
||||||
|
UltraExpanded,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,20 @@ fn to_weight(weight: font::Weight) -> cosmic_text::Weight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_stretch(stretch: font::Stretch) -> cosmic_text::Stretch {
|
||||||
|
match stretch {
|
||||||
|
font::Stretch::UltraCondensed => cosmic_text::Stretch::UltraCondensed,
|
||||||
|
font::Stretch::ExtraCondensed => cosmic_text::Stretch::ExtraCondensed,
|
||||||
|
font::Stretch::Condensed => cosmic_text::Stretch::Condensed,
|
||||||
|
font::Stretch::SemiCondensed => cosmic_text::Stretch::SemiCondensed,
|
||||||
|
font::Stretch::Normal => cosmic_text::Stretch::Normal,
|
||||||
|
font::Stretch::SemiExpanded => cosmic_text::Stretch::SemiExpanded,
|
||||||
|
font::Stretch::Expanded => cosmic_text::Stretch::Expanded,
|
||||||
|
font::Stretch::ExtraExpanded => cosmic_text::Stretch::ExtraExpanded,
|
||||||
|
font::Stretch::UltraExpanded => cosmic_text::Stretch::UltraExpanded,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
struct GlyphCache {
|
struct GlyphCache {
|
||||||
entries: FxHashMap<
|
entries: FxHashMap<
|
||||||
|
|
@ -371,6 +385,7 @@ 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))
|
||||||
.monospaced(
|
.monospaced(
|
||||||
key.font.monospaced
|
key.font.monospaced
|
||||||
|| matches!(
|
|| matches!(
|
||||||
|
|
|
||||||
|
|
@ -288,6 +288,20 @@ fn to_weight(weight: font::Weight) -> glyphon::Weight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_stretch(stretch: font::Stretch) -> glyphon::Stretch {
|
||||||
|
match stretch {
|
||||||
|
font::Stretch::UltraCondensed => glyphon::Stretch::UltraCondensed,
|
||||||
|
font::Stretch::ExtraCondensed => glyphon::Stretch::ExtraCondensed,
|
||||||
|
font::Stretch::Condensed => glyphon::Stretch::Condensed,
|
||||||
|
font::Stretch::SemiCondensed => glyphon::Stretch::SemiCondensed,
|
||||||
|
font::Stretch::Normal => glyphon::Stretch::Normal,
|
||||||
|
font::Stretch::SemiExpanded => glyphon::Stretch::SemiExpanded,
|
||||||
|
font::Stretch::Expanded => glyphon::Stretch::Expanded,
|
||||||
|
font::Stretch::ExtraExpanded => glyphon::Stretch::ExtraExpanded,
|
||||||
|
font::Stretch::UltraExpanded => glyphon::Stretch::UltraExpanded,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Cache {
|
struct Cache {
|
||||||
entries: FxHashMap<KeyHash, glyphon::Buffer>,
|
entries: FxHashMap<KeyHash, glyphon::Buffer>,
|
||||||
recently_used: FxHashSet<KeyHash>,
|
recently_used: FxHashSet<KeyHash>,
|
||||||
|
|
@ -345,6 +359,7 @@ 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))
|
||||||
.monospaced(
|
.monospaced(
|
||||||
key.font.monospaced
|
key.font.monospaced
|
||||||
|| matches!(
|
|| matches!(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue