`
huozheleisi
  • 浏览: 1237197 次
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

很多人问我如何显示汉字,总是一个一个地说,很麻烦,特此写在这里——

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

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

本文采用第二种方法。

效果两个:

1 楷体



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

2微软雅黑字体

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

关键代码:



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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics