From dc703aa96bce68cb6f1de4cf9197948014516116 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 15 Aug 2017 18:15:38 +0800 Subject: [PATCH] Repair outline bug for fireball/issues/6254 and fireball/issues/6258 --- jsb/jsb-label.js | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/jsb/jsb-label.js b/jsb/jsb-label.js index c5fe42b5c5..f59df1ef41 100644 --- a/jsb/jsb-label.js +++ b/jsb/jsb-label.js @@ -60,7 +60,7 @@ jsbLabel.prototype.getOverflow = function() { jsbLabel.prototype._enableBold = jsbLabel.prototype.enableBold; jsbLabel.prototype.enableBold = function(enabled) { - if(enabled) { + if (enabled) { this._enableBold(); } else { this.disableEffect(5); @@ -69,7 +69,7 @@ jsbLabel.prototype.enableBold = function(enabled) { jsbLabel.prototype._enableItalics = jsbLabel.prototype.enableItalics; jsbLabel.prototype.enableItalics = function(enabled) { - if(enabled) { + if (enabled) { this._enableItalics(); } else { this.disableEffect(4); @@ -78,7 +78,7 @@ jsbLabel.prototype.enableItalics = function(enabled) { jsbLabel.prototype._enableUnderline = jsbLabel.prototype.enableUnderline; jsbLabel.prototype.enableUnderline = function(enabled) { - if(enabled) { + if (enabled) { this._enableUnderline(); } else { this.disableEffect(6); @@ -117,7 +117,7 @@ jsbLabel.prototype.setLineHeight = function (height) { jsbLabel.prototype._setColor = jsbLabel.prototype.setColor; jsbLabel.prototype.setColor = function(color) { - if(this._labelType === _ccsg.Label.Type.BMFont) { + if (this._labelType === _ccsg.Label.Type.BMFont) { this._setColor(color); } else { this.setTextColor(color); @@ -141,7 +141,7 @@ jsbLabel.prototype.setContentSize = function (size, height) { var newWidth = (typeof size.width === 'number') ? size.width : size; var newHeight = (typeof size.height === 'number') ? size.height : height; - if(this.getOverflow() === cc.Label.Overflow.NONE) { + if (this.getOverflow() === cc.Label.Overflow.NONE) { newWidth = 0; newHeight = 0; } else { @@ -161,18 +161,22 @@ jsbLabel.prototype.setFontAsset = function (fontAsset) { var extName = cc.path.extname(fontHandle); if (extName === '.ttf') { - if(!this._ttfConfig) { + var outlineWidth = this.isOutlined() ? this.getOutlineWidth() : 0; + if (!this._ttfConfig) { this._ttfConfig = { fontFilePath: fontHandle, fontSize: this._fontSize, - outlineSize: 0, + outlineSize: outlineWidth, glyphs: 0, customGlyphs: "", distanceFieldEnable: false }; } + else { + this._ttfConfig.outlineSize = outlineWidth; + this._ttfConfig.fontFilePath = fontHandle; + } this._labelType = _ccsg.Label.Type.TTF; - this._ttfConfig.fontFilePath = fontHandle; this.setTTFConfig(this._ttfConfig); } else if (fontAsset.spriteFrame) { this._labelType = _ccsg.Label.Type.BMFont; @@ -194,7 +198,7 @@ jsbLabel.prototype.setFontFamily = function (fontFamily) { jsbLabel.prototype.setOutlined = function(value) { this._outlined = !!value; - if(this._outlined) { + if (this._outlined) { this.enableOutline(this.getOutlineColor(), this.getOutlineWidth()); } else { //1 equals cpp outline effect @@ -204,14 +208,24 @@ jsbLabel.prototype.setOutlined = function(value) { jsbLabel.prototype.setOutlineWidth = function(value) { this._outlineWidth = value; - if(this._outlined) { - this.enableOutline(this.getOutlineColor(), this.getOutlineWidth()); + if (this._outlined) { + var outlineWidth = this.getOutlineWidth(); + if (this._labelType === _ccsg.Label.Type.TTF) { + var ttfConfig = this.getTTFConfig(); + if (ttfConfig.outlineSize !== outlineWidth) { + ttfConfig.outlineSize = outlineWidth; + this.setTTFConfig(ttfConfig); + } + } + else { + this.enableOutline(this.getOutlineColor(), outlineWidth); + } } }; jsbLabel.prototype.setOutlineColor = function(value) { this._outlineColor = cc.color(value); - if(this._outlined) { + if (this._outlined) { this.enableOutline(this.getOutlineColor(), this.getOutlineWidth()); } };