57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#include "FontsManager.h"
|
|
|
|
#ifdef HAS_FREETYPE
|
|
#include "FreeTypeFontEngine.h"
|
|
#else
|
|
#include "BasicFontEngine.h"
|
|
#endif
|
|
|
|
#include "FontGlyph.h"
|
|
|
|
FontsManager::FontsManager()
|
|
{
|
|
#ifdef HAS_FREETYPE
|
|
mFontEngine = std::make_unique<FreeTypeFontEngine>();
|
|
mUsesGlyphs = true;
|
|
#else
|
|
mFontEngine = std::make_unique<BasicFontEngine>();
|
|
#endif
|
|
mFontEngine->initialize();
|
|
}
|
|
|
|
std::unique_ptr<FontsManager> FontsManager::Create()
|
|
{
|
|
return std::make_unique<FontsManager>();
|
|
}
|
|
|
|
bool FontsManager::usesGlyphs() const
|
|
{
|
|
return mUsesGlyphs;
|
|
}
|
|
|
|
IFontEngine* FontsManager::getFontEngine() const
|
|
{
|
|
return mFontEngine.get();
|
|
}
|
|
|
|
FontGlyph* FontsManager::getGlyph(const std::string&, float size, uint32_t c)
|
|
{
|
|
auto path = std::filesystem::path("truetype/liberation/LiberationSans-Regular.ttf");
|
|
|
|
mFontEngine->loadFontFace(path, size);
|
|
|
|
auto iter = mGlyphs.find(c);
|
|
if(iter != mGlyphs.end())
|
|
{
|
|
return iter->second.get();
|
|
}
|
|
else
|
|
{
|
|
auto glyph = mFontEngine->loadGlyph(c);
|
|
auto glyph_ptr = glyph.get();
|
|
mGlyphs[c] = std::move(glyph);
|
|
return glyph_ptr;
|
|
}
|
|
}
|
|
|
|
|