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
8 changes: 4 additions & 4 deletions cocos2d/core/labelttf/CCLabelTTF.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
setScale: function (scale, scaleY) {
this._scaleX = scale / cc.view.getDevicePixelRatio();
this._scaleY = ((scaleY || scaleY === 0) ? scaleY : scale) /
cc.view.getDevicePixelRatio();
cc.view.getDevicePixelRatio();
this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
},

Expand Down Expand Up @@ -806,18 +806,18 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
getContentSize: function () {
if (this._needUpdateTexture)
this._renderCmd._updateTTF();
return cc.Sprite.prototype.getContentSize.call(this);
return cc.size(this._contentSize);
},

_getWidth: function () {
if (this._needUpdateTexture)
this._renderCmd._updateTTF();
return cc.Sprite.prototype._getWidth.call(this);
return this._contentSize.width;
},
_getHeight: function () {
if (this._needUpdateTexture)
this._renderCmd._updateTTF();
return cc.Sprite.prototype._getHeight.call(this);
return this._contentSize.height;
},

setTextureRect: function (rect, rotated, untrimmedSize) {
Expand Down
51 changes: 31 additions & 20 deletions cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
this._isMultiLine = false;
this._status = [];
this._renderingIndex = 0;

this._texRect = cc.rect();
};
var proto = cc.LabelTTF.RenderCmd.prototype;
proto.constructor = cc.LabelTTF.RenderCmd;
Expand Down Expand Up @@ -92,7 +94,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;

proto._updateTTF = function () {
var node = this._node;
var locDimensionsWidth = node._dimensions.width, i, strLength;
var pixelRatio = cc.view.getDevicePixelRatio();
var locDimensionsWidth = node._dimensions.width * pixelRatio, i, strLength;
var locLineWidth = this._lineWidths;
locLineWidth.length = 0;

Expand Down Expand Up @@ -124,7 +127,6 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
locStrokeShadowOffsetY += Math.abs(locOffsetSize.y) * 2;
}

var pixelRatio = cc.view.getDevicePixelRatio();
//get offset for stroke and shadow
if (locDimensionsWidth === 0) {
if (this._isMultiLine)
Expand Down Expand Up @@ -155,7 +157,16 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
if(node._getFontStyle() !== "normal"){ //add width for 'italic' and 'oblique'
locSize.width = Math.ceil(locSize.width + node._fontSize * 0.3);
}
node.setContentSize(locSize);
if (this._strings.length === 0) {
this._texRect.width = 1;
this._texRect.height = locSize.height || 1;
}
else {
this._texRect.width = locSize.width;
this._texRect.height = locSize.height;
}
var nodeW = locSize.width / pixelRatio, nodeH = locSize.height / pixelRatio;
node.setContentSize(nodeW, nodeH);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are setting the design content size here...

node._strokeShadowOffsetX = locStrokeShadowOffsetX;
node._strokeShadowOffsetY = locStrokeShadowOffsetY;

Expand All @@ -167,13 +178,14 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;

proto._saveStatus = function () {
var node = this._node;
var scale = cc.view.getDevicePixelRatio();
var locStrokeShadowOffsetX = node._strokeShadowOffsetX, locStrokeShadowOffsetY = node._strokeShadowOffsetY;
var locContentSizeHeight = node._contentSize.height - locStrokeShadowOffsetY, locVAlignment = node._vAlignment,
var locContentSizeHeight = node._contentSize.height * scale - locStrokeShadowOffsetY, locVAlignment = node._vAlignment,
locHAlignment = node._hAlignment;
var dx = locStrokeShadowOffsetX * 0.5,
dy = locContentSizeHeight + locStrokeShadowOffsetY * 0.5;
var xOffset = 0, yOffset = 0, OffsetYArray = [];
var locContentWidth = node._contentSize.width - locStrokeShadowOffsetX;
var locContentWidth = node._contentSize.width * scale - locStrokeShadowOffsetX;

//lineHeight
var lineHeight = node.getLineHeight();
Expand Down Expand Up @@ -301,7 +313,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;

cc.Node.RenderCmd.prototype.updateStatus.call(this);

if (locFlag & flags.textDirty)
this._updateTexture();

Expand All @@ -313,9 +325,9 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;

proto._syncStatus = function (parentCmd) {
var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;

cc.Node.RenderCmd.prototype._syncStatus.call(this, parentCmd);

if (locFlag & flags.textDirty)
this._updateTexture();

Expand Down Expand Up @@ -371,6 +383,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
locCanvas.width = 1;
locCanvas.height = 1;
this._labelContext = locCanvas.getContext("2d");
this._texRect = cc.rect();
};

cc.LabelTTF.CacheRenderCmd.prototype = Object.create( cc.LabelTTF.RenderCmd.prototype);
Expand All @@ -382,9 +395,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
proto._updateTexture = function () {
this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.textDirty ^ this._dirtyFlag;
var node = this._node;
var locContentSize = node._contentSize;
this._updateTTF();
var width = locContentSize.width, height = locContentSize.height;
var width = this._texRect.width, height = this._texRect.height;

var locContext = this._labelContext, locLabelCanvas = this._labelCanvas;

Expand All @@ -395,24 +407,24 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
}

if (node._string.length === 0) {
locLabelCanvas.width = 1;
locLabelCanvas.height = locContentSize.height || 1;
locLabelCanvas.width = width;
locLabelCanvas.height = height;
node._texture && node._texture.handleLoadedTexture();
node.setTextureRect(cc.rect(0, 0, 1, locContentSize.height));
node.setTextureRect(this._texRect);
return true;
}

//set size for labelCanvas
locContext.font = this._fontStyleStr;

var flag = locLabelCanvas.width === width && locLabelCanvas.height === height;
locLabelCanvas.width = width;
locLabelCanvas.height = height;
locLabelCanvas.width = this._texRect.width;
locLabelCanvas.height = this._texRect.height;
if (flag) locContext.clearRect(0, 0, width, height);
this._saveStatus();
this._drawTTFInCanvas(locContext);
node._texture && node._texture.handleLoadedTexture();
node.setTextureRect(cc.rect(0, 0, width, height));
node.setTextureRect(this._texRect);
return true;
};

Expand Down Expand Up @@ -460,15 +472,14 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
proto._updateTexture = function () {
this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.textDirty ^ this._dirtyFlag;
var node = this._node;
var locContentSize = node._contentSize;
var scale = cc.view.getDevicePixelRatio();
this._updateTTF();
var width = locContentSize.width, height = locContentSize.height;
if (node._string.length === 0) {
node.setTextureRect(cc.rect(0, 0, 1, locContentSize.height));
node.setTextureRect(this._texRect);
return true;
}
this._saveStatus();
node.setTextureRect(cc.rect(0, 0, width, height));
node.setTextureRect(this._texRect);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's being overwritten here. See the default implementation of setTextureRect() in CCSprite: https://github.com/cocos2d/cocos2d-html5/blob/develop/cocos2d/core/sprites/CCSprite.js#L738

return true;
};

Expand Down
2 changes: 1 addition & 1 deletion extensions/ccui/uiwidgets/UIText.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ccui.Text = ccui.Widget.extend(/** @lends ccui.Text# */{
_fontName: "Arial",
_fontSize: 16,
_onSelectedScaleOffset:0.5,
_labelRenderer: "",
_labelRenderer: null,
_textAreaSize: null,
_textVerticalAlignment: 0,
_textHorizontalAlignment: 0,
Expand Down