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

@@ -16,11 +16,67 @@
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <iostream>
#include <iostream>
#include <streambuf>
#include <locale>
#include <cstdio>
template<typename _CharT, typename _Traits = std::char_traits<_CharT> >
class proxy_basic_streambuf : public std::basic_streambuf<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
proxy_basic_streambuf(unsigned int numChars):
_numChars(numChars) {}
/// Destructor deallocates no buffer space.
virtual ~proxy_basic_streambuf() {}
unsigned int _numChars;
protected:
virtual int_type overflow (int_type __c = traits_type::eof())
{
if (_numChars==0)
{
putchar('E');
return traits_type::eof();
}
if (__c == traits_type::eof()) return '\n'; traits_type::not_eof(__c);
//putchar('');
--_numChars;
return putchar(__c);
}
};
typedef proxy_basic_streambuf<char> proxy_streambuf;
int main( int argc, char **argv )
{
std::ifstream fin("GNUmakefile");
std::istream& ins = fin;
proxy_streambuf mystreambuf(100);
std::cout.rdbuf(&mystreambuf);
while (!fin.eof())
{
std::cout.put(fin.get());
}
std::cout<<"Exiting normally "<<std::endl;
std::cout.rdbuf(0);
/*
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv);
@@ -151,7 +207,7 @@ int main( int argc, char **argv )
}
*/
return 0;
}

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);