Experimental: use SHGetKnownFolderPath to get font path on Windows.

This commit is contained in:
Aaron van Geffen 2015-12-25 01:45:18 +09:00
parent 9b838aa0ee
commit 8bdec9f68e
1 changed files with 21 additions and 4 deletions

View File

@ -898,11 +898,28 @@ void platform_get_exe_path(utf8 *outPath)
WideCharToMultiByte(CP_UTF8, 0, exePath, countof(exePath), outPath, MAX_PATH, NULL, NULL);
}
void platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer)
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer)
{
strcpy(buffer, "C:\\Windows\\Fonts\\");
strcat(buffer, font->filename);
return true;
wchar_t *fontFolder;
if (SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_Fonts, 0, NULL, &fontFolder)))
{
// Convert wchar to utf8, then copy the font folder path to the buffer.
utf8 *outPathTemp = widechar_to_utf8(fontFolder);
strcpy(buffer, outPathTemp);
free(outPathTemp);
CoTaskMemFree(fontFolder);
// Append the requested font's file name.
const char separator[2] = { platform_get_path_separator(), 0 };
strcat(buffer, separator);
strcat(buffer, font->filename);
return true;
}
else
{
return false;
}
}
#endif