diff --git a/cocos2d/core/renderer/utils/label/ttf.js b/cocos2d/core/renderer/utils/label/ttf.js index 70ced076d2..e52ba79304 100644 --- a/cocos2d/core/renderer/utils/label/ttf.js +++ b/cocos2d/core/renderer/utils/label/ttf.js @@ -417,7 +417,7 @@ module.exports = { _measureText (ctx) { return function (string) { - return TextUtils.measureText(ctx, string); + return TextUtils.safeMeasureText(ctx, string); }; }, diff --git a/cocos2d/core/utils/text-utils.js b/cocos2d/core/utils/text-utils.js index 4be864606b..9dbdd1cdaa 100644 --- a/cocos2d/core/utils/text-utils.js +++ b/cocos2d/core/utils/text-utils.js @@ -227,7 +227,7 @@ var TextUtils = { return ((ch >= 9 && ch <= 13) || ch === 32 || ch === 133 || ch === 160 || ch === 5760 || (ch >= 8192 && ch <= 8202) || ch === 8232 || ch === 8233 || ch === 8239 || ch === 8287 || ch === 12288); }, - safeMeasureText = function (ctx, string) { + safeMeasureText: function (ctx, string) { var metric = ctx.measureText(string); return metric && metric.width || 0; },