@@ -103,6 +103,7 @@ export class TextureAtlas implements ITextureAtlas {
103
103
}
104
104
105
105
public dispose ( ) : void {
106
+ this . _tmpCanvas . remove ( ) ;
106
107
for ( const page of this . pages ) {
107
108
page . canvas . remove ( ) ;
108
109
}
@@ -122,7 +123,7 @@ export class TextureAtlas implements ITextureAtlas {
122
123
for ( let i = 33 ; i < 126 ; i ++ ) {
123
124
queue . enqueue ( ( ) => {
124
125
if ( ! this . _cacheMap . get ( i , DEFAULT_COLOR , DEFAULT_COLOR , DEFAULT_EXT ) ) {
125
- const rasterizedGlyph = this . _drawToCache ( i , DEFAULT_COLOR , DEFAULT_COLOR , DEFAULT_EXT ) ;
126
+ const rasterizedGlyph = this . _drawToCache ( i , DEFAULT_COLOR , DEFAULT_COLOR , DEFAULT_EXT , false , undefined ) ;
126
127
this . _cacheMap . set ( i , DEFAULT_COLOR , DEFAULT_COLOR , DEFAULT_EXT , rasterizedGlyph ) ;
127
128
}
128
129
} ) ;
@@ -242,12 +243,12 @@ export class TextureAtlas implements ITextureAtlas {
242
243
}
243
244
}
244
245
245
- public getRasterizedGlyphCombinedChar ( chars : string , bg : number , fg : number , ext : number , restrictToCellHeight : boolean ) : IRasterizedGlyph {
246
- return this . _getFromCacheMap ( this . _cacheMapCombined , chars , bg , fg , ext , restrictToCellHeight ) ;
246
+ public getRasterizedGlyphCombinedChar ( chars : string , bg : number , fg : number , ext : number , restrictToCellHeight : boolean , domContainer : HTMLElement | undefined ) : IRasterizedGlyph {
247
+ return this . _getFromCacheMap ( this . _cacheMapCombined , chars , bg , fg , ext , restrictToCellHeight , domContainer ) ;
247
248
}
248
249
249
- public getRasterizedGlyph ( code : number , bg : number , fg : number , ext : number , restrictToCellHeight : boolean ) : IRasterizedGlyph {
250
- return this . _getFromCacheMap ( this . _cacheMap , code , bg , fg , ext , restrictToCellHeight ) ;
250
+ public getRasterizedGlyph ( code : number , bg : number , fg : number , ext : number , restrictToCellHeight : boolean , domContainer : HTMLElement | undefined ) : IRasterizedGlyph {
251
+ return this . _getFromCacheMap ( this . _cacheMap , code , bg , fg , ext , restrictToCellHeight , domContainer ) ;
251
252
}
252
253
253
254
/**
@@ -259,11 +260,12 @@ export class TextureAtlas implements ITextureAtlas {
259
260
bg : number ,
260
261
fg : number ,
261
262
ext : number ,
262
- restrictToCellHeight : boolean = false
263
+ restrictToCellHeight : boolean ,
264
+ domContainer : HTMLElement | undefined
263
265
) : IRasterizedGlyph {
264
266
$glyph = cacheMap . get ( key , bg , fg , ext ) ;
265
267
if ( ! $glyph ) {
266
- $glyph = this . _drawToCache ( key , bg , fg , ext , restrictToCellHeight ) ;
268
+ $glyph = this . _drawToCache ( key , bg , fg , ext , restrictToCellHeight , domContainer ) ;
267
269
cacheMap . set ( key , bg , fg , ext , $glyph ) ;
268
270
}
269
271
return $glyph ;
@@ -423,12 +425,20 @@ export class TextureAtlas implements ITextureAtlas {
423
425
return this . _config . colors . contrastCache ;
424
426
}
425
427
426
- private _drawToCache ( codeOrChars : number | string , bg : number , fg : number , ext : number , restrictToCellHeight : boolean = false ) : IRasterizedGlyph {
428
+ private _drawToCache ( codeOrChars : number | string , bg : number , fg : number , ext : number , restrictToCellHeight : boolean , domContainer : HTMLElement | undefined ) : IRasterizedGlyph {
427
429
const chars = typeof codeOrChars === 'number' ? String . fromCharCode ( codeOrChars ) : codeOrChars ;
428
430
429
431
// Uncomment for debugging
430
432
// console.log(`draw to cache "${chars}"`, bg, fg, ext);
431
433
434
+ // Attach the canvas to the DOM in order to inherit font-feature-settings
435
+ // from the parent elements. This is necessary for ligatures and variants to
436
+ // work.
437
+ if ( domContainer && this . _tmpCanvas . parentElement !== domContainer ) {
438
+ this . _tmpCanvas . style . display = 'none' ;
439
+ domContainer . append ( this . _tmpCanvas ) ;
440
+ }
441
+
432
442
// Allow 1 cell width per character, with a minimum of 2 (CJK), plus some padding. This is used
433
443
// to draw the glyph to the canvas as well as to restrict the bounding box search to ensure
434
444
// giant ligatures (eg. =====>) don't impact overall performance.
0 commit comments