summaryrefslogtreecommitdiff
path: root/src/fontcache.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-03-25 20:01:34 +0000
committerrubidium <rubidium@openttd.org>2009-03-25 20:01:34 +0000
commite8d76e79ee8b58d9947c05eb9dcb53c3d0b4ec19 (patch)
tree18c01826c7b985207e18da3859c51953c551a3a8 /src/fontcache.cpp
parent28d3123dfd7c8a981496e81fb1dc5996015563d9 (diff)
downloadopenttd-e8d76e79ee8b58d9947c05eb9dcb53c3d0b4ec19.tar.xz
(svn r15849) -Codechange: provide easy access to the real height of the used fonts
Diffstat (limited to 'src/fontcache.cpp')
-rw-r--r--src/fontcache.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index ac9adffc5..287a281d0 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -27,6 +27,9 @@ static FT_Face _face_small = NULL;
static FT_Face _face_medium = NULL;
static FT_Face _face_large = NULL;
+/** Semi-constant for the height of the different sizes of fonts. */
+int _font_height[FS_END];
+
FreeTypeSettings _freetype;
enum {
@@ -529,6 +532,8 @@ static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *t
void InitFreeType()
{
+ ResetFontSizes();
+
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;
@@ -547,9 +552,18 @@ void InitFreeType()
LoadFreeTypeFont(_freetype.large_font, &_face_large, "large");
/* Set each font size */
- if (_face_small != NULL) FT_Set_Pixel_Sizes(_face_small, 0, _freetype.small_size);
- if (_face_medium != NULL) FT_Set_Pixel_Sizes(_face_medium, 0, _freetype.medium_size);
- if (_face_large != NULL) FT_Set_Pixel_Sizes(_face_large, 0, _freetype.large_size);
+ if (_face_small != NULL) {
+ FT_Set_Pixel_Sizes(_face_small, 0, _freetype.small_size);
+ _font_height[FS_SMALL] = _freetype.small_size;
+ }
+ if (_face_medium != NULL) {
+ FT_Set_Pixel_Sizes(_face_medium, 0, _freetype.medium_size);
+ _font_height[FS_NORMAL] = _freetype.medium_size;
+ }
+ if (_face_large != NULL) {
+ FT_Set_Pixel_Sizes(_face_large, 0, _freetype.large_size);
+ _font_height[FS_LARGE] = _freetype.large_size;
+ }
}
static void ResetGlyphCache();
@@ -571,6 +585,7 @@ static void UnloadFace(FT_Face *face)
*/
void UninitFreeType()
{
+ ResetFontSizes();
ResetGlyphCache();
UnloadFace(&_face_small);
@@ -783,6 +798,14 @@ 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"