FontLoader.js 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { Font } from '../extras/core/Font.js';
  2. import { FileLoader } from './FileLoader.js';
  3. import { Loader } from './Loader.js';
  4. function FontLoader( manager ) {
  5. Loader.call( this, manager );
  6. }
  7. FontLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  8. constructor: FontLoader,
  9. load: function ( url, onLoad, onProgress, onError ) {
  10. const scope = this;
  11. const loader = new FileLoader( this.manager );
  12. loader.setPath( this.path );
  13. loader.setRequestHeader( this.requestHeader );
  14. loader.load( url, function ( text ) {
  15. let json;
  16. try {
  17. json = JSON.parse( text );
  18. } catch ( e ) {
  19. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  20. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  21. }
  22. const font = scope.parse( json );
  23. if ( onLoad ) onLoad( font );
  24. }, onProgress, onError );
  25. },
  26. parse: function ( json ) {
  27. return new Font( json );
  28. }
  29. } );
  30. export { FontLoader };
粤ICP备19079148号