Update SystemFontResolver to std::filesystem::path
This commit is contained in:
@@ -37,16 +37,19 @@ namespace
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
const std::string& SystemFontResolver::GetSystemFontPath(const std::string& fontName)
|
||||
namespace
|
||||
{
|
||||
// font name -> filename
|
||||
static std::map<std::string, std::string> fontFileMapping = ReadSystemFonts();
|
||||
static std::string fallbackString;
|
||||
auto it = fontFileMapping.find(Utils::ToLower(fontName));
|
||||
return it == fontFileMapping.end() ? fallbackString : it->second;
|
||||
const std::filesystem::path FALLBACK_PATH;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> SystemFontResolver::ReadSystemFonts()
|
||||
const std::filesystem::path& SystemFontResolver::GetSystemFontPath(const std::string& fontName)
|
||||
{
|
||||
static std::map<std::string, std::filesystem::path> fontFileMapping = ReadSystemFonts();
|
||||
auto it = fontFileMapping.find(Utils::ToLower(fontName));
|
||||
return it == fontFileMapping.end() ? FALLBACK_PATH : it->second;
|
||||
}
|
||||
|
||||
std::map<std::string, std::filesystem::path> SystemFontResolver::ReadSystemFonts()
|
||||
{
|
||||
DirectWriteAutoReleasable<IDWriteFactory7> dwrite;
|
||||
HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory7), (IUnknown**) &dwrite);
|
||||
@@ -64,7 +67,7 @@ namespace OpenVulkano
|
||||
return {};
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> fontFileMapping;
|
||||
std::map<std::string, std::filesystem::path> fontFileMapping;
|
||||
const UINT32 familyCount = matchingFonts->GetFontCount();
|
||||
// thank you Microsoft for function that is not even documented, but exists and it's the only function that
|
||||
// can return real font name from font filename (e.g. font filename is times.ttf that corresponds to Times New Roman)
|
||||
@@ -133,7 +136,7 @@ namespace OpenVulkano
|
||||
const size_t realSize = strlen(fontNameCropped.data());
|
||||
fontNameCropped.resize(realSize);
|
||||
Utils::ToLower(fontNameCropped);
|
||||
fontFileMapping[std::move(fontNameCropped)] = std::string(filePath, filePath + wcslen(filePath));
|
||||
fontFileMapping[std::move(fontNameCropped)] = std::filesystem::path(std::wstring(filePath, filePath + wcslen(filePath)));
|
||||
}
|
||||
}
|
||||
return fontFileMapping;
|
||||
|
||||
Reference in New Issue
Block a user