Una volta ho scritto il codice per la piattaforma Windows per trovare un file di font basato su "Arial Bold" o un nome simile. Il codice è pubblicato qui sotto. Sta eseguendo la scansione del registro e sta cercando una corrispondenza per il nome del carattere in un file nella directory dei caratteri di Windows. Potrebbe non essere a prova di proiettile, ma ha funzionato. Una volta ottenuto il nome del file, è possibile passarlo a FreeType.
// Get system font file path
std::string GetSystemFontFile(const std::string &faceName) {
static const LPWSTR fontRegistryPath = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
HKEY hKey;
LONG result;
std::wstring wsFaceName(faceName.begin(), faceName.end());
// Open Windows font registry key
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, fontRegistryPath, 0, KEY_READ, &hKey);
if (result != ERROR_SUCCESS) {
return "";
}
DWORD maxValueNameSize, maxValueDataSize;
result = RegQueryInfoKey(hKey, 0, 0, 0, 0, 0, 0, 0, &maxValueNameSize, &maxValueDataSize, 0, 0);
if (result != ERROR_SUCCESS) {
return "";
}
DWORD valueIndex = 0;
LPWSTR valueName = new WCHAR[maxValueNameSize];
LPBYTE valueData = new BYTE[maxValueDataSize];
DWORD valueNameSize, valueDataSize, valueType;
std::wstring wsFontFile;
// Look for a matching font name
do {
wsFontFile.clear();
valueDataSize = maxValueDataSize;
valueNameSize = maxValueNameSize;
result = RegEnumValue(hKey, valueIndex, valueName, &valueNameSize, 0, &valueType, valueData, &valueDataSize);
valueIndex++;
if (result != ERROR_SUCCESS || valueType != REG_SZ) {
continue;
}
std::wstring wsValueName(valueName, valueNameSize);
// Found a match
if (_wcsnicmp(wsFaceName.c_str(), wsValueName.c_str(), wsFaceName.length()) == 0) {
wsFontFile.assign((LPWSTR)valueData, valueDataSize);
break;
}
}
while (result != ERROR_NO_MORE_ITEMS);
delete[] valueName;
delete[] valueData;
RegCloseKey(hKey);
if (wsFontFile.empty()) {
return "";
}
// Build full font file path
WCHAR winDir[MAX_PATH];
GetWindowsDirectory(winDir, MAX_PATH);
std::wstringstream ss;
ss << winDir << "\\Fonts\\" << wsFontFile;
wsFontFile = ss.str();
return std::string(wsFontFile.begin(), wsFontFile.end());
}
Nessun tipo di API esiste, proprio come dice la risposta collegata. –
Se hai il manico HFONT del font, puoi provare la mia [soluzione proposta] (http://stackoverflow.com/questions/16769758/get-a-font-filename-based-on-the-font-handle- HFONT). Non volevo aggiungere la risposta qui, perché la domanda non è chiara se hai un handle per il carattere o meno. –