fix ttf NONE content size error

This commit is contained in:
zilongshanren
2016-01-11 18:24:25 +08:00
parent 7e90c16186
commit bc962b1169
2 changed files with 31 additions and 22 deletions
+26 -19
View File
@@ -258,16 +258,22 @@ _ccsg.Label = _ccsg.Node.extend({
setOverflow: function(overflow) {
if (this._overFlow === overflow) return;
this._overFlow = overflow;
if (this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) {
this._setDimensions(this._labelDimensions.width, 0);
this._isWrapText = true;
if (this._labelType === _ccsg.Label.Type.BMFont) {
if ( this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) {
this._setDimensions(this._labelDimensions.width, 0);
this._isWrapText = true;
}
if (this._overFlow === _ccsg.Label.Overflow.NONE) {
this._isWrapText = false;
this._setDimensions(0, 0);
}
}
if (this._overFlow === _ccsg.Label.Overflow.NONE) {
this._isWrapText = false;
this._setDimensions(0, 0);
}
this._rescaleWithOriginalFontSize();
this._notifyLabelSkinDirty();
@@ -325,9 +331,6 @@ _ccsg.Label = _ccsg.Node.extend({
//todo add bmfont here
this._labelType = _ccsg.Label.Type.BMFont;
this._initBMFontWithString(this._string, fontHandle);
if(this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) {
this._setDimensions(this._labelDimensions.width, 0);
}
}
},
@@ -599,17 +602,22 @@ cc.BMFontHelper = {
var newWidth = size.width || size;
var newHeight = size.height || height;
if (this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) {
newHeight = 0;
_ccsg.Node.prototype.setContentSize.call(this, size, height);
if (this._labelType === _ccsg.Label.Type.BMFont) {
if (this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) {
newHeight = 0;
}
if (this._overFlow === _ccsg.Label.Overflow.NONE) {
newWidth = 0;
newHeight = 0;
}
}
if (this._overFlow === _ccsg.Label.Overflow.NONE) {
newWidth = 0;
newHeight = 0;
}
if (newHeight !== this._labelHeight || newWidth !== this._labelWidth) {
_ccsg.Node.prototype.setContentSize.call(this, size, height);
this._labelWidth = newWidth;
this._labelHeight = newHeight;
@@ -618,8 +626,7 @@ cc.BMFontHelper = {
this._maxLineWidth = newWidth;
if (this._labelType === _ccsg.Label.Type.BMFont
&& this._overFlow === _ccsg.Label.Overflow.SHRINK) {
if (this._labelType === _ccsg.Label.Type.BMFont && this._overFlow === _ccsg.Label.Overflow.SHRINK) {
if (this._bmFontSize > 0) {
this._restoreFontSize();
}
@@ -214,11 +214,11 @@
this._splitedStrings = this._splitedStrings.concat(this._fragmentText(paragraphedStrings[i], canvasSizeX, ctx));
}
canvasSizeY = this._splitedStrings.length * this._getLineHeight();
node.setContentSize(cc.size(canvasSizeX, canvasSizeY));
node._setDimensions(cc.size(canvasSizeX, canvasSizeY));
} else {
this._splitedStrings = paragraphedStrings;
canvasSizeY = this._splitedStrings.length * this._getLineHeight();
node.setContentSize(cc.size(canvasSizeX, canvasSizeY));
node._setDimensions(cc.size(canvasSizeX, canvasSizeY));
}
} else if(_ccsg.Label.Overflow.SHRINK === node._overFlow) {
this._splitedStrings = paragraphedStrings;
@@ -252,12 +252,14 @@
}
} else if(_ccsg.Label.Overflow.NONE == node._overFlow) {
this._splitedStrings = paragraphedStrings;
canvasSizeX = 0;
canvasSizeY = 0;
for (var i = 0; i < paragraphedStrings.length; ++i) {
var paraLength = ctx.measureText(paragraphedStrings[i]).width;
canvasSizeX = canvasSizeX > paraLength ? canvasSizeX : paraLength;
}
canvasSizeY = this._splitedStrings.length * this._getLineHeight();
node.setContentSize(cc.size(canvasSizeX, canvasSizeY));
node._setDimensions(cc.size(canvasSizeX, canvasSizeY));
} else {
//others treat it as clamp
if (node._isWrapText) {