fixed horizontal kerning is incorrect.

This commit is contained in:
Dhilan007 2014-03-07 12:03:45 +08:00
Родитель 063bde51c3
Коммит f0119ef62f
1 изменённых файлов: 12 добавлений и 18 удалений

Просмотреть файл

@ -162,24 +162,26 @@ FontAtlas * FontFreeType::createFontAtlas()
int * FontFreeType::getHorizontalKerningForTextUTF16(unsigned short *text, int &outNumLetters) const int * FontFreeType::getHorizontalKerningForTextUTF16(unsigned short *text, int &outNumLetters) const
{ {
if (!text) if (!text || !_fontRef)
return 0; return nullptr;
outNumLetters = cc_wcslen(text); outNumLetters = cc_wcslen(text);
if (!outNumLetters) if (!outNumLetters)
return 0; return nullptr;
int *sizes = new int[outNumLetters]; int *sizes = new int[outNumLetters];
if (!sizes) if (!sizes)
return 0; return nullptr;
memset(sizes,0,outNumLetters * sizeof(int));
for (int c = 0; c < outNumLetters; ++c)
bool hasKerning = FT_HAS_KERNING( _fontRef ) != 0;
if (hasKerning)
{ {
if (c < (outNumLetters-1)) for (int c = 1; c < outNumLetters; ++c)
sizes[c] = getHorizontalKerningForChars(text[c], text[c+1]); {
else sizes[c] = getHorizontalKerningForChars(text[c-1], text[c]);
sizes[c] = 0; }
} }
return sizes; return sizes;
@ -187,14 +189,6 @@ int * FontFreeType::getHorizontalKerningForTextUTF16(unsigned short *text, int &
int FontFreeType::getHorizontalKerningForChars(unsigned short firstChar, unsigned short secondChar) const 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 // get the ID to the char we need
int glyphIndex1 = FT_Get_Char_Index(_fontRef, firstChar); int glyphIndex1 = FT_Get_Char_Index(_fontRef, firstChar);