From 8c2e92b009a5c04aa068292d0fb04b05de2ac0f4 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 6 Jun 2016 16:34:22 +0800 Subject: [PATCH 1/3] add bmfont layout --- cocos2d/core/components/CCLabel.js | 1 + cocos2d/core/label/CCSGLabel.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index df0b2e04dc..c7087f23f8 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -382,6 +382,7 @@ var Label = cc.Class({ sgNode.setString(this.string); if (CC_EDITOR && this._useOriginalSize) { this.node.setContentSize(sgNode.getContentSize()); + this.lineHeight = sgNode.getBMFontLineHeight(); this._useOriginalSize = false; } else { sgNode.setContentSize(this.node.getContentSize()); diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 2a2b44baed..558de5df03 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -343,6 +343,12 @@ _ccsg.Label = _ccsg.Node.extend({ return this._lineHeight; }, + getBMFontLineHeight : function() { + if(this._fontAtlas) { + return this._fontAtlas._lineHeight; + } + }, + setFontFileOrFamily: function(fontHandle, textureUrl) { fontHandle = fontHandle || "Arial"; var extName = cc.path.extname(fontHandle); From 6098e801cdd6ee35e1e0926aff8182f7c821bcd9 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 6 Jun 2016 17:10:00 +0800 Subject: [PATCH 2/3] fix label resize height issue --- cocos2d/core/components/CCLabel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index c7087f23f8..f7b01c1cac 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -394,7 +394,7 @@ var Label = cc.Class({ _updateNodeSize: function () { var initialized = this._sgNode && this._sgNode.parent; if (initialized) { - if (this.overflow === Overflow.NONE) { + if (this.overflow === Overflow.NONE || this.overflow === Overflow.RESIZE_HEIGHT) { this.node.setContentSize(this._sgNode.getContentSize()); } } From 998cdb1dc8d8345443d46361ab8a10f8a5cabb4c Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 6 Jun 2016 18:37:19 +0800 Subject: [PATCH 3/3] only set line height when label is bmfont --- cocos2d/core/components/CCLabel.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index f7b01c1cac..1718bef2db 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -382,7 +382,9 @@ var Label = cc.Class({ sgNode.setString(this.string); if (CC_EDITOR && this._useOriginalSize) { this.node.setContentSize(sgNode.getContentSize()); - this.lineHeight = sgNode.getBMFontLineHeight(); + if (this.font instanceof cc.BitmapFont) { + this.lineHeight = sgNode.getBMFontLineHeight(); + } this._useOriginalSize = false; } else { sgNode.setContentSize(this.node.getContentSize());