1
0
Fork 0

Codechange: Helper functions for loading fonts.

pull/12690/head
Sadie del Solar 2024-05-09 02:03:29 -07:00
parent db580ab5e1
commit 1af153ef49
2 changed files with 26 additions and 22 deletions

View File

@ -28,6 +28,8 @@ static const int _default_font_ascender[FS_END] = { 8, 5, 15, 8};
FontCacheSettings _fcsettings; FontCacheSettings _fcsettings;
static void LoadFontHelper(FontSize fs);
/** /**
* Create a new font cache. * Create a new font cache.
* @param fs The size of the font. * @param fs The size of the font.
@ -121,6 +123,26 @@ void DebugPrintFontSettings(const std::string &desc)
} }
} }
#ifdef WITH_FREETYPE
extern void LoadFreeTypeFont(FontSize fs);
extern void UninitFreeType();
#elif defined(_WIN32)
extern void LoadWin32Font(FontSize fs);
#elif defined(WITH_COCOA)
extern void LoadCoreTextFont(FontSize fs);
#endif
static void LoadFontHelper(FontSize fs)
{
#ifdef WITH_FREETYPE
LoadFreeTypeFont(fs);
#elif defined(_WIN32)
LoadWin32Font(fs);
#elif defined(WITH_COCOA)
LoadCoreTextFont(fs);
#endif
}
void SetFont(FontSize font_size, const std::string &font, uint size) void SetFont(FontSize font_size, const std::string &font, uint size)
{ {
FontCacheSubSetting *setting = GetFontCacheSubSetting(font_size); FontCacheSubSetting *setting = GetFontCacheSubSetting(font_size);
@ -159,15 +181,6 @@ void SetFont(FontSize font_size, const std::string &font, uint size)
if (_save_config) SaveToConfig(); if (_save_config) SaveToConfig();
} }
#ifdef WITH_FREETYPE
extern void LoadFreeTypeFont(FontSize fs);
extern void UninitFreeType();
#elif defined(_WIN32)
extern void LoadWin32Font(FontSize fs);
#elif defined(WITH_COCOA)
extern void LoadCoreTextFont(FontSize fs);
#endif
/** /**
* Test if a font setting uses the default font. * Test if a font setting uses the default font.
* @return true iff the font is not configured and no fallback font data is present. * @return true iff the font is not configured and no fallback font data is present.
@ -188,7 +201,6 @@ uint GetFontCacheFontSize(FontSize fs)
return IsDefaultFont(setting) ? FontCache::GetDefaultFontHeight(fs) : setting.size; 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. * Get name of default font file for a given font size.
* @param fs Font size. * @param fs Font size.
@ -204,7 +216,6 @@ static std::string GetDefaultTruetypeFont(FontSize fs)
default: NOT_REACHED(); default: NOT_REACHED();
} }
} }
#endif /* defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA) */
/** /**
* Get path of default font file for a given font size. * Get path of default font file for a given font size.
@ -248,13 +259,8 @@ void InitFontCache(bool monospace)
FontCache *fc = FontCache::Get(fs); FontCache *fc = FontCache::Get(fs);
if (fc->HasParent()) delete fc; if (fc->HasParent()) delete fc;
#ifdef WITH_FREETYPE LoadFontHelper(fs);
LoadFreeTypeFont(fs);
#elif defined(_WIN32)
LoadWin32Font(fs);
#elif defined(WITH_COCOA)
LoadCoreTextFont(fs);
#endif
} }
DebugPrintFontSettings("End of initFontCache()"); DebugPrintFontSettings("End of initFontCache()");

View File

@ -228,11 +228,9 @@ uint GetFontCacheFontSize(FontSize fs);
std::string GetFontCacheFontName(FontSize fs); std::string GetFontCacheFontName(FontSize fs);
void DebugPrintFontSettings(const std::string &desc); void DebugPrintFontSettings(const std::string &desc);
bool GetFontAAState();
void InitFontCache(bool monospace); void InitFontCache(bool monospace);
void SetFont(FontSize fontsize, const std::string &font, uint size);
void UninitFontCache(); void UninitFontCache();
bool GetFontAAState();
void SetFont(FontSize fontsize, const std::string &font, uint size);
#endif /* FONTCACHE_H */ #endif /* FONTCACHE_H */