Label:Fixed create fail if the font(TTF) not contain a Unicode charmap.

This commit is contained in:
WenhaiLin 2015-07-10 14:39:21 +08:00
parent 268605270e
commit 81bc0b09da
2 changed files with 22 additions and 2 deletions

View File

@ -137,9 +137,28 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
if (FT_New_Memory_Face(getFTLibrary(), s_cacheFontData[fontName].data.getBytes(), s_cacheFontData[fontName].data.getSize(), 0, &face ))
return false;
//we want to use unicode
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE))
return false;
{
int foundIndex = -1;
for (int charmapIndex = 0; charmapIndex < face->num_charmaps; charmapIndex++)
{
if (face->charmaps[charmapIndex]->encoding != FT_ENCODING_NONE)
{
foundIndex = charmapIndex;
break;
}
}
if (foundIndex == -1)
{
return false;
}
if (FT_Select_Charmap(face, face->charmaps[foundIndex]->encoding))
{
return false;
}
}
// set the requested font size
int dpi = 72;

View File

@ -481,6 +481,7 @@ void Label::setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false *
if (_fontAtlas)
{
_batchNodes.clear();
FontAtlasCache::releaseFontAtlas(_fontAtlas);
_fontAtlas = nullptr;
}