@@ -857,6 +857,7 @@ export class Paint implements IPaint {
857857 antiAlias = true ;
858858 dither ;
859859 alpha = 255 ;
860+ letterSpacing : number ;
860861 currentContext : any ;
861862 shadowLayer ?: {
862863 radius : number ;
@@ -1096,6 +1097,16 @@ export class Paint implements IPaint {
10961097 this . mFont = this . font . withFontSize ( textSize ) ;
10971098 this . mTextAttribs = null ;
10981099 }
1100+ getLetterSpacing ( ) {
1101+ return this . letterSpacing ;
1102+ }
1103+ setLetterSpacing ( spacing ) {
1104+ if ( this . letterSpacing === spacing ) {
1105+ return ;
1106+ }
1107+ this . letterSpacing = spacing ;
1108+ this . mTextAttribs = null ;
1109+ }
10991110 get color ( ) : Color | number | string {
11001111 return this . mColor ;
11011112 }
@@ -1219,12 +1230,15 @@ export class Paint implements IPaint {
12191230 }
12201231 getDrawTextAttribs ( ) {
12211232 if ( ! this . mTextAttribs ) {
1222- this . mTextAttribs = NSMutableDictionary . dictionaryWithObjectsForKeys ( [ this . getUIFont ( ) ] , [ NSFontAttributeName ] ) ;
1233+ const iosFont = this . getUIFont ( ) ;
1234+ this . mTextAttribs = NSMutableDictionary . dictionaryWithObjectsForKeys ( [ iosFont ] , [ NSFontAttributeName ] ) ;
12231235 const color = this . getUIColor ( ) ;
1224- this . mTextAttribs = NSMutableDictionary . dictionaryWithObjectsForKeys ( [ this . getUIFont ( ) ] , [ NSFontAttributeName ] ) ;
12251236 if ( color ) {
12261237 this . mTextAttribs . setObjectForKey ( color , NSForegroundColorAttributeName ) ;
12271238 }
1239+ if ( this . letterSpacing !== undefined ) {
1240+ this . mTextAttribs . setObjectForKey ( this . letterSpacing * iosFont . pointSize , NSKernAttributeName ) ;
1241+ }
12281242 if ( this . align === Align . CENTER ) {
12291243 const paragraphStyle = NSMutableParagraphStyle . new ( ) ;
12301244 paragraphStyle . alignment = NSTextAlignment . Center ;
@@ -1925,7 +1939,6 @@ export class Canvas implements ICanvas {
19251939 x = params [ 1 ] ;
19261940 y = params [ 2 ] ;
19271941 }
1928- // const attribs = paint.getDrawTextAttribs();
19291942 // const nsstring = NSString.stringWithUTF8String(text);
19301943 // const attrString = NSAttributedString.alloc().initWithStringAttributes(text.replace(/\n/g, ' '), attribs);
19311944 let offsetx = x ;
@@ -1948,7 +1961,10 @@ export class Canvas implements ICanvas {
19481961 }
19491962 const font = paint . getUIFont ( ) ;
19501963 const color = paint . getUIColor ( ) ;
1951- if ( text instanceof NSAttributedString ) {
1964+ if ( paint . letterSpacing !== undefined ) {
1965+ const attribs = paint . getDrawTextAttribs ( ) ;
1966+ UIDrawingText . drawStringXYWithAttributes ( text , offsetx , offsety - font . ascender , attribs ) ;
1967+ } else if ( text instanceof NSAttributedString ) {
19521968 UIDrawingText . drawAttributedStringXYFontColor ( text , offsetx , offsety - font . ascender , font , color ) ;
19531969 } else {
19541970 UIDrawingText . drawStringXYFontColor ( text , offsetx , offsety - font . ascender , font , color ) ;
0 commit comments