Skip to content

Commit

Permalink
Support language-specific font variants
Browse files Browse the repository at this point in the history
Refs #3538
  • Loading branch information
glebm committed Jul 17, 2023
1 parent b01670e commit 9dded6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
24 changes: 21 additions & 3 deletions Source/engine/render/text_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ void GetFontPath(GameFontTables size, uint16_t row, string_view ext, char *out)
*fmt::format_to(out, R"(fonts\{}-{:02x}{})", FontSizes[size], row, ext) = '\0';
}

void GetFontPath(string_view language_code, GameFontTables size, uint16_t row, string_view ext, char *out)
{
*fmt::format_to(out, R"(fonts\{}\{}-{:02x}{})", language_code, FontSizes[size], row, ext) = '\0';
}

uint32_t GetFontId(GameFontTables size, uint16_t row)
{
return (size << 16) | row;
Expand All @@ -161,11 +166,23 @@ OptionalClxSpriteList LoadFont(GameFontTables size, text_color color, uint16_t r
return OptionalClxSpriteList(*hotFont->second);
}

OptionalOwnedClxSpriteList &font = Fonts[fontId];
char path[32];
GetFontPath(size, row, ".clx", &path[0]);

OptionalOwnedClxSpriteList &font = Fonts[fontId];
font = LoadOptionalClx(path);
// Try loading the language-specific variant first:
const string_view language_code = GetLanguageCode();
const string_view language_tag = language_code.substr(0, 2);
if (language_tag == "zh" || language_tag == "ja" || language_tag == "ko") {
GetFontPath(language_code, size, row, ".clx", &path[0]);
font = LoadOptionalClx(path);
}
if (!font) {
// Fall back to the base variant:
GetFontPath(size, row, ".clx", &path[0]);
font = LoadOptionalClx(path);
}

#ifndef UNPACKED_MPQS
if (!font) {
// Could be an old devilutionx.mpq or fonts.mpq with PCX instead of CLX.
//
Expand All @@ -175,6 +192,7 @@ OptionalClxSpriteList LoadFont(GameFontTables size, text_color color, uint16_t r
GetFontPath(size, row, "", &pcxPath[0]);
font = LoadPcxSpriteList(pcxPath, /*numFramesOrFrameHeight=*/256, /*transparentColor=*/1);
}
#endif

if (!font) {
LogError("Error loading font: {}", path);
Expand Down
1 change: 1 addition & 0 deletions Source/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ void OptionShowFPSChanged()

void OptionLanguageCodeChanged()
{
UnloadFonts();
LanguageInitialize();
LoadLanguageArchive();
}
Expand Down

0 comments on commit 9dded6a

Please sign in to comment.