Skip to content

Commit e2576fe

Browse files
committed
Text.padding supported and working.
1 parent 3f6c74c commit e2576fe

4 files changed

Lines changed: 17 additions & 18 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: '0f38b2a0-2a25-11e7-8a74-77857ab38da8'
2+
build: 'bbed2b40-2a8c-11e7-9394-818efff01abb'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/text/GetTextSize.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,20 @@ var GetTextSize = function (text, size, lines)
4545
lineSpacing = -lineHeight;
4646
}
4747

48-
// // Adjust for line spacing
48+
// Adjust for line spacing
4949
if (lineSpacing !== 0)
5050
{
5151
height += (lineSpacing > 0) ? lineSpacing * lines.length : lineSpacing * (lines.length - 1);
5252
}
5353

54-
return { width: maxLineWidth, height: height, lines: drawnLines, lineWidths: lineWidths, lineSpacing: lineSpacing, lineHeight: lineHeight };
54+
return {
55+
width: maxLineWidth,
56+
height: height,
57+
lines: drawnLines,
58+
lineWidths: lineWidths,
59+
lineSpacing: lineSpacing,
60+
lineHeight: lineHeight
61+
};
5562
};
5663

5764
module.exports = GetTextSize;

v3/src/gameobjects/text/MeasureText.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ var MeasureText = function (textStyle, testString)
2121
*/
2222
var context = canvas.getContext('2d');
2323

24-
// DEBUG :)
25-
// document.body.appendChild(canvas);
26-
2724
textStyle.syncFont(canvas, context);
2825

29-
var width = Math.ceil(context.measureText(testString).width);
26+
var width = Math.ceil(context.measureText(testString).width * 1.2);
3027
var baseline = width;
3128
var height = 2 * baseline;
3229

@@ -69,9 +66,6 @@ var MeasureText = function (textStyle, testString)
6966
var idx = 0;
7067
var stop = false;
7168

72-
context.fillStyle = '#00ff00';
73-
context.fillRect(0, baseline, width, 1);
74-
7569
// ascent. scan from top to bottom until we find a non red pixel
7670
for (i = 0; i < baseline; i++)
7771
{
@@ -80,8 +74,6 @@ var MeasureText = function (textStyle, testString)
8074
if (imagedata[idx + j] !== 255)
8175
{
8276
stop = true;
83-
context.fillStyle = '#ffff00';
84-
context.fillRect(0, i, width, 1);
8577
break;
8678
}
8779
}
@@ -109,8 +101,6 @@ var MeasureText = function (textStyle, testString)
109101
if (imagedata[idx + j] !== 255)
110102
{
111103
stop = true;
112-
context.fillStyle = '#ffffff';
113-
context.fillRect(0, i, width, 1);
114104
break;
115105
}
116106
}
@@ -128,9 +118,7 @@ var MeasureText = function (textStyle, testString)
128118
output.descent = (i - baseline);
129119
output.fontSize = output.ascent + output.descent;
130120

131-
// DEBUG
132-
// CanvasPool.remove(canvas);
133-
console.log(output);
121+
CanvasPool.remove(canvas);
134122

135123
return output;
136124
};

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ var Text = new Class({
6363

6464
this.resolution = 1;
6565

66-
// Move to TextStyle?
66+
/**
67+
* Specify a padding value which is added to the line width and height when calculating the Text size.
68+
* Allows you to add extra spacing if Phaser is unable to accurately determine the true font dimensions.
69+
* @property {Phaser.Point} padding
70+
*/
6771
this.padding = { x: 0, y: 0 };
6872

6973
this.width = 1;

0 commit comments

Comments
 (0)