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