diff options
author | Kirill Chibisov <wchibisovkirill@gmail.com> | 2019-12-10 01:12:44 +0300 |
---|---|---|
committer | Christian Duerr <contact@christianduerr.com> | 2019-12-09 23:12:44 +0100 |
commit | 79b19176eeb57fbd6b137160afd6bc9f5518ad33 (patch) | |
tree | a3f76e83973e1bba2090afe39fbaa688d48efbf6 /alacritty/src | |
parent | 88b4dbfc5a890569fcfac3fe400fe0ad0ea234cc (diff) | |
download | r-alacritty-79b19176eeb57fbd6b137160afd6bc9f5518ad33.tar.gz r-alacritty-79b19176eeb57fbd6b137160afd6bc9f5518ad33.tar.bz2 r-alacritty-79b19176eeb57fbd6b137160afd6bc9f5518ad33.zip |
Add support for colored emojis on Linux/BSD
Fixes #153.
Diffstat (limited to 'alacritty/src')
-rw-r--r-- | alacritty/src/cursor.rs | 24 | ||||
-rw-r--r-- | alacritty/src/renderer/mod.rs | 33 |
2 files changed, 48 insertions, 9 deletions
diff --git a/alacritty/src/cursor.rs b/alacritty/src/cursor.rs index e671bf4b..a3e6a2ca 100644 --- a/alacritty/src/cursor.rs +++ b/alacritty/src/cursor.rs @@ -18,7 +18,7 @@ use std::cmp; use alacritty_terminal::ansi::CursorStyle; -use font::{Metrics, RasterizedGlyph}; +use font::{BitmapBuffer, Metrics, RasterizedGlyph}; /// Width/Height of the cursor relative to the font width pub const CURSOR_WIDTH_PERCENTAGE: i32 = 15; @@ -55,7 +55,14 @@ pub fn get_underline_cursor_glyph(width: i32, line_width: i32) -> RasterizedGlyp let buf = vec![255u8; (width * line_width * 3) as usize]; // Create a custom glyph with the rectangle data attached to it - RasterizedGlyph { c: ' ', top: line_width, left: 0, height: line_width, width, buf } + RasterizedGlyph { + c: ' ', + top: line_width, + left: 0, + height: line_width, + width, + buf: BitmapBuffer::RGB(buf), + } } // Returns a custom beam cursor character @@ -64,7 +71,14 @@ pub fn get_beam_cursor_glyph(height: i32, line_width: i32) -> RasterizedGlyph { let buf = vec![255u8; (line_width * height * 3) as usize]; // Create a custom glyph with the rectangle data attached to it - RasterizedGlyph { c: ' ', top: height, left: 0, height, width: line_width, buf } + RasterizedGlyph { + c: ' ', + top: height, + left: 0, + height, + width: line_width, + buf: BitmapBuffer::RGB(buf), + } } // Returns a custom box cursor character @@ -86,7 +100,7 @@ pub fn get_box_cursor_glyph(height: i32, width: i32, line_width: i32) -> Rasteri } // Create a custom glyph with the rectangle data attached to it - RasterizedGlyph { c: ' ', top: height, left: 0, height, width, buf } + RasterizedGlyph { c: ' ', top: height, left: 0, height, width, buf: BitmapBuffer::RGB(buf) } } // Returns a custom block cursor character @@ -95,5 +109,5 @@ pub fn get_block_cursor_glyph(height: i32, width: i32) -> RasterizedGlyph { let buf = vec![255u8; (width * height * 3) as usize]; // Create a custom glyph with the rectangle data attached to it - RasterizedGlyph { c: ' ', top: height, left: 0, height, width, buf } + RasterizedGlyph { c: ' ', top: height, left: 0, height, width, buf: BitmapBuffer::RGB(buf) } } diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index a0617988..2d124ccc 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -22,7 +22,9 @@ use std::sync::mpsc; use std::time::Duration; use fnv::FnvHasher; -use font::{self, FontDesc, FontKey, GlyphKey, Rasterize, RasterizedGlyph, Rasterizer}; +use font::{ + self, BitmapBuffer, FontDesc, FontKey, GlyphKey, Rasterize, RasterizedGlyph, Rasterizer, +}; use log::{error, info}; use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; @@ -139,6 +141,7 @@ pub struct RectShaderProgram { #[derive(Copy, Debug, Clone)] pub struct Glyph { tex_id: GLuint, + colored: bool, top: f32, left: f32, width: f32, @@ -462,11 +465,19 @@ impl Batch { Batch { tex: 0, instances: Vec::with_capacity(BATCH_MAX) } } - pub fn add_item(&mut self, cell: RenderableCell, glyph: &Glyph) { + pub fn add_item(&mut self, mut cell: RenderableCell, glyph: &Glyph) { if self.is_empty() { self.tex = glyph.tex_id; } + if glyph.colored { + // XXX Temporary workaround to prevent emojis being rendered with a wrong colors on, at + // least, dark backgrounds. For more info see #1864. + cell.fg.r = 255; + cell.fg.g = 255; + cell.fg.b = 255; + } + self.instances.push(InstanceData { col: cell.column.0 as f32, row: cell.line.0 as f32, @@ -1091,6 +1102,7 @@ fn load_glyph( }, Err(AtlasInsertError::GlyphTooLarge) => Glyph { tex_id: atlas[*current_atlas].id, + colored: false, top: 0.0, left: 0.0, width: 0.0, @@ -1573,11 +1585,23 @@ impl Atlas { let offset_x = self.row_extent; let height = glyph.height as i32; let width = glyph.width as i32; + let colored; unsafe { gl::BindTexture(gl::TEXTURE_2D, self.id); // Load data into OpenGL + let (format, buf) = match &glyph.buf { + BitmapBuffer::RGB(buf) => { + colored = false; + (gl::RGB, buf) + }, + BitmapBuffer::RGBA(buf) => { + colored = true; + (gl::RGBA, buf) + }, + }; + gl::TexSubImage2D( gl::TEXTURE_2D, 0, @@ -1585,9 +1609,9 @@ impl Atlas { offset_y, width, height, - gl::RGB, + format, gl::UNSIGNED_BYTE, - glyph.buf.as_ptr() as *const _, + buf.as_ptr() as *const _, ); gl::BindTexture(gl::TEXTURE_2D, 0); @@ -1608,6 +1632,7 @@ impl Atlas { Glyph { tex_id: self.id, + colored, top: glyph.top as f32, width: width as f32, height: height as f32, |