关于cocos2dx 在wp8 中 如何显示中文

来源:互联网 发布:mac平台 编辑:程序博客网 时间:2024/05/22 01:29

效果如下:

在项目中 因为遇到 非英文字符不显示问题,于是各种查资料,网上说的方法大多是转码,而且是在 win32平台下实现的,关于winphone 8上显示中文的资料很少,这里我耗费了很多时间,只是因为粗心大意没有看到 labeltest里边的一句话注释::



注释中说 需要自己下载字体然后 显示,但是下载后仍然显示 ,然后就想到了转码,这里之所以想到转码是,我在win32下面已经经过转码显示出来了中文! 实验之后成功显示! 做个小记:转码的方法有很多种,這里提供两种可以参考!

char* G2U(const char* gb2312)
{
int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
wchar_t* wstr = new wchar_t[len + 1];
memset(wstr, 0, len + 1);
MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
char* str = new char[len + 1];
memset(str, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
if (wstr) delete[] wstr;
return str;
}


inline string GB2312ToUTF8(const char* pStrGB2312) {
string out = "";
// to wide char
int nStrLen = MultiByteToWideChar(936, 0, pStrGB2312, -1, NULL, 0);
wchar_t* pWStr = new wchar_t[nStrLen + 1];
memset(pWStr, 0, nStrLen + 1);
MultiByteToWideChar(936, 0, pStrGB2312, -1, pWStr, nStrLen);


// to utf-8  
nStrLen = WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, NULL, 0, NULL, NULL);
char* pStr = new char[nStrLen + 1];
memset(pStr, 0, nStrLen + 1);
WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, pStr, nStrLen, NULL, NULL);
if (pWStr) {
delete[] pWStr;
}
if (pStr) {
out = pStr;
delete[] pStr;
}
return out;
}

0 0
原创粉丝点击