Change: Rename some freetype things to fontcache.

The font cache supports more than just FreeType as a font provider, but still used freetype in some naming.

This now uses more suitable terms.
sse-blitter-set-alpha
Peter Nelson 2 years ago committed by PeterN
parent 273988551d
commit f6ad8e1c9c

@ -286,16 +286,16 @@ bool HandleBootstrap()
/* No user interface, bail out with an error. */ /* No user interface, bail out with an error. */
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure; if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure;
/* If there is no network or no freetype, then there is nothing we can do. Go straight to failure. */ /* If there is no network or no non-sprite font, then there is nothing we can do. Go straight to failure. */
#if (defined(_WIN32) && defined(WITH_UNISCRIBE)) || (defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(__APPLE__))) || defined(WITH_COCOA) #if (defined(_WIN32) && defined(WITH_UNISCRIBE)) || (defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(__APPLE__))) || defined(WITH_COCOA)
if (!_network_available) goto failure; if (!_network_available) goto failure;
/* First tell the game we're bootstrapping. */ /* First tell the game we're bootstrapping. */
_game_mode = GM_BOOTSTRAP; _game_mode = GM_BOOTSTRAP;
/* Initialise the freetype font code. */ /* Initialise the font cache. */
InitializeUnicodeGlyphMap(); InitializeUnicodeGlyphMap();
/* Next "force" finding a suitable freetype font as the local font is missing. */ /* Next "force" finding a suitable non-sprite font as the local font is missing. */
CheckForMissingGlyphs(false); CheckForMissingGlyphs(false);
/* Initialise the palette. The biggest step is 'faking' some recolour sprites. /* Initialise the palette. The biggest step is 'faking' some recolour sprites.

@ -46,7 +46,7 @@ int _debug_sprite_level;
int _debug_oldloader_level; int _debug_oldloader_level;
int _debug_npf_level; int _debug_npf_level;
int _debug_yapf_level; int _debug_yapf_level;
int _debug_freetype_level; int _debug_fontcache_level;
int _debug_script_level; int _debug_script_level;
int _debug_sl_level; int _debug_sl_level;
int _debug_gamelog_level; int _debug_gamelog_level;
@ -72,7 +72,7 @@ struct DebugLevel {
DEBUG_LEVEL(oldloader), DEBUG_LEVEL(oldloader),
DEBUG_LEVEL(npf), DEBUG_LEVEL(npf),
DEBUG_LEVEL(yapf), DEBUG_LEVEL(yapf),
DEBUG_LEVEL(freetype), DEBUG_LEVEL(fontcache),
DEBUG_LEVEL(script), DEBUG_LEVEL(script),
DEBUG_LEVEL(sl), DEBUG_LEVEL(sl),
DEBUG_LEVEL(gamelog), DEBUG_LEVEL(gamelog),

@ -46,7 +46,7 @@ extern int _debug_sprite_level;
extern int _debug_oldloader_level; extern int _debug_oldloader_level;
extern int _debug_npf_level; extern int _debug_npf_level;
extern int _debug_yapf_level; extern int _debug_yapf_level;
extern int _debug_freetype_level; extern int _debug_fontcache_level;
extern int _debug_script_level; extern int _debug_script_level;
extern int _debug_sl_level; extern int _debug_sl_level;
extern int _debug_gamelog_level; extern int _debug_gamelog_level;

@ -32,7 +32,7 @@ static const int ASCII_LETTERSTART = 32; ///< First printable ASCII letter.
static const int _default_font_height[FS_END] = {10, 6, 18, 10}; static const int _default_font_height[FS_END] = {10, 6, 18, 10};
static const int _default_font_ascender[FS_END] = { 8, 5, 15, 8}; static const int _default_font_ascender[FS_END] = { 8, 5, 15, 8};
FreeTypeSettings _freetype; FontCacheSettings _fcsettings;
/** /**
* Create a new font cache. * Create a new font cache.
@ -72,7 +72,7 @@ int GetCharacterHeight(FontSize size)
} }
/** Font cache for fonts that are based on a freetype font. */ /** Font cache for fonts that are based on a sprite font. */
class SpriteFontCache : public FontCache { class SpriteFontCache : public FontCache {
private: private:
SpriteID **glyph_to_spriteid_map; ///< Mapping of glyphs to sprite IDs. SpriteID **glyph_to_spriteid_map; ///< Mapping of glyphs to sprite IDs.
@ -259,16 +259,16 @@ TrueTypeFontCache::GlyphEntry *TrueTypeFontCache::GetGlyphPtr(GlyphID key)
void TrueTypeFontCache::SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool duplicate) void TrueTypeFontCache::SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool duplicate)
{ {
if (this->glyph_to_sprite == nullptr) { if (this->glyph_to_sprite == nullptr) {
Debug(freetype, 3, "Allocating root glyph cache for size {}", this->fs); Debug(fontcache, 3, "Allocating root glyph cache for size {}", this->fs);
this->glyph_to_sprite = CallocT<GlyphEntry*>(256); this->glyph_to_sprite = CallocT<GlyphEntry*>(256);
} }
if (this->glyph_to_sprite[GB(key, 8, 8)] == nullptr) { if (this->glyph_to_sprite[GB(key, 8, 8)] == nullptr) {
Debug(freetype, 3, "Allocating glyph cache for range 0x{:02X}00, size {}", GB(key, 8, 8), this->fs); Debug(fontcache, 3, "Allocating glyph cache for range 0x{:02X}00, size {}", GB(key, 8, 8), this->fs);
this->glyph_to_sprite[GB(key, 8, 8)] = CallocT<GlyphEntry>(256); this->glyph_to_sprite[GB(key, 8, 8)] = CallocT<GlyphEntry>(256);
} }
Debug(freetype, 4, "Set glyph for unicode character 0x{:04X}, size {}", key, this->fs); Debug(fontcache, 4, "Set glyph for unicode character 0x{:04X}, size {}", key, this->fs);
this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite; this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite;
this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].width = glyph->width; this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].width = glyph->width;
this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].duplicate = duplicate; this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].duplicate = duplicate;
@ -283,10 +283,10 @@ static bool GetFontAAState(FontSize size, bool check_blitter = true)
switch (size) { switch (size) {
default: NOT_REACHED(); default: NOT_REACHED();
case FS_NORMAL: return _freetype.medium.aa; case FS_NORMAL: return _fcsettings.medium.aa;
case FS_SMALL: return _freetype.small.aa; case FS_SMALL: return _fcsettings.small.aa;
case FS_LARGE: return _freetype.large.aa; case FS_LARGE: return _fcsettings.large.aa;
case FS_MONO: return _freetype.mono.aa; case FS_MONO: return _fcsettings.mono.aa;
} }
} }
@ -468,7 +468,7 @@ void FreeTypeFontCache::SetFontSize(FontSize fs, FT_Face face, int pixels)
this->height = this->ascender - this->descender; this->height = this->ascender - this->descender;
} else { } else {
/* Both FT_Set_Pixel_Sizes and FT_Select_Size failed. */ /* Both FT_Set_Pixel_Sizes and FT_Select_Size failed. */
Debug(freetype, 0, "Font size selection failed. Using FontCache defaults."); Debug(fontcache, 0, "Font size selection failed. Using FontCache defaults.");
} }
} }
@ -484,10 +484,10 @@ static void LoadFreeTypeFont(FontSize fs)
FreeTypeSubSetting *settings = nullptr; FreeTypeSubSetting *settings = nullptr;
switch (fs) { switch (fs) {
default: NOT_REACHED(); default: NOT_REACHED();
case FS_SMALL: settings = &_freetype.small; break; case FS_SMALL: settings = &_fcsettings.small; break;
case FS_NORMAL: settings = &_freetype.medium; break; case FS_NORMAL: settings = &_fcsettings.medium; break;
case FS_LARGE: settings = &_freetype.large; break; case FS_LARGE: settings = &_fcsettings.large; break;
case FS_MONO: settings = &_freetype.mono; break; case FS_MONO: settings = &_fcsettings.mono; break;
} }
if (settings->font.empty()) return; if (settings->font.empty()) return;
@ -498,7 +498,7 @@ static void LoadFreeTypeFont(FontSize fs)
return; return;
} }
Debug(freetype, 2, "Initialized"); Debug(fontcache, 2, "Initialized");
} }
const char *font_name = settings->font.c_str(); const char *font_name = settings->font.c_str();
@ -527,7 +527,7 @@ static void LoadFreeTypeFont(FontSize fs)
if (error != FT_Err_Ok) error = GetFontByFaceName(font_name, &face); if (error != FT_Err_Ok) error = GetFontByFaceName(font_name, &face);
if (error == FT_Err_Ok) { if (error == FT_Err_Ok) {
Debug(freetype, 2, "Requested '{}', using '{} {}'", font_name, face->family_name, face->style_name); Debug(fontcache, 2, "Requested '{}', using '{} {}'", font_name, face->family_name, face->style_name);
/* Attempt to select the unicode character map */ /* Attempt to select the unicode character map */
error = FT_Select_Charmap(face, ft_encoding_unicode); error = FT_Select_Charmap(face, ft_encoding_unicode);
@ -675,10 +675,10 @@ const void *FreeTypeFontCache::InternalGetFontTable(uint32 tag, size_t &length)
/** /**
* (Re)initialize the freetype 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. * @param monospace Whether to initialise the monospace or regular fonts.
*/ */
void InitFreeType(bool monospace) void InitFontCache(bool monospace)
{ {
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) { for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
if (monospace != (fs == FS_MONO)) continue; if (monospace != (fs == FS_MONO)) continue;
@ -701,7 +701,7 @@ void InitFreeType(bool monospace)
/** /**
* Free everything allocated w.r.t. fonts. * Free everything allocated w.r.t. fonts.
*/ */
void UninitFreeType() void UninitFontCache()
{ {
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) { for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
FontCache *fc = FontCache::Get(fs); FontCache *fc = FontCache::Get(fs);
@ -733,5 +733,5 @@ bool HasAntialiasedFonts()
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) { return FT_Err_Cannot_Open_Resource; } FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) { return FT_Err_Cannot_Open_Resource; }
#endif /* WITH_FREETYPE */ #endif /* WITH_FREETYPE */
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback) { return false; } bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback) { return false; }
#endif /* !defined(_WIN32) && !defined(__APPLE__) && !defined(WITH_FONTCONFIG) && !defined(WITH_COCOA) */ #endif /* !defined(_WIN32) && !defined(__APPLE__) && !defined(WITH_FONTCONFIG) && !defined(WITH_COCOA) */

@ -212,8 +212,8 @@ static inline bool GetDrawGlyphShadow(FontSize size)
return FontCache::Get(size)->GetDrawGlyphShadow(); return FontCache::Get(size)->GetDrawGlyphShadow();
} }
/** Settings for a single freetype font. */ /** Settings for a single font. */
struct FreeTypeSubSetting { struct FontCacheSubSetting {
std::string font; ///< The name of the font, or path to the font. std::string font; ///< The name of the font, or path to the font.
uint size; ///< The (requested) size of the font. uint size; ///< The (requested) size of the font.
bool aa; ///< Whether to do anti aliasing or not. bool aa; ///< Whether to do anti aliasing or not.
@ -221,18 +221,18 @@ struct FreeTypeSubSetting {
const void *os_handle = nullptr; ///< Optional native OS font info. Only valid during font search. const void *os_handle = nullptr; ///< Optional native OS font info. Only valid during font search.
}; };
/** Settings for the freetype fonts. */ /** Settings for the four different fonts. */
struct FreeTypeSettings { struct FontCacheSettings {
FreeTypeSubSetting small; ///< The smallest font; mostly used for zoomed out view. FontCacheSubSetting small; ///< The smallest font; mostly used for zoomed out view.
FreeTypeSubSetting medium; ///< The normal font size. FontCacheSubSetting medium; ///< The normal font size.
FreeTypeSubSetting large; ///< The largest font; mostly used for newspapers. FontCacheSubSetting large; ///< The largest font; mostly used for newspapers.
FreeTypeSubSetting mono; ///< The mono space font used for license/readme viewers. FontCacheSubSetting mono; ///< The mono space font used for license/readme viewers.
}; };
extern FreeTypeSettings _freetype; extern FontCacheSettings _fcsettings;
void InitFreeType(bool monospace); void InitFontCache(bool monospace);
void UninitFreeType(); void UninitFontCache();
bool HasAntialiasedFonts(); bool HasAntialiasedFonts();
#endif /* FONTCACHE_H */ #endif /* FONTCACHE_H */

@ -37,6 +37,6 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face);
* @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 FreeTypeSettings *settings, const char *language_isocode, int winlangid, class MissingGlyphSearcher *callback); bool SetFallbackFont(struct FontCacheSettings *settings, const char *language_isocode, int winlangid, class MissingGlyphSearcher *callback);
#endif #endif

@ -329,7 +329,7 @@ static void ShutdownGame()
/* No NewGRFs were loaded when it was still bootstrapping. */ /* No NewGRFs were loaded when it was still bootstrapping. */
if (_game_mode != GM_BOOTSTRAP) ResetNewGRFData(); if (_game_mode != GM_BOOTSTRAP) ResetNewGRFData();
UninitFreeType(); UninitFontCache();
} }
/** /**
@ -705,8 +705,8 @@ int openttd_main(int argc, char *argv[])
/* enumerate language files */ /* enumerate language files */
InitializeLanguagePacks(); InitializeLanguagePacks();
/* Initialize the regular font for FreeType */ /* Initialize the font cache */
InitFreeType(false); InitFontCache(false);
/* This must be done early, since functions use the SetWindowDirty* calls */ /* This must be done early, since functions use the SetWindowDirty* calls */
InitWindowSystem(); InitWindowSystem();

@ -57,7 +57,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
} }
if (os_err == noErr) { if (os_err == noErr) {
Debug(freetype, 3, "Font path for {}: {}", font_name, file_path); Debug(fontcache, 3, "Font path for {}: {}", font_name, file_path);
err = FT_New_Face(_library, (const char *)file_path, 0, face); err = FT_New_Face(_library, (const char *)file_path, 0, face);
} }
@ -67,7 +67,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
#endif /* WITH_FREETYPE */ #endif /* WITH_FREETYPE */
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback) bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode, int winlangid, 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. */
@ -134,7 +134,7 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
/* Save result. */ /* Save result. */
callback->SetFontNames(settings, name); callback->SetFontNames(settings, name);
if (!callback->FindMissingGlyphs()) { if (!callback->FindMissingGlyphs()) {
Debug(freetype, 2, "CT-Font for {}: {}", language_isocode, name); Debug(fontcache, 2, "CT-Font for {}: {}", language_isocode, name);
result = true; result = true;
break; break;
} }
@ -221,7 +221,7 @@ void CoreTextFontCache::SetFontSize(int pixels)
CFStringGetCString(font_name.get(), name, lengthof(name), kCFStringEncodingUTF8); CFStringGetCString(font_name.get(), name, lengthof(name), kCFStringEncodingUTF8);
this->font_name = name; this->font_name = name;
Debug(freetype, 2, "Loaded font '{}' with size {}", this->font_name, pixels); Debug(fontcache, 2, "Loaded font '{}' with size {}", this->font_name, pixels);
} }
GlyphID CoreTextFontCache::MapCharToGlyph(WChar key) GlyphID CoreTextFontCache::MapCharToGlyph(WChar key)
@ -350,13 +350,13 @@ void LoadCoreTextFont(FontSize fs)
{ {
static const char *SIZE_TO_NAME[] = { "medium", "small", "large", "mono" }; static const char *SIZE_TO_NAME[] = { "medium", "small", "large", "mono" };
FreeTypeSubSetting *settings = nullptr; FontCacheSubSetting *settings = nullptr;
switch (fs) { switch (fs) {
default: NOT_REACHED(); default: NOT_REACHED();
case FS_SMALL: settings = &_freetype.small; break; case FS_SMALL: settings = &_fcsettings.small; break;
case FS_NORMAL: settings = &_freetype.medium; break; case FS_NORMAL: settings = &_fcsettings.medium; break;
case FS_LARGE: settings = &_freetype.large; break; case FS_LARGE: settings = &_fcsettings.large; break;
case FS_MONO: settings = &_freetype.mono; break; case FS_MONO: settings = &_fcsettings.mono; break;
} }
if (settings->font.empty()) return; if (settings->font.empty()) return;

@ -94,7 +94,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
#endif /* WITH_FREETYPE */ #endif /* WITH_FREETYPE */
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback) bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback)
{ {
if (!FcInit()) return false; if (!FcInit()) return false;
@ -148,7 +148,7 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
callback->SetFontNames(settings, (const char *)file); callback->SetFontNames(settings, (const char *)file);
bool missing = callback->FindMissingGlyphs(); bool missing = callback->FindMissingGlyphs();
Debug(freetype, 1, "Font \"{}\" misses{} glyphs", file, missing ? "" : " no"); Debug(fontcache, 1, "Font \"{}\" misses{} glyphs", file, missing ? "" : " no");
if (!missing) { if (!missing) {
best_weight = value; best_weight = value;
@ -159,7 +159,7 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
if (best_font != nullptr) { if (best_font != nullptr) {
ret = true; ret = true;
callback->SetFontNames(settings, best_font); callback->SetFontNames(settings, best_font);
InitFreeType(callback->Monospace()); InitFontCache(callback->Monospace());
} }
/* Clean up the list of filenames. */ /* Clean up the list of filenames. */

@ -78,7 +78,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, FONT_DIR_NT, 0, KEY_READ, &hKey); ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, FONT_DIR_NT, 0, KEY_READ, &hKey);
if (ret != ERROR_SUCCESS) { if (ret != ERROR_SUCCESS) {
Debug(freetype, 0, "Cannot open registry key HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"); Debug(fontcache, 0, "Cannot open registry key HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
return err; return err;
} }
@ -113,7 +113,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
} }
if (!SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_FONTS, nullptr, SHGFP_TYPE_CURRENT, vbuffer))) { if (!SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_FONTS, nullptr, SHGFP_TYPE_CURRENT, vbuffer))) {
Debug(freetype, 0, "SHGetFolderPath cannot return fonts directory"); Debug(fontcache, 0, "SHGetFolderPath cannot return fonts directory");
goto folder_error; goto folder_error;
} }
@ -268,7 +268,7 @@ public:
}; };
struct EFCParam { struct EFCParam {
FreeTypeSettings *settings; FontCacheSettings *settings;
LOCALESIGNATURE locale; LOCALESIGNATURE locale;
MissingGlyphSearcher *callback; MissingGlyphSearcher *callback;
FontList fonts; FontList fonts;
@ -334,17 +334,17 @@ static int CALLBACK EnumFontCallback(const ENUMLOGFONTEX *logfont, const NEWTEXT
info->callback->SetFontNames(info->settings, font_name, &logfont->elfLogFont); info->callback->SetFontNames(info->settings, font_name, &logfont->elfLogFont);
if (info->callback->FindMissingGlyphs()) return 1; if (info->callback->FindMissingGlyphs()) return 1;
Debug(freetype, 1, "Fallback font: {} ({})", font_name, english_name); Debug(fontcache, 1, "Fallback font: {} ({})", font_name, english_name);
return 0; // stop enumerating return 0; // stop enumerating
} }
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback) bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback)
{ {
Debug(freetype, 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) { if (GetLocaleInfo(MAKELCID(winlangid, SORT_DEFAULT), LOCALE_FONTSIGNATURE, (LPTSTR)&langInfo.locale, sizeof(langInfo.locale) / sizeof(wchar_t)) == 0) {
/* Invalid langid or some other mysterious error, can't determine fallback font. */ /* Invalid langid or some other mysterious error, can't determine fallback font. */
Debug(freetype, 1, "Can't get locale info for fallback font (langid=0x{:x})", winlangid); Debug(fontcache, 1, "Can't get locale info for fallback font (langid=0x{:x})", winlangid);
return false; return false;
} }
langInfo.settings = settings; langInfo.settings = settings;
@ -439,7 +439,7 @@ void Win32FontCache::SetFontSize(FontSize fs, int pixels)
this->glyph_size.cx = otm->otmTextMetrics.tmMaxCharWidth; this->glyph_size.cx = otm->otmTextMetrics.tmMaxCharWidth;
this->glyph_size.cy = otm->otmTextMetrics.tmHeight; this->glyph_size.cy = otm->otmTextMetrics.tmHeight;
Debug(freetype, 2, "Loaded font '{}' with size {}", FS2OTTD((LPWSTR)((BYTE *)otm + (ptrdiff_t)otm->otmpFullName)), pixels); Debug(fontcache, 2, "Loaded font '{}' with size {}", FS2OTTD((LPWSTR)((BYTE *)otm + (ptrdiff_t)otm->otmpFullName)), pixels);
} }
/** /**
@ -579,12 +579,12 @@ void LoadWin32Font(FontSize fs)
{ {
static const char *SIZE_TO_NAME[] = { "medium", "small", "large", "mono" }; static const char *SIZE_TO_NAME[] = { "medium", "small", "large", "mono" };
FreeTypeSubSetting *settings = nullptr; FontCacheSubSetting *settings = nullptr;
switch (fs) { switch (fs) {
case FS_SMALL: settings = &_freetype.small; break; case FS_SMALL: settings = &_fcsettings.small; break;
case FS_NORMAL: settings = &_freetype.medium; break; case FS_NORMAL: settings = &_fcsettings.medium; break;
case FS_LARGE: settings = &_freetype.large; break; case FS_LARGE: settings = &_fcsettings.large; break;
case FS_MONO: settings = &_freetype.mono; break; case FS_MONO: settings = &_fcsettings.mono; break;
default: NOT_REACHED(); default: NOT_REACHED();
} }

@ -2011,7 +2011,7 @@ const char *GetCurrentLanguageIsoCode()
*/ */
bool MissingGlyphSearcher::FindMissingGlyphs() bool MissingGlyphSearcher::FindMissingGlyphs()
{ {
InitFreeType(this->Monospace()); InitFontCache(this->Monospace());
const Sprite *question_mark[FS_END]; const Sprite *question_mark[FS_END];
for (FontSize size = this->Monospace() ? FS_MONO : FS_BEGIN; size < (this->Monospace() ? FS_END : FS_MONO); size++) { for (FontSize size = this->Monospace() ? FS_MONO : FS_BEGIN; size < (this->Monospace() ? FS_END : FS_MONO); size++) {
@ -2036,7 +2036,7 @@ bool MissingGlyphSearcher::FindMissingGlyphs()
default: NOT_REACHED(); default: NOT_REACHED();
} }
Debug(freetype, 0, "Font is missing glyphs to display char 0x{:X} in {} font size", (int)c, size_name); Debug(fontcache, 0, "Font is missing glyphs to display char 0x{:X} in {} font size", (int)c, size_name);
return true; return true;
} }
} }
@ -2080,7 +2080,7 @@ class LanguagePackGlyphSearcher : public MissingGlyphSearcher {
return false; return false;
} }
void SetFontNames(FreeTypeSettings *settings, const char *font_name, const void *os_data) override void SetFontNames(FontCacheSettings *settings, const char *font_name, const void *os_data) override
{ {
#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA) #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
settings->small.font = font_name; settings->small.font = font_name;
@ -2116,15 +2116,15 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
if (bad_font) { if (bad_font) {
/* We found an unprintable character... lets try whether we can find /* We found an unprintable character... lets try whether we can find
* a fallback font that can print the characters in the current language. */ * a fallback font that can print the characters in the current language. */
bool any_font_configured = !_freetype.medium.font.empty(); bool any_font_configured = !_fcsettings.medium.font.empty();
FreeTypeSettings backup = _freetype; FontCacheSettings backup = _fcsettings;
_freetype.mono.os_handle = nullptr; _fcsettings.mono.os_handle = nullptr;
_freetype.medium.os_handle = nullptr; _fcsettings.medium.os_handle = nullptr;
bad_font = !SetFallbackFont(&_freetype, _langpack.langpack->isocode, _langpack.langpack->winlangid, searcher); bad_font = !SetFallbackFont(&_fcsettings, _langpack.langpack->isocode, _langpack.langpack->winlangid, searcher);
_freetype = backup; _fcsettings = backup;
if (!bad_font && any_font_configured) { if (!bad_font && any_font_configured) {
/* If the user configured a bad font, and we found a better one, /* If the user configured a bad font, and we found a better one,
@ -2143,7 +2143,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 */
InitFreeType(searcher->Monospace()); InitFontCache(searcher->Monospace());
} }
} }
#endif #endif

@ -273,7 +273,7 @@ public:
* @param font_name The new font name. * @param font_name The new font name.
* @param os_data Opaque pointer to OS-specific data. * @param os_data Opaque pointer to OS-specific data.
*/ */
virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name, const void *os_data = nullptr) = 0; virtual void SetFontNames(struct FontCacheSettings *settings, const char *font_name, const void *os_data = nullptr) = 0;
bool FindMissingGlyphs(); bool FindMissingGlyphs();
}; };

@ -181,35 +181,35 @@ def = false
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""small_font"" name = ""small_font""
type = SLE_STR type = SLE_STR
var = _freetype.small.font var = _fcsettings.small.font
def = nullptr def = nullptr
[SDTG_SSTR] [SDTG_SSTR]
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""medium_font"" name = ""medium_font""
type = SLE_STR type = SLE_STR
var = _freetype.medium.font var = _fcsettings.medium.font
def = nullptr def = nullptr
[SDTG_SSTR] [SDTG_SSTR]
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""large_font"" name = ""large_font""
type = SLE_STR type = SLE_STR
var = _freetype.large.font var = _fcsettings.large.font
def = nullptr def = nullptr
[SDTG_SSTR] [SDTG_SSTR]
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""mono_font"" name = ""mono_font""
type = SLE_STR type = SLE_STR
var = _freetype.mono.font var = _fcsettings.mono.font
def = nullptr def = nullptr
[SDTG_VAR] [SDTG_VAR]
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""small_size"" name = ""small_size""
type = SLE_UINT type = SLE_UINT
var = _freetype.small.size var = _fcsettings.small.size
def = 0 def = 0
min = 0 min = 0
max = 72 max = 72
@ -218,7 +218,7 @@ max = 72
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""medium_size"" name = ""medium_size""
type = SLE_UINT type = SLE_UINT
var = _freetype.medium.size var = _fcsettings.medium.size
def = 0 def = 0
min = 0 min = 0
max = 72 max = 72
@ -227,7 +227,7 @@ max = 72
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""large_size"" name = ""large_size""
type = SLE_UINT type = SLE_UINT
var = _freetype.large.size var = _fcsettings.large.size
def = 0 def = 0
min = 0 min = 0
max = 72 max = 72
@ -236,7 +236,7 @@ max = 72
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""mono_size"" name = ""mono_size""
type = SLE_UINT type = SLE_UINT
var = _freetype.mono.size var = _fcsettings.mono.size
def = 0 def = 0
min = 0 min = 0
max = 72 max = 72
@ -244,25 +244,25 @@ max = 72
[SDTG_BOOL] [SDTG_BOOL]
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""small_aa"" name = ""small_aa""
var = _freetype.small.aa var = _fcsettings.small.aa
def = false def = false
[SDTG_BOOL] [SDTG_BOOL]
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""medium_aa"" name = ""medium_aa""
var = _freetype.medium.aa var = _fcsettings.medium.aa
def = false def = false
[SDTG_BOOL] [SDTG_BOOL]
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""large_aa"" name = ""large_aa""
var = _freetype.large.aa var = _fcsettings.large.aa
def = false def = false
[SDTG_BOOL] [SDTG_BOOL]
ifdef = HAS_TRUETYPE_FONT ifdef = HAS_TRUETYPE_FONT
name = ""mono_aa"" name = ""mono_aa""
var = _freetype.mono.aa var = _fcsettings.mono.aa
def = false def = false
[SDTG_VAR] [SDTG_VAR]

@ -17,7 +17,7 @@ static const byte CLRA = 0; ///< Identifier to clear all glyphs at this codepoin
/* Default unicode mapping table for sprite based glyphs. /* Default unicode mapping table for sprite based glyphs.
* This table allows us use unicode characters even though the glyphs don't * This table allows us use unicode characters even though the glyphs don't
* exist, or are in the wrong place, in the standard sprite fonts. * exist, or are in the wrong place, in the standard sprite fonts.
* This is not used for FreeType rendering */ * This is not used for TrueType rendering */
static const DefaultUnicodeMapping _default_unicode_map[] = { static const DefaultUnicodeMapping _default_unicode_map[] = {
{ 0x00A0, 0x20 }, // Non-breaking space / Up arrow { 0x00A0, 0x20 }, // Non-breaking space / Up arrow

@ -215,7 +215,7 @@ void TextfileWindow::SetupScrollbars(bool force_reflow)
return true; return true;
} }
/* virtual */ void TextfileWindow::SetFontNames(FreeTypeSettings *settings, const char *font_name, const void *os_data) /* virtual */ void TextfileWindow::SetFontNames(FontCacheSettings *settings, const char *font_name, const void *os_data)
{ {
#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA) #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
settings->mono.font = font_name; settings->mono.font = font_name;

@ -52,7 +52,7 @@ struct TextfileWindow : public Window, MissingGlyphSearcher {
FontSize DefaultSize() override; FontSize DefaultSize() override;
const char *NextString() override; const char *NextString() override;
bool Monospace() override; bool Monospace() override;
void SetFontNames(FreeTypeSettings *settings, const char *font_name, const void *os_data) override; void SetFontNames(FontCacheSettings *settings, const char *font_name, const void *os_data) override;
virtual void LoadTextfile(const char *textfile, Subdirectory dir); virtual void LoadTextfile(const char *textfile, Subdirectory dir);

Loading…
Cancel
Save