diff options
author | Joe Wilm <joe@jwilm.com> | 2017-05-03 15:12:23 -0700 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-05-06 12:53:54 -0700 |
commit | 149fbaef09a56613c72855bc60355c7848256500 (patch) | |
tree | 89bb581b2135c702e2f8c03772bf9ddd4470ac8f /src/renderer | |
parent | 6659810a22e62f8b41d7bc35ed07905ccebda68b (diff) | |
download | alacritty-149fbaef09a56613c72855bc60355c7848256500.tar.gz alacritty-149fbaef09a56613c72855bc60355c7848256500.zip |
Fix glyph offsets in cell
We previously had a hard-coded value for aligning glyphs within cells.
The font descent is now used, and the offset should be correct by
default.
Diffstat (limited to 'src/renderer')
-rw-r--r-- | src/renderer/mod.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 48354018..60d83287 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -157,6 +157,8 @@ pub struct GlyphCache { /// glyph offset glyph_offset: Delta, + + metrics: ::font::Metrics, } impl GlyphCache { @@ -220,6 +222,12 @@ impl GlyphCache { .unwrap_or_else(|_| regular) }; + // Need to load at least one glyph for the face before calling metrics. + // The glyph requested here ('m' at the time of writing) has no special + // meaning. + rasterizer.get_glyph(&GlyphKey { font_key: regular, c: 'm' as char, size: font.size() })?; + let metrics = rasterizer.metrics(regular)?; + let mut cache = GlyphCache { cache: HashMap::default(), rasterizer: rasterizer, @@ -228,12 +236,13 @@ impl GlyphCache { bold_key: bold, italic_key: italic, glyph_offset: glyph_offset, + metrics: metrics }; macro_rules! load_glyphs_for_font { ($font:expr) => { for i in RangeInclusive::new(32u8, 128u8) { - cache.load_and_cache_glyph(GlyphKey { + cache.get(&GlyphKey { font_key: $font, c: i as char, size: font.size() @@ -255,33 +264,22 @@ impl GlyphCache { .expect("metrics load since font is loaded at glyph cache creation") } - fn load_and_cache_glyph<L>(&mut self, glyph_key: GlyphKey, loader: &mut L) - where L: LoadGlyph - { - let mut rasterized = self.rasterizer.get_glyph(&glyph_key) - .unwrap_or_else(|_| Default::default()); - - rasterized.left += self.glyph_offset.x as i32; - rasterized.top += self.glyph_offset.y as i32; - - let glyph = loader.load_glyph(&rasterized); - self.cache.insert(glyph_key, glyph); - } - pub fn get<'a, L>(&'a mut self, glyph_key: &GlyphKey, loader: &mut L) -> &'a Glyph where L: LoadGlyph { let glyph_offset = self.glyph_offset; let rasterizer = &mut self.rasterizer; + let metrics = &self.metrics; self.cache .entry(*glyph_key) .or_insert_with(|| { let mut rasterized = rasterizer.get_glyph(&glyph_key) .unwrap_or_else(|_| Default::default()); - // We need to apply the offset to glyphs that didn't get cached initially + // Apply offsets so they aren't computed every draw rasterized.left += glyph_offset.x as i32; rasterized.top += glyph_offset.y as i32; + rasterized.top -= metrics.descent as i32; loader.load_glyph(&rasterized) }) |