mirror of https://github.com/axmolengine/axmol.git
Merge pull request #9096 from Dhilan007/v3-label-i9095
Fix Label may display incomplete for multiline text with outline feature enabled.
This commit is contained in:
commit
68cb1d6c6a
|
@ -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;
|
||||
|
|
|
@ -81,7 +81,8 @@ static std::function<Layer*()> 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'";
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue