diff --git a/panda/src/text/dynamicTextFont.cxx b/panda/src/text/dynamicTextFont.cxx index 0e3b1afd63..0e6a59233d 100644 --- a/panda/src/text/dynamicTextFont.cxx +++ b/panda/src/text/dynamicTextFont.cxx @@ -22,6 +22,8 @@ #include "config_text.h" #include "config_util.h" +#include "config_express.h" +#include "virtualFileSystem.h" bool DynamicTextFont::_update_cleared_glyphs = text_update_cleared_glyphs; @@ -84,18 +86,33 @@ DynamicTextFont(const Filename &font_filename, int face_index) { return; } + bool exists = false; + int error; Filename path(font_filename); - path.resolve_filename(get_model_path()); - if (!path.exists()) { + if (use_vfs) { + VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); + vfs->resolve_filename(path, get_model_path()); + exists = vfs->read_file(path, _raw_font_data); + if (exists) { + error = FT_New_Memory_Face(_ft_library, + (const FT_Byte *)_raw_font_data.data(), + _raw_font_data.length(), + face_index, &_face); + } + } else { + path.resolve_filename(get_model_path()); + exists = path.exists(); + if (exists) { + string os_specific = path.to_os_specific(); + error = FT_New_Face(_ft_library, os_specific.c_str(), + face_index, &_face); + } + } + + if (!exists) { text_cat.error() << "Unable to find font file " << font_filename << "\n"; } else { - string os_specific = path.to_os_specific(); - - int error = FT_New_Face(_ft_library, - os_specific.c_str(), - face_index, - &_face); if (error == FT_Err_Unknown_File_Format) { text_cat.error() << "Unable to read font " << font_filename << ": unknown file format.\n"; diff --git a/panda/src/text/dynamicTextFont.h b/panda/src/text/dynamicTextFont.h index 2fd4effdc8..a381714e83 100644 --- a/panda/src/text/dynamicTextFont.h +++ b/panda/src/text/dynamicTextFont.h @@ -137,6 +137,11 @@ private: FT_Face _face; + // This string is used to hold the data read from the font file in + // vfs mode. Since the FreeType library keeps pointers into this + // data, we have to keep it around. + string _raw_font_data; + static FT_Library _ft_library; static bool _ft_initialized; static bool _ft_ok;