diff --git a/src/renderer/fonts/caching_shaper.rs b/src/renderer/fonts/caching_shaper.rs index 1b633c0..ebc47bd 100644 --- a/src/renderer/fonts/caching_shaper.rs +++ b/src/renderer/fonts/caching_shaper.rs @@ -39,6 +39,12 @@ impl CachingShaper { } fn current_font_pair(&mut self) -> Arc { + let default_key = FontKey { + italic: false, + bold: false, + font_selection: FontSelection::Default, + }; + let font_key = self .options .as_ref() @@ -47,15 +53,13 @@ impl CachingShaper { bold: options.bold, font_selection: options.fallback_list.first().unwrap().clone().into(), }) - .unwrap_or(FontKey { - italic: true, - bold: true, - font_selection: FontSelection::Default, - }); + .unwrap_or(default_key.clone()); + + if let Some(font_pair) = self.font_loader.get_or_load(&font_key) { + return font_pair; + } - self.font_loader - .get_or_load(&font_key) - .expect("Could not load font") + self.font_loader.get_or_load(&default_key).expect("Could not load font") } pub fn current_size(&self) -> f32 { @@ -108,7 +112,7 @@ impl CachingShaper { (metrics.ascent + metrics.leading) as u64 } - fn build_clusters(&mut self, text: &str) -> Vec<(Vec, Arc)> { + fn build_clusters(&mut self, text: &str, bold: bool, italic: bool) -> Vec<(Vec, Arc)> { let mut cluster = CharCluster::new(); // Enumerate the characters storing the glyph index in the user data so that we can position @@ -143,29 +147,46 @@ impl CachingShaper { // Add guifont fallback list if let Some(options) = &self.options { font_fallback_keys.extend(options.fallback_list.iter().map(|font_name| FontKey { - italic: options.italic, - bold: options.bold, + italic: options.italic || italic, + bold: options.bold || bold, font_selection: font_name.into(), })); - } - // Add default font - font_fallback_keys.push(FontKey { - italic: true, - bold: true, - font_selection: FontSelection::Default, - }); - // Add skia fallback - font_fallback_keys.push(FontKey { - italic: true, - bold: true, - font_selection: cluster.chars()[0].ch.into(), - }); + // Add default font + font_fallback_keys.push(FontKey { + italic: options.italic || italic, + bold: options.bold || bold, + font_selection: FontSelection::Default, + }); + + // Add skia fallback + font_fallback_keys.push(FontKey { + italic: options.italic || italic, + bold: options.bold || bold, + font_selection: cluster.chars()[0].ch.into(), + }); + } else { + // No confgured option. Default to not italic and not bold versions + + // Add default font + font_fallback_keys.push(FontKey { + italic, + bold, + font_selection: FontSelection::Default, + }); + + // Add skia fallback + font_fallback_keys.push(FontKey { + italic, + bold, + font_selection: cluster.chars()[0].ch.into(), + }); + } // Add last resort font_fallback_keys.push(FontKey { - italic: true, - bold: true, + italic: false, + bold: false, font_selection: FontSelection::LastResort, }); @@ -218,7 +239,7 @@ impl CachingShaper { grouped_results } - pub fn shape(&mut self, cells: &[String]) -> Vec { + pub fn shape(&mut self, cells: &[String], bold: bool, italic: bool) -> Vec { let current_size = self.current_size(); let (glyph_width, _) = self.font_base_dimensions(); @@ -227,7 +248,7 @@ impl CachingShaper { let text = cells.concat(); trace!("Shaping text: {}", text); - for (cluster_group, font_pair) in self.build_clusters(&text) { + for (cluster_group, font_pair) in self.build_clusters(&text, bold, italic) { let mut shaper = self .shape_context .builder(font_pair.swash_font.as_ref()) @@ -271,7 +292,7 @@ impl CachingShaper { let key = ShapeKey::new(cells.to_vec(), bold, italic); if !self.blob_cache.contains(&key) { - let blobs = self.shape(cells); + let blobs = self.shape(cells, bold, italic); self.blob_cache.put(key.clone(), blobs); } diff --git a/src/window/window_wrapper/mod.rs b/src/window/window_wrapper/mod.rs index d2419fd..8006457 100644 --- a/src/window/window_wrapper/mod.rs +++ b/src/window/window_wrapper/mod.rs @@ -18,9 +18,12 @@ use glutin::{ event_loop::{ControlFlow, EventLoop}, window::{self, Fullscreen, Icon}, ContextBuilder, GlProfile, WindowedContext, - platform::unix::WindowBuilderExtUnix, }; + +#[cfg(target_os = "linux")] +use glutin::platform::unix::WindowBuilderExtUnix; + use super::{handle_new_grid_size, settings::WindowSettings}; use crate::{ bridge::UiCommand, channel_utils::*, cmd_line::CmdLineSettings, editor::WindowCommand,