forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont_path_win.cpp
48 lines (39 loc) · 1.13 KB
/
font_path_win.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2017-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/font_path.h"
#include "base/fs.h"
#include "base/string.h"
#include <cctype>
#include <windows.h>
#include <shlobj.h>
namespace app {
void get_font_dirs(base::paths& fontDirs)
{
std::vector<wchar_t> buf(MAX_PATH+1);
// Fonts in system fonts directory
HRESULT hr = SHGetFolderPath(
nullptr, CSIDL_FONTS, nullptr,
SHGFP_TYPE_DEFAULT, &buf[0]);
if (hr == S_OK)
fontDirs.push_back(base::to_utf8(&buf[0]));
// Fonts in ...\AppData\Local\Microsoft\Windows\Fonts
hr = SHGetFolderPath(
nullptr, CSIDL_LOCAL_APPDATA, nullptr,
SHGFP_TYPE_CURRENT, &buf[0]);
if (hr == S_OK) {
std::string userPath = base::to_utf8(&buf[0]);
userPath = base::join_path(userPath, "Microsoft\\Windows\\Fonts");
if (base::is_directory(userPath) &&
(fontDirs.empty() || userPath != fontDirs.back())) {
fontDirs.push_back(userPath);
}
}
}
} // namespace app