@@ -629,8 +629,12 @@ Bitmap.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) {
629629 // Note: Firefox has a bug with textBaseline: Bug 737852
630630 // So we use 'alphabetic' here.
631631 if ( text !== undefined ) {
632+ if ( this . fontSize < Bitmap . minFontSize ) {
633+ this . drawSmallText ( text , x , y , maxWidth , lineHeight , align ) ;
634+ return ;
635+ }
632636 var tx = x ;
633- var ty = y + lineHeight - ( lineHeight - this . fontSize * 0.7 ) / 2 ;
637+ var ty = y + lineHeight - Math . round ( ( lineHeight - this . fontSize * 0.7 ) / 2 ) ;
634638 var context = this . _context ;
635639 var alpha = context . globalAlpha ;
636640 maxWidth = maxWidth || 0xffffffff ;
@@ -653,6 +657,45 @@ Bitmap.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) {
653657 }
654658} ;
655659
660+ /**
661+ * Draws the small text big once and resize it because modern broswers are poor at drawing small text.
662+ *
663+ * @method drawSmallText
664+ * @param {String } text The text that will be drawn
665+ * @param {Number } x The x coordinate for the left of the text
666+ * @param {Number } y The y coordinate for the top of the text
667+ * @param {Number } maxWidth The maximum allowed width of the text
668+ * @param {Number } lineHeight The height of the text line
669+ * @param {String } align The alignment of the text
670+ */
671+ Bitmap . prototype . drawSmallText = function ( text , x , y , maxWidth , lineHeight , align ) {
672+ var minFontSize = Bitmap . minFontSize ;
673+ var bitmap = Bitmap . drawSmallTextBitmap ;
674+ bitmap . fontFace = this . fontFace ;
675+ bitmap . fontSize = minFontSize ;
676+ bitmap . fontItalic = this . fontItalic ;
677+ bitmap . textColor = this . textColor ;
678+ bitmap . outlineColor = this . outlineColor ;
679+ bitmap . outlineWidth = this . outlineWidth * minFontSize / this . fontSize ;
680+ maxWidth = maxWidth || 816 ;
681+ var height = this . fontSize * 1.5 ;
682+ var scaledMaxWidth = maxWidth * minFontSize / this . fontSize ;
683+ var scaledMaxWidthWithOutline = scaledMaxWidth + bitmap . outlineWidth * 2 ;
684+ var scaledHeight = height * minFontSize / this . fontSize ;
685+ var scaledHeightWithOutline = scaledHeight + bitmap . outlineWidth * 2 ;
686+
687+ var bitmapWidth = bitmap . width ;
688+ var bitmapHeight = bitmap . height ;
689+ while ( scaledMaxWidthWithOutline > bitmapWidth ) bitmapWidth *= 2 ;
690+ while ( scaledHeightWithOutline > bitmapHeight ) bitmapHeight *= 2 ;
691+ if ( bitmap . width !== bitmapWidth || bitmap . height !== bitmapHeight ) bitmap . resize ( bitmapWidth , bitmapHeight ) ;
692+
693+ bitmap . drawText ( text , bitmap . outlineWidth , bitmap . outlineWidth , scaledMaxWidth , minFontSize , align ) ;
694+ this . blt ( bitmap , 0 , 0 , scaledMaxWidthWithOutline , scaledHeightWithOutline ,
695+ x - this . outlineWidth , y - this . outlineWidth + ( lineHeight - this . fontSize ) / 2 , maxWidth + this . outlineWidth * 2 , height + this . outlineWidth * 2 ) ;
696+ bitmap . clear ( ) ;
697+ } ;
698+
656699/**
657700 * Returns the width of the specified text.
658701 *
@@ -946,6 +989,10 @@ Bitmap.prototype._setDirty = function() {
946989Bitmap . prototype . checkDirty = function ( ) {
947990 if ( this . _dirty ) {
948991 this . _baseTexture . update ( ) ;
992+ var baseTexture = this . _baseTexture ;
993+ setTimeout ( function ( ) {
994+ baseTexture . update ( ) ;
995+ } , 0 ) ;
949996 this . _dirty = false ;
950997 }
951998} ;
@@ -972,7 +1019,6 @@ Bitmap.prototype._requestImage = function(url){
9721019 this . _loader = ResourceHandler . createLoader ( url , this . _requestImage . bind ( this , url ) , this . _onError . bind ( this ) ) ;
9731020 }
9741021
975- this . _image = new Image ( ) ;
9761022 this . _url = url ;
9771023 this . _loadingState = 'requesting' ;
9781024
@@ -1003,3 +1049,6 @@ Bitmap.prototype.startRequest = function(){
10031049 this . _requestImage ( this . _url ) ;
10041050 }
10051051} ;
1052+
1053+ Bitmap . minFontSize = 21 ;
1054+ Bitmap . drawSmallTextBitmap = new Bitmap ( 1632 , Bitmap . minFontSize ) ;
0 commit comments