Skip to content

Commit 4e9596e

Browse files
authored
Merge pull request cocos2d#3321 from pandamicro/develop
Fix multi line LabelTTF line height issue in retina mode
2 parents 4a3607a + 76b6c7e commit 4e9596e

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

cocos2d/core/labelttf/CCLabelTTF.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -923,13 +923,12 @@ document.body ?
923923
* @private
924924
*/
925925
cc.LabelTTF.__getFontHeightByDiv = function (fontName, fontSize) {
926-
926+
var clientHeight, labelDiv = cc.LabelTTF.__labelHeightDiv;
927927
if(fontName instanceof cc.FontDefinition){
928928
/** @type cc.FontDefinition */
929929
var fontDef = fontName;
930-
var clientHeight = cc.LabelTTF.__fontHeightCache[fontDef._getCanvasFontStr()];
930+
clientHeight = cc.LabelTTF.__fontHeightCache[fontDef._getCanvasFontStr()];
931931
if (clientHeight > 0) return clientHeight;
932-
var labelDiv = cc.LabelTTF.__labelHeightDiv;
933932
labelDiv.innerHTML = "ajghl~!";
934933
labelDiv.style.fontFamily = fontDef.fontName;
935934
labelDiv.style.fontSize = fontDef.fontSize + "px";
@@ -939,19 +938,18 @@ cc.LabelTTF.__getFontHeightByDiv = function (fontName, fontSize) {
939938
clientHeight = labelDiv.clientHeight;
940939
cc.LabelTTF.__fontHeightCache[fontDef._getCanvasFontStr()] = clientHeight;
941940
labelDiv.innerHTML = "";
942-
return clientHeight;
943941
}
944-
945-
//Default
946-
var clientHeight = cc.LabelTTF.__fontHeightCache[fontName + "." + fontSize];
947-
if (clientHeight > 0) return clientHeight;
948-
var labelDiv = cc.LabelTTF.__labelHeightDiv;
949-
labelDiv.innerHTML = "ajghl~!";
950-
labelDiv.style.fontFamily = fontName;
951-
labelDiv.style.fontSize = fontSize + "px";
952-
clientHeight = labelDiv.clientHeight;
953-
cc.LabelTTF.__fontHeightCache[fontName + "." + fontSize] = clientHeight;
954-
labelDiv.innerHTML = "";
942+
else {
943+
//Default
944+
clientHeight = cc.LabelTTF.__fontHeightCache[fontName + "." + fontSize];
945+
if (clientHeight > 0) return clientHeight;
946+
labelDiv.innerHTML = "ajghl~!";
947+
labelDiv.style.fontFamily = fontName;
948+
labelDiv.style.fontSize = fontSize + "px";
949+
clientHeight = labelDiv.clientHeight;
950+
cc.LabelTTF.__fontHeightCache[fontName + "." + fontSize] = clientHeight;
951+
labelDiv.innerHTML = "";
952+
}
955953
return clientHeight;
956954

957955
};

cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
5757
if(fontNameOrFontDef instanceof cc.FontDefinition){
5858
this._fontStyleStr = fontNameOrFontDef._getCanvasFontStr();
5959
this._fontClientHeight = cc.LabelTTF.__getFontHeightByDiv(fontNameOrFontDef);
60-
6160
}else {
6261
var deviceFontSize = fontSize * cc.view.getDevicePixelRatio();
6362
this._fontStyleStr = fontStyle + " " + fontWeight + " " + deviceFontSize + "px '" + fontNameOrFontDef + "'";
@@ -188,8 +187,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
188187
var locContentWidth = node._contentSize.width * scale - locStrokeShadowOffsetX;
189188

190189
//lineHeight
191-
var lineHeight = node.getLineHeight();
192-
var transformTop = (lineHeight - this._fontClientHeight) / 2;
190+
var lineHeight = node.getLineHeight() * scale;
191+
var transformTop = (lineHeight - this._fontClientHeight * scale) / 2;
193192

194193
if (locHAlignment === cc.TEXT_ALIGNMENT_RIGHT)
195194
xOffset += locContentWidth;

cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
proto.constructor = cc.ProgressTimer.WebGLRenderCmd;
4444

4545
proto.transform = function (parentCmd, recursive) {
46-
cc.Node.WebGLRenderCmd.prototype.transform.call(this, parentCmd, recursive);
46+
this.originTransform(parentCmd, recursive);
4747
var sp = this._node._sprite;
4848
sp._renderCmd.transform(this, recursive);
4949

0 commit comments

Comments
 (0)