We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.
使用自定义ttf字体失败
使用自定义ttf字体失败
Bug #3110 [Closed]
Redmine issue system is closed, we are using github issue system instead.
This issue was moved to https://github.com/cocos2d/cocos2d-x/issues/8248
Status: | Closed | |
---|---|---|
Start date: | 2013-11-04 | |
Priority: | Low | |
Due date: | ||
Assignee: | - | |
% Done: | 0% |
|
Category: | windows | |
Target version: | - |
CCLabelTTF* pLabelTT = CCLabelTTF::create(“Hello World”, “fonts/Schwarzwald Regular.ttf”, 24);
如果上面代码是工程中第一此使用字体的代码,则设置字体会失败,会使用默认字体显示Hello World。windows平台测试。win32平台上产生问题的具体原因是由于:
CCImage.cpp中setFont函数中如下代码
// delete old font
if (m_hFont != hDefFont)
{
DeleteObject(m_hFont);
// release old font register
if (m_curFontPath.size() > 0)
{
wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath);
if (pwszBuffer)
{
if(RemoveFontResource(pwszBuffer))
{
SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
}
delete [] pwszBuffer;
pwszBuffer = NULL;
}
}
if (fontPath.size() > 0)
m_curFontPath = fontPath;
else
m_curFontPath.clear();
// register temp font
if (m_curFontPath.size() > 0)
{
wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath);
if (pwszBuffer)
{
if(AddFontResource(pwszBuffer))
{
SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
}
delete [] pwszBuffer;
pwszBuffer = NULL;
}
}
}
当第一次设置字体时,AddFontResource未执行到,导致设置字体资源不成功。