refactoring
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
std::string SystemFontResolver::GetSystemFontPath(const std::string& fontName)
|
||||
const std::string& SystemFontResolver::GetSystemFontPath(const std::string& fontName)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -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<std::string, std::string> ReadSystemFonts();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "Host/SystemFontResolver.hpp"
|
||||
#include "Base/Utils.hpp"
|
||||
#include <Windows.h>
|
||||
#include <filesystem>
|
||||
|
||||
@@ -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<std::string, std::string> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
|
||||
FontAtlas::Ptr FontAtlasFactory::GetFontAtlas(const std::string& fontIdentifier, float ptSize,
|
||||
std::optional<SubpixelLayout> subpixelLayout,
|
||||
SubpixelLayout subpixelLayout,
|
||||
const std::set<uint32_t>& charset) const
|
||||
{
|
||||
const auto& fontData = FindFont(fontIdentifier);
|
||||
@@ -71,7 +71,7 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
|
||||
const std::set<uint32_t>& 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<char> FontAtlasFactory::FindFont(const std::string& fontIdentifier) const
|
||||
{
|
||||
Array<char> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenVulkano::Scene
|
||||
[[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,
|
||||
std::optional<SubpixelLayout> subpixelLayout = std::nullopt,
|
||||
SubpixelLayout subpixelLayout = SubpixelLayout::UNKNOWN,
|
||||
const std::set<uint32_t>& charset = {}) const;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user