Font::Font(GlyphWidth glyph_width_, const std::string& filename, int shadowsize_) : glyph_width(glyph_width_), glyph_surfaces(), shadow_surfaces(), char_height(), shadowsize(shadowsize_), glyphs(65536) { for(unsigned int i=0; i<65536;i++) glyphs[i].surface_idx = -1; const std::string fontdir = FileSystem::dirname(filename); const std::string fontname = FileSystem::basename(filename); // scan for prefix-filename in addons search path char **rc = PHYSFS_enumerateFiles(fontdir.c_str()); for (char **i = rc; *i != NULL; i++) { std::string filename(*i); if( filename.rfind(fontname) != std::string::npos ) { loadFontFile(fontdir + filename); } } PHYSFS_freeList(rc); }
std::shared_ptr<std::vector<unsigned char>> FontManager::getFontData( const std::string& fileName) { std::shared_ptr<std::vector<unsigned char>> outPtr; auto it = m_fontData.find(fileName); //The font data is currently in the vector, check if it is still valid and grab it if it is. if(it != m_fontData.end()) { outPtr = it->second.lock(); } //The font data needs reloaded. if(!outPtr) { outPtr = loadFontFile(fileName); if(it != m_fontData.end()) { it->second = std::weak_ptr<std::vector<unsigned char>>(outPtr); } else { m_fontData.emplace(fileName, std::weak_ptr<std::vector<unsigned char>>(outPtr)); } } return outPtr; }