mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Refactor InitFontCache and SetFont.
Removed the monospace flag from InitFontCache. Simplified the code in SetFont.pull/12690/head
parent
1af153ef49
commit
9b6bd1dfe1
|
@ -2280,7 +2280,7 @@ DEF_CONSOLE_CMD(ConFont)
|
||||||
FontCacheSubSetting *setting = GetFontCacheSubSetting(fs);
|
FontCacheSubSetting *setting = GetFontCacheSubSetting(fs);
|
||||||
/* Make sure all non sprite fonts are loaded. */
|
/* Make sure all non sprite fonts are loaded. */
|
||||||
if (!setting->font.empty() && !fc->HasParent()) {
|
if (!setting->font.empty() && !fc->HasParent()) {
|
||||||
InitFontCache(fs == FS_MONO);
|
InitFontCache();
|
||||||
fc = FontCache::Get(fs);
|
fc = FontCache::Get(fs);
|
||||||
}
|
}
|
||||||
IConsolePrint(CC_DEFAULT, "{} font:", FontSizeToName(fs));
|
IConsolePrint(CC_DEFAULT, "{} font:", FontSizeToName(fs));
|
||||||
|
|
|
@ -160,19 +160,7 @@ void SetFont(FontSize font_size, const std::string &font, uint size)
|
||||||
|
|
||||||
if (!changed) return;
|
if (!changed) return;
|
||||||
|
|
||||||
if (font_size != FS_MONO) {
|
CheckForMissingGlyphs();
|
||||||
/* Try to reload only the modified font. */
|
|
||||||
FontCacheSettings backup = _fcsettings;
|
|
||||||
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
|
|
||||||
if (fs == font_size) continue;
|
|
||||||
FontCache *fc = FontCache::Get(fs);
|
|
||||||
GetFontCacheSubSetting(fs)->font = fc->HasParent() ? fc->GetFontName() : "";
|
|
||||||
}
|
|
||||||
CheckForMissingGlyphs();
|
|
||||||
_fcsettings = backup;
|
|
||||||
} else {
|
|
||||||
InitFontCache(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadStringWidthTable();
|
LoadStringWidthTable();
|
||||||
UpdateAllVirtCoords();
|
UpdateAllVirtCoords();
|
||||||
|
@ -247,20 +235,20 @@ std::string GetFontCacheFontName(FontSize fs)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Re)initialize the font cache related things, i.e. load the non-sprite fonts.
|
* (Re)initialize the font cache related things, i.e. load the non-sprite fonts.
|
||||||
* @param monospace Whether to initialise the monospace or regular fonts.
|
|
||||||
*/
|
*/
|
||||||
void InitFontCache(bool monospace)
|
void InitFontCache()
|
||||||
{
|
{
|
||||||
FontCache::InitializeFontCaches();
|
FontCache::InitializeFontCaches();
|
||||||
|
|
||||||
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
|
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
|
||||||
if (monospace != (fs == FS_MONO)) continue;
|
|
||||||
|
|
||||||
FontCache *fc = FontCache::Get(fs);
|
FontCache *fc = FontCache::Get(fs);
|
||||||
if (fc->HasParent()) delete fc;
|
|
||||||
|
if (fc->HasParent()) {
|
||||||
|
delete fc;
|
||||||
|
}
|
||||||
|
|
||||||
LoadFontHelper(fs);
|
LoadFontHelper(fs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugPrintFontSettings("End of initFontCache()");
|
DebugPrintFontSettings("End of initFontCache()");
|
||||||
|
|
|
@ -229,7 +229,7 @@ std::string GetFontCacheFontName(FontSize fs);
|
||||||
|
|
||||||
void DebugPrintFontSettings(const std::string &desc);
|
void DebugPrintFontSettings(const std::string &desc);
|
||||||
bool GetFontAAState();
|
bool GetFontAAState();
|
||||||
void InitFontCache(bool monospace);
|
void InitFontCache();
|
||||||
void SetFont(FontSize fontsize, const std::string &font, uint size);
|
void SetFont(FontSize fontsize, const std::string &font, uint size);
|
||||||
void UninitFontCache();
|
void UninitFontCache();
|
||||||
|
|
||||||
|
|
|
@ -693,7 +693,7 @@ int openttd_main(std::span<char * const> arguments)
|
||||||
InitializeLanguagePacks();
|
InitializeLanguagePacks();
|
||||||
|
|
||||||
/* Initialize the font cache */
|
/* Initialize the font cache */
|
||||||
InitFontCache(false);
|
InitFontCache();
|
||||||
|
|
||||||
/* This must be done early, since functions use the SetWindowDirty* calls */
|
/* This must be done early, since functions use the SetWindowDirty* calls */
|
||||||
InitWindowSystem();
|
InitWindowSystem();
|
||||||
|
|
|
@ -170,7 +170,7 @@ bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_is
|
||||||
if (best_font != nullptr) {
|
if (best_font != nullptr) {
|
||||||
ret = true;
|
ret = true;
|
||||||
callback->SetFontNames(settings, best_font, &best_index);
|
callback->SetFontNames(settings, best_font, &best_index);
|
||||||
InitFontCache(callback->Monospace());
|
InitFontCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up the list of filenames. */
|
/* Clean up the list of filenames. */
|
||||||
|
|
|
@ -767,9 +767,9 @@ struct GameOptionsWindow : Window {
|
||||||
this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
|
this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
|
|
||||||
InitFontCache(false);
|
|
||||||
InitFontCache(true);
|
|
||||||
ClearFontCache();
|
ClearFontCache();
|
||||||
|
InitFontCache();
|
||||||
|
|
||||||
CheckForMissingGlyphs();
|
CheckForMissingGlyphs();
|
||||||
SetupWidgetDimensions();
|
SetupWidgetDimensions();
|
||||||
UpdateAllVirtCoords();
|
UpdateAllVirtCoords();
|
||||||
|
|
|
@ -2157,7 +2157,7 @@ const char *GetCurrentLanguageIsoCode()
|
||||||
*/
|
*/
|
||||||
bool MissingGlyphSearcher::FindMissingGlyphs()
|
bool MissingGlyphSearcher::FindMissingGlyphs()
|
||||||
{
|
{
|
||||||
InitFontCache(this->Monospace());
|
InitFontCache();
|
||||||
|
|
||||||
this->Reset();
|
this->Reset();
|
||||||
for (auto text = this->NextString(); text.has_value(); text = this->NextString()) {
|
for (auto text = this->NextString(); text.has_value(); text = this->NextString()) {
|
||||||
|
@ -2290,7 +2290,7 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
|
||||||
/* Our fallback font does miss characters too, so keep the
|
/* Our fallback font does miss characters too, so keep the
|
||||||
* user chosen font as that is more likely to be any good than
|
* user chosen font as that is more likely to be any good than
|
||||||
* the wild guess we made */
|
* the wild guess we made */
|
||||||
InitFontCache(searcher->Monospace());
|
InitFontCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue