@@ -2186,7 +2186,7 @@ export class PorterDuffXfermode {
21862186export class StaticLayout {
21872187 rect : CGRect ;
21882188 nsAttributedString : NSAttributedString ;
2189- public constructor ( private text : any , private paint : Paint , private width : number , private align : LayoutAlignment , private spacingmult , private spacingadd , private includepad ) {
2189+ public constructor ( private text : any , private paint : Paint , private width : number , private align : LayoutAlignment , private spacingmult ? , private spacingadd ? , private includepad ? ) {
21902190 if ( text instanceof NSAttributedString ) {
21912191 this . nsAttributedString = text ;
21922192 // } else if (!(text instanceof NSMutableAttributedString)) {
@@ -2221,19 +2221,23 @@ export class StaticLayout {
22212221 nsAttributedString . addAttributesRange ( attributes , range ) ;
22222222 } ) ;
22232223 }
2224- draw ( canvas : Canvas ) {
2224+ draw ( canvas : Canvas , maxHeight = Number . MAX_VALUE ) {
22252225 canvas . startApplyPaint ( this . paint ) ;
22262226 const ctx = canvas . ctx ;
22272227 this . createAttributedStringToDraw ( ) ;
22282228
22292229 UIGraphicsPushContext ( ctx ) ;
2230- this . toDraw . drawWithRectOptionsContext ( CGRectMake ( 0 , 0 , this . width , Number . MAX_VALUE ) , NSStringDrawingOptions . UsesLineFragmentOrigin , null ) ;
2230+ this . toDraw . drawWithRectOptionsContext ( CGRectMake ( 0 , 0 , this . width , maxHeight ) , NSStringDrawingOptions . UsesLineFragmentOrigin , null ) ;
22312231 UIGraphicsPopContext ( ) ;
22322232 canvas . finishApplyPaint ( this . paint ) ;
22332233 }
22342234 getPaint ( ) {
22352235 return this . paint ;
22362236 }
2237+ static getDesiredWidth ( source , paint ) {
2238+ const layout = new StaticLayout ( source , paint , Number . MAX_SAFE_INTEGER , LayoutAlignment . ALIGN_NORMAL ) ;
2239+ return layout . getBounds ( ) . size . width ;
2240+ }
22372241 getBounds ( ) {
22382242 if ( ! this . rect ) {
22392243 this . createAttributedStringToDraw ( ) ;
0 commit comments