(codeOrChars: number | string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined)
| 431 | } |
| 432 | |
| 433 | private _drawToCache(codeOrChars: number | string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph { |
| 434 | const chars = typeof codeOrChars === 'number' ? String.fromCharCode(codeOrChars) : codeOrChars; |
| 435 | |
| 436 | // Uncomment for debugging |
| 437 | // console.log(`draw to cache "${chars}"`, bg, fg, ext); |
| 438 | |
| 439 | // Attach the canvas to the DOM in order to inherit font-feature-settings |
| 440 | // from the parent elements. This is necessary for ligatures and variants to |
| 441 | // work. |
| 442 | if (domContainer && this._tmpCanvas.parentElement !== domContainer) { |
| 443 | this._tmpCanvas.style.display = 'none'; |
| 444 | domContainer.append(this._tmpCanvas); |
| 445 | } |
| 446 | |
| 447 | // Allow 1 cell width per character, with a minimum of 2 (CJK), plus some padding. This is used |
| 448 | // to draw the glyph to the canvas as well as to restrict the bounding box search to ensure |
| 449 | // giant ligatures (eg. =====>) don't impact overall performance. |
| 450 | const allowedWidth = Math.min(this._config.deviceCellWidth * Math.max(chars.length, 2) + TMP_CANVAS_GLYPH_PADDING * 2, this._config.deviceMaxTextureSize); |
| 451 | if (this._tmpCanvas.width < allowedWidth) { |
| 452 | this._tmpCanvas.width = allowedWidth; |
| 453 | } |
| 454 | // Include line height when drawing glyphs |
| 455 | const allowedHeight = Math.min(this._config.deviceCellHeight + TMP_CANVAS_GLYPH_PADDING * 4, this._textureSize); |
| 456 | if (this._tmpCanvas.height < allowedHeight) { |
| 457 | this._tmpCanvas.height = allowedHeight; |
| 458 | } |
| 459 | this._tmpCtx.save(); |
| 460 | |
| 461 | this._workAttributeData.fg = fg; |
| 462 | this._workAttributeData.bg = bg; |
| 463 | this._workAttributeData.extended.ext = ext; |
| 464 | |
| 465 | const invisible = !!this._workAttributeData.isInvisible(); |
| 466 | if (invisible) { |
| 467 | return NULL_RASTERIZED_GLYPH; |
| 468 | } |
| 469 | |
| 470 | const bold = !!this._workAttributeData.isBold(); |
| 471 | const inverse = !!this._workAttributeData.isInverse(); |
| 472 | const dim = !!this._workAttributeData.isDim(); |
| 473 | const italic = !!this._workAttributeData.isItalic(); |
| 474 | const underline = !!this._workAttributeData.isUnderline(); |
| 475 | const strikethrough = !!this._workAttributeData.isStrikethrough(); |
| 476 | const overline = !!this._workAttributeData.isOverline(); |
| 477 | let fgColor = this._workAttributeData.getFgColor(); |
| 478 | let fgColorMode = this._workAttributeData.getFgColorMode(); |
| 479 | let bgColor = this._workAttributeData.getBgColor(); |
| 480 | let bgColorMode = this._workAttributeData.getBgColorMode(); |
| 481 | if (inverse) { |
| 482 | const temp = fgColor; |
| 483 | fgColor = bgColor; |
| 484 | bgColor = temp; |
| 485 | const temp2 = fgColorMode; |
| 486 | fgColorMode = bgColorMode; |
| 487 | bgColorMode = temp2; |
| 488 | } |
| 489 | |
| 490 | // draw the background |
no test coverage detected