File tree 3 files changed +43
-0
lines changed
Modules/@babylonjs/react-native
3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { Tools } from '@babylonjs/core' ;
2
+
3
+ // Declare _native to get access to NativeCanvas.
4
+ declare var _native : any ;
5
+
6
+ /**
7
+ * Partial Polyfill for FontFace Web API to wrap the NativeCanvas object.
8
+ */
9
+ export class FontFace {
10
+ private source : string | ArrayBuffer | undefined ;
11
+ private _status : "unloaded" | "loading" | "loaded" | "error" = "unloaded" ;
12
+ public get status ( ) : "unloaded" | "loading" | "loaded" | "error" {
13
+ return this . _status ;
14
+ }
15
+
16
+ public get loaded ( ) : boolean {
17
+ return this . _status === "loaded" ;
18
+ }
19
+
20
+ public constructor ( public readonly family : string , source : string | ArrayBuffer ) {
21
+ this . source = source ;
22
+ }
23
+
24
+ public async load ( ) : Promise < void > {
25
+ try {
26
+ this . _status = "loading" ;
27
+ if ( typeof this . source === 'string' ) {
28
+ this . source = await Tools . LoadFileAsync ( this . source ) ;
29
+ }
30
+
31
+ await _native . NativeCanvas . loadTTFAsync ( this . family , this . source ) ;
32
+ this . source = undefined ;
33
+ this . _status = "loaded"
34
+ } catch ( ex ) {
35
+ console . error ( "Error encountered when loading font: " + ex ) ;
36
+ this . _status = "error" ;
37
+ }
38
+ }
39
+ }
Original file line number Diff line number Diff line change 1
1
export * from './EngineView' ;
2
2
export * from './EngineHook' ;
3
3
export * from './NativeCapture' ;
4
+ export * from './FontFace' ;
Original file line number Diff line number Diff line change @@ -493,6 +493,9 @@ const validate = async () => {
493
493
'Assembled/NativeCapture.d.ts' ,
494
494
'Assembled/NativeCapture.js' ,
495
495
'Assembled/NativeCapture.js.map' ,
496
+ 'Assembled/FontFace.d.ts' ,
497
+ 'Assembled/FontFace.js' ,
498
+ 'Assembled/FontFace.js.map' ,
496
499
'Assembled/package.json' ,
497
500
'Assembled/react-native-babylon.podspec' ,
498
501
'Assembled/ReactNativeEngine.d.ts' ,
You can’t perform that action at this time.
0 commit comments