osgText: improve code to search aircraft directory for font

This commit is contained in:
Jonathan Redpath 2021-12-22 14:41:35 +00:00 committed by Automatic Release Builder
parent a3bdfab17b
commit af0f7676c4

View File

@ -16,23 +16,27 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#ifdef HAVE_CONFIG_H
#include <simgear_config.h>
#endif
#include <cstdio>
#include "SGText.hxx"
#include <simgear/math/SGMath.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/strutils.hxx>
#include <osg/Geode>
#include <osg/MatrixTransform>
#include <osgText/Text>
#include <osgText/Font>
#include <simgear/misc/ResourceManager.hxx>
#include <simgear/math/SGMath.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/strutils.hxx>
#include <simgear/scene/material/Effect.hxx>
#include <simgear/scene/material/EffectGeode.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <simgear/debug/ErrorReportingCallback.hxx>
using std::string;
class SGText::UpdateCallback : public osg::NodeCallback {
@ -95,9 +99,15 @@ osg::Node * SGText::appendText(const SGPropertyNode* configNode,
osg::Geode * g = new osg::Geode;
g->addDrawable( text );
SGPath path("Fonts" );
path.append( configNode->getStringValue( "font", "Helvetica" ));
text->setFont( path.utf8Str() );
const std::string requestedFont = configNode->getStringValue("font","Helvetica");
const SGPath fontPath = simgear::ResourceManager::instance()->findPath("Fonts/" + requestedFont);
if ( !fontPath.isNull() ) {
text->setFont( fontPath.utf8Str() );
} else {
simgear::reportFailure(simgear::LoadFailure::NotFound,
simgear::ErrorCode::LoadingTexture,
"SGText: couldn;t find font:" + requestedFont);
}
text->setCharacterSize(configNode->getDoubleValue("character-size", 1.0 ),
configNode->getDoubleValue("character-aspect-ratio", 1.0 ));