It is indeed not working in the current Cocos2d-x-versions, but someone posted a fix for it. Original post was http://www.cocos2d-x.org/forums/6/topics/37224 but due to the forum upgrade you’ll get a 404. So, I don’t know who to credit. Anyway, here is the fix…
unsigned char* CCFreeTypeFont::loadSystemFont(const char *pFontName, unsigned long *size)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
//Froxul: Add the ability to use system fonts on WP8 and WinRT
//http://www.cocos2d-x.org/forums/6/topics/37224
std::string fontName(pFontName);
if (fontName.find(".ttf") == -1) fontName += ".ttf";
std::string fontPath = "C:\\Windows\\Fonts\\" + fontName;
return CCFileUtils::sharedFileUtils()->getFileData(fontPath.c_str(), "rb", size);
#else
As you can see, I’ve also added WINRT-platform, since systemfonts were also not being loaded on windows 8 by the code in the #else-block. Basically the CCFreeTypeFont::loadSystemFont-function could be replaced by the above 4 lines.
I added these four line code into my project, return ..getFileData really works, returned a pointer not NULL.
But any font of Arial, SimSun even Microsoft YaHei can’t be rasterized well. Latin characters can be rendered well, but Chinese character not.
I use the Yu Gothic-font for Japanese translation. For Chinese you can choose between DengXian for Simplified, Microsoft Mhei for Traditional on WP8. You should use the name of the ttf-file: DengXian.ttf or MSMHei.ttf. I just checked it on my phone and Chinese text was shown correct without any invalid character “squares”.
This is works really. Awesome!
I find my bug is in CCFreeTypeFont::initWithString. cocos’s default font is Helvetica, when this kind of font load fail, Arial is loaded, not any font I set. So I need to intercept Arial before it’s loaded.
Thank you so much @froxul