2006-11-16 22:05:33 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file fontcache.h Functions to read fonts from files and cache them. */
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
#ifndef FONTCACHE_H
|
|
|
|
#define FONTCACHE_H
|
|
|
|
|
2009-10-04 18:13:56 +00:00
|
|
|
#include "spritecache.h"
|
2007-12-22 23:30:28 +00:00
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
/** Get the SpriteID mapped to the given font size and key */
|
|
|
|
SpriteID GetUnicodeGlyph(FontSize size, uint32 key);
|
|
|
|
|
|
|
|
/** Map a SpriteID to the font size and key */
|
|
|
|
void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite);
|
|
|
|
|
|
|
|
/** Initialize the glyph map */
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeUnicodeGlyphMap();
|
2006-11-16 22:05:33 +00:00
|
|
|
|
|
|
|
#ifdef WITH_FREETYPE
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct FreeTypeSettings {
|
2008-11-24 18:53:17 +00:00
|
|
|
char small_font[MAX_PATH];
|
|
|
|
char medium_font[MAX_PATH];
|
|
|
|
char large_font[MAX_PATH];
|
2011-11-20 11:56:51 +00:00
|
|
|
char mono_font[MAX_PATH];
|
2006-11-16 22:05:33 +00:00
|
|
|
uint small_size;
|
|
|
|
uint medium_size;
|
|
|
|
uint large_size;
|
2011-11-20 11:56:51 +00:00
|
|
|
uint mono_size;
|
2007-06-15 16:21:56 +00:00
|
|
|
bool small_aa;
|
|
|
|
bool medium_aa;
|
|
|
|
bool large_aa;
|
2011-11-20 11:56:51 +00:00
|
|
|
bool mono_aa;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-11-16 22:05:33 +00:00
|
|
|
|
|
|
|
extern FreeTypeSettings _freetype;
|
|
|
|
|
2011-11-20 11:59:36 +00:00
|
|
|
void InitFreeType(bool monospace);
|
2008-11-24 18:53:17 +00:00
|
|
|
void UninitFreeType();
|
2009-10-04 18:13:56 +00:00
|
|
|
const Sprite *GetGlyph(FontSize size, uint32 key);
|
2006-11-16 22:05:33 +00:00
|
|
|
uint GetGlyphWidth(FontSize size, uint32 key);
|
2011-10-07 07:48:59 +00:00
|
|
|
bool GetDrawGlyphShadow();
|
2006-11-16 22:05:33 +00:00
|
|
|
|
2008-11-24 18:53:17 +00:00
|
|
|
/**
|
|
|
|
* We would like to have a fallback font as the current one
|
|
|
|
* doesn't contain all characters we need.
|
|
|
|
* This function must set all fonts of settings.
|
|
|
|
* @param settings the settings to overwrite the fontname of.
|
|
|
|
* @param language_isocode the language, e.g. en_GB.
|
|
|
|
* @param winlangid the language ID windows style.
|
2010-11-23 17:59:50 +00:00
|
|
|
* @param callback The function to call to check for missing glyphs.
|
2008-11-24 18:53:17 +00:00
|
|
|
* @return true if a font has been set, false otherwise.
|
|
|
|
*/
|
2011-11-19 18:43:00 +00:00
|
|
|
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, class MissingGlyphSearcher *callback);
|
2008-11-24 18:53:17 +00:00
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* Stub for initializiation */
|
2011-11-20 11:59:36 +00:00
|
|
|
static inline void InitFreeType(bool monospace) { extern void ResetFontSizes(bool monospace); ResetFontSizes(monospace); }
|
2011-11-20 08:08:13 +00:00
|
|
|
static inline void UninitFreeType() {}
|
2006-11-16 22:05:33 +00:00
|
|
|
|
|
|
|
/** Get the Sprite for a glyph */
|
|
|
|
static inline const Sprite *GetGlyph(FontSize size, uint32 key)
|
|
|
|
{
|
|
|
|
SpriteID sprite = GetUnicodeGlyph(size, key);
|
|
|
|
if (sprite == 0) sprite = GetUnicodeGlyph(size, '?');
|
2008-09-02 15:20:38 +00:00
|
|
|
return GetSprite(sprite, ST_FONT);
|
2006-11-16 22:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Get the width of a glyph */
|
|
|
|
static inline uint GetGlyphWidth(FontSize size, uint32 key)
|
|
|
|
{
|
|
|
|
SpriteID sprite = GetUnicodeGlyph(size, key);
|
|
|
|
if (sprite == 0) sprite = GetUnicodeGlyph(size, '?');
|
2008-09-02 15:20:38 +00:00
|
|
|
return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (size != FS_NORMAL) : 0;
|
2006-11-16 22:05:33 +00:00
|
|
|
}
|
|
|
|
|
2011-10-07 07:48:59 +00:00
|
|
|
static inline bool GetDrawGlyphShadow()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
#endif /* WITH_FREETYPE */
|
|
|
|
|
|
|
|
#endif /* FONTCACHE_H */
|