From 2f19e25ef28f49b66b521049d3d44a45e5a715f1 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Thu, 25 Feb 2016 02:48:20 +0100 Subject: [PATCH] Update itext.class.js --- src/shapes/itext.class.js | 85 +++++++++++---------------------------- 1 file changed, 23 insertions(+), 62 deletions(-) diff --git a/src/shapes/itext.class.js b/src/shapes/itext.class.js index b7c0ceb7..583f8281 100644 --- a/src/shapes/itext.class.js +++ b/src/shapes/itext.class.js @@ -743,60 +743,43 @@ * @param {CanvasRenderingContext2D} ctx Context to render on */ _renderTextLinesBackground: function(ctx) { - if (!this.textBackgroundColor && !this.styles) { - return; - } + this.callSuper('_renderTextLinesBackground', ctx); - ctx.save(); - - if (this.textBackgroundColor) { - ctx.fillStyle = this.textBackgroundColor; - } - - var lineHeights = 0; + var lineTopOffset = 0, heightOfLine, + lineWidth, lineLeftOffset, + leftOffset = this._getLeftOffset(), + topOffset = this._getTopOffset(), + line, _char, style; for (var i = 0, len = this._textLines.length; i < len; i++) { + heightOfLine = this._getHeightOfLine(ctx, i); + line = this._textLines[i]; - var heightOfLine = this._getHeightOfLine(ctx, i); - if (this._textLines[i] === '') { - lineHeights += heightOfLine; + if (line === '' || !this.styles || !this._getLineStyle(i)) { + lineTopOffset += heightOfLine; continue; } - var lineWidth = this._getLineWidth(ctx, i), - lineLeftOffset = this._getLineLeftOffset(lineWidth); + lineWidth = this._getLineWidth(ctx, i); + lineLeftOffset = this._getLineLeftOffset(lineWidth); - if (this.textBackgroundColor) { - ctx.fillStyle = this.textBackgroundColor; + for (var j = 0, jlen = line.length; j < jlen; j++) { + style = this._getStyleDeclaration(i, j); + if (!style || !style.textBackgroundColor) { + continue; + } + _char = line[j]; + + ctx.fillStyle = style.textBackgroundColor; ctx.fillRect( - this._getLeftOffset() + lineLeftOffset, - this._getTopOffset() + lineHeights, - lineWidth, + leftOffset + lineLeftOffset + this._getWidthOfCharsAt(ctx, i, j), + topOffset + lineTopOffset, + this._getWidthOfChar(ctx, _char, i, j) + 1, heightOfLine / this.lineHeight ); } - if (this._getLineStyle(i)) { - for (var j = 0, jlen = this._textLines[i].length; j < jlen; j++) { - var style = this._getStyleDeclaration(i, j); - if (style && style.textBackgroundColor) { - - var _char = this._textLines[i][j]; - - ctx.fillStyle = style.textBackgroundColor; - - ctx.fillRect( - this._getLeftOffset() + lineLeftOffset + this._getWidthOfCharsAt(ctx, i, j), - this._getTopOffset() + lineHeights, - this._getWidthOfChar(ctx, _char, i, j) + 1, - heightOfLine / this.lineHeight - ); - } - } - } - lineHeights += heightOfLine; } - ctx.restore(); }, /** @@ -1070,28 +1053,6 @@ return height; }, - /** - * This method is overwritten to account for different top offset - * @private - */ - _renderTextBoxBackground: function(ctx) { - if (!this.backgroundColor) { - return; - } - - ctx.save(); - ctx.fillStyle = this.backgroundColor; - - ctx.fillRect( - this._getLeftOffset(), - this._getTopOffset(), - this.width, - this.height - ); - - ctx.restore(); - }, - /** * Returns object representation of an instance * @method toObject