-
Notifications
You must be signed in to change notification settings - Fork 0
/
FontFace.js
35 lines (35 loc) · 965 Bytes
/
FontFace.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Tools } from '@babylonjs/core';
/**
* Partial Polyfill for FontFace Web API to wrap the NativeCanvas object.
*/
export class FontFace {
family;
source;
_status = "unloaded";
get status() {
return this._status;
}
get loaded() {
return this._status === "loaded";
}
constructor(family, source) {
this.family = family;
this.source = source;
}
async load() {
try {
this._status = "loading";
if (typeof this.source === 'string') {
this.source = await Tools.LoadFileAsync(this.source);
}
await _native.Canvas.loadTTFAsync(this.family, this.source);
this.source = undefined;
this._status = "loaded";
}
catch (ex) {
console.error("Error encountered when loading font: " + ex);
this._status = "error";
}
}
}
//# sourceMappingURL=FontFace.js.map