Load GUI from XML
This commit is contained in:
32
FontProvider.cc
Normal file
32
FontProvider.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <mutex>
|
||||
|
||||
#include "FontProvider.hh"
|
||||
|
||||
template<>
|
||||
std::unique_ptr<FontProvider> Singleton<FontProvider>::instance{nullptr};
|
||||
template<>
|
||||
std::once_flag Singleton<FontProvider>::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();
|
||||
}
|
||||
Reference in New Issue
Block a user