From d3d11d629f12da1649e685c91c7956dba58b5335 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 5 Aug 2018 17:19:58 -0700 Subject: [PATCH] fix rendering of reverse video This got broken when unifying the termwiz color type; we used to have enum variants for background and foreground colors, but now we just have Default and we need to resolve using helper methods in the palette. That means we need to resolve the colors before we swap them for reverse video. Bonus: we can lift this out of the loop for the cell cluster. --- src/opengl/render.rs | 66 +++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/opengl/render.rs b/src/opengl/render.rs index db7dbb472..a40e708af 100644 --- a/src/opengl/render.rs +++ b/src/opengl/render.rs @@ -619,18 +619,43 @@ impl Renderer { }; let style = self.fonts.match_style(attrs); - let (fg_color, bg_color) = { - let mut fg_color = &attrs.foreground; - let mut bg_color = &attrs.background; - - if attrs.reverse() { - mem::swap(&mut fg_color, &mut bg_color); + let bg_color = self.palette.resolve_bg(&attrs.background); + let fg_color = match attrs.foreground { + term::color::ColorAttribute::Default => { + if let Some(fg) = style.foreground { + fg + } else { + self.palette.resolve_fg(&attrs.foreground) + } } - - (fg_color, bg_color) + term::color::ColorAttribute::PaletteIndex(idx) if idx < 8 => { + // For compatibility purposes, switch to a brighter version + // of one of the standard ANSI colors when Bold is enabled. + // This lifts black to dark grey. + let idx = if attrs.intensity() == term::Intensity::Bold { + idx + 8 + } else { + idx + }; + self.palette + .resolve_fg(&term::color::ColorAttribute::PaletteIndex(idx)) + } + _ => self.palette.resolve_fg(&attrs.foreground), }; - let bg_color = self.palette.resolve_bg(bg_color).to_tuple_rgba(); + let (fg_color, bg_color) = { + let mut fg = fg_color; + let mut bg = bg_color; + + if attrs.reverse() { + mem::swap(&mut fg, &mut bg); + } + + (fg, bg) + }; + + let glyph_color = fg_color.to_tuple_rgba(); + let bg_color = bg_color.to_tuple_rgba(); // Shape the printable text from this cluster let glyph_info = { @@ -643,29 +668,6 @@ impl Renderer { let cell_idx = cluster.byte_to_cell_idx[info.cluster as usize]; let glyph = self.cached_glyph(info, style)?; - let glyph_color = match *fg_color { - term::color::ColorAttribute::Default => { - if let Some(fg) = style.foreground { - fg - } else { - self.palette.resolve_fg(fg_color) - } - } - term::color::ColorAttribute::PaletteIndex(idx) if idx < 8 => { - // For compatibility purposes, switch to a brighter version - // of one of the standard ANSI colors when Bold is enabled. - // This lifts black to dark grey. - let idx = if attrs.intensity() == term::Intensity::Bold { - idx + 8 - } else { - idx - }; - self.palette - .resolve_fg(&term::color::ColorAttribute::PaletteIndex(idx)) - } - _ => self.palette.resolve_fg(fg_color), - }.to_tuple_rgba(); - let left: f32 = glyph.x_offset as f32 + glyph.bearing_x as f32; let top = (self.cell_height as f32 + self.descender as f32) - (glyph.y_offset as f32 + glyph.bearing_y as f32);