1
0
Fork 0

(svn r23271) -Codechange: don't repeatedly initialise and free the freetype library

release/1.2
rubidium 2011-11-20 08:08:13 +00:00
parent 5638eaa307
commit 542c61397c
4 changed files with 41 additions and 36 deletions

View File

@ -23,6 +23,14 @@ static const int ASCII_LETTERSTART = 32; ///< First printable ASCII letter.
/** Semi-constant for the height of the different sizes of fonts. */ /** Semi-constant for the height of the different sizes of fonts. */
int _font_height[FS_END]; int _font_height[FS_END];
/** Reset the font sizes to the defaults of the sprite based fonts. */
void ResetFontSizes()
{
_font_height[FS_SMALL] = 6;
_font_height[FS_NORMAL] = 10;
_font_height[FS_LARGE] = 18;
}
#ifdef WITH_FREETYPE #ifdef WITH_FREETYPE
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
@ -809,21 +817,45 @@ static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *t
} }
static void ResetGlyphCache();
/**
* Unload a face and set it to NULL.
* @param face the face to unload
*/
static void UnloadFace(FT_Face *face)
{
if (*face == NULL) return;
FT_Done_Face(*face);
*face = NULL;
}
/**
* (Re)initialize the freetype related things, i.e. load the non-sprite fonts.
*/
void InitFreeType() void InitFreeType()
{ {
ResetFontSizes(); ResetFontSizes();
ResetGlyphCache();
UnloadFace(&_face_small);
UnloadFace(&_face_medium);
UnloadFace(&_face_large);
if (StrEmpty(_freetype.small_font) && StrEmpty(_freetype.medium_font) && StrEmpty(_freetype.large_font)) { if (StrEmpty(_freetype.small_font) && StrEmpty(_freetype.medium_font) && StrEmpty(_freetype.large_font)) {
DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead"); DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead");
return; return;
} }
if (_library == NULL) {
if (FT_Init_FreeType(&_library) != FT_Err_Ok) { if (FT_Init_FreeType(&_library) != FT_Err_Ok) {
ShowInfoF("Unable to initialize FreeType, using sprite fonts instead"); ShowInfoF("Unable to initialize FreeType, using sprite fonts instead");
return; return;
} }
DEBUG(freetype, 2, "Initialized"); DEBUG(freetype, 2, "Initialized");
}
/* Load each font */ /* Load each font */
LoadFreeTypeFont(_freetype.small_font, &_face_small, "small"); LoadFreeTypeFont(_freetype.small_font, &_face_small, "small");
@ -842,26 +874,11 @@ void InitFreeType()
} }
} }
static void ResetGlyphCache();
/**
* Unload a face and set it to NULL.
* @param face the face to unload
*/
static void UnloadFace(FT_Face *face)
{
if (*face == NULL) return;
FT_Done_Face(*face);
*face = NULL;
}
/** /**
* Free everything allocated w.r.t. fonts. * Free everything allocated w.r.t. fonts.
*/ */
void UninitFreeType() void UninitFreeType()
{ {
ResetFontSizes();
ResetGlyphCache(); ResetGlyphCache();
UnloadFace(&_face_small); UnloadFace(&_face_small);
@ -1109,14 +1126,6 @@ uint GetGlyphWidth(FontSize size, WChar key)
#endif /* WITH_FREETYPE */ #endif /* WITH_FREETYPE */
/** Reset the font sizes to the defaults of the sprite based fonts. */
void ResetFontSizes()
{
_font_height[FS_SMALL] = 6;
_font_height[FS_NORMAL] = 10;
_font_height[FS_LARGE] = 18;
}
/* Sprite based glyph mapping */ /* Sprite based glyph mapping */
#include "table/unicode.h" #include "table/unicode.h"

View File

@ -23,8 +23,6 @@ void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite);
/** Initialize the glyph map */ /** Initialize the glyph map */
void InitializeUnicodeGlyphMap(); void InitializeUnicodeGlyphMap();
void ResetFontSizes();
#ifdef WITH_FREETYPE #ifdef WITH_FREETYPE
struct FreeTypeSettings { struct FreeTypeSettings {
@ -62,8 +60,8 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
#else #else
/* Stub for initializiation */ /* Stub for initializiation */
static inline void InitFreeType() { ResetFontSizes(); } static inline void InitFreeType() { extern void ResetFontSizes(); ResetFontSizes(); }
static inline void UninitFreeType() { ResetFontSizes(); } static inline void UninitFreeType() {}
/** Get the Sprite for a glyph */ /** Get the Sprite for a glyph */
static inline const Sprite *GetGlyph(FontSize size, uint32 key) static inline const Sprite *GetGlyph(FontSize size, uint32 key)

View File

@ -303,6 +303,8 @@ static void ShutdownGame()
/* Close all and any open filehandles */ /* Close all and any open filehandles */
FioCloseAll(); FioCloseAll();
UninitFreeType();
} }
/** /**

View File

@ -1750,10 +1750,7 @@ const char *GetCurrentLanguageIsoCode()
*/ */
bool MissingGlyphSearcher::FindMissingGlyphs(const char **str) bool MissingGlyphSearcher::FindMissingGlyphs(const char **str)
{ {
#ifdef WITH_FREETYPE
UninitFreeType();
InitFreeType(); InitFreeType();
#endif
const Sprite *question_mark[FS_END]; const Sprite *question_mark[FS_END];
for (FontSize size = FS_BEGIN; size < FS_END; size++) { for (FontSize size = FS_BEGIN; size < FS_END; size++) {
@ -1856,7 +1853,6 @@ void CheckForMissingGlyphsInLoadedLanguagePack(bool base_font)
/* 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 */
UninitFreeType();
InitFreeType(); InitFreeType();
} }
} }