26FontPool *FontPool::_global_ptr =
nullptr;
32write(std::ostream &out) {
33 get_ptr()->ns_list_contents(out);
40ns_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()) {
62ns_load_font(
const string &str) {
66 lookup_filename(str, index_str, filename, face_index);
69 LightMutexHolder holder(_lock);
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) {
104 font =
new StaticTextFont(node);
109 if (font ==
nullptr || !font->is_valid()) {
112 font =
new DynamicTextFont(filename, face_index);
116 if (font ==
nullptr || !font->is_valid()) {
123 LightMutexHolder holder(_lock);
126 Fonts::const_iterator ti;
127 ti = _fonts.find(index_str);
128 if (ti != _fonts.end()) {
133 _fonts[index_str] = font;
143ns_add_font(
const string &str,
TextFont *font) {
144 LightMutexHolder holder(_lock);
149 lookup_filename(str, index_str, filename, face_index);
152 _fonts[index_str] = font;
159ns_release_font(
const string &str) {
160 LightMutexHolder holder(_lock);
165 lookup_filename(str, index_str, filename, face_index);
168 ti = _fonts.find(index_str);
169 if (ti != _fonts.end()) {
178ns_release_all_fonts() {
179 LightMutexHolder holder(_lock);
188ns_garbage_collect() {
189 LightMutexHolder holder(_lock);
191 int num_released = 0;
195 for (ti = _fonts.begin(); ti != _fonts.end(); ++ti) {
196 TextFont *font = (*ti).second;
198 if (text_cat.is_debug()) {
200 <<
"Releasing " << (*ti).first <<
"\n";
204 new_set.insert(new_set.end(), *ti);
208 _fonts.swap(new_set);
216ns_list_contents(std::ostream &out)
const {
217 LightMutexHolder holder(_lock);
219 out << _fonts.size() <<
" fonts:\n";
220 Fonts::const_iterator ti;
221 for (ti = _fonts.begin(); ti != _fonts.end(); ++ti) {
222 TextFont *font = (*ti).second;
223 out <<
" " << (*ti).first
237lookup_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) {
269 _global_ptr =
new FontPool;
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.
static Loader * get_global_ptr()
Returns a pointer to the global Loader.
get_ref_count
Returns the current reference count.
An encapsulation of a font; i.e.
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.