From 25f66995da870ce3182b0c7a9237e10ce19f5d86 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 | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/simgear/scene/model/SGText.cxx b/simgear/scene/model/SGText.cxx index 870164fa..8493eec2 100644 --- a/simgear/scene/model/SGText.cxx +++ b/simgear/scene/model/SGText.cxx @@ -16,25 +16,26 @@ // 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 +#include using std::string; @@ -105,9 +106,15 @@ osg::Node * SGText::appendText(const SGPropertyNode* configNode, if (effect) g->setEffect(effect); - SGPath path("Fonts" ); - path.append( configNode->getStringValue( "font", "Helvetica" )); - text->setFont( path.utf8Str() ); + const auto 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 ));