Panda3D

Static Public Member Functions | List of all members
FontPool Class Reference

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

`#include "fontPool.h"`

## Static Public Member Functions
static void | add_font (const std::string &filename, TextFont *font)
| Adds the indicated already-loaded font to the pool. More...
static int | garbage_collect ()
| Releases only those fonts in the pool that have a reference count of exactly 1; i.e. More...
static bool | has_font (const std::string &filename)
| Returns true if the font has ever been loaded, false otherwise. More...
static void | list_contents (std::ostream &out)
| Lists the contents of the font pool to the indicated output stream. More...
static TextFont * | load_font (const std::string &filename)
| Loads the given filename up into a font, if it has not already been loaded, and returns the new font. More...
static void | release_all_fonts ()
| Releases all fonts in the pool and restores the pool to the empty state. More...
static void | release_font (const std::string &filename)
| Removes the indicated font from the pool, indicating it will never be loaded again; the font may then be freed. More...
static bool | verify_font (const std::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. More...
static void | write (std::ostream &out)
| Lists the contents of the font pool to the indicated output stream. More...

## 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 30 of file fontPool.h.

## Member Function Documentation

## ◆ add_font()

void FontPool::add_font | ( | const std::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 48 of file fontPool.I.

## ◆ 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 77 of file fontPool.I.

## ◆ has_font()

bool FontPool::has_font | ( | const std::string & | filename | ) |
| inline static

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

Definition at line 17 of file fontPool.I.

## ◆ list_contents()

void FontPool::list_contents | ( | std::ostream & | out | ) |
| inline static

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

Definition at line 85 of file fontPool.I.

## ◆ load_font()

TextFont * FontPool::load_font | ( | const std::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 39 of file fontPool.I.

## ◆ release_all_fonts()

void FontPool::release_all_fonts | ( |  | ) |
| inline static

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

Definition at line 67 of file fontPool.I.

## ◆ release_font()

void FontPool::release_font | ( | const std::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 59 of file fontPool.I.

## ◆ verify_font()

bool FontPool::verify_font | ( | const std::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 28 of file fontPool.I.

## ◆ write()

void FontPool::write | ( | std::ostream & | out | ) |
| static

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

Definition at line 31 of file fontPool.cxx.

The documentation for this class was generated from the following files:

- panda/src/text/fontPool.h
- panda/src/text/fontPool.cxx
- panda/src/text/fontPool.I