diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 166ec788a9..6327d1cc31 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -130,8 +130,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) Rect tempRect; - FontLetterDefinition tempDef; - tempDef.offsetX = 0; + FontLetterDefinition tempDef; tempDef.anchorX = 0.0f; tempDef.anchorY = 1.0f; @@ -143,7 +142,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) tempDef.width = 0; tempDef.height = 0; tempDef.U = 0; - tempDef.V = 0; + tempDef.V = 0; + tempDef.offsetX = 0; tempDef.offsetY = 0; tempDef.textureID = 0; } @@ -152,7 +152,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) tempDef.validDefinition = true; tempDef.letteCharUTF16 = utf16String[i]; tempDef.width = tempRect.size.width + _letterPadding; - tempDef.height = _currentPageLineHeight - 1; + tempDef.height = _currentPageLineHeight - 1; + tempDef.offsetX = tempRect.origin.x; tempDef.offsetY = tempRect.origin.y; tempDef.commonLineHeight = _currentPageLineHeight; diff --git a/cocos/2d/CCFontDefinition.cpp b/cocos/2d/CCFontDefinition.cpp index 7fd10d86a1..ebb79f3172 100644 --- a/cocos/2d/CCFontDefinition.cpp +++ b/cocos/2d/CCFontDefinition.cpp @@ -222,7 +222,6 @@ FontAtlas * FontDefinitionTTF::createFontAtlas() if ( item.second.validDefinition ) { FontLetterDefinition tempDefinition = item.second; - tempDefinition.offsetX = 0; tempDefinition.anchorX = 0.0f; tempDefinition.anchorY = 1.0f; retAtlas->addLetterDefinition(tempDefinition); diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 915a333a48..c503611b71 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -176,7 +176,7 @@ bool FontFreeType::getBBOXFotChar(unsigned short theChar, Rect &outRect) const return false; // store result in the passed rectangle - outRect.origin.x = 0; + outRect.origin.x = _fontRef->glyph->metrics.horiBearingX >> 6; outRect.origin.y = - (_fontRef->glyph->metrics.horiBearingY >> 6); outRect.size.width = (_fontRef->glyph->metrics.width >> 6); outRect.size.height = (_fontRef->glyph->metrics.height >> 6); @@ -268,7 +268,7 @@ Size * FontFreeType::getAdvancesForTextUTF16(unsigned short *text, int &outNumLe int advance = 0; int kerning = 0; - advance = getAdvanceForChar(text[c]) - getBearingXForChar(text[c]); + advance = getAdvanceForChar(text[c]); if (c < (outNumLetters-1)) kerning = getHorizontalKerningForChars(text[c], text[c+1]); @@ -295,7 +295,7 @@ int FontFreeType::getAdvanceForChar(unsigned short theChar) const return 0; // get to the advance for this glyph - return (static_cast(_fontRef->glyph->advance.x >> 6)); + return (static_cast(_fontRef->glyph->metrics.horiAdvance >> 6)); } int FontFreeType::getBearingXForChar(unsigned short theChar) const