Label:Fixed line wrap error without space.

This commit is contained in:
WenhaiLin 2015-06-19 13:39:19 +08:00
parent 05522afaa1
commit d32a317ea0
4 changed files with 53 additions and 3 deletions

View File

@ -712,8 +712,8 @@ bool Label::recordLetterInfo(const cocos2d::Vec2& point,const FontLetterDefiniti
_lettersInfo[spriteIndex].def = letterDef;
_lettersInfo[spriteIndex].position = point;
_lettersInfo[spriteIndex].contentSize.width = _lettersInfo[spriteIndex].def.width;
_lettersInfo[spriteIndex].contentSize.height = _lettersInfo[spriteIndex].def.height;
_lettersInfo[spriteIndex].contentSize.width = letterDef.width;
_lettersInfo[spriteIndex].contentSize.height = letterDef.height;
_limitShowCount++;
return _lettersInfo[spriteIndex].def.validDefinition;

View File

@ -111,7 +111,7 @@ bool LabelTextFormatter::multilineText(Label *theLabel)
multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end());
last_word.clear();
startOfLine = 0.f;
startOfLine += lineWidth;
}
else
{

View File

@ -79,6 +79,7 @@ NewLabelTests::NewLabelTests()
ADD_TEST_CASE(LabelIssue11576Test);
ADD_TEST_CASE(LabelIssue11699Test);
ADD_TEST_CASE(LabelIssue12259Test);
ADD_TEST_CASE(LabelIssue12409Test);
};
LabelTTFAlignmentNew::LabelTTFAlignmentNew()
@ -1972,3 +1973,41 @@ std::string LabelIssue12259Test::subtitle() const
{
return "the texture of character should be cropped.";
}
LabelIssue12409Test::LabelIssue12409Test()
{
auto center = VisibleRect::center();
auto label = Label::createWithTTF("abcdefghijklmn", "fonts/arial.ttf", 30);
label->setWidth(70);
label->setLineBreakWithoutSpace(true);
label->setPosition(center.x, center.y);
addChild(label);
auto labelSize = label->getContentSize();
auto winSize = Director::getInstance()->getWinSize();
Vec2 labelOrigin;
labelOrigin.x = winSize.width / 2 - (labelSize.width / 2);
labelOrigin.y = winSize.height / 2 - (labelSize.height / 2);
Vec2 vertices[4] =
{
Vec2(labelOrigin.x, labelOrigin.y),
Vec2(labelOrigin.x + labelSize.width, labelOrigin.y),
Vec2(labelOrigin.x + labelSize.width, labelOrigin.y + labelSize.height),
Vec2(labelOrigin.x, labelOrigin.y + labelSize.height)
};
auto drawNode = DrawNode::create();
drawNode->drawPoly(vertices, 4, true, Color4F::WHITE);
addChild(drawNode);
}
std::string LabelIssue12409Test::title() const
{
return "Test for Issue #12409";
}
std::string LabelIssue12409Test::subtitle() const
{
return "Testing auto-wrapping without space.";
}

View File

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