您的位置:首页 > 运维架构

OpenInventor中文字符的显示和解决方法

2011-06-10 08:51 447 查看
很多人问我如何显示汉字,总是一个一个地说,很麻烦,特此写在这里——

原因:OpenInventor支持Freetype字体,但汉字采用Unicode编码,故而无法直接正确显示

解决:使用Freetype字体,或者,将Unicode编码转换为Freetype可以识别的字体(使用内置的Freetype引擎)

本文采用第二种方法。

效果两个:
1 楷体




2 微软雅黑 字体



关键代码:
SoSeparator *textSep = new SoSeparator;
 textSep->ref();

 SoFont *fontType = new SoFont;
 fontType->name = "Times New Roman : Italic";
 //fontType->name = "微软雅黑.ttf";
 fontType->name = "SIMKAI.TTF";
 fontType->size = 30;
 textSep->addChild(fontType);

 // Chinese text
 const wchar_t *str = L"Open Inventor程序设计从入门到精通";

 SoText2 *textProp = new SoText2;
 textProp->justification = SoText2::CENTER;
 textProp->string.setValue(str);
 textSep->addChild(textProp);

 // Build up
 root->addChild(textSep);

工程编辑的时候可能会出现错误:

error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall SoMFString::setValue(unsigned short const *)

这是因为 wchar_t 的问题,解决:

工程属性 C/C++语言 将……视为内置类型 yes

http://blog.sina.com.cn/s/blog_3fd731da0100s10z.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: