4#include <unordered_set>
7#include "absl/strings/str_format.h"
9#include "imgui/imgui.h"
14int CALLBACK EnumFontFamExProc(
const LOGFONT* lpelfe,
const TEXTMETRIC* lpntme,
15 DWORD FontType, LPARAM lParam) {
17 ImGuiIO& io = ImGui::GetIO();
18 io.Fonts->AddFontFromFileTTF(lpelfe->lfFaceName, 16.0f);
25 std::vector<std::string> fontPaths;
30 TEXT(
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"), 0,
31 KEY_READ, &hKey) == ERROR_SUCCESS) {
33 DWORD maxValueNameSize;
34 DWORD maxValueDataSize;
37 RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &valueCount,
38 &maxValueNameSize, &maxValueDataSize, NULL, NULL);
40 char* valueName =
new char[maxValueNameSize + 1];
41 BYTE* valueData =
new BYTE[maxValueDataSize + 1];
44 for (DWORD i = 0; i < valueCount; i++) {
45 DWORD valueNameSize = maxValueNameSize + 1;
46 DWORD valueDataSize = maxValueDataSize + 1;
50 memset(valueName, 0, valueNameSize);
51 memset(valueData, 0, valueDataSize);
54 if (RegEnumValue(hKey, i, valueName, &valueNameSize, NULL, &valueType,
55 valueData, &valueDataSize) == ERROR_SUCCESS) {
56 if (valueType == REG_SZ) {
58 std::string fontPath(
reinterpret_cast<char*
>(valueData),
61 fontPaths.push_back(fontPath);
72 ImGuiIO& io = ImGui::GetIO();
75 static const std::unordered_set<std::string> commonFontFaceNames = {
87 "Lucida Sans Unicode",
91 for (
auto& fontPath : fontPaths) {
93 if (fontPath.substr(0, 2) !=
"C:") {
95 fontPath = absl::StrFormat(
"C:\\Windows\\Fonts\\%s", fontPath.c_str());
99 std::string extension = fontPath.substr(fontPath.find_last_of(
".") + 1);
100 if (extension ==
"ttf" || extension ==
"TTF") {
102 std::string fontFaceName =
103 fontPath.substr(fontPath.find_last_of(
"\\/") + 1);
104 fontFaceName = fontFaceName.substr(0, fontFaceName.find_last_of(
"."));
107 if (commonFontFaceNames.find(fontFaceName) != commonFontFaceNames.end()) {
108 io.Fonts->AddFontFromFileTTF(fontPath.c_str(), 16.0f);
112 static const ImWchar icons_ranges[] = {
ICON_MIN_MD, 0xf900, 0};
113 ImFontConfig icons_config;
114 static const float ICON_FONT_SIZE = 18.0f;
115 icons_config.MergeMode =
true;
116 icons_config.GlyphOffset.y = 5.0f;
117 icons_config.GlyphMinAdvanceX = 13.0f;
118 icons_config.PixelSnapH =
true;
120 &icons_config, icons_ranges);
126#elif defined(__linux__)
#define FONT_ICON_FILE_NAME_MD