Projects > cpp > Issues > Bug #3110

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

使用自定义ttf字体失败

Bug #3110 [Closed]
whx_pro_fun 2013-11-04 09:29 . Updated over 8 years ago

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未执行到,导致设置字体资源不成功。

walzer@cocos2d-x.org 2014-10-08 02:48

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

Atom PDF

Status:Closed
Start date:2013-11-04
Priority:Low
Due date:
Assignee:-
% Done:

0%

Category:windows
Target version:-