(item: LoadItem, resourceManager: ResourceManager)
| 11 | @resourceLoader(AssetType.SourceFont, ["ttf", "otf", "woff"], false) |
| 12 | class SourceFontLoader extends Loader<Font> { |
| 13 | load(item: LoadItem, resourceManager: ResourceManager): AssetPromise<Font> { |
| 14 | return new AssetPromise((resolve, reject) => { |
| 15 | // @ts-ignore |
| 16 | const url = resourceManager._getRemoteUrl(item.url); |
| 17 | this._registerFont(url, url) |
| 18 | .then(() => { |
| 19 | const font = new Font(resourceManager.engine, url); |
| 20 | resolve(font); |
| 21 | }) |
| 22 | .catch((e) => { |
| 23 | reject(`load font ${url} fail`); |
| 24 | }); |
| 25 | }); |
| 26 | } |
| 27 | |
| 28 | private async _registerFont(fontName: string, fontUrl: string): Promise<void> { |
| 29 | const fontFace = new FontFace(fontName, `url(${fontUrl})`); |
no test coverage detected