From 2f1ec3b77e65088ea93853214f7e2fe815f5bbc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Fri, 20 Apr 2018 10:20:10 +0100 Subject: [PATCH] Fully use char atlas for bright & bold colors --- src/renderer/BaseRenderLayer.ts | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index caf81df3b2..9714eaaf27 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -243,23 +243,19 @@ export abstract class BaseRenderLayer implements IRenderLayer { * @param bold Whether the text is bold. */ protected drawChar(terminal: ITerminal, char: string, code: number, width: number, x: number, y: number, fg: number, bg: number, bold: boolean, dim: boolean): void { - let colorIndex = 0; - if (fg < 256) { - colorIndex = fg + 2 + (bold && terminal.options.enableBold ? 16 : 0); - } else { - // If default color and bold - if (bold && terminal.options.enableBold) { - colorIndex = 1; - } - } const isAscii = code < 256; - // A color is basic if it is one of the standard normal or bold weight - // colors of the characters held in the char atlas. Note that this excludes - // the normal weight _light_ color characters. - const isBasicColor = (colorIndex > 1 && fg < 16) && (fg < 8 || bold); + // A color is basic if it is one of the 4 bit ANSI colors. + const isBasicColor = fg < 16; const isDefaultColor = fg >= 256; const isDefaultBackground = bg >= 256; if (this._charAtlas && isAscii && (isBasicColor || isDefaultColor) && isDefaultBackground) { + let colorIndex: number; + if (isDefaultColor) { + colorIndex = (bold && terminal.options.enableBold ? 1 : 0); + } else { + colorIndex = 2 + fg + (bold && terminal.options.enableBold ? 16 : 0); + } + // ImageBitmap's draw about twice as fast as from a canvas const charAtlasCellWidth = this._scaledCharWidth + CHAR_ATLAS_CELL_SPACING; const charAtlasCellHeight = this._scaledCharHeight + CHAR_ATLAS_CELL_SPACING; @@ -269,14 +265,6 @@ export abstract class BaseRenderLayer implements IRenderLayer { this._ctx.globalAlpha = DIM_OPACITY; } - // Draw the non-bold version of the same color if bold is not enabled - if (bold && !terminal.options.enableBold) { - // Ignore default color as it's not touched above - if (colorIndex > 1) { - colorIndex -= 16; - } - } - this._ctx.drawImage(this._charAtlas, code * charAtlasCellWidth, colorIndex * charAtlasCellHeight,