Panda3D
fontPool.I
1 // Filename: fontPool.I
2 // Created by: drose (31Jan03)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: FontPool::has_font
18 // Access: Public, Static
19 // Description: Returns true if the font has ever been loaded,
20 // false otherwise.
21 ////////////////////////////////////////////////////////////////////
22 INLINE bool FontPool::
23 has_font(const string &filename) {
24  return get_ptr()->ns_has_font(filename);
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: FontPool::verify_font
29 // Access: Public, Static
30 // Description: Loads the given filename up into a font, if it has
31 // not already been loaded, and returns true to indicate
32 // success, or false to indicate failure. If this
33 // returns true, it is guaranteed that a subsequent call
34 // to load_font() with the same font name will
35 // return a valid Font pointer.
36 ////////////////////////////////////////////////////////////////////
37 INLINE bool FontPool::
38 verify_font(const string &filename) {
39  return load_font(filename) != (TextFont *)NULL;
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: FontPool::load_font
44 // Access: Public, Static
45 // Description: Loads the given filename up into a font, if it has
46 // not already been loaded, and returns the new font.
47 // If a font with the same filename was previously
48 // loaded, returns that one instead. If the font
49 // file cannot be found, returns NULL.
50 ////////////////////////////////////////////////////////////////////
51 INLINE TextFont *FontPool::
52 load_font(const string &filename) {
53  return get_ptr()->ns_load_font(filename);
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: FontPool::add_font
58 // Access: Public, Static
59 // Description: Adds the indicated already-loaded font to the
60 // pool. The font will always replace any
61 // previously-loaded font in the pool that had the
62 // same filename.
63 ////////////////////////////////////////////////////////////////////
64 INLINE void FontPool::
65 add_font(const string &filename, TextFont *font) {
66  get_ptr()->ns_add_font(filename, font);
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: FontPool::release_font
71 // Access: Public, Static
72 // Description: Removes the indicated font from the pool,
73 // indicating it will never be loaded again; the font
74 // may then be freed. If this function is never called,
75 // a reference count will be maintained on every font
76 // every loaded, and fonts will never be freed.
77 ////////////////////////////////////////////////////////////////////
78 INLINE void FontPool::
79 release_font(const string &filename) {
80  get_ptr()->ns_release_font(filename);
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: FontPool::release_all_fonts
85 // Access: Public, Static
86 // Description: Releases all fonts in the pool and restores the
87 // pool to the empty state.
88 ////////////////////////////////////////////////////////////////////
89 INLINE void FontPool::
91  get_ptr()->ns_release_all_fonts();
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: FontPool::garbage_collect
96 // Access: Public, Static
97 // Description: Releases only those fonts in the pool that have a
98 // reference count of exactly 1; i.e. only those
99 // fonts that are not being used outside of the pool.
100 // Returns the number of fonts released.
101 ////////////////////////////////////////////////////////////////////
102 INLINE int FontPool::
104  return get_ptr()->ns_garbage_collect();
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: FontPool::list_contents
109 // Access: Public, Static
110 // Description: Lists the contents of the font pool to the
111 // indicated output stream.
112 ////////////////////////////////////////////////////////////////////
113 INLINE void FontPool::
114 list_contents(ostream &out) {
115  get_ptr()->ns_list_contents(out);
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: FontPool::Constructor
120 // Access: Private
121 // Description: The constructor is not intended to be called
122 // directly; there's only supposed to be one FontPool
123 // in the universe and it constructs itself.
124 ////////////////////////////////////////////////////////////////////
125 INLINE FontPool::
126 FontPool() {
127 }
static void add_font(const string &filename, TextFont *font)
Adds the indicated already-loaded font to the pool.
Definition: fontPool.I:65
static int garbage_collect()
Releases only those fonts in the pool that have a reference count of exactly 1; i.e.
Definition: fontPool.I:103
static void list_contents(ostream &out)
Lists the contents of the font pool to the indicated output stream.
Definition: fontPool.I:114
static bool has_font(const string &filename)
Returns true if the font has ever been loaded, false otherwise.
Definition: fontPool.I:23
An encapsulation of a font; i.e.
Definition: textFont.h:36
static void release_all_fonts()
Releases all fonts in the pool and restores the pool to the empty state.
Definition: fontPool.I:90
static TextFont * load_font(const string &filename)
Loads the given filename up into a font, if it has not already been loaded, and returns the new font...
Definition: fontPool.I:52
static void release_font(const string &filename)
Removes the indicated font from the pool, indicating it will never be loaded again; the font may then...
Definition: fontPool.I:79
static 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 indic...
Definition: fontPool.I:38