diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index dfad03f4f2..f884e74f67 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -269,18 +269,16 @@ bool LabelTextFormatter::alignText(Label *theLabel) bool LabelTextFormatter::createStringSprites(Label *theLabel) { - // check for string - unsigned int stringLen = theLabel->getStringLength(); theLabel->_limitShowCount = 0; - - // no string - if (stringLen == 0) + // check for string + int stringLen = theLabel->getStringLength(); + if (stringLen <= 0) return false; - int longestLine = 0; - unsigned int totalHeight = theLabel->_commonLineHeight * theLabel->_currNumLines; - int nextFontPositionX = 0; - int nextFontPositionY = totalHeight; + auto totalHeight = theLabel->_commonLineHeight * theLabel->_currNumLines; + auto longestLine = 0.0f; + auto nextFontPositionX = 0.0f; + auto nextFontPositionY = totalHeight; auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR(); if (theLabel->_labelHeight > 0) @@ -307,7 +305,6 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) } } - Rect charRect; int charXOffset = 0; int charYOffset = 0; int charAdvance = 0; @@ -322,13 +319,13 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) float clipBottom = 0; int lineIndex = 0; bool lineStart = true; - bool clip = false; + bool clipBlank = false; if (theLabel->_currentLabelType == Label::LabelType::TTF && theLabel->_clipEnabled) { - clip = true; + clipBlank = true; } - for (unsigned int i = 0; i < stringLen; i++) + for (int i = 0; i < stringLen; i++) { char16_t c = strWhole[i]; if (fontAtlas->getLetterDefinitionForChar(c, tempDefinition)) @@ -357,7 +354,7 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) lineStart = true; continue; } - else if (clip && tempDefinition.height > 0.0f) + else if (clipBlank && tempDefinition.height > 0.0f) { if (lineStart) { @@ -382,7 +379,7 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) letterPosition.x = (nextFontPositionX + charXOffset + kernings[i]) / contentScaleFactor; letterPosition.y = (nextFontPositionY - charYOffset) / contentScaleFactor; - if( theLabel->recordLetterInfo(letterPosition,tempDefinition,i) == false) + if( theLabel->recordLetterInfo(letterPosition, tempDefinition, i) == false) { log("WARNING: can't find letter definition in font file for letter: %c", c); continue; @@ -420,7 +417,7 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel) tmpSize.height = theLabel->_labelHeight * contentScaleFactor; } - if (clip) + if (clipBlank) { int clipTotal = (clipTop + clipBottom) / contentScaleFactor; tmpSize.height -= clipTotal * contentScaleFactor; diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp index a537f53642..e998a0e6ec 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp @@ -81,7 +81,8 @@ static std::function createFunctions[] = CL(LabelIssue4999Test), CL(LabelLineHeightTest), CL(LabelAdditionalKerningTest), - CL(LabelIssue8492Test) + CL(LabelIssue8492Test), + CL(LabelMultilineWithOutline) }; #define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) @@ -1833,3 +1834,21 @@ std::string LabelIssue8492Test::subtitle() const { return "Work fine when dimensions are not enough to fit one character"; } + +LabelMultilineWithOutline::LabelMultilineWithOutline() +{ + auto label = Label::createWithTTF("Multiline txet\nwith\noutline feature", "fonts/arial.ttf", 24); + label->enableOutline(Color4B::ORANGE,1); + label->setPosition(VisibleRect::center()); + addChild(label); +} + +std::string LabelMultilineWithOutline::title() const +{ + return "Reorder issue #9095"; +} + +std::string LabelMultilineWithOutline::subtitle() const +{ + return "end in string 'outline feature'"; +} diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h index 113539ef4d..90948a20f2 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h @@ -520,6 +520,17 @@ public: virtual std::string subtitle() const override; }; +class LabelMultilineWithOutline : public AtlasDemoNew +{ +public: + CREATE_FUNC(LabelMultilineWithOutline); + + LabelMultilineWithOutline(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + // we don't support linebreak mode #endif