Una vez escribí el código para la plataforma de Windows para encontrar un archivo de fuente basado en "Arial Bold" o tal nombre. El código se publica a continuación. Está escaneando el Registro e intentando encontrar una coincidencia para el nombre de la fuente a un archivo en el directorio de fuentes de Windows. Puede que no sea a prueba de balas, pero sí funcionó. Una vez que tenga el nombre del archivo, puede pasarlo 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());
}
No existe tal API, al igual que la respuesta vinculada dice. –
Si tiene el manejador HFONT de la fuente, podría probar mi [solución propuesta] (http://stackoverflow.com/questions/16769758/get-a-font-file-filename-based-on-the-font-handle- hfont). No quería agregar la respuesta aquí, porque la pregunta no está clara si tiene un control para la fuente o no. –