summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-11-20 11:56:51 +0000
committerrubidium <rubidium@openttd.org>2011-11-20 11:56:51 +0000
commitdfefcab47d563a7274ab8f410a8dcf2abc53cd62 (patch)
tree757750e78de8a5ecbe70ffb6ed2cc1df9924a332
parent0a4a75b0afbeeab6be1eb7ccfd03ef603a4646b9 (diff)
downloadopenttd-dfefcab47d563a7274ab8f410a8dcf2abc53cd62.tar.xz
(svn r23274) -Add: internal support for a monospaced sprite font
-rw-r--r--src/fontcache.cpp19
-rw-r--r--src/fontcache.h3
-rw-r--r--src/gfx_func.h3
-rw-r--r--src/gfx_type.h1
-rw-r--r--src/table/misc_settings.ini22
5 files changed, 45 insertions, 3 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index a86792db0..1f4fa33b1 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -23,9 +23,12 @@ 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. */
+/**
+ * Reset the font sizes to the defaults of the sprite based fonts.
+ */
void ResetFontSizes()
{
+ _font_height[FS_MONO] = 10;
_font_height[FS_SMALL] = 6;
_font_height[FS_NORMAL] = 10;
_font_height[FS_LARGE] = 18;
@@ -44,6 +47,7 @@ static FT_Library _library = NULL;
static FT_Face _face_small = NULL;
static FT_Face _face_medium = NULL;
static FT_Face _face_large = NULL;
+static FT_Face _face_mono = NULL;
static int _ascender[FS_END];
FreeTypeSettings _freetype;
@@ -839,11 +843,12 @@ void InitFreeType()
ResetFontSizes();
ResetGlyphCache();
+ UnloadFace(&_face_mono);
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) && StrEmpty(_freetype.mono_font)) {
DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead");
return;
}
@@ -858,11 +863,15 @@ void InitFreeType()
}
/* Load each font */
+ LoadFreeTypeFont(_freetype.mono_font , &_face_mono, "mono");
LoadFreeTypeFont(_freetype.small_font, &_face_small, "small");
LoadFreeTypeFont(_freetype.medium_font, &_face_medium, "medium");
LoadFreeTypeFont(_freetype.large_font, &_face_large, "large");
/* Set each font size */
+ if (_face_mono != NULL) {
+ SetFontGeometry(_face_mono, FS_MONO, _freetype.mono_size);
+ }
if (_face_small != NULL) {
SetFontGeometry(_face_small, FS_SMALL, _freetype.small_size);
}
@@ -884,6 +893,7 @@ void UninitFreeType()
UnloadFace(&_face_small);
UnloadFace(&_face_medium);
UnloadFace(&_face_large);
+ UnloadFace(&_face_mono);
FT_Done_FreeType(_library);
_library = NULL;
@@ -897,6 +907,7 @@ static FT_Face GetFontFace(FontSize size)
case FS_NORMAL: return _face_medium;
case FS_SMALL: return _face_small;
case FS_LARGE: return _face_large;
+ case FS_MONO: return _face_mono;
}
}
@@ -987,6 +998,7 @@ static bool GetFontAAState(FontSize size)
case FS_NORMAL: return _freetype.medium_aa;
case FS_SMALL: return _freetype.small_aa;
case FS_LARGE: return _freetype.large_aa;
+ case FS_MONO: return _freetype.mono_aa;
}
}
@@ -1111,7 +1123,7 @@ uint GetGlyphWidth(FontSize size, WChar key)
if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) {
SpriteID sprite = GetUnicodeGlyph(size, key);
if (sprite == 0) sprite = GetUnicodeGlyph(size, '?');
- return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (size != FS_NORMAL) : 0;
+ return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (size != FS_NORMAL && size != FS_MONO) : 0;
}
glyph = GetGlyphPtr(size, key);
@@ -1141,6 +1153,7 @@ static SpriteID GetFontBase(FontSize size)
case FS_NORMAL: return SPR_ASCII_SPACE;
case FS_SMALL: return SPR_ASCII_SPACE_SMALL;
case FS_LARGE: return SPR_ASCII_SPACE_BIG;
+ case FS_MONO: return SPR_ASCII_SPACE;
}
}
diff --git a/src/fontcache.h b/src/fontcache.h
index a3cceace1..708070a7e 100644
--- a/src/fontcache.h
+++ b/src/fontcache.h
@@ -29,12 +29,15 @@ struct FreeTypeSettings {
char small_font[MAX_PATH];
char medium_font[MAX_PATH];
char large_font[MAX_PATH];
+ char mono_font[MAX_PATH];
uint small_size;
uint medium_size;
uint large_size;
+ uint mono_size;
bool small_aa;
bool medium_aa;
bool large_aa;
+ bool mono_aa;
};
extern FreeTypeSettings _freetype;
diff --git a/src/gfx_func.h b/src/gfx_func.h
index bb024f6d9..8023c3ee1 100644
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -172,6 +172,9 @@ static inline byte GetCharacterHeight(FontSize size)
/** Height of characters in the large (#FS_LARGE) font. */
#define FONT_HEIGHT_LARGE (GetCharacterHeight(FS_LARGE))
+/** Height of characters in the large (#FS_MONO) font. */
+#define FONT_HEIGHT_MONO (GetCharacterHeight(FS_MONO))
+
extern DrawPixelInfo *_cur_dpi;
/**
diff --git a/src/gfx_type.h b/src/gfx_type.h
index 77111b767..c31c61e70 100644
--- a/src/gfx_type.h
+++ b/src/gfx_type.h
@@ -165,6 +165,7 @@ enum FontSize {
FS_NORMAL, ///< Index of the normal font in the font tables.
FS_SMALL, ///< Index of the small font in the font tables.
FS_LARGE, ///< Index of the large font in the font tables.
+ FS_MONO, ///< Index of the monospaced font in the font tables.
FS_END,
FS_BEGIN = FS_NORMAL, ///< First font.
diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini
index 3becf5b50..c707025a6 100644
--- a/src/table/misc_settings.ini
+++ b/src/table/misc_settings.ini
@@ -144,6 +144,13 @@ type = SLE_STRB
var = _freetype.large_font
def = NULL
+[SDTG_STR]
+ifdef = WITH_FREETYPE
+name = ""mono_font""
+type = SLE_STRB
+var = _freetype.mono_font
+def = NULL
+
[SDTG_VAR]
ifdef = WITH_FREETYPE
name = ""small_size""
@@ -171,6 +178,15 @@ def = 16
min = 0
max = 72
+[SDTG_VAR]
+ifdef = WITH_FREETYPE
+name = ""large_mono""
+type = SLE_UINT
+var = _freetype.mono_size
+def = 10
+min = 0
+max = 72
+
[SDTG_BOOL]
ifdef = WITH_FREETYPE
name = ""small_aa""
@@ -189,6 +205,12 @@ name = ""large_aa""
var = _freetype.large_aa
def = false
+[SDTG_BOOL]
+ifdef = WITH_FREETYPE
+name = ""mono_aa""
+var = _freetype.mono_aa
+def = false
+
[SDTG_VAR]
name = ""sprite_cache_size""
type = SLE_UINT