From e2576fe512424b530bc89762197f6ad7205fd506 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Wed, 26 Apr 2017 15:34:15 +0100 Subject: [PATCH] Text.padding supported and working. --- v3/src/checksum.js | 2 +- v3/src/gameobjects/text/GetTextSize.js | 11 +++++++++-- v3/src/gameobjects/text/MeasureText.js | 16 ++-------------- v3/src/gameobjects/text/static/Text.js | 6 +++++- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 080b01b28..9c87ea656 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '0f38b2a0-2a25-11e7-8a74-77857ab38da8' +build: 'bbed2b40-2a8c-11e7-9394-818efff01abb' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/gameobjects/text/GetTextSize.js b/v3/src/gameobjects/text/GetTextSize.js index 22942622a..183cca518 100644 --- a/v3/src/gameobjects/text/GetTextSize.js +++ b/v3/src/gameobjects/text/GetTextSize.js @@ -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; diff --git a/v3/src/gameobjects/text/MeasureText.js b/v3/src/gameobjects/text/MeasureText.js index d2076d239..e95cf4d1f 100644 --- a/v3/src/gameobjects/text/MeasureText.js +++ b/v3/src/gameobjects/text/MeasureText.js @@ -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; }; diff --git a/v3/src/gameobjects/text/static/Text.js b/v3/src/gameobjects/text/static/Text.js index f9fd51900..e6d96c638 100644 --- a/v3/src/gameobjects/text/static/Text.js +++ b/v3/src/gameobjects/text/static/Text.js @@ -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;