#include #include "FontProvider.hh" template<> std::unique_ptr Singleton::instance{nullptr}; template<> std::once_flag Singleton::instance_flag{}; FontProvider::FontProvider() { } TTF_Font *FontProvider::getFont(std::string const& name, unsigned ptsize) { auto key = make_tuple(name, ptsize); auto it = fontCache_.find(key); if (it == fontCache_.end()) { TTFFontUPtr font{TTF_OpenFont(name.c_str(), ptsize)}; if (!font) throw TTFException{}; std::tie(it, std::ignore) = fontCache_.insert(make_pair(key, std::move(font))); } return it->second.get(); } void FontProvider::cleanup() { fontCache_.clear(); }