OSGEarth支持中文方法

来源:互联网 发布:盛世的蝼蚁知乎 编辑:程序博客网 时间:2024/05/22 08:09

OSGEarth 支持中文需要修改osgearth的源码:
    主要影响到plcaeNode 及labelControl  
修改步骤如下:
一:在osgearth包下,StringUtil类中添加  字符转换方法:
   StringUtil.h头文件中添加:extern OSGEARTH_EXPORT wchar_t* str2wstr( std::string s );
StringUtil.cpp中添加实现:
     wchar_t*
osgEarth::str2wstr(std::string s)//ago change
{
setlocale(LC_ALL, "chs");
//int requiredSize = mbstowcs(NULL, s, 0)+1; 
int requiredSize = s.size() * 2 + 2;
wchar_t* wtext = new wchar_t[requiredSize + 1];
mbstowcs(wtext, s.c_str(), requiredSize + 1);
return wtext;
//setlocale(LC_ALL, "C");
}

二:修改AnnotationUtils::createTextDrawable函数(在osgearth::annoation包中)
 // t->setText( text, text_encoding );  修改为:
t->setText(osgEarth::str2wstr(text.c_str()));
三:修改
LabelControl::calcSize函数中  (880行左右)
// t->setText( _text, _encoding );  改为下面:
t->setText(osgEarth::str2wstr(_text.c_str()));  //修改中文支持

0 0