|
- inline std::wstring s2ws(const std::string& s)
- {
- setlocale(LC_ALL, "chs");
- const char* _Source = s.c_str();
- size_t _Dsize = s.size() + 1;
- wchar_t *_Dest = new wchar_t[_Dsize];
- wmemset(_Dest, 0, _Dsize);
- mbstowcs(_Dest,_Source,_Dsize);
- std::wstring result = _Dest;
- delete []_Dest;
- setlocale(LC_ALL, "C");
- return result;
- }
复制代码
- osgWidget::Label* CLegend::createLabel(const std::string& l, unsigned int size)
- {
- osgWidget::Label* label = new osgWidget::Label("", "");
- label->setFont("fonts/simhei.ttf");
- label->setFontSize(size);
- label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-
- std::wstring wstr = s2ws(l);
- osgText::String showntext(wstr.c_str());
- label->setLabel(showntext);
- label->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
- label->addSize(10.0f, 5.0f);
- label->setPadding(5);
- label->setPadLeft(10);
- label->setColor(1.0f, 0.5f, 0.0f, 0.0f);
- return label;
- }
复制代码
在我的机器上,中文能够正常显示。换一台一模一样的电脑,中文不显示。
求教原因。
|
|