Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions cocos2d/core/labelttf/CCLabelTTF.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,13 +923,12 @@ document.body ?
* @private
*/
cc.LabelTTF.__getFontHeightByDiv = function (fontName, fontSize) {

var clientHeight, labelDiv = cc.LabelTTF.__labelHeightDiv;
if(fontName instanceof cc.FontDefinition){
/** @type cc.FontDefinition */
var fontDef = fontName;
var clientHeight = cc.LabelTTF.__fontHeightCache[fontDef._getCanvasFontStr()];
clientHeight = cc.LabelTTF.__fontHeightCache[fontDef._getCanvasFontStr()];
if (clientHeight > 0) return clientHeight;
var labelDiv = cc.LabelTTF.__labelHeightDiv;
labelDiv.innerHTML = "ajghl~!";
labelDiv.style.fontFamily = fontDef.fontName;
labelDiv.style.fontSize = fontDef.fontSize + "px";
Expand All @@ -939,19 +938,18 @@ cc.LabelTTF.__getFontHeightByDiv = function (fontName, fontSize) {
clientHeight = labelDiv.clientHeight;
cc.LabelTTF.__fontHeightCache[fontDef._getCanvasFontStr()] = clientHeight;
labelDiv.innerHTML = "";
return clientHeight;
}

//Default
var clientHeight = cc.LabelTTF.__fontHeightCache[fontName + "." + fontSize];
if (clientHeight > 0) return clientHeight;
var labelDiv = cc.LabelTTF.__labelHeightDiv;
labelDiv.innerHTML = "ajghl~!";
labelDiv.style.fontFamily = fontName;
labelDiv.style.fontSize = fontSize + "px";
clientHeight = labelDiv.clientHeight;
cc.LabelTTF.__fontHeightCache[fontName + "." + fontSize] = clientHeight;
labelDiv.innerHTML = "";
else {
//Default
clientHeight = cc.LabelTTF.__fontHeightCache[fontName + "." + fontSize];
if (clientHeight > 0) return clientHeight;
labelDiv.innerHTML = "ajghl~!";
labelDiv.style.fontFamily = fontName;
labelDiv.style.fontSize = fontSize + "px";
clientHeight = labelDiv.clientHeight;
cc.LabelTTF.__fontHeightCache[fontName + "." + fontSize] = clientHeight;
labelDiv.innerHTML = "";
}
return clientHeight;

};
Expand Down
5 changes: 2 additions & 3 deletions cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
if(fontNameOrFontDef instanceof cc.FontDefinition){
this._fontStyleStr = fontNameOrFontDef._getCanvasFontStr();
this._fontClientHeight = cc.LabelTTF.__getFontHeightByDiv(fontNameOrFontDef);

}else {
var deviceFontSize = fontSize * cc.view.getDevicePixelRatio();
this._fontStyleStr = fontStyle + " " + fontWeight + " " + deviceFontSize + "px '" + fontNameOrFontDef + "'";
Expand Down Expand Up @@ -188,8 +187,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
var locContentWidth = node._contentSize.width * scale - locStrokeShadowOffsetX;

//lineHeight
var lineHeight = node.getLineHeight();
var transformTop = (lineHeight - this._fontClientHeight) / 2;
var lineHeight = node.getLineHeight() * scale;
var transformTop = (lineHeight - this._fontClientHeight * scale) / 2;

if (locHAlignment === cc.TEXT_ALIGNMENT_RIGHT)
xOffset += locContentWidth;
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
proto.constructor = cc.ProgressTimer.WebGLRenderCmd;

proto.transform = function (parentCmd, recursive) {
cc.Node.WebGLRenderCmd.prototype.transform.call(this, parentCmd, recursive);
this.originTransform(parentCmd, recursive);
var sp = this._node._sprite;
sp._renderCmd.transform(this, recursive);

Expand Down