FontLoader.js 999 B

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