Bug fixes for new label

This commit is contained in:
Hanju Kim 2014-01-13 21:14:50 +09:00
parent 4bbcd91bdf
commit b45abf3f2d
4 changed files with 12 additions and 4 deletions

View File

@ -114,6 +114,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
std::unordered_map<unsigned short, FontLetterDefinition> fontDefs;
int length = cc_wcslen(utf16String);
auto yDelta = _currentPageLineHeight * 0.7;
//find out new letter
for (int i = 0; i < length; ++i)
{
@ -150,7 +152,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
tempDef.letteCharUTF16 = utf16String[i];
tempDef.width = tempRect.size.width + _letterPadding;
tempDef.height = _currentPageLineHeight - 1;
tempDef.offsetY = tempRect.origin.y;
tempDef.offsetY = tempRect.origin.y + yDelta;
tempDef.commonLineHeight = _currentPageLineHeight;
}

View File

@ -215,6 +215,7 @@ FontAtlas * FontDefinitionTTF::createFontAtlas()
// set the common line height
retAtlas->setCommonLineHeight(_commonLineHeight * 0.8);
auto yDelta = _commonLineHeight * 0.7;
for( auto &item: _fontLettersDefinitionUTF16 )
{
@ -222,6 +223,7 @@ FontAtlas * FontDefinitionTTF::createFontAtlas()
{
FontLetterDefinition tempDefinition = item.second;
tempDefinition.offsetX = 0;
tempDefinition.offsetY += yDelta;
tempDefinition.anchorX = 0.0f;
tempDefinition.anchorY = 1.0f;
retAtlas->addLetterDefinition(tempDefinition);

View File

@ -194,6 +194,8 @@ bool Label::setText(const std::string& stringToRender, float lineWidth, TextHAli
// align text
alignText();
updateColor();
// done here
return true;
}
@ -438,6 +440,8 @@ bool Label::recordLetterInfo(const cocos2d::Point& point,unsigned short int theC
if (static_cast<std::size_t>(spriteIndex) >= _lettersInfo.size())
{
LetterInfo tmpInfo;
memset(&tmpInfo, 0, sizeof(tmpInfo));
_lettersInfo.push_back(tmpInfo);
}
@ -454,6 +458,8 @@ bool Label::recordPlaceholderInfo(int spriteIndex)
if (static_cast<std::size_t>(spriteIndex) >= _lettersInfo.size())
{
LetterInfo tmpInfo;
memset(&tmpInfo, 0, sizeof(tmpInfo));
_lettersInfo.push_back(tmpInfo);
}

View File

@ -241,8 +241,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 );