mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-03-27 19:20:25 +00:00
fix for lineheight and text selection (#3094)
This commit is contained in:
parent
98f2d1b3dd
commit
6e1d2e2fd2
5 changed files with 34 additions and 18 deletions
18
dist/fabric.js
vendored
18
dist/fabric.js
vendored
|
|
@ -3542,7 +3542,8 @@ if (typeof console !== 'undefined') {
|
|||
|
||||
function hasAncestorWithNodeName(element, nodeName) {
|
||||
while (element && (element = element.parentNode)) {
|
||||
if (element.nodeName && nodeName.test(element.nodeName.replace('svg:', '')) && !element.getAttribute('instantiated_by_use')) {
|
||||
if (element.nodeName && nodeName.test(element.nodeName.replace('svg:', ''))
|
||||
&& !element.getAttribute('instantiated_by_use')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -22006,7 +22007,7 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
for (var i = startLine; i <= endLine; i++) {
|
||||
var lineOffset = this._getLineLeftOffset(this._getLineWidth(ctx, i)) || 0,
|
||||
lineHeight = this._getHeightOfLine(this.ctx, i),
|
||||
boxWidth = 0, line = this._textLines[i];
|
||||
realLineHeight = 0, boxWidth = 0, line = this._textLines[i];
|
||||
|
||||
if (i === startLine) {
|
||||
for (var j = 0, len = line.length; j < len; j++) {
|
||||
|
|
@ -22026,13 +22027,17 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
boxWidth += this._getWidthOfChar(ctx, line[j2], i, j2);
|
||||
}
|
||||
}
|
||||
realLineHeight = lineHeight;
|
||||
if (this.lineHeight < 1 || (i === endLine && this.lineHeight > 1)) {
|
||||
lineHeight /= this.lineHeight;
|
||||
}
|
||||
ctx.fillRect(
|
||||
boundaries.left + lineOffset,
|
||||
boundaries.top + boundaries.topOffset,
|
||||
boxWidth,
|
||||
lineHeight);
|
||||
|
||||
boundaries.topOffset += lineHeight;
|
||||
boundaries.topOffset += realLineHeight;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -22552,9 +22557,10 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
* @param {CanvasRenderingContext2D} ctx Context to render on
|
||||
*/
|
||||
_getTextHeight: function(ctx) {
|
||||
var height = this._getHeightOfLine(ctx, 0) / this.lineHeight;
|
||||
for (var i = 1, len = this._textLines.length; i < len; i++) {
|
||||
height += this._getHeightOfLine(ctx, i);
|
||||
var lineHeight, height = 0;
|
||||
for (var i = 0, len = this._textLines.length; i < len; i++) {
|
||||
lineHeight = this._getHeightOfLine(ctx, i);
|
||||
height += (i === len - 1 ? lineHeight / this.lineHeight : lineHeight);
|
||||
}
|
||||
return height;
|
||||
},
|
||||
|
|
|
|||
4
dist/fabric.min.js
vendored
4
dist/fabric.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/fabric.min.js.gz
vendored
BIN
dist/fabric.min.js.gz
vendored
Binary file not shown.
15
dist/fabric.require.js
vendored
15
dist/fabric.require.js
vendored
|
|
@ -10298,7 +10298,7 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass({
|
|||
ctx.fillStyle = this.selectionColor;
|
||||
var start = this.get2DCursorLocation(this.selectionStart), end = this.get2DCursorLocation(this.selectionEnd), startLine = start.lineIndex, endLine = end.lineIndex;
|
||||
for (var i = startLine; i <= endLine; i++) {
|
||||
var lineOffset = this._getLineLeftOffset(this._getLineWidth(ctx, i)) || 0, lineHeight = this._getHeightOfLine(this.ctx, i), boxWidth = 0, line = this._textLines[i];
|
||||
var lineOffset = this._getLineLeftOffset(this._getLineWidth(ctx, i)) || 0, lineHeight = this._getHeightOfLine(this.ctx, i), realLineHeight = 0, boxWidth = 0, line = this._textLines[i];
|
||||
if (i === startLine) {
|
||||
for (var j = 0, len = line.length; j < len; j++) {
|
||||
if (j >= start.charIndex && (i !== endLine || j < end.charIndex)) {
|
||||
|
|
@ -10315,8 +10315,12 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass({
|
|||
boxWidth += this._getWidthOfChar(ctx, line[j2], i, j2);
|
||||
}
|
||||
}
|
||||
realLineHeight = lineHeight;
|
||||
if (this.lineHeight < 1 || i === endLine && this.lineHeight > 1) {
|
||||
lineHeight /= this.lineHeight;
|
||||
}
|
||||
ctx.fillRect(boundaries.left + lineOffset, boundaries.top + boundaries.topOffset, boxWidth, lineHeight);
|
||||
boundaries.topOffset += lineHeight;
|
||||
boundaries.topOffset += realLineHeight;
|
||||
}
|
||||
},
|
||||
_renderChars: function(method, ctx, line, left, top, lineIndex, charOffset) {
|
||||
|
|
@ -10575,9 +10579,10 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass({
|
|||
return this.__lineHeights[lineIndex];
|
||||
},
|
||||
_getTextHeight: function(ctx) {
|
||||
var height = this._getHeightOfLine(ctx, 0) / this.lineHeight;
|
||||
for (var i = 1, len = this._textLines.length; i < len; i++) {
|
||||
height += this._getHeightOfLine(ctx, i);
|
||||
var lineHeight, height = 0;
|
||||
for (var i = 0, len = this._textLines.length; i < len; i++) {
|
||||
lineHeight = this._getHeightOfLine(ctx, i);
|
||||
height += i === len - 1 ? lineHeight / this.lineHeight : lineHeight;
|
||||
}
|
||||
return height;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -522,7 +522,7 @@
|
|||
for (var i = startLine; i <= endLine; i++) {
|
||||
var lineOffset = this._getLineLeftOffset(this._getLineWidth(ctx, i)) || 0,
|
||||
lineHeight = this._getHeightOfLine(this.ctx, i),
|
||||
boxWidth = 0, line = this._textLines[i];
|
||||
realLineHeight = 0, boxWidth = 0, line = this._textLines[i];
|
||||
|
||||
if (i === startLine) {
|
||||
for (var j = 0, len = line.length; j < len; j++) {
|
||||
|
|
@ -542,13 +542,17 @@
|
|||
boxWidth += this._getWidthOfChar(ctx, line[j2], i, j2);
|
||||
}
|
||||
}
|
||||
realLineHeight = lineHeight;
|
||||
if (this.lineHeight < 1 || (i === endLine && this.lineHeight > 1)) {
|
||||
lineHeight /= this.lineHeight;
|
||||
}
|
||||
ctx.fillRect(
|
||||
boundaries.left + lineOffset,
|
||||
boundaries.top + boundaries.topOffset,
|
||||
boxWidth,
|
||||
lineHeight);
|
||||
|
||||
boundaries.topOffset += lineHeight;
|
||||
boundaries.topOffset += realLineHeight;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -1068,9 +1072,10 @@
|
|||
* @param {CanvasRenderingContext2D} ctx Context to render on
|
||||
*/
|
||||
_getTextHeight: function(ctx) {
|
||||
var height = this._getHeightOfLine(ctx, 0) / this.lineHeight;
|
||||
for (var i = 1, len = this._textLines.length; i < len; i++) {
|
||||
height += this._getHeightOfLine(ctx, i);
|
||||
var lineHeight, height = 0;
|
||||
for (var i = 0, len = this._textLines.length; i < len; i++) {
|
||||
lineHeight = this._getHeightOfLine(ctx, i);
|
||||
height += (i === len - 1 ? lineHeight / this.lineHeight : lineHeight);
|
||||
}
|
||||
return height;
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue