From af0f7676c461c453a097c7e92bb4aa020e91f20f Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Wed, 22 Dec 2021 14:41:35 +0000 Subject: [PATCH] osgText: improve code to search aircraft directory for font --- simgear/scene/model/SGText.cxx | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/simgear/scene/model/SGText.cxx b/simgear/scene/model/SGText.cxx index 21fc0c8f..76f38eda 100644 --- a/simgear/scene/model/SGText.cxx +++ b/simgear/scene/model/SGText.cxx @@ -16,23 +16,27 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include #include "SGText.hxx" -#include -#include -#include #include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include + 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 ));