This commit is contained in:
halx99 2023-09-19 22:00:17 +08:00
parent 012e614d5a
commit 079586d060
3 changed files with 39 additions and 19 deletions

View File

@ -106,7 +106,6 @@ set(_AX_2D_SRC
2d/Grid.cpp 2d/Grid.cpp
2d/LabelAtlas.cpp 2d/LabelAtlas.cpp
2d/Label.cpp 2d/Label.cpp
2d/LabelTextFormatter.cpp
2d/Layer.cpp 2d/Layer.cpp
2d/Light.cpp 2d/Light.cpp
2d/Menu.cpp 2d/Menu.cpp

View File

@ -2854,7 +2854,7 @@ bool Label::multilineTextWrap(const std::function<int(const std::u32string&, int
{ {
float newLetterWidth = 0.f; float newLetterWidth = 0.f;
if (_horizontalKernings && letterIndex < textLen - 1) if (_horizontalKernings && letterIndex < textLen - 1)
newLetterWidth = static_cast<float>(_horizontalKernings[letterIndex + 1]); newLetterWidth = static_cast<float>(_horizontalKernings[letterIndex + 1]) * _fontScale;
newLetterWidth += letterDef.xAdvance * _fontScale + _additionalKerning; newLetterWidth += letterDef.xAdvance * _fontScale + _additionalKerning;
nextLetterX += newLetterWidth; nextLetterX += newLetterWidth;

View File

@ -53,6 +53,28 @@ enum
kTagSprite8, kTagSprite8,
}; };
class LabelIssue1336 : public AtlasDemoNew
{
public:
CREATE_FUNC(LabelIssue1336);
LabelIssue1336()
{
auto size = Director::getInstance()->getWinSize();
TTFConfig config("fonts/arial.ttf");
config.distanceFieldEnabled = true;
config.faceSize = 72;
auto overlapingLabel = Label::createWithTTF(config, "Te");
overlapingLabel->setPosition(Vec2(size.width / 2, size.height / 2));
overlapingLabel->setColor(ax::Color3B::WHITE);
overlapingLabel->setScale(10);
addChild(overlapingLabel, 1);
}
virtual std::string title() const override { return "Github Issue 1336"; }
virtual std::string subtitle() const override { return "The label char shouldn't overalpping"; }
};
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// AtlasDemoNew // AtlasDemoNew
@ -63,6 +85,7 @@ NewLabelTests::NewLabelTests()
{ {
ADD_TEST_CASE(LabelOutlineAndGlowTest); ADD_TEST_CASE(LabelOutlineAndGlowTest);
ADD_TEST_CASE(LabelTTFDistanceField); ADD_TEST_CASE(LabelTTFDistanceField);
ADD_TEST_CASE(LabelIssue1336);
ADD_TEST_CASE(LabelIssue20523); ADD_TEST_CASE(LabelIssue20523);
ADD_TEST_CASE(LabelFNTGlyphDesigner); ADD_TEST_CASE(LabelFNTGlyphDesigner);
ADD_TEST_CASE(LabelFNTColor); ADD_TEST_CASE(LabelFNTColor);
@ -1116,8 +1139,7 @@ LabelTTFCJKWrappingTest::LabelTTFCJKWrappingTest()
Color4F(1.0f, 0.0f, 0.0f, 1.0f)); Color4F(1.0f, 0.0f, 0.0f, 1.0f));
TTFConfig ttfConfig("fonts/HKYuanMini.ttf", 25, GlyphCollection::DYNAMIC); TTFConfig ttfConfig("fonts/HKYuanMini.ttf", 25, GlyphCollection::DYNAMIC);
auto label1 = auto label1 = Label::createWithTTF(ttfConfig, "你好Axmol Label.", TextHAlignment::LEFT, size.width * 0.75f);
Label::createWithTTF(ttfConfig, "你好Axmol Label.", TextHAlignment::LEFT, size.width * 0.75f);
if (label1) if (label1)
{ {
label1->setTextColor(Color4B(128, 255, 255, 255)); label1->setTextColor(Color4B(128, 255, 255, 255));
@ -1130,8 +1152,7 @@ LabelTTFCJKWrappingTest::LabelTTFCJKWrappingTest()
label1->setTTFConfig(ttfConfig); label1->setTTFConfig(ttfConfig);
} }
auto label2 = auto label2 = Label::createWithTTF(ttfConfig, "早上好Axmol Label.", TextHAlignment::LEFT, size.width * 0.75f);
Label::createWithTTF(ttfConfig, "早上好Axmol Label.", TextHAlignment::LEFT, size.width * 0.75f);
if (label2) if (label2)
{ {
label2->setTextColor(Color4B(255, 128, 255, 255)); label2->setTextColor(Color4B(255, 128, 255, 255));