@@ -9,8 +9,7 @@ var CanvasPool = require('../../dom/CanvasPool');
99*/
1010var MeasureText = function ( textStyle , testString )
1111{
12- if ( testString === undefined ) { testString = '|MÉq' ; }
13- // if (testString === undefined) { testString = 'ABCDEFG'; }
12+ if ( testString === undefined ) { testString = '|MÉqgy' ; }
1413
1514 /**
1615 * @property {HTMLCanvasElement } canvas - The canvas element that the text is rendered.
@@ -22,6 +21,9 @@ var MeasureText = function (textStyle, testString)
2221 */
2322 var context = canvas . getContext ( '2d' ) ;
2423
24+ // DEBUG :)
25+ // document.body.appendChild(canvas);
26+
2527 textStyle . syncFont ( canvas , context ) ;
2628
2729 var width = Math . ceil ( context . measureText ( testString ) . width ) ;
@@ -38,8 +40,7 @@ var MeasureText = function (textStyle, testString)
3840
3941 context . font = textStyle . font ;
4042
41- // context.textBaseline = 'alphabetic';
42- context . textBaseline = 'middle' ;
43+ context . textBaseline = 'alphabetic' ;
4344 context . fillStyle = '#000' ;
4445 context . fillText ( testString , 0 , baseline ) ;
4546
@@ -68,6 +69,9 @@ var MeasureText = function (textStyle, testString)
6869 var idx = 0 ;
6970 var stop = false ;
7071
72+ context . fillStyle = '#00ff00' ;
73+ context . fillRect ( 0 , baseline , width , 1 ) ;
74+
7175 // ascent. scan from top to bottom until we find a non red pixel
7276 for ( i = 0 ; i < baseline ; i ++ )
7377 {
@@ -76,6 +80,8 @@ var MeasureText = function (textStyle, testString)
7680 if ( imagedata [ idx + j ] !== 255 )
7781 {
7882 stop = true ;
83+ context . fillStyle = '#ffff00' ;
84+ context . fillRect ( 0 , i , width , 1 ) ;
7985 break ;
8086 }
8187 }
@@ -103,6 +109,8 @@ var MeasureText = function (textStyle, testString)
103109 if ( imagedata [ idx + j ] !== 255 )
104110 {
105111 stop = true ;
112+ context . fillStyle = '#ffffff' ;
113+ context . fillRect ( 0 , i , width , 1 ) ;
106114 break ;
107115 }
108116 }
@@ -117,11 +125,11 @@ var MeasureText = function (textStyle, testString)
117125 }
118126 }
119127
120- output . descent = ( i - baseline ) + 6 ;
128+ output . descent = ( i - baseline ) ;
121129 output . fontSize = output . ascent + output . descent ;
122130
123- CanvasPool . remove ( canvas ) ;
124-
131+ // DEBUG
132+ // CanvasPool.remove(canvas);
125133 console . log ( output ) ;
126134
127135 return output ;
0 commit comments