16 #include "staticTextFont.h" 17 #include "dynamicTextFont.h" 18 #include "config_util.h" 19 #include "config_express.h" 20 #include "virtualFileSystem.h" 23 #include "lightMutexHolder.h" 35 get_ptr()->ns_list_contents(out);
44 ns_has_font(
const string &str) {
50 lookup_filename(str, index_str, filename, face_index);
52 Fonts::const_iterator ti;
53 ti = _fonts.find(index_str);
54 if (ti != _fonts.end()) {
68 ns_load_font(
const string &str) {
72 lookup_filename(str, index_str, filename, face_index);
77 Fonts::const_iterator ti;
78 ti = _fonts.find(index_str);
79 if (ti != _fonts.end()) {
86 <<
"Loading font " << filename <<
"\n";
94 if (extension.empty() || extension ==
"egg" || extension ==
"bam") {
96 PT(
PandaNode) node = model_loader->load_sync(filename);
118 font =
new DynamicTextFont(filename, face_index);
132 Fonts::const_iterator ti;
133 ti = _fonts.find(index_str);
134 if (ti != _fonts.end()) {
139 _fonts[index_str] = font;
151 ns_add_font(
const string &str,
TextFont *font) {
157 lookup_filename(str, index_str, filename, face_index);
160 _fonts[index_str] = font;
169 ns_release_font(
const string &str) {
175 lookup_filename(str, index_str, filename, face_index);
178 ti = _fonts.find(index_str);
179 if (ti != _fonts.end()) {
190 ns_release_all_fonts() {
202 ns_garbage_collect() {
205 int num_released = 0;
209 for (ti = _fonts.begin(); ti != _fonts.end(); ++ti) {
212 if (text_cat.is_debug()) {
214 <<
"Releasing " << (*ti).first <<
"\n";
218 new_set.insert(new_set.end(), *ti);
222 _fonts.swap(new_set);
232 ns_list_contents(ostream &out)
const {
235 out << _fonts.size() <<
" fonts:\n";
236 Fonts::const_iterator ti;
237 for (ti = _fonts.begin(); ti != _fonts.end(); ++ti) {
239 out <<
" " << (*ti).first
258 lookup_filename(
const string &str,
string &index_str,
259 Filename &filename,
int &face_index) {
260 int colon = (int)str.length() - 1;
262 while (colon >= 0 && isdigit(str[colon])) {
265 if (colon >= 0 && str[colon] ==
':') {
266 string digits = str.substr(colon + 1);
267 filename = str.substr(0, colon);
268 face_index = atoi(digits.c_str());
279 strm << filename <<
":" << face_index;
280 index_str = strm.str();
291 if (_global_ptr == (
FontPool *)NULL) {
A basic node of the scene graph or data graph.
bool resolve_filename(Filename &filename, const DSearchPath &searchpath, const string &default_extension=string()) const
Searches the given search path for the filename.
This is the preferred interface for loading fonts for the TextNode system.
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
static void write(ostream &out)
Lists the contents of the font pool to the indicated output stream.
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
string get_extension() const
Returns the file extension.
An encapsulation of a font; i.e.
A StaticTextFont is loaded up from a model that was previously generated via egg-mkfont, and contains all of its glyphs already generated and available for use.
static Loader * get_global_ptr()
Returns a pointer to the global Loader.
The name of a file, such as a texture file or an Egg file.
Similar to MutexHolder, but for a light mutex.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
bool is_valid() const
Returns true if the font is valid and ready to use, false otherwise.
int get_ref_count() const
Returns the current reference count.