From 5dbbcdb6822d101eb970d1622de2e447b42e8a9a Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 5 Sep 2016 20:01:32 +0200 Subject: [PATCH] Update itext.class.js --- src/shapes/itext.class.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/shapes/itext.class.js b/src/shapes/itext.class.js index eb95a70b..486c1eb8 100644 --- a/src/shapes/itext.class.js +++ b/src/shapes/itext.class.js @@ -490,7 +490,7 @@ } boundaries = { top: topOffset, - left: leftOffset, + left: leftOffset > 0 ? leftOffset : 0, lineLeft: lineLeftOffset }; this.cursorOffsetCache = boundaries; @@ -574,7 +574,7 @@ ctx.fillRect( boundaries.left + lineOffset, boundaries.top + boundaries.topOffset, - boxWidth, + boxWidth > 0 ? boxWidth : 0, lineHeight); boundaries.topOffset += realLineHeight; @@ -653,7 +653,7 @@ _renderChar: function(method, ctx, lineIndex, i, _char, left, top, lineHeight) { var charWidth, charHeight, shouldFill, shouldStroke, decl = this._getStyleDeclaration(lineIndex, i), - offset, textDecoration, chars; + offset, textDecoration, chars, additionalSpace, _charWidth; if (decl) { charHeight = this._getHeightOfChar(ctx, _char, lineIndex, i); @@ -677,13 +677,15 @@ this._removeShadow(ctx); } if (this.charSpacing !== 0) { + additionalSpace = this._getWidthOfCharSpacing(); chars = _char.split(''); charWidth = 0; for (var j = 0, len = chars.length, char; j < len; j++) { char = chars[j]; shouldFill && ctx.fillText(char, left + charWidth, top); shouldStroke && ctx.strokeText(char, left + charWidth, top); - charWidth += ctx.measureText(char).width + this._getWidthOfCharSpacing(); + _charWidth = ctx.measureText(char).width + additionalSpace; + charWidth += _charWidth > 0 ? _charWidth : 0; } } else { @@ -992,7 +994,7 @@ width += this._getWidthOfCharSpacing(); } ctx.restore(); - return width < 0 ? 0 : width; + return width > 0 ? width : 0 }, /** @@ -1034,7 +1036,7 @@ width -= this._getWidthOfCharSpacing(); } this._isMeasuring = false; - return width; + return width > 0 ? width : 0; }, /**