diff --git a/src/app/ui/font_popup.cpp b/src/app/ui/font_popup.cpp index 7e5a201b3..17d9398e6 100644 --- a/src/app/ui/font_popup.cpp +++ b/src/app/ui/font_popup.cpp @@ -39,6 +39,8 @@ #include #endif +#include + namespace app { using namespace ui; @@ -135,31 +137,45 @@ FontPopup::FontPopup() m_popup->view()->attachToView(&m_listBox); - std::vector fontDirs; + std::queue fontDirs; #if _WIN32 { std::vector buf(MAX_PATH); HRESULT hr = SHGetFolderPath(NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_DEFAULT, &buf[0]); if (hr == S_OK) { - fontDirs.push_back(base::to_utf8(&buf[0])); + fontDirs.push(base::to_utf8(&buf[0])); } } #elif __APPLE__ { - fontDirs.push_back("/System/Library/Fonts/"); - fontDirs.push_back("/Library/Fonts"); - fontDirs.push_back("~/Library/Fonts"); + fontDirs.push("/System/Library/Fonts/"); + fontDirs.push("/Library/Fonts"); + fontDirs.push("~/Library/Fonts"); + } +#else // Unix-like + { + fontDirs.push("/usr/share/fonts"); + fontDirs.push("/usr/local/share/fonts"); + fontDirs.push("~/.fonts"); } #endif // Create a list of fullpaths to every font found in all font // directories (fontDirs) std::vector files; - for (const auto& fontDir : fontDirs) { + while (!fontDirs.empty()) { + std::string fontDir = fontDirs.front(); + fontDirs.pop(); + auto fontDirFiles = base::list_files(fontDir); - for (const auto& file : fontDirFiles) - files.push_back(base::join_path(fontDir, file)); + for (const auto& file : fontDirFiles) { + std::string fullpath = base::join_path(fontDir, file); + if (base::is_directory(fullpath)) + fontDirs.push(fullpath); // Add subdirectory + else + files.push_back(fullpath); + } } // Sort all files by "file title"