From 8926f5dd51fd65336a92f599112fb965fa2fe1f4 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Tue, 4 Feb 2025 22:17:40 +0100 Subject: [PATCH] Add global instance of font factory --- openVulkanoCpp/Scene/Text/FontAtlasFactory.cpp | 2 ++ openVulkanoCpp/Scene/Text/FontAtlasFactory.hpp | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/openVulkanoCpp/Scene/Text/FontAtlasFactory.cpp b/openVulkanoCpp/Scene/Text/FontAtlasFactory.cpp index a6b71fb..3d68dbb 100644 --- a/openVulkanoCpp/Scene/Text/FontAtlasFactory.cpp +++ b/openVulkanoCpp/Scene/Text/FontAtlasFactory.cpp @@ -14,6 +14,8 @@ namespace OpenVulkano::Scene { + FontAtlasFactory FontAtlasFactory::INSTANCE = FontAtlasFactory(); // Global factory + FontAtlasFactory::FontIdentifier::FontIdentifier(const std::string& font_, const std::set& charset, SubpixelLayout subpixelLayout_, float ptSize_, FontAtlasType atlasType_) diff --git a/openVulkanoCpp/Scene/Text/FontAtlasFactory.hpp b/openVulkanoCpp/Scene/Text/FontAtlasFactory.hpp index 7a0ef22..6ea11c2 100644 --- a/openVulkanoCpp/Scene/Text/FontAtlasFactory.hpp +++ b/openVulkanoCpp/Scene/Text/FontAtlasFactory.hpp @@ -26,19 +26,25 @@ namespace OpenVulkano::Scene float ptSize = 0; FontAtlasType atlasType; }; + + static FontAtlasFactory INSTANCE; + + const bool m_allowSystemFonts; + mutable std::map 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& charset = {}) const; + [[nodiscard]] FontAtlas::Ptr GetFontAtlas(const std::string& fontIdentifier, float ptSize, SubpixelLayout subpixelLayout = SubpixelLayout::UNKNOWN, const std::set& charset = {}) const; private: Array FindFont(const std::string& fontFile) const; - - private: - const bool m_allowSystemFonts; - mutable std::map m_atlasesCache; }; }