Merge pull request #5082 from Dhilan007/develop_label

closed #3726:Fix crash when using unknown character.
This commit is contained in:
James Chen 2014-01-16 00:10:53 -08:00
commit 21dc91bf78
4 changed files with 43 additions and 7 deletions

View File

@ -100,6 +100,7 @@ bool FontAtlas::getLetterDefinitionForChar(unsigned short letteCharUTF16, FontL
}
else
{
outDefinition.validDefinition = false;
return false;
}
}

View File

@ -68,15 +68,19 @@ bool LabelTextFormatter::multilineText(LabelTextFormatProtocol *theLabel)
while (info->def.validDefinition == false)
{
justSkipped++;
info = &leterInfo->at( j+skip+justSkipped );
tIndex = j+skip+justSkipped;
if(tIndex < strLen)
info = &leterInfo->at( tIndex );
else
break;
}
skip += justSkipped;
tIndex = j + skip;
if (i >= stringLength)
if (tIndex >= stringLength)
break;
unsigned short character = strWhole[i];
unsigned short character = strWhole[tIndex];
if (!isStartOfWord)
{
@ -241,8 +245,6 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel)
continue;
}
int index = static_cast<int>(i + lineLength - 1 + lineNumber);
if(currentChar == 0)
index -= 1;
if (index < 0) continue;
LetterInfo* info = &leterInfo->at( index );

View File

@ -66,7 +66,8 @@ static std::function<Layer*()> createFunctions[] =
CL(LabelTTFUnicodeNew),
CL(LabelBMFontTestNew),
CL(LabelTTFDistanceField),
CL(LabelTTFDistanceFieldEffect)
CL(LabelTTFDistanceFieldEffect),
CL(LabelCrashTest)
};
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
@ -1242,3 +1243,25 @@ std::string LabelTTFDistanceFieldEffect::subtitle() const
{
return "Testing effect base on DistanceField";
}
LabelCrashTest::LabelCrashTest()
{
auto size = Director::getInstance()->getWinSize();
TTFConfig ttfConfig("fonts/arial.ttf", 80, GlyphCollection::DYNAMIC,nullptr,true);
auto label1 = Label::createWithTTF(ttfConfig,"Test崩溃123", TextHAlignment::CENTER, size.width);
label1->setPosition( Point(size.width/2, size.height/2) );
label1->setAnchorPoint(Point(0.5, 0.5));
addChild(label1);
}
std::string LabelCrashTest::title() const
{
return "New Label Crash Test";
}
std::string LabelCrashTest::subtitle() const
{
return "Not crash and show [Test123] when using unknown character.";
}

View File

@ -347,6 +347,16 @@ public:
virtual std::string subtitle() const override;
};
class LabelCrashTest : public AtlasDemoNew
{
public:
CREATE_FUNC(LabelCrashTest);
LabelCrashTest();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
// we don't support linebreak mode