From e518ea04c59c3122ff99dfee427009bba511229b Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 3 Sep 2017 14:21:30 -0700 Subject: [PATCH] Get tests reporting failures again --- src/Terminal.ts | 3 +++ src/renderer/CharAtlas.ts | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Terminal.ts b/src/Terminal.ts index c3d360bb..62034017 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -43,6 +43,7 @@ import { BellSound } from './utils/Sounds'; import { DEFAULT_ANSI_COLORS } from './renderer/ColorManager'; import { IMouseZoneManager } from './input/Interfaces'; import { MouseZoneManager } from './input/MouseZoneManager'; +import { initialize as initializeCharAtlas } from './renderer/CharAtlas'; // Declare for RequireJS in loadAddon declare var define: any; @@ -562,6 +563,8 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.document = this.parent.ownerDocument; this.body = this.document.body; + initializeCharAtlas(this.document); + // Create main element container this.element = this.document.createElement('div'); this.element.classList.add('terminal'); diff --git a/src/renderer/CharAtlas.ts b/src/renderer/CharAtlas.ts index a92037a8..4fcedd1a 100644 --- a/src/renderer/CharAtlas.ts +++ b/src/renderer/CharAtlas.ts @@ -91,12 +91,20 @@ function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean { a.colors.foreground === b.colors.foreground; } +let generator: CharAtlasGenerator; + +export function initialize(document: Document): void { + if (!generator) { + generator = new CharAtlasGenerator(document); + } +} + class CharAtlasGenerator { private _canvas: HTMLCanvasElement; private _ctx: CanvasRenderingContext2D; - constructor() { - this._canvas = document.createElement('canvas'); + constructor(private _document: Document) { + this._canvas = this._document.createElement('canvas'); this._ctx = this._canvas.getContext('2d'); this._ctx.scale(window.devicePixelRatio, window.devicePixelRatio); } @@ -147,7 +155,7 @@ class CharAtlasGenerator { if (!('createImageBitmap' in window)) { // Regenerate canvas and context as they are now owned by the char atlas const result = this._canvas; - this._canvas = document.createElement('canvas'); + this._canvas = this._document.createElement('canvas'); this._ctx = this._canvas.getContext('2d'); this._ctx.scale(window.devicePixelRatio, window.devicePixelRatio); return result; @@ -159,5 +167,3 @@ class CharAtlasGenerator { return promise; } } - -const generator = new CharAtlasGenerator();