@@ -823,6 +823,16 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
823
823
return this . _labelContext ;
824
824
} ,
825
825
826
+ _maxNum : function ( numArr ) {
827
+ var num = numArr [ 0 ] ;
828
+ for ( var i = 1 ; i < numArr . length ; i ++ ) {
829
+ if ( num < numArr [ i ] ) {
830
+ num = numArr [ i ] ;
831
+ }
832
+ }
833
+ return num ;
834
+ } ,
835
+
826
836
_updateTTF : function ( ) {
827
837
var locDimensionsWidth = this . _dimensions . width , i , strLength ;
828
838
var locLineWidth = this . _lineWidths ;
@@ -842,7 +852,11 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
842
852
i += next ;
843
853
}
844
854
} else {
845
- this . _strings = this . _string . split ( '\n' ) ;
855
+ if ( / \n / . test ( this . _string ) ) {
856
+ this . _strings = this . _string . split ( '\n' ) ;
857
+ } else {
858
+ this . _strings = [ this . _string ] ;
859
+ }
846
860
for ( i = 0 , strLength = this . _strings . length ; i < strLength ; i ++ ) {
847
861
locLineWidth . push ( this . _measure ( this . _strings [ i ] ) ) ;
848
862
}
@@ -863,19 +877,33 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
863
877
//get offset for stroke and shadow
864
878
if ( locDimensionsWidth === 0 ) {
865
879
if ( this . _isMultiLine )
866
- locSize = cc . size ( 0 | ( Math . max . apply ( Math , locLineWidth ) + locStrokeShadowOffsetX ) ,
867
- 0 | ( ( this . _fontClientHeight * this . _strings . length ) + locStrokeShadowOffsetY ) ) ;
880
+ locSize = {
881
+ width : this . _maxNum ( locLineWidth ) + locStrokeShadowOffsetX | 0 ,
882
+ height : this . _fontClientHeight * this . _strings . length + locStrokeShadowOffsetY | 0
883
+ } ;
868
884
else
869
- locSize = cc . size ( 0 | ( this . _measure ( this . _string ) + locStrokeShadowOffsetX ) , 0 | ( this . _fontClientHeight + locStrokeShadowOffsetY ) ) ;
885
+ locSize = {
886
+ width : this . _measure ( this . _string ) + locStrokeShadowOffsetX | 0 ,
887
+ height : this . _fontClientHeight + locStrokeShadowOffsetY | 0
888
+ } ;
870
889
} else {
871
890
if ( this . _dimensions . height === 0 ) {
872
891
if ( this . _isMultiLine )
873
- locSize = cc . size ( 0 | ( locDimensionsWidth + locStrokeShadowOffsetX ) , 0 | ( ( this . _fontClientHeight * this . _strings . length ) + locStrokeShadowOffsetY ) ) ;
892
+ locSize = {
893
+ width : locDimensionsWidth + locStrokeShadowOffsetX | 0 ,
894
+ height : this . _fontClientHeight * this . _strings . length + locStrokeShadowOffsetY | 0
895
+ } ;
874
896
else
875
- locSize = cc . size ( 0 | ( locDimensionsWidth + locStrokeShadowOffsetX ) , 0 | ( this . _fontClientHeight + locStrokeShadowOffsetY ) ) ;
897
+ locSize = {
898
+ width : locDimensionsWidth + locStrokeShadowOffsetX | 0 ,
899
+ height : this . _fontClientHeight + locStrokeShadowOffsetY | 0
900
+ } ;
876
901
} else {
877
902
//dimension is already set, contentSize must be same as dimension
878
- locSize = cc . size ( 0 | ( locDimensionsWidth + locStrokeShadowOffsetX ) , 0 | ( this . _dimensions . height + locStrokeShadowOffsetY ) ) ;
903
+ locSize = {
904
+ width : locDimensionsWidth + locStrokeShadowOffsetX | 0 ,
905
+ height : this . _dimensions . height + locStrokeShadowOffsetY | 0
906
+ } ;
879
907
}
880
908
}
881
909
this . setContentSize ( locSize ) ;
@@ -884,8 +912,8 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
884
912
885
913
// need computing _anchorPointInPoints
886
914
var locAP = this . _anchorPoint ;
887
- this . _anchorPointInPoints . x = ( locStrokeShadowOffsetX * 0.5 ) + ( ( locSize . width - locStrokeShadowOffsetX ) * locAP . x ) ;
888
- this . _anchorPointInPoints . y = ( locStrokeShadowOffsetY * 0.5 ) + ( ( locSize . height - locStrokeShadowOffsetY ) * locAP . y ) ;
915
+ this . _anchorPointInPoints . x = ( 0.5 - locAP . x ) * locStrokeShadowOffsetX + locAP . x * locSize . width ;
916
+ this . _anchorPointInPoints . y = ( 0.5 - locAP . y ) * locStrokeShadowOffsetY + locAP . y * locSize . height ;
889
917
} ,
890
918
891
919
getContentSize : function ( ) {
0 commit comments