1
0
Fork 0

(svn r15849) -Codechange: provide easy access to the real height of the used fonts

release/1.0
rubidium 2009-03-25 20:01:34 +00:00
parent 28d3123dfd
commit e8d76e79ee
4 changed files with 38 additions and 12 deletions

View File

@ -27,6 +27,9 @@ static FT_Face _face_small = NULL;
static FT_Face _face_medium = NULL; static FT_Face _face_medium = NULL;
static FT_Face _face_large = 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; FreeTypeSettings _freetype;
enum { enum {
@ -529,6 +532,8 @@ static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *t
void InitFreeType() void InitFreeType()
{ {
ResetFontSizes();
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;
@ -547,9 +552,18 @@ void InitFreeType()
LoadFreeTypeFont(_freetype.large_font, &_face_large, "large"); LoadFreeTypeFont(_freetype.large_font, &_face_large, "large");
/* Set each font size */ /* Set each font size */
if (_face_small != NULL) FT_Set_Pixel_Sizes(_face_small, 0, _freetype.small_size); if (_face_small != NULL) {
if (_face_medium != NULL) FT_Set_Pixel_Sizes(_face_medium, 0, _freetype.medium_size); FT_Set_Pixel_Sizes(_face_small, 0, _freetype.small_size);
if (_face_large != NULL) FT_Set_Pixel_Sizes(_face_large, 0, _freetype.large_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(); static void ResetGlyphCache();
@ -571,6 +585,7 @@ static void UnloadFace(FT_Face *face)
*/ */
void UninitFreeType() void UninitFreeType()
{ {
ResetFontSizes();
ResetGlyphCache(); ResetGlyphCache();
UnloadFace(&_face_small); UnloadFace(&_face_small);
@ -783,6 +798,14 @@ 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

@ -16,6 +16,8 @@ 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 {
@ -51,8 +53,8 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
#else #else
/* Stub for initializiation */ /* Stub for initializiation */
static inline void InitFreeType() {} static inline void InitFreeType() { ResetFontSizes(); }
static inline void UninitFreeType() {} static inline void UninitFreeType() { ResetFontSizes(); }
/** 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

@ -816,7 +816,7 @@ static int ReallyDoDrawString(const char *string, int x, int y, TextColour colou
* So if the string cannot be drawn, return the original start to say so.*/ * So if the string cannot be drawn, return the original start to say so.*/
if (x >= dpi->left + dpi->width || y >= dpi->top + dpi->height) return x; if (x >= dpi->left + dpi->width || y >= dpi->top + dpi->height) return x;
if (colour != TC_INVALID) { // the invalid colour flag test should not really occur. But better be safe if (colour != TC_INVALID) { // the invalid colour flag test should not really occur. But better be safe
switch_colour:; switch_colour:;
SetColourRemap(colour); SetColourRemap(colour);
} }

View File

@ -158,14 +158,15 @@ byte GetCharacterWidth(FontSize size, uint32 key);
*/ */
static inline byte GetCharacterHeight(FontSize size) static inline byte GetCharacterHeight(FontSize size)
{ {
switch (size) { assert(size < FS_END);
default: NOT_REACHED(); extern int _font_height[FS_END];
case FS_NORMAL: return 10; return _font_height[size];
case FS_SMALL: return 6;
case FS_LARGE: return 18;
}
} }
#define FONT_HEIGHT_SMALL (GetCharacterHeight(FS_SMALL))
#define FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))
#define FONT_HEIGHT_LARGE (GetCharacterHeight(FS_LARGE))
extern DrawPixelInfo *_cur_dpi; extern DrawPixelInfo *_cur_dpi;
/** /**