atlas factory Windows implementation
This commit is contained in:
@@ -394,4 +394,10 @@ namespace OpenVulkano
|
||||
{
|
||||
return InterfaceOrientation::Landscape; // TODO?
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetSystemFontPath(const std::string& fontName)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,7 +111,7 @@ namespace OpenVulkano
|
||||
{
|
||||
NSOperatingSystemVersion sysVersion = [NSProcessInfo processInfo].operatingSystemVersion;
|
||||
osVersion = { static_cast<int>(sysVersion.majorVersion), static_cast<int>(sysVersion.minorVersion),
|
||||
static_cast<int>(sysVersion.patchVersion), 0 };
|
||||
static_cast<int>(sysVersion.patchVersion), 0 };
|
||||
}
|
||||
return osVersion;
|
||||
}
|
||||
@@ -202,4 +202,9 @@ namespace OpenVulkano
|
||||
{
|
||||
return InterfaceOrientation::Landscape; //TODO?
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetSystemFontPath(const std::string& fontName)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace OpenVulkano
|
||||
static DeviceOrientation GetDeviceOrientation();
|
||||
static void EnableDeviceOrientationEvents();
|
||||
static InterfaceOrientation GetInterfaceOrientation();
|
||||
static std::string GetSystemFontPath(const std::string& fontName);
|
||||
|
||||
static Event<> OnLowPowerModeChanged;
|
||||
static Event<> OnBatteryStateChanged;
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
#include <guiddef.h>
|
||||
#include <comdef.h>
|
||||
#include <Wbemidl.h>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
||||
// NOTE(vb): Windows defines macros like GetUserName that are used to automatically select the appropriate function version (GetUserNameA for ANSI and GetUserNameW for Unicode)
|
||||
// based on whether the _UNICODE macro is defined, so we manually undefine these macros to avoid naming collisions.
|
||||
@@ -28,6 +31,8 @@
|
||||
#pragma comment(lib, "PowrProf.lib")
|
||||
#pragma comment(lib, "wbemuuid.lib")
|
||||
|
||||
#define QFR_DESCRIPTION 1
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
namespace
|
||||
@@ -585,4 +590,56 @@ namespace OpenVulkano
|
||||
return InterfaceOrientation::Landscape;
|
||||
}
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetSystemFontPath(const std::string& fontName)
|
||||
{
|
||||
// font name -> filename
|
||||
static std::map<std::string, std::string> fontFileMapping;
|
||||
if (fontFileMapping.empty())
|
||||
{
|
||||
// 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)
|
||||
int(WINAPI * GetFontResourceInfoW)(wchar_t*, unsigned long*, void*, unsigned long);
|
||||
*(FARPROC*) &GetFontResourceInfoW = GetProcAddress(GetModuleHandleA("gdi32"), "GetFontResourceInfoW");
|
||||
|
||||
std::wstring winDir;
|
||||
winDir.resize(MAX_PATH);
|
||||
UINT len = GetWindowsDirectoryW(winDir.data(), MAX_PATH);
|
||||
winDir.resize(len);
|
||||
std::filesystem::path fontsDir = std::filesystem::path(winDir) / "Fonts";
|
||||
for (const auto& fontFilename : std::filesystem::directory_iterator(fontsDir))
|
||||
{
|
||||
unsigned long size = 0;
|
||||
std::wstring ws = fontFilename.path().wstring();
|
||||
if (!GetFontResourceInfoW(ws.data(), &size, NULL, QFR_DESCRIPTION))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
std::wstring fontName;
|
||||
fontName.resize(size);
|
||||
if (GetFontResourceInfoW(ws.data(), &size, fontName.data(), QFR_DESCRIPTION))
|
||||
{
|
||||
// remove null-terminated characters since size is always bigger than needed
|
||||
std::string fontNameCropped(fontName.begin(), fontName.end());
|
||||
size_t realSize = 0;
|
||||
for (; realSize < fontNameCropped.size(); realSize++)
|
||||
{
|
||||
if (fontNameCropped[realSize] == '\0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
fontNameCropped.resize(realSize);
|
||||
fontFileMapping[std::move(fontNameCropped)] = fontFilename.path().string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// maybe check everything in lower case ? so that we can use Arial/arial as input parameter
|
||||
if (fontFileMapping.contains(fontName))
|
||||
{
|
||||
return fontFileMapping.at(fontName);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ namespace OpenVulkano
|
||||
{
|
||||
NSOperatingSystemVersion osVersion = [NSProcessInfo processInfo].operatingSystemVersion;
|
||||
osv = { static_cast<int>(osVersion.majorVersion), static_cast<int>(osVersion.minorVersion),
|
||||
static_cast<int>(osVersion.patchVersion), 0 };
|
||||
static_cast<int>(osVersion.patchVersion), 0 };
|
||||
}
|
||||
return osv;
|
||||
}
|
||||
@@ -288,4 +288,9 @@ namespace OpenVulkano
|
||||
}
|
||||
return InterfaceOrientation::Landscape;
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetSystemFontPath(const std::string& fontName)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user