|
24 | 24 | #include "fios.h" |
25 | 25 | #include "fileio_func.h" |
26 | 26 | #include "fontcache.h" |
| 27 | +#include "fontdetection.h" |
| 28 | +#include "language.h" |
27 | 29 | #include "screenshot.h" |
28 | 30 | #include "genworld.h" |
29 | 31 | #include "strings_func.h" |
|
46 | 48 | #include "company_cmd.h" |
47 | 49 | #include "misc_cmd.h" |
48 | 50 |
|
| 51 | +#include <charconv> |
49 | 52 | #include <sstream> |
50 | 53 |
|
51 | 54 | #include "safeguards.h" |
@@ -2125,6 +2128,54 @@ DEF_CONSOLE_CMD(ConContent) |
2125 | 2128 | } |
2126 | 2129 | #endif /* defined(WITH_ZLIB) */ |
2127 | 2130 |
|
| 2131 | +/* List all the fonts available via console */ |
| 2132 | +DEF_CONSOLE_CMD(ConListFonts) |
| 2133 | +{ |
| 2134 | + if (argc == 0) { |
| 2135 | + IConsolePrint(CC_HELP, "List all fonts."); |
| 2136 | + return true; |
| 2137 | + } |
| 2138 | + |
| 2139 | + FontSearcher *fs = FontSearcher::GetFontSearcher(); |
| 2140 | + if (fs == nullptr) { |
| 2141 | + IConsolePrint(CC_ERROR, "No font searcher exists."); |
| 2142 | + return true; |
| 2143 | + } |
| 2144 | + |
| 2145 | + if (argc == 1) { |
| 2146 | + auto families = fs->ListFamilies(_current_language->isocode, _current_language->winlangid); |
| 2147 | + std::sort(std::begin(families), std::end(families)); |
| 2148 | + |
| 2149 | + int i = 0; |
| 2150 | + for (auto &family : families) { |
| 2151 | + IConsolePrint(CC_DEFAULT, "{}) {}", i, family); |
| 2152 | + ++i; |
| 2153 | + } |
| 2154 | + } else if (argc == 2) { |
| 2155 | + std::string family = argv[1]; |
| 2156 | + |
| 2157 | + /* If argv is a number treat it as an index into the list of fonts, which we need to get again... */ |
| 2158 | + int index; |
| 2159 | + auto [_, err] = std::from_chars(family.data(), family.data() + family.size(), index, 10); |
| 2160 | + if (err == std::errc()) { |
| 2161 | + auto families = fs->ListFamilies(_current_language->isocode, _current_language->winlangid); |
| 2162 | + std::sort(std::begin(families), std::end(families)); |
| 2163 | + if (IsInsideMM(index, 0, families.size())) family = families[index]; |
| 2164 | + } |
| 2165 | + |
| 2166 | + auto styles = fs->ListStyles(_current_language->isocode, _current_language->winlangid, family); |
| 2167 | + std::sort(std::begin(styles), std::end(styles), FontFamilySorter); |
| 2168 | + |
| 2169 | + int i = 0; |
| 2170 | + for (auto &font : styles) { |
| 2171 | + IConsolePrint(CC_DEFAULT, "{}) {}, {}", i, font.family, font.style); |
| 2172 | + i++; |
| 2173 | + } |
| 2174 | + } |
| 2175 | + |
| 2176 | + return true; |
| 2177 | +} |
| 2178 | + |
2128 | 2179 | DEF_CONSOLE_CMD(ConFont) |
2129 | 2180 | { |
2130 | 2181 | if (argc == 0) { |
@@ -2681,6 +2732,7 @@ void IConsoleStdLibRegister() |
2681 | 2732 | IConsole::CmdRegister("saveconfig", ConSaveConfig); |
2682 | 2733 | IConsole::CmdRegister("ls", ConListFiles); |
2683 | 2734 | IConsole::CmdRegister("list_saves", ConListFiles); |
| 2735 | + IConsole::CmdRegister("list_fonts", ConListFonts); |
2684 | 2736 | IConsole::CmdRegister("list_scenarios", ConListScenarios); |
2685 | 2737 | IConsole::CmdRegister("list_heightmaps", ConListHeightmaps); |
2686 | 2738 | IConsole::CmdRegister("cd", ConChangeDirectory); |
|
0 commit comments