11/* 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' ;
33import type { View } from '@nativescript/core' ;
44import { arrayToNativeArray } from '@nativescript-community/arraybuffers' ;
55import { FontStyleType , FontWeightType } from '@nativescript/core/ui/styling/font-interfaces' ;
@@ -166,6 +166,7 @@ class Canvas extends ProxyClass<android.graphics.Canvas> {
166166 }
167167}
168168
169+ let FONT_SIZE_FACTOR ;
169170export class Paint extends ProxyClass < android . graphics . Paint > {
170171 mNative : android . graphics . Paint ;
171172 mFontInternal : Font ;
@@ -191,13 +192,17 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
191192 return this ;
192193 }
193194 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' ) {
197196 if ( ! args [ 0 ] ) {
198197 return ;
199198 }
200199 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 ;
201206 } else if ( methodName === 'setTypeface' ) {
202207 if ( args [ 0 ] instanceof Font ) {
203208 this . mFontInternal = args [ 0 ] ;
@@ -210,6 +215,8 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
210215 return true ;
211216 } else if ( methodName === 'getLetterSpacing' && sdkVersion < 21 ) {
212217 return 0 ;
218+ } else if ( methodName === 'setShadowLayer' ) {
219+ args [ 3 ] = createColorParam ( args [ 3 ] ) ;
213220 }
214221 }
215222 setFont ( font : Font ) {
0 commit comments