Add global instance of font factory

This commit is contained in:
Georg Hagen
2025-02-04 22:17:40 +01:00
parent a8d4946751
commit 8926f5dd51
2 changed files with 13 additions and 5 deletions

View File

@@ -14,6 +14,8 @@
namespace OpenVulkano::Scene
{
FontAtlasFactory FontAtlasFactory::INSTANCE = FontAtlasFactory(); // Global factory
FontAtlasFactory::FontIdentifier::FontIdentifier(const std::string& font_, const std::set<uint32_t>& charset,
SubpixelLayout subpixelLayout_, float ptSize_,
FontAtlasType atlasType_)

View File

@@ -26,19 +26,25 @@ namespace OpenVulkano::Scene
float ptSize = 0;
FontAtlasType atlasType;
};
static FontAtlasFactory INSTANCE;
const bool m_allowSystemFonts;
mutable std::map<FontIdentifier, FontAtlas::Ptr> m_atlasesCache;
public:
FontAtlasFactory(bool allowSystemFonts = true) : m_allowSystemFonts(allowSystemFonts) {}
static FontAtlasFactory& GetInstance() { return INSTANCE; }
FontAtlasFactory(const bool allowSystemFonts = true) : m_allowSystemFonts(allowSystemFonts) {}
[[nodiscard]] FontAtlas::Ptr GetFontAtlasScalable(const std::string& fontIdentifier, bool msdf = true,
const std::set<uint32_t>& charset = {}) const;
[[nodiscard]] FontAtlas::Ptr GetFontAtlas(const std::string& fontIdentifier, float ptSize,
SubpixelLayout subpixelLayout = SubpixelLayout::UNKNOWN,
const std::set<uint32_t>& charset = {}) const;
private:
Array<char> FindFont(const std::string& fontFile) const;
private:
const bool m_allowSystemFonts;
mutable std::map<FontIdentifier, FontAtlas::Ptr> m_atlasesCache;
};
}