Cache for characters from fonts. More...
#include "stdafx.h"
#include "fontcache.h"
#include "blitter/factory.hpp"
#include "core/math_func.hpp"
#include "strings_func.h"
#include "zoom_type.h"
#include "table/sprites.h"
#include "table/control_codes.h"
#include <ft2build.h>
#include <FT_FREETYPE_H>
#include <FT_GLYPH_H>
#include <FT_TRUETYPE_TABLES_H>
#include <fontconfig/fontconfig.h>
#include "table/unicode.h"
Go to the source code of this file.
Data Structures | |
struct | GlyphEntry |
Functions | |
void | ResetFontSizes (bool monospace) |
Reset the font sizes to the defaults of the sprite based fonts. | |
static FT_Error | GetFontByFaceName (const char *font_name, FT_Face *face) |
Get the font loaded into a Freetype face by using a font-name. | |
bool | SetFallbackFont (FreeTypeSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback) |
We would like to have a fallback font as the current one doesn't contain all characters we need. | |
static void | SetFontGeometry (FT_Face face, FontSize size, int pixels) |
static void | LoadFreeTypeFont (const char *font_name, FT_Face *face, const char *type) |
Loads the freetype font. | |
static void | ResetGlyphCache (bool monospace) |
Clear the complete cache. | |
static void | UnloadFace (FT_Face *face) |
Unload a face and set it to NULL. | |
void | InitFreeType (bool monospace) |
(Re)initialize the freetype related things, i.e. | |
void | UninitFreeType () |
Free everything allocated w.r.t. | |
void | ClearFontCache () |
Reset cached glyphs. | |
static FT_Face | GetFontFace (FontSize size) |
static GlyphEntry * | GetGlyphPtr (FontSize size, WChar key) |
static void | SetGlyphPtr (FontSize size, WChar key, const GlyphEntry *glyph, bool duplicate=false) |
static void * | AllocateFont (size_t size) |
static bool | GetFontAAState (FontSize size) |
const Sprite * | GetGlyph (FontSize size, WChar key) |
bool | GetDrawGlyphShadow () |
uint | GetGlyphWidth (FontSize size, WChar key) |
static SpriteID | GetFontBase (FontSize size) |
Get the SpriteID of the first glyph for the given font size. | |
SpriteID | GetUnicodeGlyph (FontSize size, uint32 key) |
Get the SpriteID mapped to the given font size and key. | |
void | SetUnicodeGlyph (FontSize size, uint32 key, SpriteID sprite) |
Map a SpriteID to the font size and key. | |
void | InitializeUnicodeGlyphMap () |
Initialize the glyph map. | |
Variables | |
static const int | ASCII_LETTERSTART = 32 |
First printable ASCII letter. | |
static const int | MAX_FONT_SIZE = 72 |
Maximum font size. | |
int | _font_height [FS_END] |
Semi-constant for the height of the different sizes of fonts. | |
static const int | _default_font_height [FS_END] = {10, 6, 18, 10} |
Default heights for the different sizes of fonts. | |
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 |
static const byte | FACE_COLOUR = 1 |
static const byte | SHADOW_COLOUR = 2 |
static GlyphEntry ** | _glyph_ptr [FS_END] |
static SpriteID ** | _unicode_glyph_map [FS_END] |
Cache for characters from fonts.
Definition in file fontcache.cpp.
static FT_Error GetFontByFaceName | ( | const char * | font_name, | |
FT_Face * | face | |||
) | [static] |
Get the font loaded into a Freetype face by using a font-name.
If no appropriate font is found, the function returns an error
Definition at line 673 of file fontcache.cpp.
References free(), and ShowInfoF().
Referenced by LoadFreeTypeFont().
void InitFreeType | ( | bool | monospace | ) |
(Re)initialize the freetype related things, i.e.
load the non-sprite fonts.
monospace | Whether to initialise the monospace or regular fonts. |
Definition at line 925 of file fontcache.cpp.
References DEBUG, FS_LARGE, FS_MONO, FS_NORMAL, FS_SMALL, LoadFreeTypeFont(), ResetFontSizes(), ResetGlyphCache(), ShowInfoF(), StrEmpty(), and UnloadFace().
Referenced by CheckForMissingGlyphs(), MissingGlyphSearcher::FindMissingGlyphs(), and SetFallbackFont().
static void LoadFreeTypeFont | ( | const char * | font_name, | |
FT_Face * | face, | |||
const char * | type | |||
) | [static] |
Loads the freetype font.
First type to load the fontname as if it were a path. If that fails, try to resolve the filename of the font using fontconfig, where the format is 'font family name' or 'font family name, font style'.
Definition at line 862 of file fontcache.cpp.
References DEBUG, GetFontByFaceName(), ShowInfoF(), and StrEmpty().
Referenced by InitFreeType().
void ResetFontSizes | ( | bool | monospace | ) |
Reset the font sizes to the defaults of the sprite based fonts.
monospace | Whether to reset the monospace or regular fonts. |
Definition at line 34 of file fontcache.cpp.
References _default_font_height, and _font_height.
Referenced by InitFreeType().
static void ResetGlyphCache | ( | bool | monospace | ) | [static] |
Clear the complete cache.
monospace | Whether to reset the monospace or regular font. |
Definition at line 1040 of file fontcache.cpp.
References free(), FS_BEGIN, and FS_MONO.
Referenced by ClearFontCache(), InitFreeType(), and UninitFreeType().
bool SetFallbackFont | ( | FreeTypeSettings * | settings, | |
const char * | language_isocode, | |||
int | winlangid, | |||
class MissingGlyphSearcher * | callback | |||
) |
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.
settings | the settings to overwrite the fontname of. | |
language_isocode | the language, e.g. en_GB. | |
winlangid | the language ID windows style. | |
callback | The function to call to check for missing glyphs. |
Definition at line 739 of file fontcache.cpp.
References DEBUG, MissingGlyphSearcher::FindMissingGlyphs(), InitFreeType(), lastof, MissingGlyphSearcher::Monospace(), seprintf(), and MissingGlyphSearcher::SetFontNames().
Referenced by CheckForMissingGlyphs().
void UninitFreeType | ( | ) |
Free everything allocated w.r.t.
fonts.
Definition at line 980 of file fontcache.cpp.
References ResetGlyphCache(), and UnloadFace().
Referenced by ShutdownGame().
static void UnloadFace | ( | FT_Face * | face | ) | [static] |
Unload a face and set it to NULL.
face | the face to unload |
Definition at line 913 of file fontcache.cpp.
Referenced by InitFreeType(), and UninitFreeType().
const int _default_font_height[FS_END] = {10, 6, 18, 10} [static] |
Default heights for the different sizes of fonts.
Definition at line 28 of file fontcache.cpp.
Referenced by ResetFontSizes().
int _font_height[FS_END] |
Semi-constant for the height of the different sizes of fonts.
Definition at line 26 of file fontcache.cpp.
Referenced by GetCharacterHeight(), and ResetFontSizes().