UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

56 lines (46 loc) 1.27 kB
import {FileLoader, Loader, LoadingManager} from 'three'; import {isString} from '../../Type'; import {Font, FontData} from './Font'; type OnLoad = (font: Font) => void; type OnProgress = (event: ProgressEvent<EventTarget>) => void; type OnError = (error: any) => void; export class FontLoader extends Loader<Font> { constructor(manager: LoadingManager) { super(manager); } override load(url: string, onLoad: OnLoad, onProgress?: OnProgress, onError?: OnError) { const scope = this; const loader = new FileLoader(this.manager); loader.setPath(this.path); loader.setRequestHeader(this.requestHeader); loader.setWithCredentials(scope.withCredentials); loader.load( url, function (text) { if (!isString(text)) { return; } let json: FontData | undefined; try { json = JSON.parse(text as string); } catch (e) { console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' ); json = JSON.parse((text as string).substring(65, text.length - 2)); } if (!json) { return; } const font = scope.parse(json); if (onLoad) onLoad(font); }, onProgress, onError ); } parse(json: FontData) { return new Font(json); } } //