| 1 | // Aseprite |
| 2 | // Copyright (C) 2017-2018 David Capello |
| 3 | // |
| 4 | // This program is distributed under the terms of |
| 5 | // the End-User License Agreement for Aseprite. |
| 6 | |
| 7 | #ifdef HAVE_CONFIG_H |
| 8 | #include "config.h" |
| 9 | #endif |
| 10 | |
| 11 | #include "app/font_path.h" |
| 12 | |
| 13 | #include "base/fs.h" |
| 14 | |
| 15 | #include <queue> |
| 16 | |
| 17 | namespace app { |
| 18 | |
| 19 | base::paths g_cache; |
| 20 | |
| 21 | void get_font_dirs(base::paths& fontDirs) |
| 22 | { |
| 23 | if (!g_cache.empty()) { |
| 24 | fontDirs = g_cache; |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | std::queue<std::string> q; |
| 29 | q.push("~/.fonts" ); |
| 30 | q.push("/usr/local/share/fonts" ); |
| 31 | q.push("/usr/share/fonts" ); |
| 32 | |
| 33 | while (!q.empty()) { |
| 34 | std::string fontDir = q.front(); |
| 35 | q.pop(); |
| 36 | |
| 37 | fontDirs.push_back(fontDir); |
| 38 | |
| 39 | for (const auto& file : base::list_files(fontDir)) { |
| 40 | std::string fullpath = base::join_path(fontDir, file); |
| 41 | if (base::is_directory(fullpath)) |
| 42 | q.push(fullpath); // Add subdirectory in the queue |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | g_cache = fontDirs; |
| 47 | } |
| 48 | |
| 49 | } // namespace app |
| 50 | |