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

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

 

原因: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

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值