@@ -3,7 +3,7 @@ import { FontStyle, FontWeight } from '@nativescript/core/ui/styling/font';
3
3
import { android as androidApp } from '@nativescript/core/application' ;
4
4
import lazy from '@nativescript/core/utils/lazy' ;
5
5
import { layout } from '@nativescript/core/utils/utils' ;
6
- import { Canvas as ICanvas , Paint as IPaint } from './canvas' ;
6
+ import { Canvas as ICanvas , Paint as IPaint , TypedArray } from './canvas' ;
7
7
import { CanvasBase , hardwareAcceleratedProperty } from './canvas.common' ;
8
8
9
9
declare global {
@@ -60,7 +60,7 @@ export function createArrayBufferOrNativeArray(length: number, useInts = false)
60
60
return createArrayBuffer ( length , useInts ) ;
61
61
}
62
62
}
63
- export function createArrayBuffer ( length : number , useInts = false ) {
63
+ export function createArrayBuffer ( length : number , useInts = false ) : TypedArray {
64
64
if ( ! supportsDirectArrayBuffers ( ) ) {
65
65
let bb : java . nio . ByteBuffer ;
66
66
if ( useInts ) {
@@ -69,11 +69,13 @@ export function createArrayBuffer(length: number, useInts = false) {
69
69
bb = java . nio . ByteBuffer . allocateDirect ( length * 4 ) . order ( java . nio . ByteOrder . LITTLE_ENDIAN ) ;
70
70
}
71
71
const result = ( ArrayBuffer as any ) . from ( bb ) ;
72
+ //@ts -ignore
72
73
return useInts ? new Int8Array ( result ) : new Float32Array ( result ) ;
73
74
}
75
+ //@ts -ignore
74
76
return useInts ? new Int8Array ( length ) : new Float32Array ( length ) ;
75
77
}
76
- export function pointsFromBuffer ( typedArray : Float32Array | Int8Array , useInts = false ) {
78
+ export function pointsFromBuffer ( typedArray : TypedArray , useInts = false ) {
77
79
if ( ! supportsDirectArrayBuffers ( ) ) {
78
80
if ( useInts ) {
79
81
const buffer = typedArray . buffer ;
@@ -88,12 +90,12 @@ export function pointsFromBuffer(typedArray: Float32Array | Int8Array, useInts =
88
90
return typedArray ;
89
91
}
90
92
91
- export function arrayToNativeArray ( array , useInts = false ) {
93
+ export function arrayToNativeArray ( array : number [ ] | TypedArray , useInts = false ) {
92
94
if ( ! Array . isArray ( array ) ) {
93
95
return array ;
94
96
}
95
97
const length = array . length ;
96
- const typedArray = createArrayBuffer ( length , useInts ) ;
98
+ const typedArray = ArrayBuffer . isView ( array ) ? ( array as any as TypedArray ) : createArrayBuffer ( length , useInts ) ;
97
99
98
100
return pointsFromBuffer ( typedArray , useInts ) ;
99
101
}
@@ -289,7 +291,7 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
289
291
if ( paint ) {
290
292
this . mNative = new android . graphics . Paint ( paint . getNative ( ) ) ;
291
293
} else {
292
- this . mNative = new android . graphics . Paint ( 1 ) ; //android.graphics.Paint.ANTI_ALIAS_FLAG
294
+ this . mNative = new android . graphics . Paint ( 1 ) ; //android.graphics.Paint.ANTI_ALIAS_FLAG
293
295
}
294
296
this . mNative . setLinearText ( true ) ; // ensure we are drawing fonts correctly
295
297
return this ;
0 commit comments