From 306a61707a04b01accc682fcb4639408dcd275ad Mon Sep 17 00:00:00 2001 From: ViusualSJ Date: Fri, 20 May 2016 15:28:51 +0800 Subject: [PATCH] remove useSystemFont from CCGLabel --- cocos2d/core/components/CCLabel.js | 15 +++++++++------ cocos2d/core/label/CCSGLabel.js | 14 -------------- jsb/jsb-label.js | 12 ------------ 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index 0f2cc81b1a..47c38be379 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -245,7 +245,7 @@ var Label = cc.Class({ set: function (value) { this._N$file = value; this._bmFontOriginalSize = -1; - if (this._sgNode) { + if (this._sgNode && !this._isSystemFontUsed) { if ( typeof value === 'string' ) { cc.warn('Sorry, the cc.Font has been modified from Raw Asset to Asset.' + @@ -276,18 +276,21 @@ var Label = cc.Class({ */ useSystemFont: { get: function(){ - if (this._sgNode) { - this._isSystemFontUsed = this._sgNode.isSystemFontUsed(); - } return this._isSystemFontUsed; }, set: function(value){ - this._isSystemFontUsed = value; + this._isSystemFontUsed = !!value; if (value) { this.font = null; if (this._sgNode) { - this._sgNode.setSystemFontUsed(value); + this._sgNode.setFontFileOrFamily('Arial'); } + } else { + value = this._N$file; + var isAsset = value instanceof cc.Font; + var fntRawUrl = isAsset ? value.rawUrl : ''; + var textureUrl = isAsset ? value.texture : ''; + this._sgNode.setFontFileOrFamily(fntRawUrl, textureUrl); } }, diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 4fb05e9f3b..78c4a8a6ff 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -115,7 +115,6 @@ _ccsg.Label = _ccsg.Node.extend({ _spacingX: 0, _blendFunc: null, - _isUseSystemFont: true, _labelType: 0, //0 is ttf, 1 is bmfont. _fontHandle: "", //a ttf font name or a bmfont file path. _lineSpacing: 0, @@ -176,18 +175,7 @@ _ccsg.Label = _ccsg.Node.extend({ this._spriteBatchNode = null; } }, - isSystemFontUsed: function() { - return this._isUseSystemFont; - }, - setSystemFontUsed: function(value) { - if (this._isUseSystemFont === value) return; - - if (value) { - this.setFontFileOrFamily("Arial"); - } - this._isUseSystemFont = value; - }, setHorizontalAlign: function(align) { if (this._hAlign === align) return; this._hAlign = align; @@ -359,12 +347,10 @@ _ccsg.Label = _ccsg.Node.extend({ this._fontHandle = fontHandle; this._labelType = _ccsg.Label.Type.SystemFont; this._notifyLabelSkinDirty(); - this._isUseSystemFont = true; this.emit('load'); return; } - this._isUseSystemFont = false; if (extName === ".ttf") { this._labelType = _ccsg.Label.Type.TTF; this._fontHandle = this._loadTTFFont(fontHandle); diff --git a/jsb/jsb-label.js b/jsb/jsb-label.js index c1e79ce072..03304c829c 100644 --- a/jsb/jsb-label.js +++ b/jsb/jsb-label.js @@ -58,18 +58,6 @@ jsbLabel.prototype.getOverflow = function() { return this._overFlow; }; -if (!jsbLabel.prototype.isSystemFontUsed) { - jsbLabel.prototype.isSystemFontUsed = function() { - return this._isSystemFontUsed; - }; - - jsbLabel.prototype.setSystemFontUsed = function(value) { - this._isSystemFontUsed = value; - this.setSystemFontName("Arial"); - this.setSystemFontSize(this.getFontSize()); - } -} - jsbLabel.prototype.setFontSize = function (size) { this._fontSize = size; if (this._labelType === _ccsg.Label.Type.SystemFont) {