diff options
Diffstat (limited to 'alacritty/src/renderer/mod.rs')
-rw-r--r-- | alacritty/src/renderer/mod.rs | 68 |
1 files changed, 30 insertions, 38 deletions
diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index e97ac025..f628d24f 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -19,7 +19,7 @@ use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; use alacritty_terminal::config::Cursor; use alacritty_terminal::index::{Column, Line}; -use alacritty_terminal::term::cell::{self, Flags}; +use alacritty_terminal::term::cell::Flags; use alacritty_terminal::term::color::Rgb; use alacritty_terminal::term::{CursorKey, RenderableCell, RenderableCellContent, SizeInfo}; use alacritty_terminal::thread; @@ -436,7 +436,7 @@ impl Batch { Self { tex: 0, instances: Vec::with_capacity(BATCH_MAX) } } - pub fn add_item(&mut self, cell: RenderableCell, glyph: &Glyph) { + pub fn add_item(&mut self, cell: &RenderableCell, glyph: &Glyph) { if self.is_empty() { self.tex = glyph.tex_id; } @@ -953,11 +953,7 @@ impl<'a> RenderApi<'a> { .map(|(i, c)| RenderableCell { line, column: Column(i), - inner: RenderableCellContent::Chars({ - let mut chars = [' '; cell::MAX_ZEROWIDTH_CHARS + 1]; - chars[0] = c; - chars - }), + inner: RenderableCellContent::Chars((c, None)), flags: Flags::empty(), bg_alpha, fg, @@ -971,7 +967,7 @@ impl<'a> RenderApi<'a> { } #[inline] - fn add_render_item(&mut self, cell: RenderableCell, glyph: &Glyph) { + fn add_render_item(&mut self, cell: &RenderableCell, glyph: &Glyph) { // Flush batch if tex changing. if !self.batch.is_empty() && self.batch.tex != glyph.tex_id { self.render_batch(); @@ -985,8 +981,8 @@ impl<'a> RenderApi<'a> { } } - pub fn render_cell(&mut self, cell: RenderableCell, glyph_cache: &mut GlyphCache) { - let chars = match cell.inner { + pub fn render_cell(&mut self, mut cell: RenderableCell, glyph_cache: &mut GlyphCache) { + let (mut c, zerowidth) = match cell.inner { RenderableCellContent::Cursor(cursor_key) => { // Raw cell pixel buffers like cursors don't need to go through font lookup. let metrics = glyph_cache.metrics; @@ -1000,10 +996,10 @@ impl<'a> RenderApi<'a> { self.cursor_config.thickness(), )) }); - self.add_render_item(cell, glyph); + self.add_render_item(&cell, glyph); return; }, - RenderableCellContent::Chars(chars) => chars, + RenderableCellContent::Chars((c, ref mut zerowidth)) => (c, zerowidth.take()), }; // Get font key for cell. @@ -1014,37 +1010,33 @@ impl<'a> RenderApi<'a> { _ => glyph_cache.font_key, }; - // Don't render text of HIDDEN cells. - let mut chars = if cell.flags.contains(Flags::HIDDEN) { - [' '; cell::MAX_ZEROWIDTH_CHARS + 1] - } else { - chars - }; - - // Render tabs as spaces in case the font doesn't support it. - if chars[0] == '\t' { - chars[0] = ' '; + // Ignore hidden cells and render tabs as spaces to prevent font issues. + let hidden = cell.flags.contains(Flags::HIDDEN); + if c == '\t' || hidden { + c = ' '; } - let mut glyph_key = GlyphKey { font_key, size: glyph_cache.font_size, c: chars[0] }; + let mut glyph_key = GlyphKey { font_key, size: glyph_cache.font_size, 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 i16; - - self.add_render_item(cell, &glyph); + self.add_render_item(&cell, glyph); + + // Render visible zero-width characters. + if let Some(zerowidth) = zerowidth.filter(|_| !hidden) { + for c in zerowidth { + 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 i16; + + self.add_render_item(&cell, &glyph); + } } } } |