From 51de968fdecdebd541c1480bc0622bf5ce8c2606 Mon Sep 17 00:00:00 2001 From: Bruno Ribeito Date: Sun, 12 Nov 2017 23:05:27 +0000 Subject: [PATCH] Fix non-white colors not being drawn as bold --- src/renderer/BaseRenderLayer.ts | 11 ++--------- src/renderer/CharAtlas.ts | 12 ++++++++---- src/renderer/TextRenderLayer.ts | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index a5f4370c..977cbf52 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -251,13 +251,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) { - // Ignore default color as it's not touched above - if (colorIndex > 1) { - colorIndex -= 8; - } - } this._ctx.drawImage(this._charAtlas, code * charAtlasCellWidth, @@ -333,9 +326,9 @@ export abstract class BaseRenderLayer implements IRenderLayer { /** * Gets the current font. * @param terminal The terminal. - * @param isBold The font weight that should be used uses terminal option as fallback. + * @param isBold If we should use the bold fontWeight. */ - private _getFont(terminal: ITerminal, isBold: boolean): string { + protected _getFont(terminal: ITerminal, isBold: boolean): string { const fontWeight = isBold ? terminal.options.fontWeightBold : terminal.options.fontWeight; return `${fontWeight} ${terminal.options.fontSize * window.devicePixelRatio}px ${terminal.options.fontFamily}`; diff --git a/src/renderer/CharAtlas.ts b/src/renderer/CharAtlas.ts index 50b9b9bd..1458ba76 100644 --- a/src/renderer/CharAtlas.ts +++ b/src/renderer/CharAtlas.ts @@ -143,7 +143,7 @@ class CharAtlasGenerator { this._ctx.save(); this._ctx.fillStyle = foreground; - this._ctx.font = `${fontWeight} ${fontSize * window.devicePixelRatio}px ${fontFamily}`; + this._ctx.font = this._getFont(fontWeight, fontSize, fontFamily); this._ctx.textBaseline = 'top'; // Default color @@ -157,7 +157,7 @@ class CharAtlasGenerator { } // Default color bold this._ctx.save(); - this._ctx.font = `${fontWeightBold} ${fontSize * window.devicePixelRatio}px ${fontFamily}`; + this._ctx.font = this._getFont(fontWeightBold, fontSize, fontFamily); for (let i = 0; i < 256; i++) { this._ctx.save(); this._ctx.beginPath(); @@ -169,11 +169,11 @@ class CharAtlasGenerator { this._ctx.restore(); // Colors 0-15 - this._ctx.font = `${fontWeight} ${fontSize * window.devicePixelRatio}px ${fontFamily}`; + this._ctx.font = this._getFont(fontWeight, fontSize, fontFamily); for (let colorIndex = 0; colorIndex < 16; colorIndex++) { // colors 8-15 are bold if (colorIndex === 8) { - this._ctx.font = `${fontWeightBold} ${fontSize * window.devicePixelRatio}px ${fontFamily}`; + this._ctx.font = this._getFont(fontWeightBold, fontSize, fontFamily); } const y = (colorIndex + 2) * cellHeight; // Draw ascii characters @@ -225,4 +225,8 @@ class CharAtlasGenerator { } } } + + private _getFont(fontWeight: string, fontSize: number, fontFamily: string): string { + return `${fontWeight} ${fontSize * window.devicePixelRatio}px ${fontFamily}`; + } } diff --git a/src/renderer/TextRenderLayer.ts b/src/renderer/TextRenderLayer.ts index 5a13242f..41454adb 100644 --- a/src/renderer/TextRenderLayer.ts +++ b/src/renderer/TextRenderLayer.ts @@ -33,7 +33,7 @@ export class TextRenderLayer extends BaseRenderLayer { super.resize(terminal, dim, charSizeChanged); // Clear the character width cache if the font or width has changed - const terminalFont = `${terminal.options.fontWeight} ${terminal.options.fontSize * window.devicePixelRatio}px ${terminal.options.fontFamily}`; + const terminalFont = this._getFont(terminal, false); if (this._characterWidth !== dim.scaledCharWidth || this._characterFont !== terminalFont) { this._characterWidth = dim.scaledCharWidth; this._characterFont = terminalFont; @@ -166,7 +166,7 @@ export class TextRenderLayer extends BaseRenderLayer { this._ctx.save(); if (flags & FLAGS.BOLD) { - this._ctx.font = `bold ${this._ctx.font}`; + this._ctx.font = this._getFont(terminal, true); // Convert the FG color to the bold variant if (fg < 8) { fg += 8;