我想在Qt中使用FTGL(FreeType2的包装器)在OGL中显示文本。我有unicode的问题 - > FTGL必须有实际渲染char的charcode,才能从truetype字体中获取字形,这在例如以下字符之一时会出现问题:'Zażółćgęśląjaźń'。
你有任何想法,为什么这个代码:
const unsigned char *string=(const unsigned char*)"POCZUJ GĘŚLĄ JAŹŃ";
// for multibyte - we can't rely on sizeof(T) == character
FTUnicodeStringItr<T> ustr(string);
for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++)
{
unsigned int thisChar = *ustr++;
unsigned int nextChar = *ustr;
if(CheckGlyph(thisChar))
{
position += glyphList->Render(thisChar, nextChar,
position, renderMode);
}
}
在Visual中工作,但在Qt中没有(它没有得到正确的字符代码,所以显示括号)?
FTUnicodeStringItr模板如下所示:http://www.nopaste.pl/11xt 感谢。
答案 0 :(得分:0)
您遇到的问题是,C / C ++在源代码中并不真正支持Unicode /宽字符。要正确完成,您必须通过\uXXXX
转义序列(如果编译器支持这些)指定unicode字符,或者通过\xXX\xXX
序列从头开始构建代码点。 Visual C ++具有广泛的字符支持(原因很简单,Windows中的所有字符串操作都是以宽字符完成的 - 不要将其与Unicode代码点混淆!)。
我建议您执行以下操作:Qt内置了国际化支持。归结为通过tr(...)
辅助函数/宏以默认语言(即英文字符串)定义字符串。然后,Qt Linguist可用于创建替换规则,这些规则通过tr(...)
的使用来应用,并且在完全支持Unicode的情况下执行此操作。