From b45abf3f2d3c80125f7fe8b460e020085743e4fd Mon Sep 17 00:00:00 2001 From: Hanju Kim Date: Mon, 13 Jan 2014 21:14:50 +0900 Subject: [PATCH] Bug fixes for new label --- cocos/2d/CCFontAtlas.cpp | 4 +++- cocos/2d/CCFontDefinition.cpp | 4 +++- cocos/2d/CCLabel.cpp | 6 ++++++ cocos/2d/CCLabelTextFormatter.cpp | 2 -- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 4d35ce980d..d1abc79a8d 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -114,6 +114,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) std::unordered_map 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; } diff --git a/cocos/2d/CCFontDefinition.cpp b/cocos/2d/CCFontDefinition.cpp index c0d8af5051..d2c74ebf30 100644 --- a/cocos/2d/CCFontDefinition.cpp +++ b/cocos/2d/CCFontDefinition.cpp @@ -215,13 +215,15 @@ FontAtlas * FontDefinitionTTF::createFontAtlas() // set the common line height retAtlas->setCommonLineHeight(_commonLineHeight * 0.8); - + auto yDelta = _commonLineHeight * 0.7; + for( auto &item: _fontLettersDefinitionUTF16 ) { if ( item.second.validDefinition ) { FontLetterDefinition tempDefinition = item.second; tempDefinition.offsetX = 0; + tempDefinition.offsetY += yDelta; tempDefinition.anchorX = 0.0f; tempDefinition.anchorY = 1.0f; retAtlas->addLetterDefinition(tempDefinition); diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index d7125bcd30..d343bcd241 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -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(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(spriteIndex) >= _lettersInfo.size()) { LetterInfo tmpInfo; + + memset(&tmpInfo, 0, sizeof(tmpInfo)); _lettersInfo.push_back(tmpInfo); } diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index 956c5c3bb1..b4977c8a92 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -241,8 +241,6 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel) continue; } int index = static_cast(i + lineLength - 1 + lineNumber); - if(currentChar == 0) - index -= 1; if (index < 0) continue; LetterInfo* info = &leterInfo->at( index );