From d32a317ea03400736ad987ca6f911a058b3eddf9 Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Fri, 19 Jun 2015 13:39:19 +0800 Subject: [PATCH] Label:Fixed line wrap error without space. --- cocos/2d/CCLabel.cpp | 4 +- cocos/2d/CCLabelTextFormatter.cpp | 2 +- .../Classes/LabelTest/LabelTestNew.cpp | 39 +++++++++++++++++++ .../Classes/LabelTest/LabelTestNew.h | 11 ++++++ 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 8a37a60c16..f1e674876e 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -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; diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index 5b2027b62e..638897965e 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -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 { diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp index f1b7fd52c5..e367f96e05 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp @@ -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."; +} diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h index 6daece44e8..826efbea20 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h @@ -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