Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

FontPool Class Reference

This is the preferred interface for loading fonts for the TextNode system. More...

#include <fontPool.h>

List of all members.

Static Public Member Functions

bool has_font (const string &filename)
 Returns true if the font has ever been loaded, false otherwise.

bool verify_font (const string &filename)
 Loads the given filename up into a font, if it has not already been loaded, and returns true to indicate success, or false to indicate failure.

TextFontload_font (const string &filename)
 Loads the given filename up into a font, if it has not already been loaded, and returns the new font.

void add_font (const string &filename, TextFont *font)
 Adds the indicated already-loaded font to the pool.

void release_font (const string &filename)
 Removes the indicated font from the pool, indicating it will never be loaded again; the font may then be freed.

void release_all_fonts ()
 Releases all fonts in the pool and restores the pool to the empty state.

int garbage_collect ()
 Releases only those fonts in the pool that have a reference count of exactly 1; i.e.

void list_contents (ostream &out)
 Lists the contents of the font pool to the indicated output stream.


Private Types

typedef pmap< string, PT(TextFontFonts )

Private Member Functions

 FontPool ()
 The constructor is not intended to be called directly; there's only supposed to be one FontPool in the universe and it constructs itself.

bool ns_has_font (const string &str)
 The nonstatic implementation of has_font().

TextFontns_load_font (const string &str)
 The nonstatic implementation of load_font().

void ns_add_font (const string &filename, TextFont *font)
 The nonstatic implementation of add_font().

void ns_release_font (const string &filename)
 The nonstatic implementation of release_font().

void ns_release_all_fonts ()
 The nonstatic implementation of release_all_fonts().

int ns_garbage_collect ()
 The nonstatic implementation of garbage_collect().

void ns_list_contents (ostream &out)
 The nonstatic implementation of list_contents().


Static Private Member Functions

void lookup_filename (const string &str, Filename &filename, int &face_index)
 Accepts a font "filename", which might consist of a filename followed by an optional colon and a face index, and splits it out into its two components.

FontPool * get_ptr ()
 Initializes and/or returns the global pointer to the one FontPool object in the system.


Private Attributes

Fonts _fonts

Static Private Attributes

FontPool * _global_ptr = (FontPool *)NULL


Detailed Description

This is the preferred interface for loading fonts for the TextNode system.

It is similar to ModelPool and TexturePool in that it unifies references to the same filename.

Definition at line 46 of file fontPool.h.


Member Typedef Documentation

typedef pmap<string, PT(TextFont) FontPool::Fonts) [private]
 

Definition at line 79 of file fontPool.h.


Constructor & Destructor Documentation

FontPool::FontPool  )  [inline, private]
 

The constructor is not intended to be called directly; there's only supposed to be one FontPool in the universe and it constructs itself.

Definition at line 184 of file fontPool.I.


Member Function Documentation

void FontPool::add_font const string &  filename,
TextFont font
[inline, static]
 

Adds the indicated already-loaded font to the pool.

The font will always replace any previously-loaded font in the pool that had the same filename.

Definition at line 97 of file fontPool.I.

References get_ptr(), INLINE, and ns_garbage_collect().

int FontPool::garbage_collect  )  [inline, static]
 

Releases only those fonts in the pool that have a reference count of exactly 1; i.e.

only those fonts that are not being used outside of the pool. Returns the number of fonts released.

Definition at line 152 of file fontPool.I.

FontPool * FontPool::get_ptr  )  [static, private]
 

Initializes and/or returns the global pointer to the one FontPool object in the system.

Definition at line 264 of file fontPool.cxx.

Referenced by add_font(), load_font(), and release_font().

bool FontPool::has_font const string &  filename  )  [inline, static]
 

Returns true if the font has ever been loaded, false otherwise.

Definition at line 34 of file fontPool.I.

References INLINE, load_font(), and NULL.

void FontPool::list_contents ostream &  out  )  [inline, static]
 

Lists the contents of the font pool to the indicated output stream.

Definition at line 167 of file fontPool.I.

TextFont * FontPool::load_font const string &  filename  )  [inline, static]
 

Loads the given filename up into a font, if it has not already been loaded, and returns the new font.

If a font with the same filename was previously loaded, returns that one instead. If the font file cannot be found, returns NULL.

Definition at line 78 of file fontPool.I.

References get_ptr(), INLINE, and ns_release_font().

Referenced by has_font().

void FontPool::lookup_filename const string &  str,
Filename filename,
int &  face_index
[static, private]
 

Accepts a font "filename", which might consist of a filename followed by an optional colon and a face index, and splits it out into its two components.

Then it looks up the filename on the model path. Sets the filename and face index accordingly.

Definition at line 226 of file fontPool.cxx.

References _global_ptr, and NULL.

void FontPool::ns_add_font const string &  filename,
TextFont font
[private]
 

The nonstatic implementation of add_font().

Definition at line 124 of file fontPool.cxx.

References _fonts.

int FontPool::ns_garbage_collect  )  [private]
 

The nonstatic implementation of garbage_collect().

Definition at line 168 of file fontPool.cxx.

References _fonts, and ReferenceCount::get_ref_count().

Referenced by add_font().

bool FontPool::ns_has_font const string &  str  )  [private]
 

The nonstatic implementation of has_font().

Definition at line 42 of file fontPool.cxx.

void FontPool::ns_list_contents ostream &  out  )  [private]
 

The nonstatic implementation of list_contents().

Definition at line 199 of file fontPool.cxx.

Referenced by release_font().

TextFont * FontPool::ns_load_font const string &  str  )  [private]
 

The nonstatic implementation of load_font().

Definition at line 66 of file fontPool.cxx.

void FontPool::ns_release_all_fonts  )  [private]
 

The nonstatic implementation of release_all_fonts().

Definition at line 155 of file fontPool.cxx.

void FontPool::ns_release_font const string &  filename  )  [private]
 

The nonstatic implementation of release_font().

Definition at line 138 of file fontPool.cxx.

References _fonts.

Referenced by load_font().

void FontPool::release_all_fonts  )  [inline, static]
 

Releases all fonts in the pool and restores the pool to the empty state.

Definition at line 133 of file fontPool.I.

void FontPool::release_font const string &  filename  )  [inline, static]
 

Removes the indicated font from the pool, indicating it will never be loaded again; the font may then be freed.

If this function is never called, a reference count will be maintained on every font every loaded, and fonts will never be freed.

Definition at line 118 of file fontPool.I.

References get_ptr(), and ns_list_contents().

bool FontPool::verify_font const string &  filename  )  [inline, static]
 

Loads the given filename up into a font, if it has not already been loaded, and returns true to indicate success, or false to indicate failure.

If this returns true, it is guaranteed that a subsequent call to load_font() with the same font name will return a valid Font pointer.

Definition at line 57 of file fontPool.I.


Member Data Documentation

Fonts FontPool::_fonts [private]
 

Definition at line 80 of file fontPool.h.

Referenced by ns_add_font(), ns_garbage_collect(), and ns_release_font().

FontPool * FontPool::_global_ptr = (FontPool *)NULL [static, private]
 

Definition at line 29 of file fontPool.cxx.

Referenced by lookup_filename().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:50:43 2003 for Panda by doxygen1.3