peter1138@5108: /* $Id$ */ peter1138@5108: rubidium@9111: /** @file fontcache.h Functions to read fonts from files and cache them. */ rubidium@9111: peter1138@5108: #ifndef FONTCACHE_H peter1138@5108: #define FONTCACHE_H peter1138@5108: rubidium@8123: #include "gfx_type.h" rubidium@8121: peter1138@5108: /** Get the SpriteID mapped to the given font size and key */ peter1138@5108: SpriteID GetUnicodeGlyph(FontSize size, uint32 key); peter1138@5108: peter1138@5108: /** Map a SpriteID to the font size and key */ peter1138@5108: void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite); peter1138@5108: peter1138@5108: /** Initialize the glyph map */ rubidium@6247: void InitializeUnicodeGlyphMap(); peter1138@5108: peter1138@5108: #ifdef WITH_FREETYPE peter1138@5108: rubidium@6248: struct FreeTypeSettings { rubidium@10367: char small_font[MAX_PATH]; rubidium@10367: char medium_font[MAX_PATH]; rubidium@10367: char large_font[MAX_PATH]; peter1138@5108: uint small_size; peter1138@5108: uint medium_size; peter1138@5108: uint large_size; peter1138@6913: bool small_aa; peter1138@6913: bool medium_aa; peter1138@6913: bool large_aa; rubidium@6248: }; peter1138@5108: peter1138@5108: extern FreeTypeSettings _freetype; peter1138@5108: rubidium@6247: void InitFreeType(); rubidium@10367: void UninitFreeType(); peter1138@5108: const struct Sprite *GetGlyph(FontSize size, uint32 key); peter1138@5108: uint GetGlyphWidth(FontSize size, uint32 key); peter1138@5108: rubidium@10367: /** rubidium@10367: * We would like to have a fallback font as the current one rubidium@10367: * doesn't contain all characters we need. rubidium@10367: * This function must set all fonts of settings. rubidium@10367: * @param settings the settings to overwrite the fontname of. rubidium@10367: * @param language_isocode the language, e.g. en_GB. rubidium@10367: * @param winlangid the language ID windows style. rubidium@10367: * @return true if a font has been set, false otherwise. rubidium@10367: */ rubidium@10367: bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid); rubidium@10367: peter1138@5108: #else peter1138@5108: peter1138@5108: /* Stub for initializiation */ rubidium@6247: static inline void InitFreeType() {} rubidium@10367: static inline void UninitFreeType() {} peter1138@5108: peter1138@5108: /** Get the Sprite for a glyph */ peter1138@5108: static inline const Sprite *GetGlyph(FontSize size, uint32 key) peter1138@5108: { peter1138@5108: SpriteID sprite = GetUnicodeGlyph(size, key); peter1138@5108: if (sprite == 0) sprite = GetUnicodeGlyph(size, '?'); rubidium@10056: return GetSprite(sprite, ST_FONT); peter1138@5108: } peter1138@5108: peter1138@5108: peter1138@5108: /** Get the width of a glyph */ peter1138@5108: static inline uint GetGlyphWidth(FontSize size, uint32 key) peter1138@5108: { peter1138@5108: SpriteID sprite = GetUnicodeGlyph(size, key); peter1138@5108: if (sprite == 0) sprite = GetUnicodeGlyph(size, '?'); rubidium@10056: return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (size != FS_NORMAL) : 0; peter1138@5108: } peter1138@5108: peter1138@5108: #endif /* WITH_FREETYPE */ peter1138@5108: peter1138@5108: #endif /* FONTCACHE_H */