Skip to content

Commit

Permalink
try remove the ie11 fix (#4772)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur committed Mar 1, 2018
1 parent aa9b8a6 commit d0a4ecb
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/shapes/text.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
'use strict';

var fabric = global.fabric || (global.fabric = { }),
clone = fabric.util.object.clone,
MIN_TEXT_WIDTH = 2,
CACHE_FONT_SIZE = 200;
clone = fabric.util.object.clone;

if (fabric.Text) {
fabric.warn('fabric.Text is already defined');
Expand Down Expand Up @@ -296,6 +294,22 @@
*/
__charBounds: [],

/**
* use this size when measuring text. To avoid IE11 rounding errors
* @type {Number}
* @default
* @readonly
* @private
*/
CACHE_FONT_SIZE: 400,

/**
* contains the min text width to avoid getting 0
* @type {Number}
* @default
*/
MIN_TEXT_WIDTH: 2,

/**
* Constructor
* @param {String} text Text string
Expand Down Expand Up @@ -353,7 +367,7 @@
}
this._splitText();
this._clearCache();
this.width = this.calcTextWidth() || this.cursorWidth || MIN_TEXT_WIDTH;
this.width = this.calcTextWidth() || this.cursorWidth || this.MIN_TEXT_WIDTH;
if (this.textAlign.indexOf('justify') !== -1) {
// once text is measured we need to make space fatter to make justified text.
this.enlargeSpaces();
Expand Down Expand Up @@ -619,7 +633,7 @@
var fontCache = this.getFontCache(charStyle), fontDeclaration = this._getFontDeclaration(charStyle),
previousFontDeclaration = this._getFontDeclaration(prevCharStyle), couple = previousChar + _char,
stylesAreEqual = fontDeclaration === previousFontDeclaration, width, coupleWidth, previousWidth,
fontMultiplier = charStyle.fontSize / CACHE_FONT_SIZE, kernedWidth;
fontMultiplier = charStyle.fontSize / this.CACHE_FONT_SIZE, kernedWidth;

if (previousChar && fontCache[previousChar]) {
previousWidth = fontCache[previousChar];
Expand Down Expand Up @@ -649,13 +663,6 @@
coupleWidth = ctx.measureText(couple).width;
fontCache[couple] = coupleWidth;
kernedWidth = coupleWidth - previousWidth;
// try to fix a MS browsers oddity
if (kernedWidth > width) {
var diff = kernedWidth - width;
fontCache[_char] = kernedWidth;
fontCache[couple] += diff;
width = kernedWidth;
}
}
return { width: width * fontMultiplier, kernedWidth: kernedWidth * fontMultiplier };
},
Expand Down Expand Up @@ -1210,7 +1217,7 @@
// node-canvas needs "weight style", while browsers need "style weight"
(fabric.isLikelyNode ? style.fontWeight : style.fontStyle),
(fabric.isLikelyNode ? style.fontStyle : style.fontWeight),
forMeasuring ? CACHE_FONT_SIZE + 'px' : style.fontSize + 'px',
forMeasuring ? this.CACHE_FONT_SIZE + 'px' : style.fontSize + 'px',
(fabric.isLikelyNode ? ('"' + style.fontFamily + '"') : style.fontFamily)
].join(' ');
},
Expand Down

0 comments on commit d0a4ecb

Please sign in to comment.