Merge pull request #13084 from WenhaiLin/v3.8-label-df-contentsize-fix

Fixed the content size of Label is incorrect with GLOW effect.
This commit is contained in:
子龙山人 2015-07-30 11:29:48 +08:00
commit c039c7a9bd
6 changed files with 41 additions and 87 deletions

View File

@ -323,7 +323,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u16string& utf16Text)
if (bitmapHeight > _currLineHeight)
{
_currLineHeight = static_cast<int>(bitmapHeight)+1;
_currLineHeight = static_cast<int>(bitmapHeight) + _letterPadding + 1;
}
if (_currentPageOrigX + tempDef.width > CacheTextureWidth)
{

View File

@ -52,15 +52,8 @@ FontAtlas * FontAtlasCache::getFontAtlasTTF(const TTFConfig & config)
{
useDistanceField = false;
}
int fontSize = config.fontSize;
auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR();
if (useDistanceField)
{
fontSize = Label::DistanceFieldFontSize / contentScaleFactor;
}
auto atlasName = generateFontName(config.fontFilePath, fontSize, GlyphCollection::DYNAMIC, useDistanceField);
auto atlasName = generateFontName(config.fontFilePath, config.fontSize, GlyphCollection::DYNAMIC, useDistanceField);
atlasName.append("_outline_");
std::stringstream ss;
ss << config.outlineSize;
@ -70,7 +63,7 @@ FontAtlas * FontAtlasCache::getFontAtlasTTF(const TTFConfig & config)
if ( it == _atlasMap.end() )
{
auto font = FontFreeType::create(config.fontFilePath, fontSize, config.glyphs,
auto font = FontFreeType::create(config.fontFilePath, config.fontSize, config.glyphs,
config.customGlyphs, useDistanceField, config.outlineSize);
if (font)
{

View File

@ -41,8 +41,6 @@
NS_CC_BEGIN
const int Label::DistanceFieldFontSize = 50;
/**
* LabelLetter used to update the quad in texture atlas without SpriteBatchNode.
*/
@ -449,7 +447,6 @@ void Label::reset()
_shadowEnabled = false;
_shadowBlurRadius = 0.f;
_correctionScale = 1.f;
_useDistanceField = false;
_useA8Shader = false;
_clipEnabled = false;
@ -556,10 +553,6 @@ bool Label::setTTFConfig(const TTFConfig& ttfConfig)
{
_currLabelEffect = LabelEffect::NORMAL;
updateShaderProgram();
if(ttfConfig.distanceFieldEnabled)
{
this->setCorrectionScale(1.0f * ttfConfig.fontSize / DistanceFieldFontSize);
}
}
return true;
@ -639,57 +632,6 @@ void Label::setLineBreakWithoutSpace(bool breakWithoutSpace)
}
}
void Label::setScale(float scale)
{
if (_useDistanceField)
{
scale *= _correctionScale;
}
Node::setScale(scale);
}
void Label::setScaleX(float scaleX)
{
if (_useDistanceField)
{
scaleX *= _correctionScale;
}
Node::setScaleX(scaleX);
}
void Label::setScaleY(float scaleY)
{
if (_useDistanceField)
{
scaleY *= _correctionScale;
}
Node::setScaleY(scaleY);
}
float Label::getScaleY() const
{
if (_useDistanceField)
{
return _scaleY / _correctionScale;
}
else
{
return _scaleY;
}
}
float Label::getScaleX() const
{
if (_useDistanceField)
{
return _scaleX / _correctionScale;
}
else
{
return _scaleX;
}
}
void Label::alignText()
{
if (_fontAtlas == nullptr || _utf16Text.empty())
@ -983,12 +925,6 @@ void Label::disableEffect(LabelEffect effect)
}
}
void Label::setCorrectionScale(float correctionScale)
{
_correctionScale = correctionScale * CC_CONTENT_SCALE_FACTOR();
Node::setScale(_correctionScale);
}
void Label::createSpriteForSystemFont(const FontDefinition& fontDef)
{
_currentLabelType = LabelType::STRING_TEXTURE;

View File

@ -107,8 +107,6 @@ class EventListenerCustom;
class CC_DLL Label : public Node, public LabelProtocol, public BlendProtocol
{
public:
static const int DistanceFieldFontSize;
/// @name Creators
/// @{
@ -455,12 +453,6 @@ public:
virtual void updateDisplayedColor(const Color3B& parentColor) override;
virtual void updateDisplayedOpacity(GLubyte parentOpacity) override;
virtual void setScale(float scale) override;
virtual void setScaleX(float scaleX) override;
virtual void setScaleY(float scaleY) override;
virtual float getScaleX() const override;
virtual float getScaleY() const override;
virtual std::string getDescription() const override;
virtual const Size& getContentSize() const override;
@ -516,8 +508,6 @@ protected:
virtual void setFontAtlas(FontAtlas* atlas, bool distanceFieldEnabled = false, bool useA8Shader = false);
void setCorrectionScale(float fontScale);
void computeStringNumLines();
void onDraw(const Mat4& transform, bool transformUpdated);
@ -591,9 +581,6 @@ protected:
float _tailoredTopY;
float _tailoredBottomY;
//the correction scale for distance field.
float _correctionScale;
LabelEffect _currLabelEffect;
Color4F _effectColorF;
Color4B _textColor;

View File

@ -84,6 +84,7 @@ NewLabelTests::NewLabelTests()
ADD_TEST_CASE(LabelIssue12775Test);
ADD_TEST_CASE(LabelIssue11585Test);
ADD_TEST_CASE(LabelFullTypeFontTest);
ADD_TEST_CASE(LabelIssue10688Test);
};
LabelTTFAlignmentNew::LabelTTFAlignmentNew()
@ -2031,3 +2032,29 @@ std::string LabelFullTypeFontTest::title() const
{
return "Test font supported by FullType";
}
LabelIssue10688Test::LabelIssue10688Test()
{
auto center = VisibleRect::center();
auto label = Label::createWithTTF("Glow MenuItemLabel", "fonts/arial.ttf", 30);
label->setTextColor(Color4B::RED);
label->enableGlow(Color4B::YELLOW);
auto menuItem1 = MenuItemLabel::create(label, [](Ref*){});
menuItem1->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
menuItem1->setPosition(center.x - label->getContentSize().width/2, center.y);
auto menu = Menu::create(menuItem1, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu);
}
std::string LabelIssue10688Test::title() const
{
return "Test for Issue #10688";
}
std::string LabelIssue10688Test::subtitle() const
{
return "The MenuItemLabel should be displayed in the middle of the screen.";
}

View File

@ -647,4 +647,15 @@ public:
virtual std::string title() const override;
};
class LabelIssue10688Test : public AtlasDemoNew
{
public:
CREATE_FUNC(LabelIssue10688Test);
LabelIssue10688Test();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
#endif