1
0
Fork 0

Splash screen: support text encoded in UTF-8

This fixes handling of non-ASCII splashscreen text for me (Debian
GNU/Linux). The XML input files don't technically *have* to be encoded
in UTF-8, as long as they properly declare the encoding and it is
supported by Expat. Of course, we prefer UTF-8 nowadays.

With this commit, startup tips and splash screen progress strings
("Loading scenery", "Initializing subsystems", etc.) can at last be
written correctly in languages that need non-ASCII characters.

The Expat doc is unfortunately unclear on its *output* encoding, saying
the following (expat.h):

  The characters are passed exactly as they were in the XML document
  except that they will be encoded in UTF-8 or UTF-16.

The only relevant header I can see in SimGear is
3rdparty/expat/sg_expat_external.h, which has interesting stuff around
XML_UNICODE, however it doesn't seem to take position.

I fear that whether UTF-8 or UTF-16 is used for Expat's output (and thus
for what easyxml.cxx gives us) depends on how it was compiled. Let's
hope everyone has it compiled for UTF-8 output...
This commit is contained in:
Florent Rougon 2017-05-08 15:22:33 +02:00
parent 33c54e5d76
commit 7f59846644

View file

@ -37,6 +37,7 @@
#include <osg/Version> #include <osg/Version>
#include <osgText/Text> #include <osgText/Text>
#include <osgText/String>
#include <osgDB/ReadFile> #include <osgDB/ReadFile>
#include <simgear/compiler.h> #include <simgear/compiler.h>
@ -348,7 +349,7 @@ void SplashScreen::addText(osg::Geode* geode ,
t->setFont(path.utf8Str()); t->setFont(path.utf8Str());
t->setColor(textColor); t->setColor(textColor);
t->setFontResolution(64, 64); t->setFontResolution(64, 64);
t->setText(text); t->setText(text, osgText::String::Encoding::ENCODING_UTF8);
t->setBackdropType(osgText::Text::OUTLINE); t->setBackdropType(osgText::Text::OUTLINE);
t->setBackdropColor(osg::Vec4(0.2, 0.2, 0.2, 1)); t->setBackdropColor(osg::Vec4(0.2, 0.2, 0.2, 1));
t->setBackdropOffset(0.04); t->setBackdropOffset(0.04);
@ -459,7 +460,9 @@ void SplashScreen::doUpdate()
for (const TextItem& item : _items) { for (const TextItem& item : _items) {
if (item.dynamicContent) { if (item.dynamicContent) {
item.textNode->setText(item.dynamicContent->getStringValue()); item.textNode->setText(
item.dynamicContent->getStringValue(),
osgText::String::Encoding::ENCODING_UTF8);
} }
} }
@ -526,7 +529,8 @@ void SplashScreen::updateText()
std::string tipText = locale->getLocalizedStringWithIndex("tip", "tips", tipIndex); std::string tipText = locale->getLocalizedStringWithIndex("tip", "tips", tipIndex);
// find the item to switch // find the item to switch
_items.front().textNode->setText(tipText); _items.front().textNode->setText(
tipText, osgText::String::Encoding::ENCODING_UTF8);
} }
} }