From f0119ef62f7e9aa58337bbc4562d16bd99d11a12 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Fri, 7 Mar 2014 12:03:45 +0800 Subject: [PATCH] fixed horizontal kerning is incorrect. --- cocos/2d/CCFontFreeType.cpp | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 28c771f84f..5713238a88 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -162,24 +162,26 @@ FontAtlas * FontFreeType::createFontAtlas() int * FontFreeType::getHorizontalKerningForTextUTF16(unsigned short *text, int &outNumLetters) const { - if (!text) - return 0; + if (!text || !_fontRef) + return nullptr; outNumLetters = cc_wcslen(text); if (!outNumLetters) - return 0; + return nullptr; int *sizes = new int[outNumLetters]; if (!sizes) - return 0; - - for (int c = 0; c < outNumLetters; ++c) + return nullptr; + memset(sizes,0,outNumLetters * sizeof(int)); + + bool hasKerning = FT_HAS_KERNING( _fontRef ) != 0; + if (hasKerning) { - if (c < (outNumLetters-1)) - sizes[c] = getHorizontalKerningForChars(text[c], text[c+1]); - else - sizes[c] = 0; + for (int c = 1; c < outNumLetters; ++c) + { + sizes[c] = getHorizontalKerningForChars(text[c-1], text[c]); + } } return sizes; @@ -187,14 +189,6 @@ int * FontFreeType::getHorizontalKerningForTextUTF16(unsigned short *text, int & int FontFreeType::getHorizontalKerningForChars(unsigned short firstChar, unsigned short secondChar) const { - if (!_fontRef) - return 0; - - bool hasKerning = FT_HAS_KERNING( _fontRef ) != 0; - - if (!hasKerning) - return 0; - // get the ID to the char we need int glyphIndex1 = FT_Get_Char_Index(_fontRef, firstChar);