Add a dummy NoneCharAtlas implementation

This adds the logic needed to switch between multiple char atlas
implementations, and an example second implementation to test it out
with.

This also offers an escape hatch if something goes wrong with the char
atlas implementation(s).
This commit is contained in:
Benjamin Woodruff
2018-04-15 18:03:55 -07:00
parent 6f21385cd8
commit 8c980bc30d
8 changed files with 67 additions and 4 deletions
+2
View File
@@ -102,6 +102,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = {
bellSound: DEFAULT_BELL_SOUND,
bellStyle: 'none',
enableBold: true,
experimentalCharAtlas: 'static',
fontFamily: 'courier-new, courier, monospace',
fontSize: 15,
fontWeight: 'normal',
@@ -454,6 +455,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
this.charMeasure.measure(this.options);
}
break;
case 'experimentalCharAtlas':
case 'enableBold':
case 'letterSpacing':
case 'lineHeight':
+9 -3
View File
@@ -4,11 +4,17 @@
*/
import { ITerminal } from '../../Types';
import BaseCharAtlas from './BaseCharAtlas';
import StaticCharAtlas from './StaticCharAtlas';
import { IColorSet } from '../Types';
import { ICharAtlasConfig } from '../../shared/atlas/Types';
import { generateConfig, configEquals } from './CharAtlasUtils';
import BaseCharAtlas from './BaseCharAtlas';
import NoneCharAtlas from './NoneCharAtlas';
import StaticCharAtlas from './StaticCharAtlas';
const charAtlasImplementations = {
'none': NoneCharAtlas,
'static': StaticCharAtlas,
};
interface ICharAtlasCacheEntry {
atlas: BaseCharAtlas;
@@ -64,7 +70,7 @@ export function acquireCharAtlas(
}
const newEntry: ICharAtlasCacheEntry = {
atlas: new StaticCharAtlas(
atlas: new charAtlasImplementations[terminal.options.experimentalCharAtlas](
document,
newConfig,
),
+3 -1
View File
@@ -17,6 +17,7 @@ export function generateConfig(scaledCharWidth: number, scaledCharHeight: number
ansi: colors.ansi.slice(0, 16)
};
return {
type: terminal.options.experimentalCharAtlas,
devicePixelRatio: window.devicePixelRatio,
scaledCharWidth,
scaledCharHeight,
@@ -35,7 +36,8 @@ export function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean
return false;
}
}
return a.devicePixelRatio === b.devicePixelRatio &&
return a.type === b.type &&
a.devicePixelRatio === b.devicePixelRatio &&
a.fontFamily === b.fontFamily &&
a.fontSize === b.fontSize &&
a.fontWeight === b.fontWeight &&
+25
View File
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
* @license MIT
*
* A dummy CharAtlas implementation that always fails to draw characters.
*/
import { IGlyphIdentifier } from './Types';
import { ICharAtlasConfig } from '../../shared/atlas/Types';
import BaseCharAtlas from './BaseCharAtlas';
export default class NoneCharAtlas extends BaseCharAtlas {
constructor(document: Document, config: ICharAtlasConfig) {
super();
}
public draw(
ctx: CanvasRenderingContext2D,
glyph: IGlyphIdentifier,
x: number,
y: number
): boolean {
return false;
}
}
+1
View File
@@ -9,6 +9,7 @@ import { IColorSet } from '../Types';
export const CHAR_ATLAS_CELL_SPACING = 1;
export interface ICharAtlasConfig {
type: 'none' | 'static';
devicePixelRatio: number;
fontSize: number;
fontFamily: string;