因为要在Linux下使用FreeType显示中 文,而FreeType需要UNICODE的字符,所以要把字符转成UNICODE。
1) 检查系统是哪种编码,我的系统是FC6,用命令locale显示本机当前编码格式:
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
2) 使用iconv转到UNICODE
void utf2unicode(char *in, wchar_t *out, int out_size)
{
iconv_t cd;
size_t in_len = (size_t)strlen(in);
memset(out, 0, out_size);
cd = iconv_open("UCS2", "UTF8");
iconv(cd, &in, &in_len, (char**)&out, (size_t*)&out_size);
iconv_close(cd);
}