diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index f977d4c545..4d626e4ba3 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -5,12 +5,11 @@ import { IRenderLayer, IColorSet, IRenderDimensions } from './Types'; import { CharData, ITerminal, ITerminalOptions } from '../Types'; -import { acquireCharAtlas, CHAR_ATLAS_CELL_SPACING } from './CharAtlas'; +import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from './atlas/Types'; +import { CHAR_ATLAS_CELL_SPACING } from '../shared/atlas/Types'; +import { acquireCharAtlas } from './atlas/CharAtlas'; import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from '../Buffer'; -export const INVERTED_DEFAULT_COLOR = -1; -const DIM_OPACITY = 0.5; - export abstract class BaseRenderLayer implements IRenderLayer { private _canvas: HTMLCanvasElement; protected _ctx: CanvasRenderingContext2D; diff --git a/src/renderer/LinkRenderLayer.ts b/src/renderer/LinkRenderLayer.ts index 4071523a08..10a33d11e8 100644 --- a/src/renderer/LinkRenderLayer.ts +++ b/src/renderer/LinkRenderLayer.ts @@ -7,7 +7,8 @@ import { ILinkHoverEvent, ITerminal, ILinkifierAccessor, IBuffer, ICharMeasure, import { CHAR_DATA_ATTR_INDEX } from '../Buffer'; import { GridCache } from './GridCache'; import { FLAGS, IColorSet, IRenderDimensions } from './Types'; -import { BaseRenderLayer, INVERTED_DEFAULT_COLOR } from './BaseRenderLayer'; +import { INVERTED_DEFAULT_COLOR } from './atlas/Types'; +import { BaseRenderLayer } from './BaseRenderLayer'; export class LinkRenderLayer extends BaseRenderLayer { private _state: ILinkHoverEvent = null; diff --git a/src/renderer/TextRenderLayer.ts b/src/renderer/TextRenderLayer.ts index 3ab1fdf098..df65ef8bf5 100644 --- a/src/renderer/TextRenderLayer.ts +++ b/src/renderer/TextRenderLayer.ts @@ -6,8 +6,9 @@ import { CHAR_DATA_ATTR_INDEX, CHAR_DATA_CODE_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX } from '../Buffer'; import { FLAGS, IColorSet, IRenderDimensions } from './Types'; import { CharData, IBuffer, ICharMeasure, ITerminal } from '../Types'; +import { INVERTED_DEFAULT_COLOR } from './atlas/Types'; import { GridCache } from './GridCache'; -import { BaseRenderLayer, INVERTED_DEFAULT_COLOR } from './BaseRenderLayer'; +import { BaseRenderLayer } from './BaseRenderLayer'; /** * This CharData looks like a null character, which will forc a clear and render diff --git a/src/renderer/CharAtlas.ts b/src/renderer/atlas/CharAtlas.ts similarity index 58% rename from src/renderer/CharAtlas.ts rename to src/renderer/atlas/CharAtlas.ts index ff8990b308..d688d32889 100644 --- a/src/renderer/CharAtlas.ts +++ b/src/renderer/atlas/CharAtlas.ts @@ -3,23 +3,12 @@ * @license MIT */ -import { ITerminal } from '../Types'; -import { IColorSet } from './Types'; -import { isFirefox } from '../shared/utils/Browser'; -import { generateCharAtlas, ICharAtlasRequest } from '../shared/CharAtlasGenerator'; - -export const CHAR_ATLAS_CELL_SPACING = 1; - -interface ICharAtlasConfig { - fontSize: number; - fontFamily: string; - fontWeight: string; - fontWeightBold: string; - scaledCharWidth: number; - scaledCharHeight: number; - allowTransparency: boolean; - colors: IColorSet; -} +import { ITerminal } from '../../Types'; +import { IColorSet } from '../Types'; +import { ICharAtlasConfig } from './Types'; +import { isFirefox } from '../../shared/utils/Browser'; +import { generateCharAtlas, ICharAtlasRequest } from '../../shared/atlas/CharAtlasGenerator'; +import { generateConfig, configEquals } from './CharAtlasUtils'; interface ICharAtlasCacheEntry { bitmap: HTMLCanvasElement | Promise; @@ -96,41 +85,3 @@ export function acquireCharAtlas(terminal: ITerminal, colors: IColorSet, scaledC charAtlasCache.push(newEntry); return newEntry.bitmap; } - -function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: ITerminal, colors: IColorSet): ICharAtlasConfig { - const clonedColors = { - foreground: colors.foreground, - background: colors.background, - cursor: null, - cursorAccent: null, - selection: null, - ansi: colors.ansi.slice(0, 16) - }; - return { - scaledCharWidth, - scaledCharHeight, - fontFamily: terminal.options.fontFamily, - fontSize: terminal.options.fontSize, - fontWeight: terminal.options.fontWeight, - fontWeightBold: terminal.options.fontWeightBold, - allowTransparency: terminal.options.allowTransparency, - colors: clonedColors - }; -} - -function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean { - for (let i = 0; i < a.colors.ansi.length; i++) { - if (a.colors.ansi[i] !== b.colors.ansi[i]) { - return false; - } - } - return a.fontFamily === b.fontFamily && - a.fontSize === b.fontSize && - a.fontWeight === b.fontWeight && - a.fontWeightBold === b.fontWeightBold && - a.allowTransparency === b.allowTransparency && - a.scaledCharWidth === b.scaledCharWidth && - a.scaledCharHeight === b.scaledCharHeight && - a.colors.foreground === b.colors.foreground && - a.colors.background === b.colors.background; -} diff --git a/src/renderer/atlas/CharAtlasUtils.ts b/src/renderer/atlas/CharAtlasUtils.ts new file mode 100644 index 0000000000..57e362af68 --- /dev/null +++ b/src/renderer/atlas/CharAtlasUtils.ts @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { ITerminal } from '../../Types'; +import { ITheme } from 'xterm'; +import { IColorSet } from '../Types'; +import { ICharAtlasConfig } from './Types'; + +export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: ITerminal, colors: IColorSet): ICharAtlasConfig { + const clonedColors = { + foreground: colors.foreground, + background: colors.background, + cursor: null, + cursorAccent: null, + selection: null, + ansi: colors.ansi.slice(0, 16) + }; + return { + scaledCharWidth, + scaledCharHeight, + fontFamily: terminal.options.fontFamily, + fontSize: terminal.options.fontSize, + fontWeight: terminal.options.fontWeight, + fontWeightBold: terminal.options.fontWeightBold, + allowTransparency: terminal.options.allowTransparency, + colors: clonedColors + }; +} + +export function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean { + for (let i = 0; i < a.colors.ansi.length; i++) { + if (a.colors.ansi[i] !== b.colors.ansi[i]) { + return false; + } + } + return a.fontFamily === b.fontFamily && + a.fontSize === b.fontSize && + a.fontWeight === b.fontWeight && + a.fontWeightBold === b.fontWeightBold && + a.allowTransparency === b.allowTransparency && + a.scaledCharWidth === b.scaledCharWidth && + a.scaledCharHeight === b.scaledCharHeight && + a.colors.foreground === b.colors.foreground && + a.colors.background === b.colors.background; +} diff --git a/src/renderer/atlas/Types.ts b/src/renderer/atlas/Types.ts new file mode 100644 index 0000000000..a79cb327e2 --- /dev/null +++ b/src/renderer/atlas/Types.ts @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { FontWeight } from 'xterm'; +import { IColorSet } from '../Types'; + +export const INVERTED_DEFAULT_COLOR = -1; +export const DIM_OPACITY = 0.5; + +export interface ICharAtlasConfig { + fontSize: number; + fontFamily: string; + fontWeight: FontWeight; + fontWeightBold: FontWeight; + scaledCharWidth: number; + scaledCharHeight: number; + allowTransparency: boolean; + colors: IColorSet; +} diff --git a/src/shared/CharAtlasGenerator.ts b/src/shared/atlas/CharAtlasGenerator.ts similarity index 97% rename from src/shared/CharAtlasGenerator.ts rename to src/shared/atlas/CharAtlasGenerator.ts index 96cf6cc63e..cf17bbb8fe 100644 --- a/src/shared/CharAtlasGenerator.ts +++ b/src/shared/atlas/CharAtlasGenerator.ts @@ -4,7 +4,8 @@ */ import { FontWeight } from 'xterm'; -import { isFirefox } from './utils/Browser'; +import { CHAR_ATLAS_CELL_SPACING } from './Types'; +import { isFirefox } from '../utils/Browser'; declare const Promise: any; @@ -29,8 +30,6 @@ export interface ICharAtlasRequest { allowTransparency: boolean; } -export const CHAR_ATLAS_CELL_SPACING = 1; - /** * Generates a char atlas. * @param context The window or worker context. diff --git a/src/shared/atlas/Types.ts b/src/shared/atlas/Types.ts new file mode 100644 index 0000000000..e8bb6b0a7c --- /dev/null +++ b/src/shared/atlas/Types.ts @@ -0,0 +1,6 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +export const CHAR_ATLAS_CELL_SPACING = 1;