@@ -47,6 +47,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
4747 this . _isMultiLine = false ;
4848 this . _status = [ ] ;
4949 this . _renderingIndex = 0 ;
50+
51+ this . _texRect = cc . rect ( ) ;
5052 } ;
5153 var proto = cc . LabelTTF . RenderCmd . prototype ;
5254 proto . constructor = cc . LabelTTF . RenderCmd ;
@@ -92,7 +94,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
9294
9395 proto . _updateTTF = function ( ) {
9496 var node = this . _node ;
95- var locDimensionsWidth = node . _dimensions . width , i , strLength ;
97+ var pixelRatio = cc . view . getDevicePixelRatio ( ) ;
98+ var locDimensionsWidth = node . _dimensions . width * pixelRatio , i , strLength ;
9699 var locLineWidth = this . _lineWidths ;
97100 locLineWidth . length = 0 ;
98101
@@ -124,7 +127,6 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
124127 locStrokeShadowOffsetY += Math . abs ( locOffsetSize . y ) * 2 ;
125128 }
126129
127- var pixelRatio = cc . view . getDevicePixelRatio ( ) ;
128130 //get offset for stroke and shadow
129131 if ( locDimensionsWidth === 0 ) {
130132 if ( this . _isMultiLine )
@@ -155,7 +157,16 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
155157 if ( node . _getFontStyle ( ) !== "normal" ) { //add width for 'italic' and 'oblique'
156158 locSize . width = Math . ceil ( locSize . width + node . _fontSize * 0.3 ) ;
157159 }
158- node . setContentSize ( locSize ) ;
160+ if ( this . _strings . length === 0 ) {
161+ this . _texRect . width = 1 ;
162+ this . _texRect . height = locSize . height || 1 ;
163+ }
164+ else {
165+ this . _texRect . width = locSize . width ;
166+ this . _texRect . height = locSize . height ;
167+ }
168+ var nodeW = locSize . width / pixelRatio , nodeH = locSize . height / pixelRatio ;
169+ node . setContentSize ( nodeW , nodeH ) ;
159170 node . _strokeShadowOffsetX = locStrokeShadowOffsetX ;
160171 node . _strokeShadowOffsetY = locStrokeShadowOffsetY ;
161172
@@ -167,13 +178,14 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
167178
168179 proto . _saveStatus = function ( ) {
169180 var node = this . _node ;
181+ var scale = cc . view . getDevicePixelRatio ( ) ;
170182 var locStrokeShadowOffsetX = node . _strokeShadowOffsetX , locStrokeShadowOffsetY = node . _strokeShadowOffsetY ;
171- var locContentSizeHeight = node . _contentSize . height - locStrokeShadowOffsetY , locVAlignment = node . _vAlignment ,
183+ var locContentSizeHeight = node . _contentSize . height * scale - locStrokeShadowOffsetY , locVAlignment = node . _vAlignment ,
172184 locHAlignment = node . _hAlignment ;
173185 var dx = locStrokeShadowOffsetX * 0.5 ,
174186 dy = locContentSizeHeight + locStrokeShadowOffsetY * 0.5 ;
175187 var xOffset = 0 , yOffset = 0 , OffsetYArray = [ ] ;
176- var locContentWidth = node . _contentSize . width - locStrokeShadowOffsetX ;
188+ var locContentWidth = node . _contentSize . width * scale - locStrokeShadowOffsetX ;
177189
178190 //lineHeight
179191 var lineHeight = node . getLineHeight ( ) ;
@@ -301,7 +313,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
301313 var flags = cc . Node . _dirtyFlags , locFlag = this . _dirtyFlag ;
302314
303315 cc . Node . RenderCmd . prototype . updateStatus . call ( this ) ;
304-
316+
305317 if ( locFlag & flags . textDirty )
306318 this . _updateTexture ( ) ;
307319
@@ -313,9 +325,9 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
313325
314326 proto . _syncStatus = function ( parentCmd ) {
315327 var flags = cc . Node . _dirtyFlags , locFlag = this . _dirtyFlag ;
316-
328+
317329 cc . Node . RenderCmd . prototype . _syncStatus . call ( this , parentCmd ) ;
318-
330+
319331 if ( locFlag & flags . textDirty )
320332 this . _updateTexture ( ) ;
321333
@@ -371,6 +383,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
371383 locCanvas . width = 1 ;
372384 locCanvas . height = 1 ;
373385 this . _labelContext = locCanvas . getContext ( "2d" ) ;
386+ this . _texRect = cc . rect ( ) ;
374387 } ;
375388
376389 cc . LabelTTF . CacheRenderCmd . prototype = Object . create ( cc . LabelTTF . RenderCmd . prototype ) ;
@@ -382,9 +395,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
382395 proto . _updateTexture = function ( ) {
383396 this . _dirtyFlag = this . _dirtyFlag & cc . Node . _dirtyFlags . textDirty ^ this . _dirtyFlag ;
384397 var node = this . _node ;
385- var locContentSize = node . _contentSize ;
386398 this . _updateTTF ( ) ;
387- var width = locContentSize . width , height = locContentSize . height ;
399+ var width = this . _texRect . width , height = this . _texRect . height ;
388400
389401 var locContext = this . _labelContext , locLabelCanvas = this . _labelCanvas ;
390402
@@ -395,24 +407,24 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
395407 }
396408
397409 if ( node . _string . length === 0 ) {
398- locLabelCanvas . width = 1 ;
399- locLabelCanvas . height = locContentSize . height || 1 ;
410+ locLabelCanvas . width = width ;
411+ locLabelCanvas . height = height ;
400412 node . _texture && node . _texture . handleLoadedTexture ( ) ;
401- node . setTextureRect ( cc . rect ( 0 , 0 , 1 , locContentSize . height ) ) ;
413+ node . setTextureRect ( this . _texRect ) ;
402414 return true ;
403415 }
404416
405417 //set size for labelCanvas
406418 locContext . font = this . _fontStyleStr ;
407419
408420 var flag = locLabelCanvas . width === width && locLabelCanvas . height === height ;
409- locLabelCanvas . width = width ;
410- locLabelCanvas . height = height ;
421+ locLabelCanvas . width = this . _texRect . width ;
422+ locLabelCanvas . height = this . _texRect . height ;
411423 if ( flag ) locContext . clearRect ( 0 , 0 , width , height ) ;
412424 this . _saveStatus ( ) ;
413425 this . _drawTTFInCanvas ( locContext ) ;
414426 node . _texture && node . _texture . handleLoadedTexture ( ) ;
415- node . setTextureRect ( cc . rect ( 0 , 0 , width , height ) ) ;
427+ node . setTextureRect ( this . _texRect ) ;
416428 return true ;
417429 } ;
418430
@@ -460,15 +472,14 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
460472 proto . _updateTexture = function ( ) {
461473 this . _dirtyFlag = this . _dirtyFlag & cc . Node . _dirtyFlags . textDirty ^ this . _dirtyFlag ;
462474 var node = this . _node ;
463- var locContentSize = node . _contentSize ;
475+ var scale = cc . view . getDevicePixelRatio ( ) ;
464476 this . _updateTTF ( ) ;
465- var width = locContentSize . width , height = locContentSize . height ;
466477 if ( node . _string . length === 0 ) {
467- node . setTextureRect ( cc . rect ( 0 , 0 , 1 , locContentSize . height ) ) ;
478+ node . setTextureRect ( this . _texRect ) ;
468479 return true ;
469480 }
470481 this . _saveStatus ( ) ;
471- node . setTextureRect ( cc . rect ( 0 , 0 , width , height ) ) ;
482+ node . setTextureRect ( this . _texRect ) ;
472483 return true ;
473484 } ;
474485
0 commit comments