Warm glyph cache for correct scale factor
This commit is contained in:
1 parent
f0be43cbdd
commit
fe9434e4f0
2 files changed
+13
-8
No files matched your search
+7
-4
@@ -75,8 +75,6 @@ impl Fonts {
|
||||
};
|
||||
|
||||
fonts.register_fonts();
|
||||
fonts.preload_common_characters(14.0);
|
||||
fonts.preload_common_characters(16.0);
|
||||
|
||||
fonts
|
||||
}
|
||||
@@ -109,7 +107,8 @@ impl Fonts {
|
||||
self.atlas.take_delta()
|
||||
}
|
||||
|
||||
pub fn preload_common_characters(&mut self, font_size: f32) {
|
||||
/// Warms the glyph cache for common ACSII characters
|
||||
pub fn preload_common_characters(&mut self, font_size: f32, scale_factor: ScaleFactor<f32>) {
|
||||
const ASCII_PRINTABLE_START: u8 = 32;
|
||||
const ASCII_PRINTABLE_END: u8 = 126;
|
||||
|
||||
@@ -126,6 +125,7 @@ impl Fonts {
|
||||
FontFamily::Single(FontFamilyName::Generic(GenericFamily::Monospace)),
|
||||
None,
|
||||
parley::FontStyle::Normal,
|
||||
scale_factor,
|
||||
);
|
||||
self.preload_text(
|
||||
&common_chars,
|
||||
@@ -133,6 +133,7 @@ impl Fonts {
|
||||
FontFamily::Single(FontFamilyName::Generic(GenericFamily::SansSerif)),
|
||||
None,
|
||||
parley::FontStyle::Normal,
|
||||
scale_factor,
|
||||
);
|
||||
self.preload_text(
|
||||
&common_chars,
|
||||
@@ -140,6 +141,7 @@ impl Fonts {
|
||||
FontFamily::Single(FontFamilyName::Generic(GenericFamily::SansSerif)),
|
||||
Some(FontWeight::BOLD),
|
||||
parley::FontStyle::Normal,
|
||||
scale_factor,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -150,6 +152,7 @@ impl Fonts {
|
||||
font_family: FontFamily,
|
||||
font_weight: Option<FontWeight>,
|
||||
font_style: parley::FontStyle,
|
||||
scale_factor: ScaleFactor<f32>,
|
||||
) {
|
||||
profiling::scope!("preload_text");
|
||||
|
||||
@@ -175,7 +178,7 @@ impl Fonts {
|
||||
&mut self.atlas,
|
||||
&run,
|
||||
LayoutVector::new(horizontal_offset, 0.0),
|
||||
ScaleFactor::identity(),
|
||||
scale_factor,
|
||||
)
|
||||
.for_each(|_| {});
|
||||
}
|
||||
|
||||
+6
-4
@@ -6,7 +6,7 @@ use winit::window::Window;
|
||||
|
||||
use crate::{
|
||||
args::Args,
|
||||
dpi::PhysicalPoint,
|
||||
dpi::{PhysicalPoint, ScaleFactor},
|
||||
draw_commands::DrawCommandRecorder,
|
||||
fonts::Fonts,
|
||||
input::{InputState, key_as_str, mousebutton_as_str},
|
||||
@@ -239,9 +239,11 @@ impl PathOfBuilding {
|
||||
}
|
||||
StageEvent::ScaleFactorChanged(scale_factor) => {
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
self.ctx_mut()
|
||||
.window_state
|
||||
.set_scale_factor(scale_factor as f32);
|
||||
let mut ctx = self.ctx_mut();
|
||||
ctx.window_state.set_scale_factor(scale_factor as f32);
|
||||
ctx.fonts
|
||||
.borrow_mut()
|
||||
.preload_common_characters(16.0, ScaleFactor::new(scale_factor as f32));
|
||||
}
|
||||
StageEvent::FocusChanged(focused) => {
|
||||
self.ctx_mut().window_state.is_focused = focused;
|
||||
|
||||
Reference in new issue
Block a user