Panda3D
 All Classes Functions Variables Enumerations
fontPool.h
00001 // Filename: fontPool.h
00002 // Created by:  drose (31Jan03)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef FONTPOOL_H
00016 #define FONTPOOL_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "texture.h"
00021 #include "textFont.h"
00022 #include "filename.h"
00023 #include "lightMutex.h"
00024 #include "pmap.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : FontPool
00028 // Description : This is the preferred interface for loading fonts for
00029 //               the TextNode system.  It is similar to ModelPool and
00030 //               TexturePool in that it unifies references to the same
00031 //               filename.
00032 ////////////////////////////////////////////////////////////////////
00033 class EXPCL_PANDA_TEXT FontPool {
00034 PUBLISHED:
00035   // These functions take string parameters instead of Filenames
00036   // because the parameters may not be entirely an actual filename:
00037   // they may be a filename followed by a face index.
00038 
00039   INLINE static bool has_font(const string &filename);
00040   INLINE static bool verify_font(const string &filename);
00041   BLOCKING INLINE static TextFont *load_font(const string &filename);
00042   INLINE static void add_font(const string &filename, TextFont *font);
00043   INLINE static void release_font(const string &filename);
00044   INLINE static void release_all_fonts();
00045 
00046   INLINE static int garbage_collect();
00047 
00048   INLINE static void list_contents(ostream &out);
00049   static void write(ostream &out);
00050 
00051 private:
00052   INLINE FontPool();
00053 
00054   bool ns_has_font(const string &str);
00055   TextFont *ns_load_font(const string &str);
00056   void ns_add_font(const string &str, TextFont *font);
00057   void ns_release_font(const string &str);
00058   void ns_release_all_fonts();
00059   int ns_garbage_collect();
00060   void ns_list_contents(ostream &out) const;
00061 
00062   static void lookup_filename(const string &str, string &index_str,
00063                               Filename &filename, int &face_index);
00064 
00065   static FontPool *get_ptr();
00066   static FontPool *_global_ptr;
00067 
00068   LightMutex _lock;
00069   typedef pmap<string,  PT(TextFont) > Fonts;
00070   Fonts _fonts;
00071 };
00072 
00073 #include "fontPool.I"
00074 
00075 #endif
 All Classes Functions Variables Enumerations