changeset 18432:91f57bc199b4 draft

(svn r23274) -Add: internal support for a monospaced sprite font
author rubidium <rubidium@openttd.org>
date Sun, 20 Nov 2011 11:56:51 +0000
parents d167deadae56
children db2505634ce4
files src/fontcache.cpp src/fontcache.h src/gfx_func.h src/gfx_type.h src/table/misc_settings.ini
diffstat 5 files changed, 45 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -23,9 +23,12 @@
 /** 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_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 @@
 	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 @@
 	}
 
 	/* 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 @@
 	UnloadFace(&_face_small);
 	UnloadFace(&_face_medium);
 	UnloadFace(&_face_large);
+	UnloadFace(&_face_mono);
 
 	FT_Done_FreeType(_library);
 	_library = NULL;
@@ -897,6 +907,7 @@
 		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 @@
 		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 @@
 	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 @@
 		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;
 	}
 }
 
--- a/src/fontcache.h
+++ b/src/fontcache.h
@@ -29,12 +29,15 @@
 	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;
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -172,6 +172,9 @@
 /** 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;
 
 /**
--- a/src/gfx_type.h
+++ b/src/gfx_type.h
@@ -165,6 +165,7 @@
 	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.
--- a/src/table/misc_settings.ini
+++ b/src/table/misc_settings.ini
@@ -144,6 +144,13 @@
 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 @@
 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 @@
 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