Convert BaseFontLoader.bind to be async, and only utilize BaseFontLoader._queueLoadingCallback when actually necessary

Currently all fonts are using the `_queueLoadingCallback` method to determine when they have been loaded[1]. However in most cases this is just adding unnecessary overhead, especially with `BaseFontLoader.bind` now being asynchronous, given how fonts are loaded:
 - For fonts loaded using the Font Loading API, it's already possible to easily tell when a font has been loaded simply by checking the `loaded` promise on the FontFace object itself.
 - For browsers, e.g. Firefox, which support synchronous font loading it's already assumed that fonts are immediately available.

Hence the `_queueLoadingCallback` method is moved into the `GenericFontLoader`, such that it's only utilized for fonts which are loaded using CSS.

---
[1] In the "fonts loaded using CSS" case, this is already a hack anyway as outlined in the comments.
This commit is contained in:
Jonas Jenwald 2019-02-10 14:01:49 +01:00
parent dfe7d9bc26
commit af3fcca88d
2 changed files with 38 additions and 34 deletions

View file

@ -1944,11 +1944,10 @@ class WorkerTransport {
onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
fontRegistry,
});
const fontReady = (fontObjs) => {
this.commonObjs.resolve(id, font);
};
this.fontLoader.bind([font], fontReady);
this.fontLoader.bind([font]).then(() => {
this.commonObjs.resolve(id, font);
});
break;
case 'FontPath':
this.commonObjs.resolve(id, exportedData);