enable bold/italic highlight styles

macos-click-through
Keith Simmons 3 years ago
parent f99c21d971
commit 2fc74f83ca

@ -39,6 +39,12 @@ impl CachingShaper {
} }
fn current_font_pair(&mut self) -> Arc<FontPair> { fn current_font_pair(&mut self) -> Arc<FontPair> {
let default_key = FontKey {
italic: false,
bold: false,
font_selection: FontSelection::Default,
};
let font_key = self let font_key = self
.options .options
.as_ref() .as_ref()
@ -47,15 +53,13 @@ impl CachingShaper {
bold: options.bold, bold: options.bold,
font_selection: options.fallback_list.first().unwrap().clone().into(), font_selection: options.fallback_list.first().unwrap().clone().into(),
}) })
.unwrap_or(FontKey { .unwrap_or(default_key.clone());
italic: true,
bold: true, if let Some(font_pair) = self.font_loader.get_or_load(&font_key) {
font_selection: FontSelection::Default, return font_pair;
}); }
self.font_loader self.font_loader.get_or_load(&default_key).expect("Could not load font")
.get_or_load(&font_key)
.expect("Could not load font")
} }
pub fn current_size(&self) -> f32 { pub fn current_size(&self) -> f32 {
@ -108,7 +112,7 @@ impl CachingShaper {
(metrics.ascent + metrics.leading) as u64 (metrics.ascent + metrics.leading) as u64
} }
fn build_clusters(&mut self, text: &str) -> Vec<(Vec<CharCluster>, Arc<FontPair>)> { fn build_clusters(&mut self, text: &str, bold: bool, italic: bool) -> Vec<(Vec<CharCluster>, Arc<FontPair>)> {
let mut cluster = CharCluster::new(); let mut cluster = CharCluster::new();
// Enumerate the characters storing the glyph index in the user data so that we can position // 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 // Add guifont fallback list
if let Some(options) = &self.options { if let Some(options) = &self.options {
font_fallback_keys.extend(options.fallback_list.iter().map(|font_name| FontKey { font_fallback_keys.extend(options.fallback_list.iter().map(|font_name| FontKey {
italic: options.italic, italic: options.italic || italic,
bold: options.bold, bold: options.bold || bold,
font_selection: font_name.into(), font_selection: font_name.into(),
})); }));
}
// Add default font
font_fallback_keys.push(FontKey {
italic: true,
bold: true,
font_selection: FontSelection::Default,
});
// Add skia fallback // Add default font
font_fallback_keys.push(FontKey { font_fallback_keys.push(FontKey {
italic: true, italic: options.italic || italic,
bold: true, bold: options.bold || bold,
font_selection: cluster.chars()[0].ch.into(), 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 // Add last resort
font_fallback_keys.push(FontKey { font_fallback_keys.push(FontKey {
italic: true, italic: false,
bold: true, bold: false,
font_selection: FontSelection::LastResort, font_selection: FontSelection::LastResort,
}); });
@ -218,7 +239,7 @@ impl CachingShaper {
grouped_results grouped_results
} }
pub fn shape(&mut self, cells: &[String]) -> Vec<TextBlob> { pub fn shape(&mut self, cells: &[String], bold: bool, italic: bool) -> Vec<TextBlob> {
let current_size = self.current_size(); let current_size = self.current_size();
let (glyph_width, _) = self.font_base_dimensions(); let (glyph_width, _) = self.font_base_dimensions();
@ -227,7 +248,7 @@ impl CachingShaper {
let text = cells.concat(); let text = cells.concat();
trace!("Shaping text: {}", text); 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 let mut shaper = self
.shape_context .shape_context
.builder(font_pair.swash_font.as_ref()) .builder(font_pair.swash_font.as_ref())
@ -271,7 +292,7 @@ impl CachingShaper {
let key = ShapeKey::new(cells.to_vec(), bold, italic); let key = ShapeKey::new(cells.to_vec(), bold, italic);
if !self.blob_cache.contains(&key) { 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); self.blob_cache.put(key.clone(), blobs);
} }

@ -18,9 +18,12 @@ use glutin::{
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
window::{self, Fullscreen, Icon}, window::{self, Fullscreen, Icon},
ContextBuilder, GlProfile, WindowedContext, ContextBuilder, GlProfile, WindowedContext,
platform::unix::WindowBuilderExtUnix,
}; };
#[cfg(target_os = "linux")]
use glutin::platform::unix::WindowBuilderExtUnix;
use super::{handle_new_grid_size, settings::WindowSettings}; use super::{handle_new_grid_size, settings::WindowSettings};
use crate::{ use crate::{
bridge::UiCommand, channel_utils::*, cmd_line::CmdLineSettings, editor::WindowCommand, bridge::UiCommand, channel_utils::*, cmd_line::CmdLineSettings, editor::WindowCommand,

Loading…
Cancel
Save