From 7f59846644cfe234cf130db282934c23a1675de8 Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Mon, 8 May 2017 15:22:33 +0200 Subject: [PATCH] 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... --- src/Viewer/splash.cxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Viewer/splash.cxx b/src/Viewer/splash.cxx index bbc3ded09..a8b430dc6 100644 --- a/src/Viewer/splash.cxx +++ b/src/Viewer/splash.cxx @@ -37,6 +37,7 @@ #include #include +#include #include #include @@ -348,7 +349,7 @@ void SplashScreen::addText(osg::Geode* geode , t->setFont(path.utf8Str()); t->setColor(textColor); t->setFontResolution(64, 64); - t->setText(text); + t->setText(text, osgText::String::Encoding::ENCODING_UTF8); t->setBackdropType(osgText::Text::OUTLINE); t->setBackdropColor(osg::Vec4(0.2, 0.2, 0.2, 1)); t->setBackdropOffset(0.04); @@ -459,7 +460,9 @@ void SplashScreen::doUpdate() for (const TextItem& item : _items) { 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); // find the item to switch - _items.front().textNode->setText(tipText); + _items.front().textNode->setText( + tipText, osgText::String::Encoding::ENCODING_UTF8); } }