diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index c1c0c8d386..56bc1d55fe 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -151,16 +151,20 @@ bool LabelTextFormatter::multilineText(Label *theLabel) else { StringUtils::trimUTF16Vector(last_word); + if (isStartOfLine) + last_word.push_back(character); last_word.push_back('\n'); - + multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end()); last_word.clear(); + if (!isStartOfLine) + --j; + isStartOfWord = false; isStartOfLine = false; startOfWord = -1; startOfLine = -1; - --j; } } else diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp index 2c8788703f..a537f53642 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp @@ -80,7 +80,8 @@ static std::function createFunctions[] = CL(LabelIssue4428Test), CL(LabelIssue4999Test), CL(LabelLineHeightTest), - CL(LabelAdditionalKerningTest) + CL(LabelAdditionalKerningTest), + CL(LabelIssue8492Test) }; #define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) @@ -1814,3 +1815,21 @@ std::string LabelAdditionalKerningTest::subtitle() const { return "Testing additional kerning of label"; } + +LabelIssue8492Test::LabelIssue8492Test() +{ + auto label = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", "中国中国中国中国中国"); + label->setDimensions(5,100); + label->setPosition(VisibleRect::center()); + addChild(label); +} + +std::string LabelIssue8492Test::title() const +{ + return "Reorder issue #8492"; +} + +std::string LabelIssue8492Test::subtitle() const +{ + return "Work fine when dimensions are not enough to fit one character"; +} diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h index 9e588e4931..113539ef4d 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h @@ -509,6 +509,17 @@ private: Label* label; }; +class LabelIssue8492Test : public AtlasDemoNew +{ +public: + CREATE_FUNC(LabelIssue8492Test); + + LabelIssue8492Test(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + // we don't support linebreak mode #endif