From aa0d9be86168634663ace435e72333a25f3a8ddd Mon Sep 17 00:00:00 2001 From: arbassic Date: Mon, 5 Dec 2022 22:10:45 +0100 Subject: [PATCH] Add lineSpacing property to BitmapText --- .../bitmaptext/GetBitmapTextSize.js | 5 +- .../bitmaptext/static/BitmapText.js | 60 +++++++++++++++++++ .../static/BitmapTextCanvasRenderer.js | 4 +- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/gameobjects/bitmaptext/GetBitmapTextSize.js b/src/gameobjects/bitmaptext/GetBitmapTextSize.js index 040ebc352..b36ecc4d9 100644 --- a/src/gameobjects/bitmaptext/GetBitmapTextSize.js +++ b/src/gameobjects/bitmaptext/GetBitmapTextSize.js @@ -73,6 +73,7 @@ var GetBitmapTextSize = function (src, round, updateOrigin, out) var chars = src.fontData.chars; var lineHeight = src.fontData.lineHeight; var letterSpacing = src.letterSpacing; + var lineSpacing = src.lineSpacing; var xAdvance = 0; var yAdvance = 0; @@ -128,7 +129,7 @@ var GetBitmapTextSize = function (src, round, updateOrigin, out) } xAdvance = 0; - yAdvance += lineHeight; + yAdvance += lineHeight + lineSpacing; lastGlyph = null; continue; @@ -291,7 +292,7 @@ var GetBitmapTextSize = function (src, round, updateOrigin, out) } xAdvance = 0; - yAdvance += lineHeight; + yAdvance += lineHeight + lineSpacing; lastGlyph = null; lineWidths[currentLine] = currentLineWidth; diff --git a/src/gameobjects/bitmaptext/static/BitmapText.js b/src/gameobjects/bitmaptext/static/BitmapText.js index 2b0519b7a..55cbbc9c0 100644 --- a/src/gameobjects/bitmaptext/static/BitmapText.js +++ b/src/gameobjects/bitmaptext/static/BitmapText.js @@ -153,6 +153,18 @@ var BitmapText = new Class({ */ this._letterSpacing = 0; + /** + * Adds / Removes spacing lines in a multiline BitmapText object. + * + * Can be a negative or positive number. + * + * @name Phaser.GameObjects.BitmapText#_lineSpacing + * @type {number} + * @private + * @since 3.60.0 + */ + this._lineSpacing = 0; + /** * Controls the alignment of each line of text in this BitmapText object. * Only has any effect when this BitmapText contains multiple lines of text, split with carriage-returns. @@ -381,6 +393,28 @@ var BitmapText = new Class({ return this; }, + + /** + * The line spacing value. + * This value is added to the font height to calculate the overall line height. + * Only has an effect if this Text object contains multiple lines of text. + * + * + * @name Phaser.GameObjects.Text#lineSpacing + * @type {number} + * @since 3.60.0 + */ + setLineSpacing: function (spacing) + { + if (spacing === undefined) { spacing = 0; } + + this._lineSpacing = spacing; + + this._dirty = true; + + return this; + }, + /** * Set the textual content of this BitmapText. * @@ -922,6 +956,32 @@ var BitmapText = new Class({ }, + /** + * Adds / Removes spacing between lines. + * + * Can be a negative or positive number. + * + * You can also use the method `setLineSpacing` if you want a chainable way to change the line spacing. + * + * @name Phaser.GameObjects.BitmapText#lineSpacing + * @type {number} + * @since 3.60.0 + */ + lineSpacing: { + + set: function (value) + { + this._lineSpacing = value; + this._dirty = true; + }, + + get: function () + { + return this._lineSpacing; + } + + }, + /** * The maximum display width of this BitmapText in pixels. * diff --git a/src/gameobjects/bitmaptext/static/BitmapTextCanvasRenderer.js b/src/gameobjects/bitmaptext/static/BitmapTextCanvasRenderer.js index f9ba50939..4fa1800c3 100644 --- a/src/gameobjects/bitmaptext/static/BitmapTextCanvasRenderer.js +++ b/src/gameobjects/bitmaptext/static/BitmapTextCanvasRenderer.js @@ -41,6 +41,7 @@ var BitmapTextCanvasRenderer = function (renderer, src, camera, parentMatrix) var chars = src.fontData.chars; var lineHeight = src.fontData.lineHeight; var letterSpacing = src._letterSpacing; + var lineSpacing = src._lineSpacing; var xAdvance = 0; var yAdvance = 0; @@ -113,7 +114,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, camera, parentMatrix) } xAdvance = 0; - yAdvance += lineHeight; + yAdvance += lineHeight + lineSpacing; + lastGlyph = null; continue;