From 46e8a66e325f26bd3fa6fbedd7f69d4a096977ca Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Mon, 17 Jul 2023 12:19:20 +0900 Subject: [PATCH] Support language-specific font variants Refs #3538 --- Source/engine/render/text_render.cpp | 24 +++++++++++++++++++++--- Source/options.cpp | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Source/engine/render/text_render.cpp b/Source/engine/render/text_render.cpp index e81942eb6..61203d05b 100644 --- a/Source/engine/render/text_render.cpp +++ b/Source/engine/render/text_render.cpp @@ -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; @@ -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. // @@ -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); diff --git a/Source/options.cpp b/Source/options.cpp index 5ce48b217..6d8396b7a 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -309,6 +309,7 @@ void OptionShowFPSChanged() void OptionLanguageCodeChanged() { + UnloadFonts(); LanguageInitialize(); LoadLanguageArchive(); }