diff --git a/src/core/text/Text.js b/src/core/text/Text.js index e4c603c..314b0b4 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -319,9 +319,12 @@ { const trimmed = trimCanvas(canvas); - canvas.width = trimmed.width; - canvas.height = trimmed.height; - this.context.putImageData(trimmed.data, 0, 0); + if (trimmed.data) + { + canvas.width = trimmed.width; + canvas.height = trimmed.height; + this.context.putImageData(trimmed.data, 0, 0); + } } const texture = this._texture; diff --git a/src/core/text/Text.js b/src/core/text/Text.js index e4c603c..314b0b4 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -319,9 +319,12 @@ { const trimmed = trimCanvas(canvas); - canvas.width = trimmed.width; - canvas.height = trimmed.height; - this.context.putImageData(trimmed.data, 0, 0); + if (trimmed.data) + { + canvas.width = trimmed.width; + canvas.height = trimmed.height; + this.context.putImageData(trimmed.data, 0, 0); + } } const texture = this._texture; diff --git a/src/core/utils/trimCanvas.js b/src/core/utils/trimCanvas.js index 5af6de0..596b17e 100644 --- a/src/core/utils/trimCanvas.js +++ b/src/core/utils/trimCanvas.js @@ -25,6 +25,7 @@ right: null, bottom: null, }; + let data = null; let i; let x; let y; @@ -70,10 +71,12 @@ } } - width = bound.right - bound.left; - height = bound.bottom - bound.top + 1; - - const data = context.getImageData(bound.left, bound.top, width, height); + if (bound.top !== null) + { + width = bound.right - bound.left; + height = bound.bottom - bound.top + 1; + data = context.getImageData(bound.left, bound.top, width, height); + } return { height, diff --git a/src/core/text/Text.js b/src/core/text/Text.js index e4c603c..314b0b4 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -319,9 +319,12 @@ { const trimmed = trimCanvas(canvas); - canvas.width = trimmed.width; - canvas.height = trimmed.height; - this.context.putImageData(trimmed.data, 0, 0); + if (trimmed.data) + { + canvas.width = trimmed.width; + canvas.height = trimmed.height; + this.context.putImageData(trimmed.data, 0, 0); + } } const texture = this._texture; diff --git a/src/core/utils/trimCanvas.js b/src/core/utils/trimCanvas.js index 5af6de0..596b17e 100644 --- a/src/core/utils/trimCanvas.js +++ b/src/core/utils/trimCanvas.js @@ -25,6 +25,7 @@ right: null, bottom: null, }; + let data = null; let i; let x; let y; @@ -70,10 +71,12 @@ } } - width = bound.right - bound.left; - height = bound.bottom - bound.top + 1; - - const data = context.getImageData(bound.left, bound.top, width, height); + if (bound.top !== null) + { + width = bound.right - bound.left; + height = bound.bottom - bound.top + 1; + data = context.getImageData(bound.left, bound.top, width, height); + } return { height, diff --git a/test/core/Text.js b/test/core/Text.js index 07b47fe..cf909ab 100644 --- a/test/core/Text.js +++ b/test/core/Text.js @@ -109,6 +109,13 @@ expect(text.text).to.equal(' '); }); + it('should trim an empty string', function () + { + const text = new PIXI.Text('', { trim: true }); + + expect(text.text).to.equal(' '); + }); + it('should prevent setting \'\'', function () { const text = new PIXI.Text('');