Last active
January 12, 2018 11:56
-
-
Save mikoim/498dfcdd39439316e3eb9b8897914302 to your computer and use it in GitHub Desktop.
Alacritty calculates the cell width from maximum advance via freetype2. But its value is too wide with some font. So this patch makes it use the average of rasterized glyph width instead of maximum advance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/display.rs b/src/display.rs | |
index 14c5a66..a5a8980 100644 | |
--- a/src/display.rs | |
+++ b/src/display.rs | |
@@ -239,7 +239,7 @@ impl Display { | |
// font metrics should be computed before creating the window in the first | |
// place so that a resize is not needed. | |
let metrics = glyph_cache.font_metrics(); | |
- let cell_width = (metrics.average_advance + font.offset().x as f64) as u32; | |
+ let cell_width = (glyph_cache.true_average_width() + font.offset().x as f64) as u32; | |
let cell_height = (metrics.line_height + font.offset().y as f64) as u32; | |
Ok((glyph_cache, cell_width as f32, cell_height as f32)) | |
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs | |
index 237c841..87cae66 100644 | |
--- a/src/renderer/mod.rs | |
+++ b/src/renderer/mod.rs | |
@@ -273,6 +273,10 @@ impl GlyphCache { | |
.expect("metrics load since font is loaded at glyph cache creation") | |
} | |
+ pub fn true_average_width(&self) -> f64 { | |
+ (self.cache.values().fold(0., |sum, g| sum + g.width) / self.cache.len() as f32 + 2.) as f64 | |
+ } | |
+ | |
pub fn get<'a, L>(&'a mut self, glyph_key: &GlyphKey, loader: &mut L) -> &'a Glyph | |
where L: LoadGlyph | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment