| 183 | } |
| 184 | |
| 185 | FontStack LoadFont(GameFontTables size, text_color color, uint16_t row) |
| 186 | { |
| 187 | if (ColorTranslations[color] != nullptr && !ColorTranslationsData[color]) { |
| 188 | ColorTranslationsData[color].emplace(); |
| 189 | LoadFileInMem(ColorTranslations[color], *ColorTranslationsData[color]); |
| 190 | } |
| 191 | |
| 192 | const uint32_t fontId = GetFontId(size, row); |
| 193 | auto hotFont = Fonts.find(fontId); |
| 194 | if (hotFont != Fonts.end()) { |
| 195 | return FontStack(hotFont->second); |
| 196 | } |
| 197 | |
| 198 | OwnedFontStack &font = Fonts[fontId]; |
| 199 | char path[32]; |
| 200 | |
| 201 | // Load language-specific glyphs: |
| 202 | const string_view languageCode = GetLanguageCode(); |
| 203 | const string_view lang = languageCode.substr(0, 2); |
| 204 | if (lang == "zh" || lang == "ja" || lang == "ko" |
| 205 | || (lang == "tr" && row == 0)) { |
| 206 | GetFontPath(languageCode, size, row, ".clx", &path[0]); |
| 207 | font.overrideFont = LoadOptionalClx(path); |
| 208 | } |
| 209 | |
| 210 | // Load the base glyphs: |
| 211 | GetFontPath(size, row, ".clx", &path[0]); |
| 212 | font.baseFont = LoadOptionalClx(path); |
| 213 | |
| 214 | #ifndef UNPACKED_MPQS |
| 215 | if (!font.baseFont.has_value()) { |
| 216 | // Could be an old devilutionx.mpq or fonts.mpq with PCX instead of CLX. |
| 217 | // |
| 218 | // We'll show an error elsewhere (in `CheckArchivesUpToDate`) and we need to load |
| 219 | // the font files to display it. |
| 220 | char pcxPath[32]; |
| 221 | GetFontPath(size, row, "", &pcxPath[0]); |
| 222 | font.baseFont = LoadPcxSpriteList(pcxPath, /*numFramesOrFrameHeight=*/256, /*transparentColor=*/1); |
| 223 | } |
| 224 | #endif |
| 225 | |
| 226 | if (!font.baseFont.has_value()) { |
| 227 | LogError("Error loading font: {}", path); |
| 228 | } |
| 229 | |
| 230 | return FontStack(font); |
| 231 | } |
| 232 | |
| 233 | class CurrentFont { |
| 234 | public: |
no test coverage detected