Removed the font cache from the FreeType plugin, moving the support across to

osgDB::Registry.
This commit is contained in:
Robert Osfield
2004-11-02 11:10:44 +00:00
parent 5d49c88240
commit 2718058173
4 changed files with 71 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ FreeTypeLibrary::FreeTypeLibrary()
FreeTypeLibrary::~FreeTypeLibrary()
{
#ifdef USE_LOCAL_CACHE
// need to remove the implementations from the Fonts here
// just in case the Fonts continue to have external references
// to them, otherwise they will try to point to an object thats
@@ -38,6 +39,7 @@ FreeTypeLibrary::~FreeTypeLibrary()
osgText::Font* font = itr->second.get();
font->setImplementation(0);
}
#endif
FT_Done_FreeType( _ftlibrary);
}
@@ -51,8 +53,10 @@ FreeTypeLibrary* FreeTypeLibrary::instance()
osgText::Font* FreeTypeLibrary::getFont(const std::string& fontfile,unsigned int index)
{
#ifdef USE_LOCAL_CACHE
FontMap::iterator itr = _fontMap.find(fontfile);
if (itr!=_fontMap.end()) return itr->second.get();
#endif
FT_Face face; /* handle to face object */
FT_Error error = FT_New_Face( _ftlibrary, fontfile.c_str(), index, &face );
@@ -71,7 +75,10 @@ osgText::Font* FreeTypeLibrary::getFont(const std::string& fontfile,unsigned int
FreeTypeFont* fontImp = new FreeTypeFont(fontfile,face);
osgText::Font* font = new osgText::Font(fontImp);
#ifdef USE_LOCAL_CACHE
_fontMap[fontfile]=font;
#endif
return font;

View File

@@ -17,6 +17,8 @@
#include "FreeTypeFont.h"
#include <osgText/Font>
//#define USE_LOCAL_CACHE
class FreeTypeLibrary
{
public:
@@ -39,7 +41,10 @@ protected:
FT_Library _ftlibrary;
#ifdef USE_LOCAL_CACHE
FontMap _fontMap;
#endif
};

View File

@@ -67,7 +67,7 @@ osgText::Font* osgText::readFontFile(const std::string& filename)
std::string foundFile = findFontFile(filename);
if (foundFile.empty()) return 0;
osg::Object* object = osgDB::readObjectFile(foundFile);
osg::Object* object = osgDB::readObjectFile(foundFile, osgDB::Registry::CACHE_OBJECTS);
// if the object is a font then return it.
osgText::Font* font = dynamic_cast<osgText::Font*>(object);