Created
January 14, 2025 09:27
-
-
Save Shtille/07980761700091308e7820b4e40f45e5 to your computer and use it in GitHub Desktop.
Get platform-specific font locations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if defined(_WIN32) || defined(_WIN64) // Windows | |
# include <shlobj.h> | |
#endif | |
#include <string> | |
#include <vector> | |
#include <filesystem> | |
static std::vector<std::wstring> GetStandardFontsLocations() | |
{ | |
std::vector<std::wstring> result; | |
#if defined(_WIN32) || defined(_WIN64) // Windows | |
// Get standard fonts location via system call | |
// this API will require Shell32.dll, but we're getting it by using Qt by default | |
WCHAR szPath[MAX_PATH]; | |
::SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_DEFAULT, szPath); | |
result.push_back(szPath); | |
#elif defined(__APPLE__) && defined(__MACH__) // Mac OS X | |
result.push_back(L"/System/Library/Fonts"); | |
result.push_back(L"/Library/Fonts"); | |
result.push_back(L"~/Library/Fonts"); | |
result.push_back(L"/Network/Library/Fonts"); | |
#elif defined(__unix__) || defined(__unix) // Linux | |
result.push_back(L"/usr/share/fonts"); | |
result.push_back(L"/usr/local/share/fonts"); | |
result.push_back(L"~/.fonts"); | |
#else | |
# error "Unknown target platform to get fonts location" | |
#endif | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment