mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r23274) -Add: internal support for a monospaced sprite font
This commit is contained in:
parent
0a4a75b0af
commit
dfefcab47d
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user