home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / FontHandler.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-06  |  1.0 KB  |  50 lines

  1. #include "FontHandler.h"
  2.  
  3. #include "Tokenizer.h"
  4. #include "log.h"
  5.  
  6. // init of static members
  7. std::vector<texFontRefCounterPair_t> FontHandler::fonts;
  8.  
  9. texFont_t* FontHandler::getFont(const char* filename){
  10.  
  11.     std::vector<texFontRefCounterPair_t>::iterator i;
  12.     for(i=fonts.begin();i<fonts.end();i++){
  13.         if(i->first->filename!=NULL && streq(filename, i->first->filename)){
  14.             i->second++;
  15.             return i->first;
  16.         }
  17.     }
  18.  
  19.     texFont_t* f=::loadFont(filename);
  20.     if(f==NULL)
  21.         return NULL;
  22.  
  23.     texFontRefCounterPair_t p(f, 1);
  24.     fonts.push_back(p);
  25.  
  26.     return f;
  27. }
  28.  
  29. int FontHandler::getNumFonts(){
  30.     return fonts.size();
  31. }
  32.  
  33. void FontHandler::releaseFont(texFont_t* font){
  34.     if(font==NULL)
  35.         return;
  36.  
  37.     std::vector<texFontRefCounterPair_t>::iterator i;
  38.     for(i=fonts.begin();i<fonts.end();i++){
  39.         if(i->first==font){
  40.             i->second--;
  41.             if(i->second==0){
  42. //                log("FontHandler::releaseFont(): Font '%s' not referenced any more (I'll delete it).\n", i->first->filename);
  43.                 freeFont(i->first);
  44.                 fonts.erase(i);
  45.             }
  46.         }
  47.     }
  48. }
  49.  
  50.