How to render Chinese characters on Android platform

Hello cocos2d-x comrades,

I’m a guy from WeiFang China and also a beginner in cocos2d-x. Now one of my puzzles is around Chinese characters rendering on android. In win32 case, I’ve got the following method which I think is ENOUGH:

@ std::string menuItemStr = “新局”;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
GBKToUTF8(menuItemStr,“gb2312”,“utf-8”);//调用字符转换函数
#endif
CCLabelTTF* lblNew = CCLabelTTF::create(menuItemStr.c_str(),“Marker Felt”, 24);
@

However, when I shift above code to android, Chinese characters cannot be displayed, with only some messed stuff. I surfed the web, but found no satisfying answers. So, I come again here for help.

My idea is try to find a good way that works both on Win32 case and on android platform, one of the reasons being that win32 debugging is rather faster than android, as well as more convinient. Hence, I tried to use the below coding under WIN32:

CCLabelBMFont* pLabel = CCLabelBMFont::create("中国", "fonts/bitmapFontChinese.fnt");

And also, I put the two files, bitmapFontChinese.fnt and bitmapFontChinese.png, under the folder fonts which lies under the folder Resources. However, when I run the above code under win32 case, “Assertion failed!” is still thrown out, as shown in the attached .jpg file. When I pressed “Retry” to track the debugging, the code stopped at the following position:

@
unsigned int key = c;
HASH_FIND_INT(m_pConfiguration->m_pFontDefDictionary, &key, element);
CCAssert(element, “FontDefinition could not be found!”);

@
NOTE: the above code is in function void CCLabelBMFont::createFontChars()
. So, does it means I put the above two files at the wrong sites? Am I wrong in some other related cases?

Expect your quick help. And thanks in advance.

regards,

googleman


assertionfail.jpg (55.2 KB)


assertionfail.jpg (55.2 KB)

Hi,

I’ve just run the demo testcpp on Win32 and everything run OK — the LabelTest can render perfect

Chinese characters with the following code:

@
CCLabelTTF *pLable = CCLabelTTF::create(“中国”, “Marker Felt”, 30);
@

And also OK:

@
CCSize size = CCDirector::sharedDirector()>getWinSize;
CCLabelBMFont* pLable = CCLabelBMFont::create;
pLable
>setPosition(ccp(size.width / 2, size.height /2));
this->addChild(pLable);

@

So, where am I wrong as described in my first submission? Long to give some hint.

regards,

Hi,

Now, I can make success in the following forms of code:

@
CCDictionary strings = CCDictionary::createWithContentsOfFile;
const char
chinese = ((CCString**)strings~~>objectForKey)>m_sString.c_str;
const charjapanese = ((CCString)strings
>objectForKey)>m_sString.c_str;
const char**spanish = ((CCString*)strings
>objectForKey)~~>m_sString.c_str();

CCSize s = CCDirector::sharedDirector()>getWinSize;
CCLabelBMFont **label1 = CCLabelBMFont::create;
addChild;
label1
>setPosition);
CCLabelBMFont *label2 = CCLabelBMFont::create;
addChild;
label2~~>setPosition);
CCLabelBMFont**label3 = CCLabelBMFont::create;
addChild;
label3~~>setPosition(ccp(s.width/2, s.height/4*1));

@

Now, my puzzle is still around the cases covered in the first submission. Could anyone lend me some help?