summaryrefslogtreecommitdiffstats
path: root/wgpu/src/text
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--graphics/fonts/Icons.ttf (renamed from wgpu/src/text/icons.ttf)bin4912 -> 4912 bytes
-rw-r--r--graphics/src/font/source.rs (renamed from wgpu/src/text/font.rs)12
-rw-r--r--wgpu/src/text.rs21
3 files changed, 13 insertions, 20 deletions
diff --git a/wgpu/src/text/icons.ttf b/graphics/fonts/Icons.ttf
index 1c832f86..1c832f86 100644
--- a/wgpu/src/text/icons.ttf
+++ b/graphics/fonts/Icons.ttf
Binary files differ
diff --git a/wgpu/src/text/font.rs b/graphics/src/font/source.rs
index 7346ccdb..917291ff 100644
--- a/wgpu/src/text/font.rs
+++ b/graphics/src/font/source.rs
@@ -1,18 +1,24 @@
-pub use font_kit::{
- error::SelectionError as LoadError, family_name::FamilyName as Family,
-};
+use crate::font::{Family, LoadError};
+/// A font source that can find and load system fonts.
+#[allow(missing_debug_implementations)]
pub struct Source {
raw: font_kit::source::SystemSource,
}
impl Source {
+ /// Creates a new [`Source`].
+ ///
+ /// [`Source`]: struct.Source.html
pub fn new() -> Self {
Source {
raw: font_kit::source::SystemSource::new(),
}
}
+ /// Finds and loads a font matching the set of provided family priorities.
+ ///
+ /// [`Source`]: struct.Source.html
pub fn load(&self, families: &[Family]) -> Result<Vec<u8>, LoadError> {
let font = self.raw.select_best_match(
families,
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index 7b6bef6c..5ee7b856 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -1,24 +1,12 @@
-mod font;
-
use crate::Transformation;
-
+use iced_graphics::font;
use std::{cell::RefCell, collections::HashMap};
use wgpu_glyph::ab_glyph;
-pub const BUILTIN_ICONS: iced_native::Font = iced_native::Font::External {
- name: "iced_wgpu icons",
- bytes: include_bytes!("text/icons.ttf"),
-};
-
-pub const CHECKMARK_ICON: char = '\u{F00C}';
-
-const FALLBACK_FONT: &[u8] = include_bytes!("../fonts/Lato-Regular.ttf");
-
#[derive(Debug)]
pub struct Pipeline {
draw_brush: RefCell<wgpu_glyph::GlyphBrush<()>>,
draw_font_map: RefCell<HashMap<String, wgpu_glyph::FontId>>,
-
measure_brush: RefCell<glyph_brush::GlyphBrush<()>>,
}
@@ -35,7 +23,7 @@ impl Pipeline {
default_font.map(|slice| slice.to_vec()).unwrap_or_else(|| {
font_source
.load(&[font::Family::SansSerif, font::Family::Serif])
- .unwrap_or_else(|_| FALLBACK_FONT.to_vec())
+ .unwrap_or_else(|_| font::FALLBACK.to_vec())
});
let font = ab_glyph::FontArc::try_from_vec(default_font)
@@ -45,7 +33,7 @@ impl Pipeline {
embedded font..."
);
- ab_glyph::FontArc::try_from_slice(FALLBACK_FONT)
+ ab_glyph::FontArc::try_from_slice(font::FALLBACK)
.expect("Load fallback font")
});
@@ -61,7 +49,6 @@ impl Pipeline {
Pipeline {
draw_brush: RefCell::new(draw_brush),
draw_font_map: RefCell::new(HashMap::new()),
-
measure_brush: RefCell::new(measure_brush),
}
}
@@ -121,7 +108,7 @@ impl Pipeline {
}
}
- pub fn clear_measurement_cache(&mut self) {
+ pub fn trim_measurement_cache(&mut self) {
// TODO: We should probably use a `GlyphCalculator` for this. However,
// it uses a lifetimed `GlyphCalculatorGuard` with side-effects on drop.
// This makes stuff quite inconvenient. A manual method for trimming the