1
0
Fork 0

Fix #12735: Default fonts should use default font size as-is. (#12814)

Minimum readable font size should only apply to fallback and configured fonts.
pull/12819/head
Peter Nelson 2024-06-26 12:45:39 +01:00 committed by GitHub
parent 88e53dbdc8
commit 209b0320d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 3 deletions

View File

@ -145,6 +145,26 @@ extern void LoadWin32Font(FontSize fs);
extern void LoadCoreTextFont(FontSize fs);
#endif
/**
* Test if a font setting uses the default font.
* @return true iff the font is not configured and no fallback font data is present.
*/
static bool IsDefaultFont(const FontCacheSubSetting &setting)
{
return setting.font.empty() && setting.os_handle == nullptr;
}
/**
* Get the scalable font size to use for a FontSize.
* @param fs FontSize to get the scalable font size for.
* @return Scalable font size to use.
*/
uint GetFontCacheFontSize(FontSize fs)
{
const FontCacheSubSetting &setting = *GetFontCacheSubSetting(fs);
return IsDefaultFont(setting) ? FontCache::GetDefaultFontHeight(fs) : setting.size;
}
#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
/**
* Get name of default font file for a given font size.

View File

@ -224,6 +224,7 @@ inline FontCacheSubSetting *GetFontCacheSubSetting(FontSize fs)
}
}
uint GetFontCacheFontSize(FontSize fs);
std::string GetFontCacheFontName(FontSize fs);
void InitFontCache(bool monospace);
void UninitFontCache();

View File

@ -192,7 +192,7 @@ void LoadFreeTypeFont(FontSize fs)
if (error != FT_Err_Ok) error = GetFontByFaceName(font_name, &face);
if (error == FT_Err_Ok) {
error = LoadFont(fs, face, font_name, settings->size);
error = LoadFont(fs, face, font_name, GetFontCacheFontSize(fs));
if (error != FT_Err_Ok) {
ShowInfo("Unable to use '{}' for {} font, FreeType reported error 0x{:X}, using sprite font instead", font_name, FontSizeToName(fs), error);
}

View File

@ -369,5 +369,5 @@ void LoadCoreTextFont(FontSize fs)
return;
}
new CoreTextFontCache(fs, std::move(font_ref), settings->size);
new CoreTextFontCache(fs, std::move(font_ref), GetFontCacheFontSize(fs));
}

View File

@ -378,5 +378,5 @@ void LoadWin32Font(FontSize fs)
convert_to_fs(font_name, logfont.lfFaceName, lengthof(logfont.lfFaceName));
}
LoadWin32Font(fs, logfont, settings->size, font_name);
LoadWin32Font(fs, logfont, GetFontCacheFontSize(fs), font_name);
}