@@ -47,6 +47,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
47
47
this . _isMultiLine = false ;
48
48
this . _status = [ ] ;
49
49
this . _renderingIndex = 0 ;
50
+
51
+ this . _texRect = cc . rect ( ) ;
50
52
} ;
51
53
var proto = cc . LabelTTF . RenderCmd . prototype ;
52
54
proto . constructor = cc . LabelTTF . RenderCmd ;
@@ -92,7 +94,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
92
94
93
95
proto . _updateTTF = function ( ) {
94
96
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 ;
96
99
var locLineWidth = this . _lineWidths ;
97
100
locLineWidth . length = 0 ;
98
101
@@ -124,7 +127,6 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
124
127
locStrokeShadowOffsetY += Math . abs ( locOffsetSize . y ) * 2 ;
125
128
}
126
129
127
- var pixelRatio = cc . view . getDevicePixelRatio ( ) ;
128
130
//get offset for stroke and shadow
129
131
if ( locDimensionsWidth === 0 ) {
130
132
if ( this . _isMultiLine )
@@ -155,25 +157,35 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
155
157
if ( node . _getFontStyle ( ) !== "normal" ) { //add width for 'italic' and 'oblique'
156
158
locSize . width = Math . ceil ( locSize . width + node . _fontSize * 0.3 ) ;
157
159
}
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 ) ;
159
170
node . _strokeShadowOffsetX = locStrokeShadowOffsetX ;
160
171
node . _strokeShadowOffsetY = locStrokeShadowOffsetY ;
161
172
162
173
// need computing _anchorPointInPoints
163
174
var locAP = node . _anchorPoint ;
164
175
this . _anchorPointInPoints . x = ( locStrokeShadowOffsetX * 0.5 ) + ( ( locSize . width - locStrokeShadowOffsetX ) * locAP . x ) ;
165
- this . _anchorPointInPoints . y = ( locStrokeShadowOffsetY * 0.5 ) + ( ( locSize . height - locStrokeShadowOffsetY ) * locAP . y ) ;
176
+ this . _anchorPointInPoints . y = ( locStrokeShadowOffsetY * 0.5 ) + ( ( locSize . width - locStrokeShadowOffsetY ) * locAP . y ) ;
166
177
} ;
167
178
168
179
proto . _saveStatus = function ( ) {
169
180
var node = this . _node ;
181
+ var scale = cc . view . getDevicePixelRatio ( ) ;
170
182
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 ,
172
184
locHAlignment = node . _hAlignment ;
173
185
var dx = locStrokeShadowOffsetX * 0.5 ,
174
186
dy = locContentSizeHeight + locStrokeShadowOffsetY * 0.5 ;
175
187
var xOffset = 0 , yOffset = 0 , OffsetYArray = [ ] ;
176
- var locContentWidth = node . _contentSize . width - locStrokeShadowOffsetX ;
188
+ var locContentWidth = node . _contentSize . width * scale - locStrokeShadowOffsetX ;
177
189
178
190
//lineHeight
179
191
var lineHeight = node . getLineHeight ( ) ;
@@ -301,7 +313,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
301
313
var flags = cc . Node . _dirtyFlags , locFlag = this . _dirtyFlag ;
302
314
303
315
cc . Node . RenderCmd . prototype . updateStatus . call ( this ) ;
304
-
316
+
305
317
if ( locFlag & flags . textDirty )
306
318
this . _updateTexture ( ) ;
307
319
@@ -313,9 +325,9 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
313
325
314
326
proto . _syncStatus = function ( parentCmd ) {
315
327
var flags = cc . Node . _dirtyFlags , locFlag = this . _dirtyFlag ;
316
-
328
+
317
329
cc . Node . RenderCmd . prototype . _syncStatus . call ( this , parentCmd ) ;
318
-
330
+
319
331
if ( locFlag & flags . textDirty )
320
332
this . _updateTexture ( ) ;
321
333
@@ -371,6 +383,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
371
383
locCanvas . width = 1 ;
372
384
locCanvas . height = 1 ;
373
385
this . _labelContext = locCanvas . getContext ( "2d" ) ;
386
+ this . _texRect = cc . rect ( ) ;
374
387
} ;
375
388
376
389
cc . LabelTTF . CacheRenderCmd . prototype = Object . create ( cc . LabelTTF . RenderCmd . prototype ) ;
@@ -382,9 +395,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
382
395
proto . _updateTexture = function ( ) {
383
396
this . _dirtyFlag = this . _dirtyFlag & cc . Node . _dirtyFlags . textDirty ^ this . _dirtyFlag ;
384
397
var node = this . _node ;
385
- var locContentSize = node . _contentSize ;
386
398
this . _updateTTF ( ) ;
387
- var width = locContentSize . width , height = locContentSize . height ;
399
+ var width = this . _texRect . width , height = this . _texRect . height ;
388
400
389
401
var locContext = this . _labelContext , locLabelCanvas = this . _labelCanvas ;
390
402
@@ -395,24 +407,24 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
395
407
}
396
408
397
409
if ( node . _string . length === 0 ) {
398
- locLabelCanvas . width = 1 ;
399
- locLabelCanvas . height = locContentSize . height || 1 ;
410
+ locLabelCanvas . width = width ;
411
+ locLabelCanvas . height = height ;
400
412
node . _texture && node . _texture . handleLoadedTexture ( ) ;
401
- node . setTextureRect ( cc . rect ( 0 , 0 , 1 , locContentSize . height ) ) ;
413
+ node . setTextureRect ( this . _texRect ) ;
402
414
return true ;
403
415
}
404
416
405
417
//set size for labelCanvas
406
418
locContext . font = this . _fontStyleStr ;
407
419
408
420
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 ;
411
423
if ( flag ) locContext . clearRect ( 0 , 0 , width , height ) ;
412
424
this . _saveStatus ( ) ;
413
425
this . _drawTTFInCanvas ( locContext ) ;
414
426
node . _texture && node . _texture . handleLoadedTexture ( ) ;
415
- node . setTextureRect ( cc . rect ( 0 , 0 , width , height ) ) ;
427
+ node . setTextureRect ( this . _texRect ) ;
416
428
return true ;
417
429
} ;
418
430
@@ -460,15 +472,14 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
460
472
proto . _updateTexture = function ( ) {
461
473
this . _dirtyFlag = this . _dirtyFlag & cc . Node . _dirtyFlags . textDirty ^ this . _dirtyFlag ;
462
474
var node = this . _node ;
463
- var locContentSize = node . _contentSize ;
475
+ var scale = cc . view . getDevicePixelRatio ( ) ;
464
476
this . _updateTTF ( ) ;
465
- var width = locContentSize . width , height = locContentSize . height ;
466
477
if ( node . _string . length === 0 ) {
467
- node . setTextureRect ( cc . rect ( 0 , 0 , 1 , locContentSize . height ) ) ;
478
+ node . setTextureRect ( this . _texRect ) ;
468
479
return true ;
469
480
}
470
481
this . _saveStatus ( ) ;
471
- node . setTextureRect ( cc . rect ( 0 , 0 , width , height ) ) ;
482
+ node . setTextureRect ( this . _texRect ) ;
472
483
return true ;
473
484
} ;
474
485
0 commit comments