@@ -351,96 +351,99 @@ Phaser.Text.prototype.setStyle = function (style) {
351351*/
352352Phaser . Text . prototype . updateText = function ( ) {
353353
354+ this . texture . baseTexture . resolution = this . resolution ;
355+
354356 this . context . font = this . style . font ;
355357
356358 var outputText = this . text ;
357359
358360 // word wrap
359361 // preserve original text
360- if ( this . style . wordWrap )
361- {
362- outputText = this . runWordWrap ( this . text ) ;
363- }
362+ if ( this . style . wordWrap ) outputText = this . wordWrap ( this . text ) ;
364363
365364 //split text into lines
366365 var lines = outputText . split ( / (?: \r \n | \r | \n ) / ) ;
367366
368367 //calculate text width
369368 var lineWidths = [ ] ;
370369 var maxLineWidth = 0 ;
371-
370+ var fontProperties = this . determineFontProperties ( this . style . font ) ;
372371 for ( var i = 0 ; i < lines . length ; i ++ )
373372 {
374373 var lineWidth = this . context . measureText ( lines [ i ] ) . width ;
375374 lineWidths [ i ] = lineWidth ;
376375 maxLineWidth = Math . max ( maxLineWidth , lineWidth ) ;
377376 }
378377
379- this . canvas . width = maxLineWidth + this . style . strokeThickness ;
378+ var width = maxLineWidth + this . style . strokeThickness ;
380379
380+ this . canvas . width = ( width + this . context . lineWidth ) * this . resolution ;
381+
381382 //calculate text height
382- var lineHeight = this . determineFontHeight ( 'font: ' + this . style . font + ';' ) + this . style . strokeThickness + this . _lineSpacing + this . style . shadowOffsetY ;
383+ var lineHeight = fontProperties . fontSize + this . style . strokeThickness ;
384+
385+ var height = lineHeight * lines . length ;
383386
384- this . canvas . height = lineHeight * lines . length ;
387+ this . canvas . height = height * this . resolution ;
385388
386- if ( navigator . isCocoonJS )
387- {
388- this . context . clearRect ( 0 , 0 , this . canvas . width , this . canvas . height ) ;
389- }
389+ this . context . scale ( this . resolution , this . resolution ) ;
390390
391- //set canvas text styles
391+ if ( navigator . isCocoonJS ) this . context . clearRect ( 0 , 0 , this . canvas . width , this . canvas . height ) ;
392+
392393 this . context . fillStyle = this . style . fill ;
393394 this . context . font = this . style . font ;
394-
395395 this . context . strokeStyle = this . style . stroke ;
396- this . context . lineWidth = this . style . strokeThickness ;
397-
396+ this . context . textBaseline = 'alphabetic' ;
398397 this . context . shadowOffsetX = this . style . shadowOffsetX ;
399398 this . context . shadowOffsetY = this . style . shadowOffsetY ;
400399 this . context . shadowColor = this . style . shadowColor ;
401400 this . context . shadowBlur = this . style . shadowBlur ;
402-
403- this . context . textBaseline = 'top' ;
401+ this . context . lineWidth = this . style . strokeThickness ;
404402 this . context . lineCap = 'round' ;
405403 this . context . lineJoin = 'round' ;
406404
405+ var linePositionX ;
406+ var linePositionY ;
407+
407408 this . _charCount = 0 ;
408409
409410 //draw lines line by line
410411 for ( i = 0 ; i < lines . length ; i ++ )
411412 {
412- var linePosition = new PIXI . Point ( this . style . strokeThickness / 2 , this . style . strokeThickness / 2 + i * lineHeight ) ;
413+ linePositionX = this . style . strokeThickness / 2 ;
414+ linePositionY = ( this . style . strokeThickness / 2 + i * lineHeight ) + fontProperties . ascent ;
413415
414416 if ( this . style . align === 'right' )
415417 {
416- linePosition . x += maxLineWidth - lineWidths [ i ] ;
418+ linePositionX += maxLineWidth - lineWidths [ i ] ;
417419 }
418420 else if ( this . style . align === 'center' )
419421 {
420- linePosition . x += ( maxLineWidth - lineWidths [ i ] ) / 2 ;
422+ linePositionX += ( maxLineWidth - lineWidths [ i ] ) / 2 ;
421423 }
422424
423- linePosition . y += this . _lineSpacing ;
425+ linePositionY += this . _lineSpacing ;
424426
425427 if ( this . colors . length > 0 )
426428 {
427- this . updateLine ( lines [ i ] , linePosition . x , linePosition . y ) ;
429+ this . updateLine ( lines [ i ] , linePositionX , linePositionY ) ;
428430 }
429431 else
430432 {
431433 if ( this . style . stroke && this . style . strokeThickness )
432434 {
433- this . context . strokeText ( lines [ i ] , linePosition . x , linePosition . y ) ;
435+ this . context . strokeText ( lines [ i ] , linePositionX , linePositionY ) ;
434436 }
435437
436438 if ( this . style . fill )
437439 {
438- this . context . fillText ( lines [ i ] , linePosition . x , linePosition . y ) ;
440+ this . context . fillText ( lines [ i ] , linePositionX , linePositionY ) ;
439441 }
440442 }
441443 }
442444
443445 this . updateTexture ( ) ;
446+
444447} ;
445448
446449Phaser . Text . prototype . updateLine = function ( line , x , y ) {
0 commit comments