From 1d0c44fb255f5fbf5a03e7c737e40ab66d39de9e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 2 Feb 2023 01:24:27 +0100 Subject: Implement basic text caching in `iced_wgpu` --- core/src/font.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'core/src/font.rs') diff --git a/core/src/font.rs b/core/src/font.rs index 3f9ad2b5..130e378e 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -1,3 +1,5 @@ +use std::hash::{Hash, Hasher}; + /// A font. #[derive(Debug, Clone, Copy)] pub enum Font { @@ -22,3 +24,17 @@ impl Default for Font { Font::Default } } + +impl Hash for Font { + fn hash(&self, hasher: &mut H) { + match self { + Self::Default => { + 0.hash(hasher); + } + Self::External { name, .. } => { + 1.hash(hasher); + name.hash(hasher); + } + } + } +} -- cgit From b29de28d1f0f608f8029c93d154cfd1b0f8b8cbb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Feb 2023 07:33:33 +0100 Subject: Overhaul `Font` type to allow font family selection --- core/src/font.rs | 53 +++++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) (limited to 'core/src/font.rs') diff --git a/core/src/font.rs b/core/src/font.rs index 130e378e..1f774a70 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -1,40 +1,29 @@ -use std::hash::{Hash, Hasher}; +use std::hash::Hash; /// A font. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Font { - /// The default font. - /// - /// This is normally a font configured in a renderer or loaded from the - /// system. - Default, + /// The name of a font family of choice. + Name(&'static str), - /// An external font. - External { - /// The name of the external font - name: &'static str, + /// Serif fonts represent the formal text style for a script. + Serif, - /// The bytes of the external font - bytes: &'static [u8], - }, -} + /// Glyphs in sans-serif fonts, as the term is used in CSS, are generally low + /// contrast and have stroke endings that are plain — without any flaring, + /// cross stroke, or other ornamentation. + SansSerif, -impl Default for Font { - fn default() -> Font { - Font::Default - } -} + /// Glyphs in cursive fonts generally use a more informal script style, and + /// the result looks more like handwritten pen or brush writing than printed + /// letterwork. + Cursive, + + /// Fantasy fonts are primarily decorative or expressive fonts that contain + /// decorative or expressive representations of characters. + Fantasy, -impl Hash for Font { - fn hash(&self, hasher: &mut H) { - match self { - Self::Default => { - 0.hash(hasher); - } - Self::External { name, .. } => { - 1.hash(hasher); - name.hash(hasher); - } - } - } + /// The sole criterion of a monospace font is that all glyphs have the same + /// fixed width. + Monospace, } -- cgit From 32309f0140efb4ea92e3e35e3adc5c740909f196 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Feb 2023 18:26:09 +0100 Subject: Introduce `Weight` enum to `font` --- core/src/font.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'core/src/font.rs') diff --git a/core/src/font.rs b/core/src/font.rs index 1f774a70..b67c08af 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -1,3 +1,4 @@ +//! Load and use fonts. use std::hash::Hash; /// A font. @@ -27,3 +28,18 @@ pub enum Font { /// fixed width. Monospace, } + +/// The weight of some text. +#[allow(missing_docs)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum Weight { + Thin, + ExtraLight, + Light, + Normal, + Medium, + Semibold, + Bold, + ExtraBold, + Black, +} -- cgit From 707de9d788dc3c49d4ac57a19afac1bb938b78d9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 30 Mar 2023 00:56:00 +0200 Subject: Introduce support for `Font` attributes --- core/src/font.rs | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'core/src/font.rs') diff --git a/core/src/font.rs b/core/src/font.rs index b67c08af..920b3dd5 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -2,8 +2,44 @@ use std::hash::Hash; /// A font. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum Font { +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] +pub struct Font { + /// The [`Family`] of the [`Font`]. + pub family: Family, + /// The [`Weight`] of the [`Font`]. + pub weight: Weight, + /// Whether if the [`Font`] is monospaced or not. + pub monospaced: bool, +} + +impl Font { + /// A non-monospaced sans-serif font with normal [`Weight`]. + pub const DEFAULT: Font = Font { + family: Family::SansSerif, + weight: Weight::Normal, + monospaced: false, + }; + + /// A monospaced font with normal [`Weight`]. + pub const MONOSPACE: Font = Font { + family: Family::Monospace, + monospaced: true, + ..Self::DEFAULT + }; + + /// Creates a non-monospaced [`Font`] with the given [`Family::Name`] and + /// normal [`Weight`]. + pub const fn with_name(name: &'static str) -> Self { + Font { + family: Family::Name(name), + ..Self::DEFAULT + } + } +} + +/// A font family. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] +pub enum Family { /// The name of a font family of choice. Name(&'static str), @@ -13,6 +49,7 @@ pub enum Font { /// Glyphs in sans-serif fonts, as the term is used in CSS, are generally low /// contrast and have stroke endings that are plain — without any flaring, /// cross stroke, or other ornamentation. + #[default] SansSerif, /// Glyphs in cursive fonts generally use a more informal script style, and @@ -31,11 +68,12 @@ pub enum Font { /// The weight of some text. #[allow(missing_docs)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] pub enum Weight { Thin, ExtraLight, Light, + #[default] Normal, Medium, Semibold, -- cgit From 0b459c8e240abf83bb62902a504c018194acdbb6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 30 Mar 2023 02:01:20 +0200 Subject: Introduce `font::Stretch` --- core/src/font.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'core/src/font.rs') diff --git a/core/src/font.rs b/core/src/font.rs index 920b3dd5..bb425fd6 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -8,6 +8,8 @@ pub struct Font { pub family: Family, /// The [`Weight`] of the [`Font`]. pub weight: Weight, + /// The [`Stretch`] of the [`Font`]. + pub stretch: Stretch, /// Whether if the [`Font`] is monospaced or not. pub monospaced: bool, } @@ -17,6 +19,7 @@ impl Font { pub const DEFAULT: Font = Font { family: Family::SansSerif, weight: Weight::Normal, + stretch: Stretch::Normal, monospaced: false, }; @@ -81,3 +84,19 @@ pub enum Weight { ExtraBold, 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, +} -- cgit