@@ -520,20 +520,27 @@ var TextStyle = new Class({
520520 */
521521 setFont : function ( font )
522522 {
523- if ( typeof font === 'string' )
523+ var fontFamily = font ;
524+ var fontSize = '' ;
525+ var fontStyle = '' ;
526+
527+ if ( typeof font !== 'string' )
524528 {
525- this . fontFamily = font ;
526- this . fontSize = '' ;
527- this . fontStyle = '' ;
529+ fontFamily = GetValue ( font , 'fontFamily' , 'Courier' ) ;
530+ fontSize = GetValue ( font , 'fontSize' , '16px' ) ;
531+ fontStyle = GetValue ( font , 'fontStyle' , '' ) ;
528532 }
529- else
533+
534+ if ( fontFamily !== this . fontFamily || fontSize !== this . fontSize || fontStyle !== this . fontStyle )
530535 {
531- this . fontFamily = GetValue ( font , 'fontFamily' , 'Courier' ) ;
532- this . fontSize = GetValue ( font , 'fontSize' , '16px' ) ;
533- this . fontStyle = GetValue ( font , 'fontStyle' , '' ) ;
536+ this . fontFamily = fontFamily ;
537+ this . fontSize = fontSize ;
538+ this . fontStyle = fontStyle ;
539+
540+ this . update ( true ) ;
534541 }
535542
536- return this . update ( true ) ;
543+ return this . parent ;
537544 } ,
538545
539546 /**
@@ -548,9 +555,14 @@ var TextStyle = new Class({
548555 */
549556 setFontFamily : function ( family )
550557 {
551- this . fontFamily = family ;
558+ if ( this . fontFamily !== family )
559+ {
560+ this . fontFamily = family ;
552561
553- return this . update ( true ) ;
562+ this . update ( true ) ;
563+ }
564+
565+ return this . parent ;
554566 } ,
555567
556568 /**
@@ -565,9 +577,14 @@ var TextStyle = new Class({
565577 */
566578 setFontStyle : function ( style )
567579 {
568- this . fontStyle = style ;
580+ if ( this . fontStyle !== style )
581+ {
582+ this . fontStyle = style ;
569583
570- return this . update ( true ) ;
584+ this . update ( true ) ;
585+ }
586+
587+ return this . parent ;
571588 } ,
572589
573590 /**
@@ -587,9 +604,14 @@ var TextStyle = new Class({
587604 size = size . toString ( ) + 'px' ;
588605 }
589606
590- this . fontSize = size ;
607+ if ( this . fontSize !== size )
608+ {
609+ this . fontSize = size ;
591610
592- return this . update ( true ) ;
611+ this . update ( true ) ;
612+ }
613+
614+ return this . parent ;
593615 } ,
594616
595617 /**
@@ -727,24 +749,31 @@ var TextStyle = new Class({
727749 */
728750 setStroke : function ( color , thickness )
729751 {
730- if ( color === undefined )
752+ if ( thickness === undefined ) { thickness = this . strokeThickness ; }
753+
754+ if ( color === undefined && this . strokeThickness !== 0 )
731755 {
732756 // Reset the stroke to zero (disabling it)
733757 this . strokeThickness = 0 ;
758+
759+ this . update ( true ) ;
734760 }
735- else
761+ else if ( this . stroke !== color || this . strokeThickness !== thickness )
736762 {
737- if ( thickness === undefined ) { thickness = this . strokeThickness ; }
738-
739763 this . stroke = color ;
740764 this . strokeThickness = thickness ;
765+
766+ this . update ( true ) ;
741767 }
742768
743- return this . update ( true ) ;
769+ return this . parent ;
744770 } ,
745771
746772 /**
747773 * Set the shadow settings.
774+ *
775+ * Calling this method always re-measures the parent Text object,
776+ * so only call it when you actually change the shadow settings.
748777 *
749778 * @method Phaser.GameObjects.Text.TextStyle#setShadow
750779 * @since 3.0.0
0 commit comments