From b6ba7439ea3634f3c006cf8f284141d9a09aee94 Mon Sep 17 00:00:00 2001 From: Vincent Woo Date: Tue, 3 Apr 2018 18:44:35 -0700 Subject: [PATCH] Addon that refreshes xterm upon webfont load --- demo/webfont/index.html | 20 ++++++++++++++++++++ src/addons/webfont/package.json | 5 +++++ src/addons/webfont/tsconfig.json | 11 +++++++++++ src/addons/webfont/webfont.ts | 19 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 demo/webfont/index.html create mode 100644 src/addons/webfont/package.json create mode 100644 src/addons/webfont/tsconfig.json create mode 100644 src/addons/webfont/webfont.ts diff --git a/demo/webfont/index.html b/demo/webfont/index.html new file mode 100644 index 0000000000..a6e7cf2b8d --- /dev/null +++ b/demo/webfont/index.html @@ -0,0 +1,20 @@ + + + + + + + + + + +
+ + + + diff --git a/src/addons/webfont/package.json b/src/addons/webfont/package.json new file mode 100644 index 0000000000..2fb93a9a19 --- /dev/null +++ b/src/addons/webfont/package.json @@ -0,0 +1,5 @@ +{ + "name": "xterm.webfont", + "main": "webfont.js", + "private": true +} diff --git a/src/addons/webfont/tsconfig.json b/src/addons/webfont/tsconfig.json new file mode 100644 index 0000000000..e368852fa9 --- /dev/null +++ b/src/addons/webfont/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "rootDir": ".", + "outDir": "../../../lib/addons/webfont/", + "sourceMap": true, + "removeComments": true, + "declaration": true + } +} diff --git a/src/addons/webfont/webfont.ts b/src/addons/webfont/webfont.ts new file mode 100644 index 0000000000..ea09775f16 --- /dev/null +++ b/src/addons/webfont/webfont.ts @@ -0,0 +1,19 @@ +/// + +import { Terminal } from 'xterm'; + +export function apply(terminalConstructor: typeof Terminal): void { + (terminalConstructor.prototype).loadWebfontAndOpen = function (element: HTMLElement): void { + const FontFaceObserver = (typeof window === 'object' && (window).FontFaceObserver); + if (!FontFaceObserver) { + console.warn('FontFaceObserver not available, opening xterm normally!'); + return this.open(element); + } + const regular = new FontFaceObserver(this.options.fontFamily).load(); + const bold = new FontFaceObserver(this.options.fontFamily, { weight: 'bold' }).load(); + + regular.constructor.all([regular, bold]).then(() => { + this.open(element); + }); + }; +}