pcsms_YV05bkic 发表于 2019-3-13 21:28:31

osgEarth earthfile 加载汉字lable问题

本帖最后由 pcsms_YV05bkic 于 2019-3-13 21:30 编辑

osgEarth 代码显示汉字问题可以设置Encoing 为UTF-8解决,但是earth file Style样式文件中text-encoing:utf-8不起作用,为何,如何解决?

yxuef 发表于 2019-3-13 21:52:11

//中文字体设置
osg::ref_ptr<osgText::Font> font = osgText::readFontFile("Fonts/msyh.ttc");

//2. 设置标题
LabelControl* title = new LabelControl("ViewPoint", 14, osg::Vec4f(1, 1, 0, 1));
title->setEncoding(osgText::String::ENCODING_UTF8);
title->setFont(font.get());
title->setText(unicodeToUTF8(L"信息"));

3. 转换函数
string unicodeToUTF8(const wstring &src)
{
        string result = "";
        int n = WideCharToMultiByte(CP_UTF8, 0, src.c_str(), -1, 0, 0, 0, 0);
        result.resize(n);
        ::WideCharToMultiByte(CP_UTF8, 0, src.c_str(), -1, (char*)result.c_str(), (int)result.length(), 0, 0);
        return result;
}

4. 哦啦.

pcsms_YV05bkic 发表于 2019-3-13 21:57:58

本帖最后由 pcsms_YV05bkic 于 2019-3-13 22:04 编辑

yxuef 发表于 2019-3-13 21:52
//中文字体设置
osg::ref_ptr font = osgText::readFontFile("Fonts/msyh.ttc");



你好,这是代码加载,我的意思earthfile中遇到加载中文字体shapefile如何解决!

<style type="text/css">            
                cities {
                  icon:         "../data/downarrow.png";
                  icon-placement: centroid;
                  icon-declutter: true;
                  icon-align:   center-bottom;
                  text-content:   ;
                  text-encoding:utf-8;
                  text-font:      "Fonts/msyh.ttc"
                  text-priority:;
                  text-align:   center-bottom;
                  text-halo:      #1f1f1f;
                  text-size:      6+2*;
                }   
            </style>

不起作用!

pcsms_YV05bkic 发表于 2019-3-14 17:09:05

本帖最后由 pcsms_YV05bkic 于 2019-3-14 17:10 编辑

通过修改并编译源代码解决了,也许不是最好的解决办法,谢谢!

mingming8world 发表于 2019-9-8 01:21:11

pcsms_YV05bkic 发表于 2019-3-14 17:09
通过修改并编译源代码解决了,也许不是最好的解决办法,谢谢!

请问怎么解决的?能把编译好的分享吗?

liyihongcug 发表于 2020-4-13 19:21:03

遇到同羊问题
页: [1]
查看完整版本: osgEarth earthfile 加载汉字lable问题