@@ -101,6 +101,8 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
101
101
_lineWidths : null ,
102
102
_className : "LabelTTF" ,
103
103
104
+ _lineHeight : 0 ,
105
+
104
106
/**
105
107
* Initializes the cc.LabelTTF with a font name, alignment, dimension and font size, do not call it by yourself,
106
108
* you should pass the correct arguments in constructor to initialize the label.
@@ -215,6 +217,14 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
215
217
this . _setColorsString ( ) ;
216
218
} ,
217
219
220
+ getLineHiehgt : function ( ) {
221
+ return this . _lineHeight || this . _fontClientHeight ;
222
+ } ,
223
+
224
+ setLineHeight : function ( lineHeight ) {
225
+ this . _lineHeight = lineHeight ;
226
+ } ,
227
+
218
228
/**
219
229
* Returns the text of the label
220
230
* @return {String }
@@ -752,6 +762,11 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
752
762
context . textAlign = cc . LabelTTF . _textAlign [ locHAlignment ] ;
753
763
754
764
var locContentWidth = this . _contentSize . width - locStrokeShadowOffsetX ;
765
+
766
+ //lineHiehgt
767
+ var lineHeight = this . getLineHiehgt ( ) ;
768
+ var transformTop = ( lineHeight - this . _fontClientHeight ) / 2 ;
769
+
755
770
if ( locHAlignment === cc . TEXT_ALIGNMENT_RIGHT )
756
771
xOffset += locContentWidth ;
757
772
else if ( locHAlignment === cc . TEXT_ALIGNMENT_CENTER )
@@ -761,13 +776,13 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
761
776
if ( this . _isMultiLine ) {
762
777
var locStrLen = this . _strings . length ;
763
778
if ( locVAlignment === cc . VERTICAL_TEXT_ALIGNMENT_BOTTOM )
764
- yOffset = locFontHeight + locContentSizeHeight - locFontHeight * locStrLen ;
779
+ yOffset = lineHeight - transformTop * 2 + locContentSizeHeight - lineHeight * locStrLen ;
765
780
else if ( locVAlignment === cc . VERTICAL_TEXT_ALIGNMENT_CENTER )
766
- yOffset = locFontHeight / 2 + ( locContentSizeHeight - locFontHeight * locStrLen ) / 2 ;
781
+ yOffset = ( lineHeight - transformTop * 2 ) / 2 + ( locContentSizeHeight - lineHeight * locStrLen ) / 2 ;
767
782
768
783
for ( var i = 0 ; i < locStrLen ; i ++ ) {
769
784
var line = this . _strings [ i ] ;
770
- var tmpOffsetY = - locContentSizeHeight + ( locFontHeight * i ) + yOffset ;
785
+ var tmpOffsetY = - locContentSizeHeight + ( lineHeight * i + transformTop ) + yOffset ;
771
786
if ( locStrokeEnabled )
772
787
context . strokeText ( line , xOffset , tmpOffsetY ) ;
773
788
context . fillText ( line , xOffset , tmpOffsetY ) ;
@@ -923,9 +938,9 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
923
938
} else {
924
939
if ( this . _dimensions . height === 0 ) {
925
940
if ( this . _isMultiLine )
926
- locSize = cc . size ( 0 | ( locDimensionsWidth + locStrokeShadowOffsetX ) , 0 | ( ( this . _fontClientHeight * this . _strings . length ) + locStrokeShadowOffsetY ) ) ;
941
+ locSize = cc . size ( 0 | ( locDimensionsWidth + locStrokeShadowOffsetX ) , 0 | ( ( this . getLineHiehgt ( ) * this . _strings . length ) + locStrokeShadowOffsetY ) ) ;
927
942
else
928
- locSize = cc . size ( 0 | ( locDimensionsWidth + locStrokeShadowOffsetX ) , 0 | ( this . _fontClientHeight + locStrokeShadowOffsetY ) ) ;
943
+ locSize = cc . size ( 0 | ( locDimensionsWidth + locStrokeShadowOffsetX ) , 0 | ( this . getLineHiehgt ( ) + locStrokeShadowOffsetY ) ) ;
929
944
} else {
930
945
//dimension is already set, contentSize must be same as dimension
931
946
locSize = cc . size ( 0 | ( locDimensionsWidth + locStrokeShadowOffsetX ) , 0 | ( this . _dimensions . height + locStrokeShadowOffsetY ) ) ;
0 commit comments