1 | import { Font } from '../extras/core/Font.js';
|
2 | import { FileLoader } from './FileLoader.js';
|
3 | import { DefaultLoadingManager } from './LoadingManager.js';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function FontLoader( manager ) {
|
10 |
|
11 | this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
|
12 |
|
13 | }
|
14 |
|
15 | Object.assign( FontLoader.prototype, {
|
16 |
|
17 | load: function ( url, onLoad, onProgress, onError ) {
|
18 |
|
19 | var scope = this;
|
20 |
|
21 | var loader = new FileLoader( this.manager );
|
22 | loader.setPath( this.path );
|
23 | loader.load( url, function ( text ) {
|
24 |
|
25 | var json;
|
26 |
|
27 | try {
|
28 |
|
29 | json = JSON.parse( text );
|
30 |
|
31 | } catch ( e ) {
|
32 |
|
33 | console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
|
34 | json = JSON.parse( text.substring( 65, text.length - 2 ) );
|
35 |
|
36 | }
|
37 |
|
38 | var font = scope.parse( json );
|
39 |
|
40 | if ( onLoad ) onLoad( font );
|
41 |
|
42 | }, onProgress, onError );
|
43 |
|
44 | },
|
45 |
|
46 | parse: function ( json ) {
|
47 |
|
48 | return new Font( json );
|
49 |
|
50 | },
|
51 |
|
52 | setPath: function ( value ) {
|
53 |
|
54 | this.path = value;
|
55 | return this;
|
56 |
|
57 | }
|
58 |
|
59 | } );
|
60 |
|
61 |
|
62 | export { FontLoader };
|