# fontcache.cpp File Reference

Cache for characters from fonts. More...

`#include "stdafx.h"`
`#include "fontcache.h"`
`#include "blitter/factory.hpp"`
`#include "core/math_func.hpp"`
`#include "table/sprites.h"`
`#include "table/control_codes.h"`
`#include <ft2build.h>`
`#include <FT_FREETYPE_H>`
`#include <FT_GLYPH_H>`
`#include <fontconfig/fontconfig.h>`
`#include "table/unicode.h"`

Go to the source code of this file.

## Data Structures
struct | GlyphEntry
## Functions
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, SetFallbackFontCallback *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.
void | InitFreeType ()
static void | ResetGlyphCache ()
| Clear the complete cache.
static void | UnloadFace (FT_Face *face)
| Unload a face and set it to NULL.
void | UninitFreeType ()
| Free everything allocated w.r.t.
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)
uint | GetGlyphWidth (FontSize size, WChar key)
void | ResetFontSizes ()
| Reset the font sizes to the defaults of the sprite based fonts.
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.
int | _font_height [FS_END]
| Semi-constant for the height of 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 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]

## Detailed Description

Cache for characters from fonts.

Definition in file fontcache.cpp.

## Function Documentation

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 appropiate font is found, the function returns an error

Definition at line 620 of file fontcache.cpp.

References ShowInfoF().

Referenced by LoadFreeTypeFont().

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 769 of file fontcache.cpp.

References DEBUG, error(), GetFontByFaceName(), ShowInfoF(), and StrEmpty().

void ResetFontSizes | ( |  | ) |

Reset the font sizes to the defaults of the sprite based fonts.

Definition at line 1098 of file fontcache.cpp.

References _font_height, FS_LARGE, FS_NORMAL, and FS_SMALL.

Referenced by UninitFreeType().

bool SetFallbackFont | ( | FreeTypeSettings * | settings,
|  | const char * | language_isocode,
|  | int | winlangid,
|  | SetFallbackFontCallback * | 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.

Parameters:

  | 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.

Returns:
  true if a font has been set, false otherwise.

Definition at line 686 of file fontcache.cpp.

References DEBUG, lastof, seprintf(), and strecpy().

Referenced by CheckForMissingGlyphsInLoadedLanguagePack().

void UninitFreeType | ( |  | ) |

Free everything allocated w.r.t.

fonts.

Definition at line 864 of file fontcache.cpp.

References ResetFontSizes(), ResetGlyphCache(), and UnloadFace().

Referenced by CheckForMissingGlyphsInLoadedLanguagePack(), and FindMissingGlyphs().

static void UnloadFace | ( | FT_Face * | face | ) | `[static]`

Unload a face and set it to NULL.

Parameters:

  | face | the face to unload

Definition at line 853 of file fontcache.cpp.

Referenced by UninitFreeType().

## Variable Documentation

int _font_height[FS_END]

Semi-constant for the height of the different sizes of fonts.

Definition at line 23 of file fontcache.cpp.

Referenced by GetCharacterHeight(), and ResetFontSizes().