Update itext.class.js

This commit is contained in:
Andrea Bogazzi 2016-02-25 02:48:20 +01:00
parent f15b7f5d3c
commit 2f19e25ef2

View file

@ -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