diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2018-12-09 15:28:22 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-09 15:28:22 +0000 |
commit | 1cebcd660bf0b6dc514341fe6bc7a392b1572849 (patch) | |
tree | 47a4012107030a73c986e9746aee4bd3a23f1807 /src/renderer/mod.rs | |
parent | 47f8f1bac6f0b41fe1ad9c4267687db7a42068de (diff) | |
download | alacritty-1cebcd660bf0b6dc514341fe6bc7a392b1572849.tar.gz alacritty-1cebcd660bf0b6dc514341fe6bc7a392b1572849.zip |
Fix rendering of zero-width characters
Instead of rendering zero-width characters as full characters, they are
now properly rendered without advancing the cursor.
Because of performance limitations, this implementation only supports up
to 5 zero-width characters per cell. However, as a result of this
limitation there should not be any performance impact.
This fixes #1317, fixes #696 and closes #1318.
Diffstat (limited to 'src/renderer/mod.rs')
-rw-r--r-- | src/renderer/mod.rs | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index ef5a1e76..18699ab7 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -120,7 +120,7 @@ pub struct ShaderProgram { u_background: GLint, } -#[derive(Debug, Clone)] +#[derive(Copy, Debug, Clone)] pub struct Glyph { tex_id: GLuint, top: f32, @@ -835,7 +835,11 @@ impl<'a> RenderApi<'a> { .map(|(i, c)| RenderableCell { line, column: col + i, - c, + chars: { + let mut chars = [' '; cell::MAX_ZEROWIDTH_CHARS + 1]; + chars[0] = c; + chars + }, bg: color, fg: Rgb { r: 0, g: 0, b: 0 }, flags: cell::Flags::empty(), @@ -879,23 +883,40 @@ impl<'a> RenderApi<'a> { glyph_cache.font_key }; + // Don't render text of HIDDEN cells + let chars = if cell.flags.contains(cell::Flags::HIDDEN) { + [' '; cell::MAX_ZEROWIDTH_CHARS + 1] + } else { + cell.chars + }; + let mut glyph_key = GlyphKey { font_key, size: glyph_cache.font_size, - c: cell.c, + c: chars[0], }; - // Don't render text of HIDDEN cells - if cell.flags.contains(cell::Flags::HIDDEN) { - glyph_key.c = ' '; - } - // Add cell to batch { let glyph = glyph_cache.get(glyph_key, self); self.add_render_item(&cell, glyph); } + // Render zero-width characters + for c in (&chars[1..]).iter().filter(|c| **c != ' ') { + glyph_key.c = *c; + let mut glyph = *glyph_cache.get(glyph_key, self); + + // The metrics of zero-width characters are based on rendering + // the character after the current cell, with the anchor at the + // right side of the preceding character. Since we render the + // zero-width characters inside the preceding character, the + // anchor has been moved to the right by one cell. + glyph.left += glyph_cache.metrics.average_advance as f32; + + self.add_render_item(&cell, &glyph); + } + // FIXME This is a super hacky way to do underlined text. During // a time crunch to release 0.1, this seemed like a really // easy, clean hack. |