Buggy code:
CCImage_richlabel . setColorSpan ( top , rich , colorStart , span . pos , elapsedTime ) ; colorStart = span . pos ; } colorStack . push ( span ) ; break ; } case FONT : { Typeface curFont = fontStack . peek ( ) ; if ( ( span . pos ) > fontStart ) { rich . setSpan ( new CCImage_richlabel . CustomTypefaceSpan ( "" , curFont ) , fontStart , span . pos , SPAN_EXCLUSIVE_EXCLUSIVE ) ; fontStart = span . pos ; } Typeface font = null ; if ( span . fontName . endsWith ( ".ttf" ) ) { try { font = Cocos2dxTypefaces . get ( Cocos2dxActivity . getContext ( ) , span . fontName ) ; } catch ( final Exception e ) { } } else { font = Typeface . create ( span . fontName , NORMAL ) ; if ( font == null ) { font = Typeface . DEFAULT ; } } fontStack . push ( font ) ; break ; } case SIZE : { if ( ( span . pos ) > sizeStart ) { float size = fontSizeStack . peek ( ) ; rich . setSpan ( new AbsoluteSizeSpan ( ( ( int ) ( size * contentScaleFactor ) ) ) , fontStart , span . pos , SPAN_EXCLUSIVE_EXCLUSIVE ) ; sizeStart = span . pos ; } fontSizeStack . push ( span . fontSize ) ; break ; } case BOLD : { Typeface curFont = fontStack . peek ( ) ; if ( ( span . pos ) > fontStart ) { rich . setSpan ( new CCImage_richlabel . CustomTypefaceSpan ( "" , curFont ) , fontStart , span . pos , SPAN_EXCLUSIVE_EXCLUSIVE ) ; fontStart = span . pos ; } Typeface font = Typeface . create ( curFont , ( ( Typeface . BOLD ) | ( curFont . getStyle ( ) ) ) ) ; fontStack . push ( font ) ; break ; } case ITALIC : { Typeface curFont = fontStack . peek ( ) ; if ( ( span . pos ) > fontStart ) { rich . setSpan ( new CCImage_richlabel . CustomTypefaceSpan ( "" , curFont ) , fontStart , span . pos , SPAN_EXCLUSIVE_EXCLUSIVE ) ; fontStart = span . pos ; } Typeface font = Typeface . create ( curFont , ( ( Typeface . ITALIC ) | ( curFont . getStyle ( ) ) ) ) ; fontStack . push ( font ) ; break ; } case UNDERLINE : { underlineStart = span . pos ; break ; } case IMAGE : { openSpan = span ; break ; } default : break ; } } } if ( ( plain . length ( ) ) > colorStart ) { CCImage_richlabel . Span top = colorStack . peek ( ) ; CCImage_richlabel . setColorSpan ( top , rich , colorStart , plain . length ( ) , elapsedTime ) ; } if ( ( plain . length ( ) ) > sizeStart ) { float size = fontSizeStack . peek ( ) ; rich . setSpan ( new AbsoluteSizeSpan ( ( ( int ) ( size * contentScaleFactor ) ) ) , fontStart , plain . length ( ) , SPAN_EXCLUSIVE_EXCLUSIVE ) ; } if ( ( plain . length ( ) ) > fontStart ) { Typeface curFont = fontStack . peek ( ) ; rich . setSpan ( new CCImage_richlabel . CustomTypefaceSpan ( "" , curFont ) , fontStart , plain . length ( ) , SPAN_EXCLUSIVE_EXCLUSIVE ) ; } <START_BUG> StaticLayout layout = new StaticLayout ( rich , paint , ( pWidth <= 0 ? ( ( int ) ( StaticLayout . getDesiredWidth ( rich , paint ) ) ) : pWidth ) , align , 1 , lineSpacing , false ) ; <END_BUG> int width = layout . getWidth ( ) ; int height = layout . getHeight ( ) ; width += shadowStrokePaddingX ; height += shadowStrokePaddingY ; int startY = 0 ; int startX = 0 ; if ( pHeight > height ) { if ( verticalAlignment == ( CCImage_richlabel . VERTICALALIGN_TOP ) ) { startY = 0 ; } else if ( verticalAlignment == ( CCImage_richlabel . VERTICALALIGN_CENTER ) ) { startY = ( pHeight - height ) // 2 ; } else { startY = pHeight - height ; } } if ( shadow ) { if ( shadowDY < 0 ) { startY -= shadowDY ; } if ( shadowDX < 0 ) { startX -= shadowDX ; } } if ( ( pHeight > 0 ) && ( pHeight < height ) ) height = pHeight ; if ( ! sizeOnly ) { CCImage_richlabel . nativeSaveShadowStrokePadding ( startX , Math . max ( 0 , ( ( height - ( layout . getHeight ( ) ) ) - startY ) ) ) ; Bitmap bitmap = Bitmap . createBitmap ( width , height , ARGB_8888 ) ; Canvas c = new Canvas ( bitmap ) ; c . translate ( startX , startY ) ; layout . draw ( c ) ; if ( stroke ) { paint . setStyle ( STROKE ) ; paint . setStrokeWidth ( strokeSize ) ; paint . setARGB ( 255 , ( ( ( int ) ( strokeR ) ) * 255 ) , ( ( ( int ) ( strokeG ) ) * 255 ) , ( ( ( int ) ( strokeB ) ) * 255 ) ) ; paint . clearShadowLayer ( ) ; for ( ForegroundColorSpan span : rich . getSpans ( 0 , rich . length ( ) , ForegroundColorSpan . class ) ) { rich . removeSpan ( span ) ; } for ( UnderlineSpan span : rich . getSpans ( 0 , rich . length ( ) , UnderlineSpan . class ) ) { rich . removeSpan ( span ) ; }

Fix:
StaticLayout layout = new StaticLayout ( rich , paint , ( pWidth <= 0 ? ( ( int ) ( Math . ceil ( StaticLayout . getDesiredWidth ( rich , paint ) ) ) ) : pWidth ) , align , 1 , lineSpacing , false ) ;