26 FontPool *FontPool::_global_ptr =
nullptr;
32 write(std::ostream &out) {
33 get_ptr()->ns_list_contents(out);
40 ns_has_font(
const string &str) {
46 lookup_filename(str, index_str, filename, face_index);
48 Fonts::const_iterator ti;
49 ti = _fonts.find(index_str);
50 if (ti != _fonts.end()) {
62 ns_load_font(
const string &str) {
66 lookup_filename(str, index_str, filename, face_index);
71 Fonts::const_iterator ti;
72 ti = _fonts.find(index_str);
73 if (ti != _fonts.end()) {
80 <<
"Loading font " << filename <<
"\n";
88 if (extension.empty() || extension ==
"egg" || extension ==
"bam") {
90 PT(
PandaNode) node = model_loader->load_sync(filename);
91 if (node !=
nullptr) {
109 if (font ==
nullptr || !font->is_valid()) {
112 font =
new DynamicTextFont(filename, face_index);
116 if (font ==
nullptr || !font->is_valid()) {
126 Fonts::const_iterator ti;
127 ti = _fonts.find(index_str);
128 if (ti != _fonts.end()) {
133 _fonts[index_str] = font;
143 ns_add_font(
const string &str,
TextFont *font) {
149 lookup_filename(str, index_str, filename, face_index);
152 _fonts[index_str] = font;
159 ns_release_font(
const string &str) {
165 lookup_filename(str, index_str, filename, face_index);
168 ti = _fonts.find(index_str);
169 if (ti != _fonts.end()) {
178 ns_release_all_fonts() {
188 ns_garbage_collect() {
191 int num_released = 0;
195 for (ti = _fonts.begin(); ti != _fonts.end(); ++ti) {
198 if (text_cat.is_debug()) {
200 <<
"Releasing " << (*ti).first <<
"\n";
204 new_set.insert(new_set.end(), *ti);
208 _fonts.swap(new_set);
216 ns_list_contents(std::ostream &out)
const {
219 out << _fonts.size() <<
" fonts:\n";
220 Fonts::const_iterator ti;
221 for (ti = _fonts.begin(); ti != _fonts.end(); ++ti) {
223 out <<
" " << (*ti).first
237 lookup_filename(
const string &str,
string &index_str,
238 Filename &filename,
int &face_index) {
239 int colon = (int)str.length() - 1;
241 while (colon >= 0 && isdigit(str[colon])) {
244 if (colon >= 0 && str[colon] ==
':') {
245 string digits = str.substr(colon + 1);
246 filename = str.substr(0, colon);
247 face_index = atoi(digits.c_str());
257 std::ostringstream strm;
258 strm << filename <<
":" << face_index;
259 index_str = strm.str();
268 if (_global_ptr ==
nullptr) {
The name of a file, such as a texture file or an Egg file.
std::string get_extension() const
Returns the file extension.
This is the preferred interface for loading fonts for the TextNode system.
static void write(std::ostream &out)
Lists the contents of the font pool to the indicated output stream.
Similar to MutexHolder, but for a light mutex.
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
static Loader * get_global_ptr()
Returns a pointer to the global Loader.
A basic node of the scene graph or data graph.
get_ref_count
Returns the current reference count.
A StaticTextFont is loaded up from a model that was previously generated via egg-mkfont,...
An encapsulation of a font; i.e.
A hierarchy of directories and files that appears to be one continuous file system,...
bool resolve_filename(Filename &filename, const DSearchPath &searchpath, const std::string &default_extension=std::string()) const
Searches the given search path for the filename.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.