diff --git a/cocos2dx/label_nodes/CCFontDefinition.cpp b/cocos2dx/label_nodes/CCFontDefinition.cpp index 97f4ba8855..79a3c3f918 100644 --- a/cocos2dx/label_nodes/CCFontDefinition.cpp +++ b/cocos2dx/label_nodes/CCFontDefinition.cpp @@ -91,7 +91,7 @@ bool FontDefinitionTTF::prepareLetterDefinitions(TextFontPagesDef *pageDefs) float letterHeight = pPages->getPageAt(cPages)->getLineAt(cLines)->getHeight(); // add this letter definition - LetterDefinition tempDef; + FontLetterDefinition tempDef; // carloX little hack (this should be done outside the loop) @@ -174,7 +174,7 @@ bool FontDefinitionTTF::initDefinition(const char *fontName, int fontSize, const return prepareLetterDefinitions(_textImages->getPages()); } -void FontDefinitionTTF::addLetterDefinition(LetterDefinition &defToAdd) +void FontDefinitionTTF::addLetterDefinition(FontLetterDefinition &defToAdd) { if (_fontLettersDefinitionUTF16.find(defToAdd.letteCharUTF16) == _fontLettersDefinitionUTF16.end()) { @@ -182,7 +182,7 @@ void FontDefinitionTTF::addLetterDefinition(LetterDefinition &defToAdd) } } -LetterDefinition & FontDefinitionTTF::getLetterDefinition(unsigned short int theLetter) +FontLetterDefinition & FontDefinitionTTF::getLetterDefinition(unsigned short int theLetter) { return _fontLettersDefinitionUTF16[theLetter]; } @@ -226,30 +226,17 @@ FontAtlas * FontDefinitionTTF::createFontAtlas() // set the common line height retAtlas->setCommonLineHeight(getCommonLineHeight() * 0.8); - // add all the letter definitions - std::map::iterator ITER; - for(ITER = _fontLettersDefinitionUTF16.begin(); ITER!=_fontLettersDefinitionUTF16.end(); ++ITER) + + for( auto &item: _fontLettersDefinitionUTF16 ) { - FontLetterDefinition tempDefinition; - tempDefinition.letteCharUTF16 = (*ITER).second.letteCharUTF16; - tempDefinition.validDefinition = (*ITER).second.validDefinition; - - if (tempDefinition.validDefinition) + if ( item.second.validDefinition ) { - tempDefinition.U = (*ITER).second.U; - tempDefinition.V = (*ITER).second.V; - tempDefinition.width = (*ITER).second.width; - tempDefinition.height = (*ITER).second.height; - // carloX not useed here tempDefinition.offsetX = (*ITER).second.offsetX; - tempDefinition.offsetX = 0; - tempDefinition.offsetY = (*ITER).second.offsetY; - tempDefinition.textureID = (*ITER).second.textureID; - tempDefinition.commonLineHeight = (*ITER).second.commonLineHeight; + FontLetterDefinition tempDefinition = item.second; + tempDefinition.offsetX = 0; tempDefinition.anchorX = 0.0f; tempDefinition.anchorY = 1.0f; retAtlas->addLetterDefinition(tempDefinition); } - } // done here diff --git a/cocos2dx/label_nodes/CCFontDefinition.h b/cocos2dx/label_nodes/CCFontDefinition.h index 99ee99d56d..3229b4b21a 100644 --- a/cocos2dx/label_nodes/CCFontDefinition.h +++ b/cocos2dx/label_nodes/CCFontDefinition.h @@ -31,23 +31,8 @@ NS_CC_BEGIN - #define DEFAULT_ATLAS_TEXTURE_SIZE 1024 -struct LetterDefinition -{ - unsigned short letteCharUTF16; - float U; - float V; - float width; - float height; - float offsetX; - float offsetY; - int textureID; - float commonLineHeight; - bool validDefinition; -}; - /** */ class CC_DLL FontDefinitionTTF : public Object @@ -55,7 +40,7 @@ class CC_DLL FontDefinitionTTF : public Object public: static FontDefinitionTTF* create(const char *fontName, int fontSize, const char *letters, int textureSize = DEFAULT_ATLAS_TEXTURE_SIZE); - LetterDefinition & getLetterDefinition(unsigned short int theLetter); + FontLetterDefinition & getLetterDefinition(unsigned short int theLetter); Texture2D * getTexture(int index); int getNumTextures(); Font * getFont() { return _textImages->getFont(); } @@ -69,11 +54,11 @@ private: bool initDefinition(const char *fontName, int fontSize, const char *letters, int textureSize); bool prepareLetterDefinitions(TextFontPagesDef *pageDefs); - void addLetterDefinition(LetterDefinition &defToAdd); + void addLetterDefinition(FontLetterDefinition &defToAdd); - TextImage * _textImages; - std::map _fontLettersDefinitionUTF16; - float _commonLineHeight; + TextImage * _textImages; + std::map _fontLettersDefinitionUTF16; + float _commonLineHeight; };