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
|
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "gfx_type.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
|
|
|
|
2009-03-25 20:01:34 +00:00
|
|
|
void ResetFontSizes();
|
|
|
|
|
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];
|
2006-11-16 22:05:33 +00:00
|
|
|
uint small_size;
|
|
|
|
uint medium_size;
|
|
|
|
uint large_size;
|
2007-06-15 16:21:56 +00:00
|
|
|
bool small_aa;
|
|
|
|
bool medium_aa;
|
|
|
|
bool large_aa;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-11-16 22:05:33 +00:00
|
|
|
|
|
|
|
extern FreeTypeSettings _freetype;
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitFreeType();
|
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);
|
|
|
|
|
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.
|
|
|
|
* @return true if a font has been set, false otherwise.
|
|
|
|
*/
|
2009-10-17 22:36:43 +00:00
|
|
|
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, const char *str);
|
2008-11-24 18:53:17 +00:00
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* Stub for initializiation */
|
2009-03-25 20:01:34 +00:00
|
|
|
static inline void InitFreeType() { ResetFontSizes(); }
|
|
|
|
static inline void UninitFreeType() { ResetFontSizes(); }
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_FREETYPE */
|
|
|
|
|
|
|
|
#endif /* FONTCACHE_H */
|