Codechange: Remove per font AA settings. (#12413)

OpenTTD will use the global AA font setting for all fonts from now on.
This commit is contained in:
ladysadie 2024-04-15 12:44:33 -07:00 committed by GitHub
parent a1b03ee69e
commit 727392e0b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 20 additions and 79 deletions

View File

@ -2181,10 +2181,10 @@ DEF_CONSOLE_CMD(ConFont)
IConsolePrint(CC_HELP, " Print out the fonts configuration.");
IConsolePrint(CC_HELP, " The \"Currently active\" configuration is the one actually in effect (after interface scaling and replacing unavailable fonts).");
IConsolePrint(CC_HELP, " The \"Requested\" configuration is the one requested via console command or config file.");
IConsolePrint(CC_HELP, "Usage 'font [medium|small|large|mono] [<font name>] [<size>] [aa|noaa]'.");
IConsolePrint(CC_HELP, "Usage 'font [medium|small|large|mono] [<font name>] [<size>]'.");
IConsolePrint(CC_HELP, " Change the configuration for a font.");
IConsolePrint(CC_HELP, " Omitting an argument will keep the current value.");
IConsolePrint(CC_HELP, " Set <font name> to \"\" for the default font. Note that <size> and aa/noaa have no effect if the default font is in use, and fixed defaults are used instead.");
IConsolePrint(CC_HELP, " Set <font name> to \"\" for the default font. Note that <size> has no effect if the default font is in use, and fixed defaults are used instead.");
IConsolePrint(CC_HELP, " If the sprite font is enabled in Game Options, it is used instead of the default font.");
IConsolePrint(CC_HELP, " The <size> is automatically multiplied by the current interface scaling.");
return true;
@ -2202,38 +2202,23 @@ DEF_CONSOLE_CMD(ConFont)
FontCacheSubSetting *setting = GetFontCacheSubSetting(argfs);
std::string font = setting->font;
uint size = setting->size;
bool aa = setting->aa;
uint v;
uint8_t arg_index = 2;
/* We may encounter "aa" or "noaa" but it must be the last argument. */
if (StrEqualsIgnoreCase(argv[arg_index], "aa") || StrEqualsIgnoreCase(argv[arg_index], "noaa")) {
aa = !StrStartsWithIgnoreCase(argv[arg_index++], "no");
if (argc > arg_index) return false;
} else {
/* For <name> we want a string. */
uint v;
if (!GetArgumentInteger(&v, argv[arg_index])) {
font = argv[arg_index++];
}
/* For <name> we want a string. */
if (!GetArgumentInteger(&v, argv[arg_index])) {
font = argv[arg_index++];
}
if (argc > arg_index) {
/* For <size> we want a number. */
uint v;
if (GetArgumentInteger(&v, argv[arg_index])) {
size = v;
arg_index++;
}
}
if (argc > arg_index) {
/* Last argument must be "aa" or "noaa". */
if (!StrEqualsIgnoreCase(argv[arg_index], "aa") && !StrEqualsIgnoreCase(argv[arg_index], "noaa")) return false;
aa = !StrStartsWithIgnoreCase(argv[arg_index++], "no");
if (argc > arg_index) return false;
}
SetFont(argfs, font, size, aa);
SetFont(argfs, font, size);
}
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
@ -2245,8 +2230,8 @@ DEF_CONSOLE_CMD(ConFont)
fc = FontCache::Get(fs);
}
IConsolePrint(CC_DEFAULT, "{} font:", FontSizeToName(fs));
IConsolePrint(CC_DEFAULT, "Currently active: \"{}\", size {}, {}", fc->GetFontName(), fc->GetFontSize(), GetFontAAState(fs) ? "aa" : "noaa");
IConsolePrint(CC_DEFAULT, "Requested: \"{}\", size {}, {}", setting->font, setting->size, setting->aa ? "aa" : "noaa");
IConsolePrint(CC_DEFAULT, "Currently active: \"{}\", size {}", fc->GetFontName(), fc->GetFontSize());
IConsolePrint(CC_DEFAULT, "Requested: \"{}\", size {}", setting->font, setting->size);
}
return true;

View File

@ -91,15 +91,15 @@ int GetCharacterHeight(FontSize size)
}
/* Check if a glyph should be rendered with anti-aliasing. */
bool GetFontAAState(FontSize size, bool check_blitter)
bool GetFontAAState()
{
/* AA is only supported for 32 bpp */
if (check_blitter && BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 32) return false;
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 32) return false;
return _fcsettings.global_aa || GetFontCacheSubSetting(size)->aa;
return _fcsettings.global_aa;
}
void SetFont(FontSize fontsize, const std::string &font, uint size, bool aa)
void SetFont(FontSize fontsize, const std::string &font, uint size)
{
FontCacheSubSetting *setting = GetFontCacheSubSetting(fontsize);
bool changed = false;
@ -114,11 +114,6 @@ void SetFont(FontSize fontsize, const std::string &font, uint size, bool aa)
changed = true;
}
if (setting->aa != aa) {
setting->aa = aa;
changed = true;
}
if (!changed) return;
if (fontsize != FS_MONO) {
@ -233,19 +228,6 @@ void UninitFontCache()
#endif /* WITH_FREETYPE */
}
/**
* Should any of the active fonts be anti-aliased?
* @return True if any of the loaded fonts want anti-aliased drawing.
*/
bool HasAntialiasedFonts()
{
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
if (!FontCache::Get(fs)->IsBuiltInFont() && GetFontAAState(fs, false)) return true;
}
return false;
}
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(WITH_FONTCONFIG) && !defined(WITH_COCOA)
bool SetFallbackFont(FontCacheSettings *, const std::string &, int, MissingGlyphSearcher *) { return false; }

View File

@ -207,7 +207,6 @@ inline bool GetDrawGlyphShadow(FontSize size)
struct FontCacheSubSetting {
std::string font; ///< The name of the font, or path to the font.
uint size; ///< The (requested) size of the font.
bool aa; ///< Whether to do anti aliasing or not.
const void *os_handle = nullptr; ///< Optional native OS font info. Only valid during font search.
};
@ -242,9 +241,8 @@ inline FontCacheSubSetting *GetFontCacheSubSetting(FontSize fs)
void InitFontCache(bool monospace);
void UninitFontCache();
bool HasAntialiasedFonts();
bool GetFontAAState(FontSize size, bool check_blitter = true);
void SetFont(FontSize fontsize, const std::string &font, uint size, bool aa);
bool GetFontAAState();
void SetFont(FontSize fontsize, const std::string &font, uint size);
#endif /* FONTCACHE_H */

View File

@ -91,7 +91,7 @@ void TrueTypeFontCache::SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool d
bool TrueTypeFontCache::GetDrawGlyphShadow()
{
return this->fs == FS_NORMAL && GetFontAAState(FS_NORMAL);
return this->fs == FS_NORMAL && GetFontAAState();
}
uint TrueTypeFontCache::GetGlyphWidth(GlyphID key)
@ -162,7 +162,7 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key)
}
}
return this->InternalGetGlyph(key, GetFontAAState(this->fs));
return this->InternalGetGlyph(key, GetFontAAState());
}
const void *TrueTypeFontCache::GetFontTable(uint32_t tag, size_t &length)

View File

@ -151,7 +151,7 @@ void ICURun::Shape(UChar *buff, size_t buff_length)
{
auto hbfont = hb_ft_font_create_referenced(*(static_cast<const FT_Face *>(font->fc->GetOSHandle())));
/* Match the flags with how we render the glyphs. */
hb_ft_font_set_load_flags(hbfont, GetFontAAState(this->font->fc->GetSize()) ? FT_LOAD_TARGET_NORMAL : FT_LOAD_TARGET_MONO);
hb_ft_font_set_load_flags(hbfont, GetFontAAState() ? FT_LOAD_TARGET_NORMAL : FT_LOAD_TARGET_MONO);
/* ICU buffer is in UTF-16. */
auto hbbuf = hb_buffer_create();

View File

@ -266,7 +266,7 @@ static bool SwitchNewGRFBlitter()
if (c->palette & GRFP_BLT_32BPP) depth_wanted_by_grf = 32;
}
/* We need a 32bpp blitter for font anti-alias. */
if (HasAntialiasedFonts()) depth_wanted_by_grf = 32;
if (GetFontAAState()) depth_wanted_by_grf = 32;
/* Search the best blitter. */
static const struct {

View File

@ -237,30 +237,6 @@ def = 0
min = 0
max = 72
[SDTG_BOOL]
ifdef = HAS_TRUETYPE_FONT
name = ""small_aa""
var = _fcsettings.small.aa
def = false
[SDTG_BOOL]
ifdef = HAS_TRUETYPE_FONT
name = ""medium_aa""
var = _fcsettings.medium.aa
def = false
[SDTG_BOOL]
ifdef = HAS_TRUETYPE_FONT
name = ""large_aa""
var = _fcsettings.large.aa
def = false
[SDTG_BOOL]
ifdef = HAS_TRUETYPE_FONT
name = ""mono_aa""
var = _fcsettings.mono.aa
def = false
[SDTG_BOOL]
ifdef = HAS_TRUETYPE_FONT
name = ""global_aa""