mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 13:21:38 +03:00
shaping: add test for FiraCode
Adds a test and seemingly a fix for https://github.com/wez/wezterm/issues/478#issuecomment-787520977 Fira Code is OFL-1.1 licensed like the other fonts we include, however, I'm not distributing Fira Code with wezterm.
This commit is contained in:
parent
f7c26d1866
commit
d56c5178da
BIN
assets/fonts/FiraCode-Regular.ttf
Normal file
BIN
assets/fonts/FiraCode-Regular.ttf
Normal file
Binary file not shown.
@ -218,6 +218,7 @@ impl TextStyle {
|
||||
.trim_end_matches(" Thin")
|
||||
.trim_end_matches(" Extra Light")
|
||||
.trim_end_matches(" Normal")
|
||||
.trim_end_matches(" Regular")
|
||||
.trim_end_matches(" Medium")
|
||||
.trim_end_matches(" Semi Bold")
|
||||
.trim_end_matches(" Bold")
|
||||
|
@ -305,6 +305,10 @@ pub fn use_test_configuration() {
|
||||
CONFIG.use_test();
|
||||
}
|
||||
|
||||
pub fn use_this_configuration(config: Config) {
|
||||
CONFIG.use_this_config(config);
|
||||
}
|
||||
|
||||
/// Returns a handle to the current configuration
|
||||
pub fn configuration() -> ConfigHandle {
|
||||
CONFIG.get()
|
||||
@ -464,6 +468,10 @@ impl ConfigInner {
|
||||
fn use_test(&mut self) {
|
||||
let mut config = Config::default_config();
|
||||
config.font_locator = FontLocatorSelection::ConfigDirsOnly;
|
||||
let exe_name = std::env::current_exe().unwrap();
|
||||
config
|
||||
.font_dirs
|
||||
.push(exe_name.parent().unwrap().join("../../../assets/fonts"));
|
||||
// Specify the same DPI used on non-mac systems so
|
||||
// that we have consistent values regardless of the
|
||||
// operating system that we're running tests on
|
||||
@ -1317,7 +1325,7 @@ impl Config {
|
||||
|
||||
/// In some cases we need to compute expanded values based
|
||||
/// on those provided by the user. This is where we do that.
|
||||
fn compute_extra_defaults(&self, config_path: Option<&Path>) -> Self {
|
||||
pub fn compute_extra_defaults(&self, config_path: Option<&Path>) -> Self {
|
||||
let mut cfg = self.clone();
|
||||
|
||||
// Convert any relative font dirs to their config file relative locations
|
||||
|
@ -214,11 +214,6 @@ impl FontConfigInner {
|
||||
/// Given a text style, load (with caching) the font that best
|
||||
/// matches according to the fontconfig pattern.
|
||||
fn resolve_font(&self, myself: &Rc<Self>, style: &TextStyle) -> anyhow::Result<Rc<LoadedFont>> {
|
||||
let global_config = configuration();
|
||||
let current_generation = global_config.generation();
|
||||
if current_generation != self.config.borrow().generation() {
|
||||
self.config_changed(&global_config)?;
|
||||
}
|
||||
let config = self.config.borrow();
|
||||
|
||||
let mut fonts = self.fonts.borrow_mut();
|
||||
|
@ -53,7 +53,12 @@ where
|
||||
for (info, glyph) in infos.iter().zip(glyphs.iter()) {
|
||||
if !info.is_space && glyph.texture.is_none() {
|
||||
if let Some(shaped) = pos.last_mut() {
|
||||
if shaped.pos.bitmap_pixel_width as f32 > shaped.pos.bearing_x {
|
||||
// if bearing_x == 0, then the glyph could be a blank
|
||||
// in a <blank>, <blank>, "..." sequence, and it shouldn't
|
||||
// be swept into the "a" in a sequence like "a..."
|
||||
if shaped.pos.bearing_x > 0.
|
||||
&& shaped.pos.bitmap_pixel_width as f32 > shaped.pos.bearing_x
|
||||
{
|
||||
// This space-like glyph belongs to the preceding glyph
|
||||
shaped.pos.num_cells += 1;
|
||||
continue;
|
||||
@ -214,7 +219,7 @@ mod test {
|
||||
use crate::shapecache::GlyphPosition;
|
||||
use crate::shapecache::ShapedInfo;
|
||||
use crate::utilsprites::RenderMetrics;
|
||||
use config::TextStyle;
|
||||
use config::{FontAttributes, TextStyle};
|
||||
use k9::assert_equal as assert_eq;
|
||||
use std::rc::Rc;
|
||||
use termwiz::cell::CellAttributes;
|
||||
@ -263,7 +268,55 @@ mod test {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ligatures() {
|
||||
fn ligatures_fira() {
|
||||
config::use_test_configuration();
|
||||
let _ = pretty_env_logger::formatted_builder()
|
||||
.is_test(true)
|
||||
.filter_level(log::LevelFilter::Trace)
|
||||
.try_init();
|
||||
|
||||
let config = config::configuration();
|
||||
let mut config: config::Config = (*config).clone();
|
||||
config.font = TextStyle {
|
||||
font: vec![FontAttributes::new("Fira Code")],
|
||||
foreground: None,
|
||||
};
|
||||
config.font_rules.clear();
|
||||
config.compute_extra_defaults(None);
|
||||
config::use_this_configuration(config);
|
||||
|
||||
let fonts = Rc::new(FontConfiguration::new(None).unwrap());
|
||||
let render_metrics = RenderMetrics::new(&fonts).unwrap();
|
||||
let mut glyph_cache = GlyphCache::new_in_memory(&fonts, 128, &render_metrics).unwrap();
|
||||
|
||||
let style = TextStyle::default();
|
||||
let font = fonts.resolve_font(&style).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
cluster_and_shape(&mut glyph_cache, &style, &font, "a..."),
|
||||
vec![
|
||||
GlyphPosition {
|
||||
glyph_idx: 180,
|
||||
cluster: 0,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
bitmap_pixel_width: 7,
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 637,
|
||||
cluster: 1,
|
||||
num_cells: 3,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 4.0,
|
||||
bitmap_pixel_width: 16,
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ligatures_jetbrains() {
|
||||
config::use_test_configuration();
|
||||
let _ = pretty_env_logger::formatted_builder()
|
||||
.is_test(true)
|
||||
@ -329,6 +382,28 @@ mod test {
|
||||
]
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
cluster_and_shape(&mut glyph_cache, &style, &font, "a..."),
|
||||
vec![
|
||||
GlyphPosition {
|
||||
glyph_idx: 180,
|
||||
cluster: 0,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
bitmap_pixel_width: 7,
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 637,
|
||||
cluster: 1,
|
||||
num_cells: 3,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 4.0,
|
||||
bitmap_pixel_width: 16,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
cluster_and_shape(&mut glyph_cache, &style, &font, "a b"),
|
||||
vec![
|
||||
|
Loading…
Reference in New Issue
Block a user