Skip to content

Commit 38f0dd9

Browse files
authored
apply to dom and webgl too (#3742)
1 parent 6d80131 commit 38f0dd9

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ export class WebglCharAtlas implements IDisposable {
216216
}
217217
}
218218

219-
private _getForegroundCss(bg: number, bgColorMode: number, bgColor: number, fg: number, fgColorMode: number, fgColor: number, inverse: boolean, bold: boolean): string {
220-
const minimumContrastCss = this._getMinimumContrastCss(bg, bgColorMode, bgColor, fg, fgColorMode, fgColor, inverse, bold);
219+
private _getForegroundCss(bg: number, bgColorMode: number, bgColor: number, fg: number, fgColorMode: number, fgColor: number, inverse: boolean, bold: boolean, isPowerLineGlyph: boolean): string {
220+
const minimumContrastCss = this._getMinimumContrastCss(bg, bgColorMode, bgColor, fg, fgColorMode, fgColor, inverse, bold, isPowerLineGlyph);
221221
if (minimumContrastCss) {
222222
return minimumContrastCss;
223223
}
@@ -281,8 +281,8 @@ export class WebglCharAtlas implements IDisposable {
281281
}
282282
}
283283

284-
private _getMinimumContrastCss(bg: number, bgColorMode: number, bgColor: number, fg: number, fgColorMode: number, fgColor: number, inverse: boolean, bold: boolean): string | undefined {
285-
if (this._config.minimumContrastRatio === 1) {
284+
private _getMinimumContrastCss(bg: number, bgColorMode: number, bgColor: number, fg: number, fgColorMode: number, fgColor: number, inverse: boolean, bold: boolean, isPowerLineGlyph: boolean): string | undefined {
285+
if (this._config.minimumContrastRatio === 1 || isPowerLineGlyph) {
286286
return undefined;
287287
}
288288

@@ -370,13 +370,6 @@ export class WebglCharAtlas implements IDisposable {
370370
`${fontStyle} ${fontWeight} ${this._config.fontSize * this._config.devicePixelRatio}px ${this._config.fontFamily}`;
371371
this._tmpCtx.textBaseline = TEXT_BASELINE;
372372

373-
this._tmpCtx.fillStyle = this._getForegroundCss(bg, bgColorMode, bgColor, fg, fgColorMode, fgColor, inverse, bold);
374-
375-
// Apply alpha to dim the character
376-
if (dim) {
377-
this._tmpCtx.globalAlpha = DIM_OPACITY;
378-
}
379-
380373
// Check if the char is a powerline glyph, these will be restricted to a single cell glyph, no
381374
// padding on either side that are allowed for other glyphs since they are designed to be pixel
382375
// perfect but may render with "bad" anti-aliasing
@@ -387,6 +380,12 @@ export class WebglCharAtlas implements IDisposable {
387380
isPowerlineGlyph = true;
388381
}
389382
}
383+
this._tmpCtx.fillStyle = this._getForegroundCss(bg, bgColorMode, bgColor, fg, fgColorMode, fgColor, inverse, bold, isPowerlineGlyph);
384+
385+
// Apply alpha to dim the character
386+
if (dim) {
387+
this._tmpCtx.globalAlpha = DIM_OPACITY;
388+
}
390389

391390
// For powerline glyphs left/top padding is excluded (https://github.com/microsoft/vscode/issues/120129)
392391
const padding = isPowerlineGlyph ? 0 : TMP_CANVAS_GLYPH_PADDING;

src/browser/renderer/dom/DomRendererRowFactory.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @license MIT
44
*/
55

6-
import { IBufferLine } from 'common/Types';
6+
import { IBufferLine, ICellData } from 'common/Types';
77
import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants';
88
import { NULL_CELL_CODE, WHITESPACE_CELL_CHAR, Attributes } from 'common/buffer/Constants';
99
import { CellData } from 'common/buffer/CellData';
@@ -178,7 +178,7 @@ export class DomRendererRowFactory {
178178
if (cell.isBold() && fg < 8 && this._optionsService.rawOptions.drawBoldTextInBrightColors) {
179179
fg += 8;
180180
}
181-
if (!this._applyMinimumContrast(charElement, this._colors.background, this._colors.ansi[fg])) {
181+
if (!this._applyMinimumContrast(charElement, this._colors.background, this._colors.ansi[fg], cell)) {
182182
charElement.classList.add(`xterm-fg-${fg}`);
183183
}
184184
break;
@@ -188,13 +188,13 @@ export class DomRendererRowFactory {
188188
(fg >> 8) & 0xFF,
189189
(fg ) & 0xFF
190190
);
191-
if (!this._applyMinimumContrast(charElement, this._colors.background, color)) {
191+
if (!this._applyMinimumContrast(charElement, this._colors.background, color, cell)) {
192192
this._addStyle(charElement, `color:#${padStart(fg.toString(16), '0', 6)}`);
193193
}
194194
break;
195195
case Attributes.CM_DEFAULT:
196196
default:
197-
if (!this._applyMinimumContrast(charElement, this._colors.background, this._colors.foreground)) {
197+
if (!this._applyMinimumContrast(charElement, this._colors.background, this._colors.foreground, cell)) {
198198
if (isInverse) {
199199
charElement.classList.add(`xterm-fg-${INVERTED_DEFAULT_COLOR}`);
200200
}
@@ -224,8 +224,9 @@ export class DomRendererRowFactory {
224224
return fragment;
225225
}
226226

227-
private _applyMinimumContrast(element: HTMLElement, bg: IColor, fg: IColor): boolean {
228-
if (this._optionsService.rawOptions.minimumContrastRatio === 1) {
227+
private _applyMinimumContrast(element: HTMLElement, bg: IColor, fg: IColor, cell: ICellData): boolean {
228+
const codepoint = cell.getCode();
229+
if (this._optionsService.rawOptions.minimumContrastRatio === 1 || 57344 <= codepoint && codepoint <= 63743) {
229230
return false;
230231
}
231232

0 commit comments

Comments
 (0)