1
1
/* eslint-disable no-duplicate-imports */
2
- import { Application , Color , Device , Font , ImageSource , Utils } from '@nativescript/core' ;
2
+ import { Application , Color , Device , Font , ImageSource , Screen , Utils } from '@nativescript/core' ;
3
3
import type { View } from '@nativescript/core' ;
4
4
import { arrayToNativeArray } from '@nativescript-community/arraybuffers' ;
5
5
import { FontStyleType , FontWeightType } from '@nativescript/core/ui/styling/font-interfaces' ;
@@ -166,6 +166,7 @@ class Canvas extends ProxyClass<android.graphics.Canvas> {
166
166
}
167
167
}
168
168
169
+ let FONT_SIZE_FACTOR ;
169
170
export class Paint extends ProxyClass < android . graphics . Paint > {
170
171
mNative : android . graphics . Paint ;
171
172
mFontInternal : Font ;
@@ -191,13 +192,17 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
191
192
return this ;
192
193
}
193
194
handleCustomMethods ( target , native , methodName : string , args : any [ ] ) : any {
194
- if ( methodName === 'setShadowLayer' ) {
195
- args [ 3 ] = createColorParam ( args [ 3 ] ) ;
196
- } else if ( methodName === 'setColor' ) {
195
+ if ( methodName === 'setColor' ) {
197
196
if ( ! args [ 0 ] ) {
198
197
return ;
199
198
}
200
199
args [ 0 ] = createColorParam ( args [ 0 ] ) ;
200
+ } else if ( methodName === 'setTextSize' ) {
201
+ // we apply a small factor so that font size is the same as in TextView
202
+ if ( ! FONT_SIZE_FACTOR ) {
203
+ FONT_SIZE_FACTOR = com . akylas . canvas . CanvasView . getFontSizeFactor ( Utils . android . getApplicationContext ( ) ) / Screen . mainScreen . scale ;
204
+ }
205
+ args [ 0 ] *= FONT_SIZE_FACTOR ;
201
206
} else if ( methodName === 'setTypeface' ) {
202
207
if ( args [ 0 ] instanceof Font ) {
203
208
this . mFontInternal = args [ 0 ] ;
@@ -210,6 +215,8 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
210
215
return true ;
211
216
} else if ( methodName === 'getLetterSpacing' && sdkVersion < 21 ) {
212
217
return 0 ;
218
+ } else if ( methodName === 'setShadowLayer' ) {
219
+ args [ 3 ] = createColorParam ( args [ 3 ] ) ;
213
220
}
214
221
}
215
222
setFont ( font : Font ) {
0 commit comments