From 8bdec9f68e7b09b1519668f4c0b447c3c0344959 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 25 Dec 2015 01:45:18 +0900 Subject: [PATCH] Experimental: use SHGetKnownFolderPath to get font path on Windows. --- src/platform/windows.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/platform/windows.c b/src/platform/windows.c index 5b1476b769..39b478d69b 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -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