fix endless loop when dimensions that are not enough to fit one character

This commit is contained in:
Dhilan007 2014-10-08 18:22:35 +08:00
parent 442f767c89
commit 8ea473de7b
3 changed files with 37 additions and 3 deletions

View File

@ -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

View File

@ -80,7 +80,8 @@ static std::function<Layer*()> 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";
}

View File

@ -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