MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / LoadFont

Function LoadFont

Source/engine/render/text_render.cpp:185–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183}
184
185FontStack 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
233class CurrentFont {
234public:

Callers 2

loadMethod · 0.85
DoDrawStringFunction · 0.85

Calls 10

LoadFileInMemFunction · 0.85
GetFontIdFunction · 0.85
FontStackClass · 0.85
GetLanguageCodeFunction · 0.85
GetFontPathFunction · 0.85
LoadOptionalClxFunction · 0.85
LoadPcxSpriteListFunction · 0.85
LogErrorFunction · 0.85
endMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected