@@ -103,6 +103,7 @@ export class TextureAtlas implements ITextureAtlas {
103103 }
104104
105105 public dispose ( ) : void {
106+ this . _tmpCanvas . remove ( ) ;
106107 for ( const page of this . pages ) {
107108 page . canvas . remove ( ) ;
108109 }
@@ -122,7 +123,7 @@ export class TextureAtlas implements ITextureAtlas {
122123 for ( let i = 33 ; i < 126 ; i ++ ) {
123124 queue . enqueue ( ( ) => {
124125 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 ) ;
126127 this . _cacheMap . set ( i , DEFAULT_COLOR , DEFAULT_COLOR , DEFAULT_EXT , rasterizedGlyph ) ;
127128 }
128129 } ) ;
@@ -242,12 +243,12 @@ export class TextureAtlas implements ITextureAtlas {
242243 }
243244 }
244245
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 ) ;
247248 }
248249
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 ) ;
251252 }
252253
253254 /**
@@ -259,11 +260,12 @@ export class TextureAtlas implements ITextureAtlas {
259260 bg : number ,
260261 fg : number ,
261262 ext : number ,
262- restrictToCellHeight : boolean = false
263+ restrictToCellHeight : boolean ,
264+ domContainer : HTMLElement | undefined
263265 ) : IRasterizedGlyph {
264266 $glyph = cacheMap . get ( key , bg , fg , ext ) ;
265267 if ( ! $glyph ) {
266- $glyph = this . _drawToCache ( key , bg , fg , ext , restrictToCellHeight ) ;
268+ $glyph = this . _drawToCache ( key , bg , fg , ext , restrictToCellHeight , domContainer ) ;
267269 cacheMap . set ( key , bg , fg , ext , $glyph ) ;
268270 }
269271 return $glyph ;
@@ -423,12 +425,20 @@ export class TextureAtlas implements ITextureAtlas {
423425 return this . _config . colors . contrastCache ;
424426 }
425427
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 {
427429 const chars = typeof codeOrChars === 'number' ? String . fromCharCode ( codeOrChars ) : codeOrChars ;
428430
429431 // Uncomment for debugging
430432 // console.log(`draw to cache "${chars}"`, bg, fg, ext);
431433
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+
432442 // Allow 1 cell width per character, with a minimum of 2 (CJK), plus some padding. This is used
433443 // to draw the glyph to the canvas as well as to restrict the bounding box search to ensure
434444 // giant ligatures (eg. =====>) don't impact overall performance.
0 commit comments