summaryrefslogtreecommitdiff
path: root/src/fontcache.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-11-20 08:08:13 +0000
committerrubidium <rubidium@openttd.org>2011-11-20 08:08:13 +0000
commit542c61397cc3ad6a56e70221a7a0901bb755a8bd (patch)
tree07bfd73cac0497a36d7aa6f3146d6b537fbe92b2 /src/fontcache.cpp
parent5638eaa3073bfec338b45d4b951bfa9ab211d91e (diff)
downloadopenttd-542c61397cc3ad6a56e70221a7a0901bb755a8bd.tar.xz
(svn r23271) -Codechange: don't repeatedly initialise and free the freetype library
Diffstat (limited to 'src/fontcache.cpp')
-rw-r--r--src/fontcache.cpp65
1 files changed, 37 insertions, 28 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index ec63b1614..a86792db0 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -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. */
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
#include <ft2build.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()
{
ResetFontSizes();
+ ResetGlyphCache();
+
+ UnloadFace(&_face_small);
+ UnloadFace(&_face_medium);
+ UnloadFace(&_face_large);
if (StrEmpty(_freetype.small_font) && StrEmpty(_freetype.medium_font) && StrEmpty(_freetype.large_font)) {
DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead");
return;
}
- if (FT_Init_FreeType(&_library) != FT_Err_Ok) {
- ShowInfoF("Unable to initialize FreeType, using sprite fonts instead");
- return;
- }
+ if (_library == NULL) {
+ if (FT_Init_FreeType(&_library) != FT_Err_Ok) {
+ ShowInfoF("Unable to initialize FreeType, using sprite fonts instead");
+ return;
+ }
- DEBUG(freetype, 2, "Initialized");
+ DEBUG(freetype, 2, "Initialized");
+ }
/* Load each font */
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.
*/
void UninitFreeType()
{
- ResetFontSizes();
ResetGlyphCache();
UnloadFace(&_face_small);
@@ -1109,14 +1126,6 @@ uint GetGlyphWidth(FontSize size, WChar key)
#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 */
#include "table/unicode.h"