Added search path to osgText::readFontFile.
This commit is contained in:
@@ -16,18 +16,58 @@
|
||||
#include <osg/State>
|
||||
#include <osg/Notify>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osg/GLU>
|
||||
|
||||
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 \""<<str<<"\" not found."<<std::endl;
|
||||
return std::string();
|
||||
}
|
||||
|
||||
osgText::Font* osgText::readFontFile(const std::string& filename)
|
||||
{
|
||||
std::string foundFile = findFontFile(filename);
|
||||
if (foundFile.empty()) return 0;
|
||||
|
||||
osg::Object* object = osgDB::readObjectFile(filename);
|
||||
|
||||
|
||||
// if the object is a font then return it.
|
||||
osgText::Font* font = dynamic_cast<osgText::Font*>(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;
|
||||
|
||||
Reference in New Issue
Block a user