diff --git a/src/renderer/atlas/DynamicCharAtlas.ts b/src/browser/renderer/atlas/DynamicCharAtlas.ts similarity index 95% rename from src/renderer/atlas/DynamicCharAtlas.ts rename to src/browser/renderer/atlas/DynamicCharAtlas.ts index 9af79e01e..d591c173b 100644 --- a/src/renderer/atlas/DynamicCharAtlas.ts +++ b/src/browser/renderer/atlas/DynamicCharAtlas.ts @@ -3,10 +3,9 @@ * @license MIT */ -import { ICharAtlasConfig } from './Types'; import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants'; -import { IGlyphIdentifier } from 'browser/renderer/atlas/Types'; -import { BaseCharAtlas } from '../../browser/renderer/atlas/BaseCharAtlas'; +import { IGlyphIdentifier, ICharAtlasConfig } from 'browser/renderer/atlas/Types'; +import { BaseCharAtlas } from 'browser/renderer/atlas/BaseCharAtlas'; import { DEFAULT_ANSI_COLORS } from 'browser/ColorManager'; import { LRUMap } from 'browser/renderer/atlas/LRUMap'; import { isFirefox, isSafari } from 'common/Platform'; @@ -90,12 +89,12 @@ export class DynamicCharAtlas extends BaseCharAtlas { // The canvas needs alpha because we use clearColor to convert the background color to alpha. // It might also contain some characters with transparent backgrounds if allowTransparency is // set. - this._cacheCtx = this._cacheCanvas.getContext('2d', {alpha: true}); + this._cacheCtx = throwIfFalsy(this._cacheCanvas.getContext('2d', {alpha: true})); const tmpCanvas = document.createElement('canvas'); tmpCanvas.width = this._config.scaledCharWidth; tmpCanvas.height = this._config.scaledCharHeight; - this._tmpCtx = tmpCanvas.getContext('2d', {alpha: this._config.allowTransparency}); + this._tmpCtx = throwIfFalsy(tmpCanvas.getContext('2d', {alpha: this._config.allowTransparency})); this._width = Math.floor(TEXTURE_WIDTH / this._config.scaledCharWidth); this._height = Math.floor(TEXTURE_HEIGHT / this._config.scaledCharHeight); @@ -145,7 +144,7 @@ export class DynamicCharAtlas extends BaseCharAtlas { index = this._cacheMap.size; } else { // we're out of space, so our call to set will delete this item - index = this._cacheMap.peek().index; + index = this._cacheMap.peek()!.index; } const cacheValue = this._drawToCache(glyph, index); this._cacheMap.set(glyphKey, cacheValue); @@ -187,7 +186,7 @@ export class DynamicCharAtlas extends BaseCharAtlas { const cacheX = this._toCoordinateX(cacheValue.index); const cacheY = this._toCoordinateY(cacheValue.index); ctx.drawImage( - cacheValue.inBitmap ? this._bitmap : this._cacheCanvas, + cacheValue.inBitmap ? this._bitmap! : this._cacheCanvas, cacheX, cacheY, this._config.scaledCharWidth, @@ -367,3 +366,10 @@ function clearColor(imageData: ImageData, color: IColor): boolean { } return isEmpty; } + +export function throwIfFalsy(value: T | undefined | null): T { + if (!value) { + throw new Error('value must not be falsy'); + } + return value; +} diff --git a/src/browser/renderer/atlas/Types.d.ts b/src/browser/renderer/atlas/Types.d.ts index fd5b596cb..0724b163f 100644 --- a/src/browser/renderer/atlas/Types.d.ts +++ b/src/browser/renderer/atlas/Types.d.ts @@ -3,6 +3,9 @@ * @license MIT */ +import { FontWeight } from 'common/services/Services'; +import { IColorSet } from 'browser/Types'; + export interface IGlyphIdentifier { chars: string; code: number; @@ -12,3 +15,15 @@ export interface IGlyphIdentifier { dim: boolean; italic: boolean; } + +export interface ICharAtlasConfig { + devicePixelRatio: number; + fontSize: number; + fontFamily: string; + fontWeight: FontWeight; + fontWeightBold: FontWeight; + scaledCharWidth: number; + scaledCharHeight: number; + allowTransparency: boolean; + colors: IColorSet; +} diff --git a/src/renderer/atlas/CharAtlasCache.ts b/src/renderer/atlas/CharAtlasCache.ts index f9bd68a1f..ec66b67a7 100644 --- a/src/renderer/atlas/CharAtlasCache.ts +++ b/src/renderer/atlas/CharAtlasCache.ts @@ -6,8 +6,8 @@ import { ITerminal } from '../../Types'; import { generateConfig, configEquals } from './CharAtlasUtils'; import { BaseCharAtlas } from 'browser/renderer/atlas/BaseCharAtlas'; -import { DynamicCharAtlas } from './DynamicCharAtlas'; -import { ICharAtlasConfig } from './Types'; +import { DynamicCharAtlas } from '../../browser/renderer/atlas/DynamicCharAtlas'; +import { ICharAtlasConfig } from 'browser/renderer/atlas/Types'; import { IColorSet } from 'browser/Types'; interface ICharAtlasCacheEntry { diff --git a/src/renderer/atlas/CharAtlasUtils.ts b/src/renderer/atlas/CharAtlasUtils.ts index ee787a7ba..da067f520 100644 --- a/src/renderer/atlas/CharAtlasUtils.ts +++ b/src/renderer/atlas/CharAtlasUtils.ts @@ -4,7 +4,7 @@ */ import { ITerminal } from '../../Types'; -import { ICharAtlasConfig } from './Types'; +import { ICharAtlasConfig } from 'browser/renderer/atlas/Types'; import { DEFAULT_COLOR } from 'common/buffer/Constants'; import { IColorSet } from 'browser/Types'; diff --git a/src/renderer/atlas/Types.d.ts b/src/renderer/atlas/Types.d.ts deleted file mode 100644 index f717381c8..000000000 --- a/src/renderer/atlas/Types.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2017 The xterm.js authors. All rights reserved. - * @license MIT - */ - -import { FontWeight } from 'xterm'; -import { IColorSet } from 'browser/Types'; - -export interface ICharAtlasConfig { - devicePixelRatio: number; - fontSize: number; - fontFamily: string; - fontWeight: FontWeight; - fontWeightBold: FontWeight; - scaledCharWidth: number; - scaledCharHeight: number; - allowTransparency: boolean; - colors: IColorSet; -}