Add FontResolver

This commit is contained in:
Georg Hagen
2025-11-22 20:33:11 +01:00
parent 79b5bbf165
commit b6f2e2e16e
4 changed files with 68 additions and 24 deletions

View File

@@ -7,7 +7,7 @@
#include "FontAtlasFactory.hpp"
#include "SdfFontAtlasGenerator.hpp"
#include "BitmapFontAtlasGenerator.hpp"
#include "Host/SystemFontResolver.hpp"
#include "Host/FontResolver.hpp"
#include "Base/Logger.hpp"
#include "Host/ResourceLoader.hpp"
#include <utility>
@@ -45,7 +45,7 @@ namespace OpenVulkano::Scene
return atlas;
}
const auto& fontData = FindFont(fontIdentifier);
const auto& fontData = FontResolver::GetFontData(fontIdentifier, m_allowSystemFonts);
if (fontData.Empty())
{
Logger::DATA->warn("Could not find font {}", fontIdentifier);
@@ -82,7 +82,7 @@ namespace OpenVulkano::Scene
return it->second;
}
const auto& fontData = FindFont(fontIdentifier);
const auto& fontData = FontResolver::GetFontData(fontIdentifier, m_allowSystemFonts);
if (fontData.Empty())
{
Logger::DATA->warn("Could not find font {}", fontIdentifier);
@@ -95,22 +95,4 @@ namespace OpenVulkano::Scene
if (charset.empty()) m_atlasesCache.emplace(id, bitmapGen.GetAtlas());
return bitmapGen.GetAtlas();
}
Array<char> FontAtlasFactory::FindFont(const std::string& fontIdentifier) const
{
Array<char> resource = ResourceLoader::GetInstance().GetResource(fontIdentifier);
if (resource.Empty())
{
if (!std::filesystem::exists(fontIdentifier))
{
if (!m_allowSystemFonts)
{
return {};
}
return Utils::ReadFile(SystemFontResolver::GetSystemFontPath(fontIdentifier), true);
}
return Utils::ReadFile(fontIdentifier);
}
return resource;
}
}