mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-10 06:44:44 +00:00
Update itext.class.js
This commit is contained in:
parent
f15b7f5d3c
commit
2f19e25ef2
1 changed files with 23 additions and 62 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue