@@ -2186,7 +2186,7 @@ export class PorterDuffXfermode {
2186
2186
export class StaticLayout {
2187
2187
rect : CGRect ;
2188
2188
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 ? ) {
2190
2190
if ( text instanceof NSAttributedString ) {
2191
2191
this . nsAttributedString = text ;
2192
2192
// } else if (!(text instanceof NSMutableAttributedString)) {
@@ -2221,19 +2221,23 @@ export class StaticLayout {
2221
2221
nsAttributedString . addAttributesRange ( attributes , range ) ;
2222
2222
} ) ;
2223
2223
}
2224
- draw ( canvas : Canvas ) {
2224
+ draw ( canvas : Canvas , maxHeight = Number . MAX_VALUE ) {
2225
2225
canvas . startApplyPaint ( this . paint ) ;
2226
2226
const ctx = canvas . ctx ;
2227
2227
this . createAttributedStringToDraw ( ) ;
2228
2228
2229
2229
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 ) ;
2231
2231
UIGraphicsPopContext ( ) ;
2232
2232
canvas . finishApplyPaint ( this . paint ) ;
2233
2233
}
2234
2234
getPaint ( ) {
2235
2235
return this . paint ;
2236
2236
}
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
+ }
2237
2241
getBounds ( ) {
2238
2242
if ( ! this . rect ) {
2239
2243
this . createAttributedStringToDraw ( ) ;
0 commit comments