1
0
Fork 0

Codechange: [WIN32] Use language isocode for fallback font detection (#13310)

pull/13350/head
Loïc Guilloux 2025-01-21 15:57:09 +01:00 committed by GitHub
parent 90e8dd9f10
commit ef826a048a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 13 additions and 16 deletions

View File

@ -252,5 +252,5 @@ void UninitFontCache()
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(WITH_FONTCONFIG) && !defined(WITH_COCOA) #if !defined(_WIN32) && !defined(__APPLE__) && !defined(WITH_FONTCONFIG) && !defined(WITH_COCOA)
bool SetFallbackFont(FontCacheSettings *, const std::string &, int, MissingGlyphSearcher *) { return false; } bool SetFallbackFont(FontCacheSettings *, const std::string &, MissingGlyphSearcher *) { return false; }
#endif /* !defined(_WIN32) && !defined(__APPLE__) && !defined(WITH_FONTCONFIG) && !defined(WITH_COCOA) */ #endif /* !defined(_WIN32) && !defined(__APPLE__) && !defined(WITH_FONTCONFIG) && !defined(WITH_COCOA) */

View File

@ -33,10 +33,9 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face);
* This function must set all fonts of settings. * This function must set all fonts of settings.
* @param settings the settings to overwrite the fontname of. * @param settings the settings to overwrite the fontname of.
* @param language_isocode the language, e.g. en_GB. * @param language_isocode the language, e.g. en_GB.
* @param winlangid the language ID windows style.
* @param callback The function to call to check for missing glyphs. * @param callback The function to call to check for missing glyphs.
* @return true if a font has been set, false otherwise. * @return true if a font has been set, false otherwise.
*/ */
bool SetFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, int winlangid, class MissingGlyphSearcher *callback); bool SetFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback);
#endif #endif

View File

@ -24,7 +24,7 @@
#include "safeguards.h" #include "safeguards.h"
bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, int, MissingGlyphSearcher *callback) bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback)
{ {
/* Determine fallback font using CoreText. This uses the language isocode /* Determine fallback font using CoreText. This uses the language isocode
* to find a suitable font. CoreText is available from 10.5 onwards. */ * to find a suitable font. CoreText is available from 10.5 onwards. */

View File

@ -98,7 +98,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
return err; return err;
} }
bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, int, MissingGlyphSearcher *callback) bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback)
{ {
bool ret = false; bool ret = false;

View File

@ -86,13 +86,14 @@ static int CALLBACK EnumFontCallback(const ENUMLOGFONTEX *logfont, const NEWTEXT
return 0; // stop enumerating return 0; // stop enumerating
} }
bool SetFallbackFont(FontCacheSettings *settings, const std::string &, int winlangid, MissingGlyphSearcher *callback) bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback)
{ {
Debug(fontcache, 1, "Trying fallback fonts"); Debug(fontcache, 1, "Trying fallback fonts");
EFCParam langInfo; EFCParam langInfo;
if (GetLocaleInfo(MAKELCID(winlangid, SORT_DEFAULT), LOCALE_FONTSIGNATURE, (LPTSTR)&langInfo.locale, sizeof(langInfo.locale) / sizeof(wchar_t)) == 0) { std::wstring lang = OTTD2FS(language_isocode.substr(0, language_isocode.find('_')));
/* Invalid langid or some other mysterious error, can't determine fallback font. */ if (GetLocaleInfoEx(lang.c_str(), LOCALE_FONTSIGNATURE, reinterpret_cast<LPWSTR>(&langInfo.locale), sizeof(langInfo.locale) / sizeof(wchar_t)) == 0) {
Debug(fontcache, 1, "Can't get locale info for fallback font (langid=0x{:x})", winlangid); /* Invalid isocode or some other mysterious error, can't determine fallback font. */
Debug(fontcache, 1, "Can't get locale info for fallback font (isocode={})", language_isocode);
return false; return false;
} }
langInfo.settings = settings; langInfo.settings = settings;

View File

@ -11,12 +11,9 @@
#define STDAFX_H #define STDAFX_H
#if defined(_WIN32) #if defined(_WIN32)
/* MinGW defaults to Windows 7 if none of these are set, and they must be set before any MinGW header is included */ /* Minimum supported version is Windows 7. */
# define NTDDI_VERSION NTDDI_WINXP // Windows XP # define NTDDI_VERSION NTDDI_WIN7
# define _WIN32_WINNT 0x501 // Windows XP # define _WIN32_WINNT _WIN32_WINNT_WIN7
# define _WIN32_WINDOWS 0x501 // Windows XP
# define WINVER 0x0501 // Windows XP
# define _WIN32_IE_ 0x0600 // 6.0 (XP+)
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@ -2297,7 +2297,7 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
_fcsettings.mono.os_handle = nullptr; _fcsettings.mono.os_handle = nullptr;
_fcsettings.medium.os_handle = nullptr; _fcsettings.medium.os_handle = nullptr;
bad_font = !SetFallbackFont(&_fcsettings, _langpack.langpack->isocode, _langpack.langpack->winlangid, searcher); bad_font = !SetFallbackFont(&_fcsettings, _langpack.langpack->isocode, searcher);
_fcsettings = backup; _fcsettings = backup;