@@ -13,14 +13,18 @@ var GetBitmapTextSize = function (src)
1313
1414 if ( textLength === 0 )
1515 {
16- console . log ( 'bailed' ) ;
1716 return bounds ;
1817 }
1918
2019 bounds . x = Number . MAX_VALUE ;
2120 bounds . y = Number . MAX_VALUE ;
22- bounds . width = - 1 ;
23- bounds . height = - 1 ;
21+ bounds . width = 0 ;
22+ bounds . height = 0 ;
23+
24+ // var sx = src.scaleX;
25+ // var sy = src.scaleY;
26+ // var prevX;
27+ // var prevY;
2428
2529 var textureFrame = src . frame ;
2630
@@ -34,8 +38,8 @@ var GetBitmapTextSize = function (src)
3438 var charCode = 0 ;
3539
3640 var glyph = null ;
37- var glyphX = 0 ;
38- var glyphY = 0 ;
41+ // var glyphX = 0;
42+ // var glyphY = 0;
3943 var glyphW = 0 ;
4044 var glyphH = 0 ;
4145
@@ -45,8 +49,8 @@ var GetBitmapTextSize = function (src)
4549 var lastGlyph = null ;
4650 var lastCharCode = 0 ;
4751
48- var textureX = textureFrame . cutX ;
49- var textureY = textureFrame . cutY ;
52+ // var textureX = textureFrame.cutX;
53+ // var textureY = textureFrame.cutY;
5054
5155 var scale = ( src . fontSize / src . fontData . size ) ;
5256
@@ -70,8 +74,8 @@ var GetBitmapTextSize = function (src)
7074 continue ;
7175 }
7276
73- glyphX = textureX + glyph . x ;
74- glyphY = textureY + glyph . y ;
77+ // glyphX = textureX + glyph.x;
78+ // glyphY = textureY + glyph.y;
7579
7680 glyphW = glyph . width ;
7781 glyphH = glyph . height ;
@@ -85,55 +89,48 @@ var GetBitmapTextSize = function (src)
8589 x += ( kerningOffset !== undefined ) ? kerningOffset : 0 ;
8690 }
8791
92+ // prevX = x;
93+ // prevY = y;
94+
8895 x *= scale ;
8996 y *= scale ;
9097
91- // ctx.save();
92- // ctx.translate(x, y);
93- // ctx.rotate(rotation);
94- // ctx.scale(scale, scale);
95-
96- // ctx.fillStyle = 'rgb(255,0,255)';
97- // ctx.fillRect(0, 0, glyphW, glyphH);
98-
9998 // ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH);
10099
101- // var xs = x * scale;
102- // var ys = y * scale;
100+ xAdvance += glyph . xAdvance ;
101+ indexCount += 1 ;
102+ lastGlyph = glyph ;
103+ lastCharCode = charCode ;
103104
104- if ( bounds . x > x )
105+ if ( x < bounds . x )
105106 {
106107 bounds . x = x ;
107108 }
108109
109- if ( bounds . y > y )
110+ if ( y < bounds . y )
110111 {
111112 bounds . y = y ;
112113 }
113114
114115 var gw = x + ( glyphW * scale ) ;
115116 var gh = y + ( glyphH * scale ) ;
116117
117- if ( bounds . width < gw )
118+ if ( gw > bounds . width )
118119 {
119- bounds . width = gw - bounds . x ;
120+ bounds . width = gw ;
120121 }
121122
122- if ( bounds . height < gh )
123+ if ( gh > bounds . height )
123124 {
124- bounds . height = gh - bounds . y ;
125+ bounds . height = gh ;
125126 }
126127
127- // console.log('Letter', text[index]);
128+ // console.log('Letter', text[index], 'code', charCode );
128129 // console.log('pos', x, y);
130+ // console.log('prev', prevX, prevY);
129131 // console.log('wh', glyphW, glyphH);
130132 // console.log('scaled', gw, gh);
131- // console.log('bounds', bounds.width, bounds.height);
132-
133- xAdvance += glyph . xAdvance ;
134- indexCount += 1 ;
135- lastGlyph = glyph ;
136- lastCharCode = charCode ;
133+ // console.log('xAdvance', xAdvance);
137134 }
138135
139136 return bounds ;
0 commit comments