Skip to content

Commit 3f6c74c

Browse files
committed
More work on Text Metrics.
1 parent 4073db3 commit 3f6c74c

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '82df6ea0-29e5-11e7-b20f-b54acd53d89d'
2+
build: '0f38b2a0-2a25-11e7-8a74-77857ab38da8'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/text/MeasureText.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ var CanvasPool = require('../../dom/CanvasPool');
99
*/
1010
var 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;

v3/src/gameobjects/text/static/Text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ var Text = new Class({
221221

222222
style.syncFont(canvas, context);
223223

224-
context.textBaseline = 'middle';
224+
context.textBaseline = 'alphabetic';
225225

226226
// Apply padding
227227
context.translate(padding.x, padding.y);

0 commit comments

Comments
 (0)