From b871020222424db0fe69bb9f9c254e6500fccb45 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 3 Mar 2003 16:42:48 +0000 Subject: [PATCH] Added search path to osgText::readFontFile. --- src/osgText/Font.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 64cfa234f..b7947b8cc 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -16,18 +16,58 @@ #include #include #include +#include #include using namespace osgText; +std::string findFontFile(const std::string& str) +{ + // try looking in OSGFILEPATH etc first for fonts. + std::string filename = osgDB::findDataFile(str); + if (!filename.empty()) return std::string(filename); + + + static osgDB::FilePathList s_FontFilePath; + static bool initialized = false; + if (!initialized) + { + initialized = true; + #if defined(WIN32) + osgDB::Registry::convertStringPathIntoFilePathList( + ".;C:/winnt/fonts;C:/windows/fonts", + s_FontFilePath); + + char *ptr; + if ((ptr = getenv( "windir" ))) + { + s_FontFilePath.push_back(ptr); + } + #else + osgDB::Registry::convertStringPathIntoFilePathList( + ".:/usr/share/fonts/ttf:/usr/share/fonts/ttf/western:/usr/share/fonts/ttf/decoratives", + s_FontFilePath); + #endif + } + + filename = osgDB::findFileInPath(str,s_FontFilePath); + if (!filename.empty()) return filename; + + osg::notify(osg::WARN)<<"Warning: font file \""<(object); if (font) return font; - + // otherwise if the object has zero references then delete it by doing another unref(). if (object && object->referenceCount()==0) object->unref(); return 0;