diff --git a/openVulkanoCpp/Host/MacOS/SystemFontResolver.cpp b/openVulkanoCpp/Host/MacOS/SystemFontResolver.cpp index f370d2c..b8d32c8 100644 --- a/openVulkanoCpp/Host/MacOS/SystemFontResolver.cpp +++ b/openVulkanoCpp/Host/MacOS/SystemFontResolver.cpp @@ -9,7 +9,7 @@ namespace OpenVulkano { - std::string SystemFontResolver::GetSystemFontPath(const std::string& fontName) + const std::string& SystemFontResolver::GetSystemFontPath(const std::string& fontName) { return ""; } diff --git a/openVulkanoCpp/Host/SystemFontResolver.hpp b/openVulkanoCpp/Host/SystemFontResolver.hpp index eb4c8b3..83dac87 100644 --- a/openVulkanoCpp/Host/SystemFontResolver.hpp +++ b/openVulkanoCpp/Host/SystemFontResolver.hpp @@ -14,7 +14,7 @@ namespace OpenVulkano class SystemFontResolver { public: - static std::string GetSystemFontPath(const std::string& fontName); + static const std::string& GetSystemFontPath(const std::string& fontName); private: static std::map ReadSystemFonts(); diff --git a/openVulkanoCpp/Host/Windows/SystemFontResolver.cpp b/openVulkanoCpp/Host/Windows/SystemFontResolver.cpp index 2d59940..a3e908f 100644 --- a/openVulkanoCpp/Host/Windows/SystemFontResolver.cpp +++ b/openVulkanoCpp/Host/Windows/SystemFontResolver.cpp @@ -5,6 +5,7 @@ */ #include "Host/SystemFontResolver.hpp" +#include "Base/Utils.hpp" #include #include @@ -12,12 +13,11 @@ namespace OpenVulkano { - std::string SystemFontResolver::GetSystemFontPath(const std::string& fontName) + const std::string& SystemFontResolver::GetSystemFontPath(const std::string& fontName) { // font name -> filename static std::map fontFileMapping = ReadSystemFonts(); - // maybe check everything in lower case ? so that we can use Arial/arial as input parameter - auto it = fontFileMapping.find(fontName); + auto it = fontFileMapping.find(Utils::ToLower(fontName)); return it == fontFileMapping.end() ? "" : it->second; } @@ -57,6 +57,7 @@ namespace OpenVulkano } } fontNameCropped.resize(realSize); + Utils::ToLower(fontNameCropped); fontFileMapping[std::move(fontNameCropped)] = fontFilename.path().string(); } } diff --git a/openVulkanoCpp/Scene/Text/FontAtlasFactory.cpp b/openVulkanoCpp/Scene/Text/FontAtlasFactory.cpp index a6f4ba2..5b60fbc 100644 --- a/openVulkanoCpp/Scene/Text/FontAtlasFactory.cpp +++ b/openVulkanoCpp/Scene/Text/FontAtlasFactory.cpp @@ -60,7 +60,7 @@ namespace OpenVulkano::Scene } FontAtlas::Ptr FontAtlasFactory::GetFontAtlas(const std::string& fontIdentifier, float ptSize, - std::optional subpixelLayout, + SubpixelLayout subpixelLayout, const std::set& charset) const { const auto& fontData = FindFont(fontIdentifier); @@ -71,7 +71,7 @@ namespace OpenVulkano::Scene } const std::set& setRef = (charset.empty() ? FontAtlasGeneratorBase::LoadAllGlyphs(fontData) : charset); - FontIdentifier id(fontIdentifier, setRef, subpixelLayout.value_or(SubpixelLayout::UNKNOWN), ptSize, + FontIdentifier id(fontIdentifier, setRef, subpixelLayout, ptSize, subpixelLayout ? FontAtlasType::BITMAP_SUBPIXEL : FontAtlasType::BITMAP); auto it = m_atlasesCache.find(id); @@ -88,19 +88,21 @@ namespace OpenVulkano::Scene Array FontAtlasFactory::FindFont(const std::string& fontIdentifier) const { - Array resource = ResourceLoader::GetInstance().GetResource(fontIdentifier); - if (resource.Empty()) + try { - if (!std::filesystem::exists(fontIdentifier)) - { - if (!m_allowSystemFonts) - { - return {}; - } - return Utils::ReadFile(SystemFontResolver::GetSystemFontPath(fontIdentifier)); - } - return Utils::ReadFile(fontIdentifier); + return ResourceLoader::GetInstance().GetResource(fontIdentifier); } - return resource; + catch (...) + { + } + if (!std::filesystem::exists(fontIdentifier)) + { + if (!m_allowSystemFonts) + { + return {}; + } + return Utils::ReadFile(SystemFontResolver::GetSystemFontPath(fontIdentifier), true); + } + return Utils::ReadFile(fontIdentifier); } } diff --git a/openVulkanoCpp/Scene/Text/FontAtlasFactory.hpp b/openVulkanoCpp/Scene/Text/FontAtlasFactory.hpp index 22a8e53..3759c2c 100644 --- a/openVulkanoCpp/Scene/Text/FontAtlasFactory.hpp +++ b/openVulkanoCpp/Scene/Text/FontAtlasFactory.hpp @@ -31,7 +31,7 @@ namespace OpenVulkano::Scene [[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, - std::optional subpixelLayout = std::nullopt, + SubpixelLayout subpixelLayout = SubpixelLayout::UNKNOWN, const std::set& charset = {}) const; private: