srctree

Robin Linden parent 10b958ad cf3744f6
os: Fix Windows font path containing a bonus null terminator

inlinesplit
os/windows.cpp added: 6, removed: 3, total 3
@@ -7,15 +7,18 @@
#include <Objbase.h>
#include <Shlobj.h>
 
#include <cwchar>
 
namespace os {
 
std::vector<std::string> font_paths() {
PWSTR bad_font_path{nullptr};
SHGetKnownFolderPath(FOLDERID_Fonts, 0, NULL, &bad_font_path);
auto chars_needed = WideCharToMultiByte(CP_UTF8, 0, bad_font_path, -1, nullptr, 0, NULL, NULL);
auto bad_font_path_len = static_cast<int>(std::wcslen(bad_font_path));
auto chars_needed = WideCharToMultiByte(CP_UTF8, 0, bad_font_path, bad_font_path_len, nullptr, 0, NULL, NULL);
std::string font_path;
font_path.resize(chars_needed);
WideCharToMultiByte(CP_UTF8, 0, bad_font_path, -1, font_path.data(), chars_needed, NULL, NULL);
WideCharToMultiByte(CP_UTF8, 0, bad_font_path, bad_font_path_len, font_path.data(), chars_needed, NULL, NULL);
CoTaskMemFree(bad_font_path);
return {font_path};
}