@@ -189,58 +189,84 @@ export class WebglCharAtlas implements IDisposable {
189189 return this . _config . colors . ansi [ idx ] ;
190190 }
191191
192- private _getBackgroundColor ( bgColorMode : number , bgColor : number , inverse : boolean ) : IColor {
192+ private _getBackgroundColor ( bgColorMode : number , bgColor : number , inverse : boolean , dim : boolean ) : IColor {
193193 if ( this . _config . allowTransparency ) {
194194 // The background color might have some transparency, so we need to render it as fully
195195 // transparent in the atlas. Otherwise we'd end up drawing the transparent background twice
196196 // around the anti-aliased edges of the glyph, and it would look too dark.
197197 return TRANSPARENT_COLOR ;
198198 }
199199
200+ let result : IColor ;
200201 switch ( bgColorMode ) {
201202 case Attributes . CM_P16 :
202203 case Attributes . CM_P256 :
203- return this . _getColorFromAnsiIndex ( bgColor ) ;
204+ result = this . _getColorFromAnsiIndex ( bgColor ) ;
205+ break ;
204206 case Attributes . CM_RGB :
205207 const arr = AttributeData . toColorRGB ( bgColor ) ;
206208 // TODO: This object creation is slow
207- return {
208- rgba : bgColor << 8 ,
209- css : `#${ toPaddedHex ( arr [ 0 ] ) } ${ toPaddedHex ( arr [ 1 ] ) } ${ toPaddedHex ( arr [ 2 ] ) } `
210- } ;
209+ result = rgba . toColor ( arr [ 0 ] , arr [ 1 ] , arr [ 2 ] ) ;
210+ break ;
211211 case Attributes . CM_DEFAULT :
212212 default :
213213 if ( inverse ) {
214- return this . _config . colors . foreground ;
214+ result = this . _config . colors . foreground ;
215+ } else {
216+ result = this . _config . colors . background ;
215217 }
216- return this . _config . colors . background ;
218+ break ;
219+ }
220+
221+ if ( dim ) {
222+ // Blend here instead of using opacity because transparent colors mess with clipping the
223+ // glyph's bounding box
224+ result = color . blend ( this . _config . colors . background , color . multiplyOpacity ( result , 0.5 ) ) ;
217225 }
226+
227+ return result ;
218228 }
219229
220- private _getForegroundColor ( bg : number , bgColorMode : number , bgColor : number , fg : number , fgColorMode : number , fgColor : number , inverse : boolean , bold : boolean , excludeFromContrastRatioDemands : boolean ) : IColor {
221- const minimumContrastColor = this . _getMinimumContrastColor ( bg , bgColorMode , bgColor , fg , fgColorMode , fgColor , inverse , bold , excludeFromContrastRatioDemands ) ;
230+ private _getForegroundColor ( bg : number , bgColorMode : number , bgColor : number , fg : number , fgColorMode : number , fgColor : number , inverse : boolean , dim : boolean , bold : boolean , excludeFromContrastRatioDemands : boolean ) : IColor {
231+ // TODO: Pass dim along to get min contrast?
232+ const minimumContrastColor = this . _getMinimumContrastColor ( bg , bgColorMode , bgColor , fg , fgColorMode , fgColor , false , bold , excludeFromContrastRatioDemands ) ;
222233 if ( minimumContrastColor ) {
223234 return minimumContrastColor ;
224235 }
225236
237+ let result : IColor ;
226238 switch ( fgColorMode ) {
227239 case Attributes . CM_P16 :
228240 case Attributes . CM_P256 :
229241 if ( this . _config . drawBoldTextInBrightColors && bold && fgColor < 8 ) {
230242 fgColor += 8 ;
231243 }
232- return this . _getColorFromAnsiIndex ( fgColor ) ;
244+ result = this . _getColorFromAnsiIndex ( fgColor ) ;
245+ break ;
233246 case Attributes . CM_RGB :
234247 const arr = AttributeData . toColorRGB ( fgColor ) ;
235- return rgba . toColor ( arr [ 0 ] , arr [ 1 ] , arr [ 2 ] ) ;
248+ result = rgba . toColor ( arr [ 0 ] , arr [ 1 ] , arr [ 2 ] ) ;
249+ break ;
236250 case Attributes . CM_DEFAULT :
237251 default :
238252 if ( inverse ) {
239- // Inverse should always been opaque, even when transparency is used
240- return color . opaque ( this . _config . colors . background ) ;
253+ result = this . _config . colors . background ;
254+ } else {
255+ result = this . _config . colors . foreground ;
241256 }
242- return this . _config . colors . foreground ;
243257 }
258+
259+ // Always use an opaque color regardless of allowTransparency
260+ if ( this . _config . allowTransparency ) {
261+ result = color . opaque ( result ) ;
262+ }
263+
264+ // Apply dim to the color, opacity is fine to use for the foreground color
265+ if ( dim ) {
266+ result = color . multiplyOpacity ( result , 0.5 ) ;
267+ }
268+
269+ return result ;
244270 }
245271
246272 private _resolveBackgroundRgba ( bgColorMode : number , bgColor : number , inverse : boolean ) : number {
@@ -357,7 +383,7 @@ export class WebglCharAtlas implements IDisposable {
357383 }
358384
359385 // draw the background
360- const backgroundColor = this . _getBackgroundColor ( bgColorMode , bgColor , inverse ) ;
386+ const backgroundColor = this . _getBackgroundColor ( bgColorMode , bgColor , inverse , dim ) ;
361387 // Use a 'copy' composite operation to clear any existing glyph out of _tmpCtxWithAlpha, regardless of
362388 // transparency in backgroundColor
363389 this . _tmpCtx . globalCompositeOperation = 'copy' ;
@@ -373,14 +399,9 @@ export class WebglCharAtlas implements IDisposable {
373399 this . _tmpCtx . textBaseline = TEXT_BASELINE ;
374400
375401 const powerLineGlyph = chars . length === 1 && isPowerlineGlyph ( chars . charCodeAt ( 0 ) ) ;
376- const foregroundColor = this . _getForegroundColor ( bg , bgColorMode , bgColor , fg , fgColorMode , fgColor , inverse , bold , excludeFromContrastRatioDemands ( chars . charCodeAt ( 0 ) ) ) ;
402+ const foregroundColor = this . _getForegroundColor ( bg , bgColorMode , bgColor , fg , fgColorMode , fgColor , inverse , dim , bold , excludeFromContrastRatioDemands ( chars . charCodeAt ( 0 ) ) ) ;
377403 this . _tmpCtx . fillStyle = foregroundColor . css ;
378404
379- // Apply alpha to dim the character
380- if ( dim ) {
381- this . _tmpCtx . globalAlpha = DIM_OPACITY ;
382- }
383-
384405 // For powerline glyphs left/top padding is excluded (https://github.com/microsoft/vscode/issues/120129)
385406 const padding = powerLineGlyph ? 0 : TMP_CANVAS_GLYPH_PADDING ;
386407
0 commit comments