mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 07:01:20 +00:00
Text.padding supported and working.
This commit is contained in:
parent
3f6c74c1f7
commit
e2576fe512
4 changed files with 17 additions and 18 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '0f38b2a0-2a25-11e7-8a74-77857ab38da8'
|
||||
build: 'bbed2b40-2a8c-11e7-9394-818efff01abb'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -45,13 +45,20 @@ var GetTextSize = function (text, size, lines)
|
|||
lineSpacing = -lineHeight;
|
||||
}
|
||||
|
||||
// // Adjust for line spacing
|
||||
// Adjust for line spacing
|
||||
if (lineSpacing !== 0)
|
||||
{
|
||||
height += (lineSpacing > 0) ? lineSpacing * lines.length : lineSpacing * (lines.length - 1);
|
||||
}
|
||||
|
||||
return { width: maxLineWidth, height: height, lines: drawnLines, lineWidths: lineWidths, lineSpacing: lineSpacing, lineHeight: lineHeight };
|
||||
return {
|
||||
width: maxLineWidth,
|
||||
height: height,
|
||||
lines: drawnLines,
|
||||
lineWidths: lineWidths,
|
||||
lineSpacing: lineSpacing,
|
||||
lineHeight: lineHeight
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = GetTextSize;
|
||||
|
|
|
@ -21,12 +21,9 @@ var MeasureText = function (textStyle, testString)
|
|||
*/
|
||||
var context = canvas.getContext('2d');
|
||||
|
||||
// DEBUG :)
|
||||
// document.body.appendChild(canvas);
|
||||
|
||||
textStyle.syncFont(canvas, context);
|
||||
|
||||
var width = Math.ceil(context.measureText(testString).width);
|
||||
var width = Math.ceil(context.measureText(testString).width * 1.2);
|
||||
var baseline = width;
|
||||
var height = 2 * baseline;
|
||||
|
||||
|
@ -69,9 +66,6 @@ var MeasureText = function (textStyle, testString)
|
|||
var idx = 0;
|
||||
var stop = false;
|
||||
|
||||
context.fillStyle = '#00ff00';
|
||||
context.fillRect(0, baseline, width, 1);
|
||||
|
||||
// ascent. scan from top to bottom until we find a non red pixel
|
||||
for (i = 0; i < baseline; i++)
|
||||
{
|
||||
|
@ -80,8 +74,6 @@ var MeasureText = function (textStyle, testString)
|
|||
if (imagedata[idx + j] !== 255)
|
||||
{
|
||||
stop = true;
|
||||
context.fillStyle = '#ffff00';
|
||||
context.fillRect(0, i, width, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -109,8 +101,6 @@ var MeasureText = function (textStyle, testString)
|
|||
if (imagedata[idx + j] !== 255)
|
||||
{
|
||||
stop = true;
|
||||
context.fillStyle = '#ffffff';
|
||||
context.fillRect(0, i, width, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -128,9 +118,7 @@ var MeasureText = function (textStyle, testString)
|
|||
output.descent = (i - baseline);
|
||||
output.fontSize = output.ascent + output.descent;
|
||||
|
||||
// DEBUG
|
||||
// CanvasPool.remove(canvas);
|
||||
console.log(output);
|
||||
CanvasPool.remove(canvas);
|
||||
|
||||
return output;
|
||||
};
|
||||
|
|
|
@ -63,7 +63,11 @@ var Text = new Class({
|
|||
|
||||
this.resolution = 1;
|
||||
|
||||
// Move to TextStyle?
|
||||
/**
|
||||
* Specify a padding value which is added to the line width and height when calculating the Text size.
|
||||
* Allows you to add extra spacing if Phaser is unable to accurately determine the true font dimensions.
|
||||
* @property {Phaser.Point} padding
|
||||
*/
|
||||
this.padding = { x: 0, y: 0 };
|
||||
|
||||
this.width = 1;
|
||||
|
|
Loading…
Reference in a new issue