OpenTTD
Data Structures | Macros | Functions | Variables
fontcache.cpp File Reference

Cache for characters from fonts. More...

#include "stdafx.h"
#include "fontcache.h"
#include "fontdetection.h"
#include "blitter/factory.hpp"
#include "core/math_func.hpp"
#include "core/smallmap_type.hpp"
#include "strings_func.h"
#include "zoom_type.h"
#include "gfx_layout.h"
#include "zoom_func.h"
#include "table/sprites.h"
#include "table/control_codes.h"
#include "table/unicode.h"
#include "safeguards.h"
#include <ft2build.h>
#include <FT_FREETYPE_H>
#include <FT_GLYPH_H>
#include <FT_TRUETYPE_TABLES_H>

Go to the source code of this file.

Data Structures

class  SpriteFontCache
 Font cache for fonts that are based on a freetype font. More...
 
class  FreeTypeFontCache
 Font cache for fonts that are based on a freetype font. More...
 
struct  FreeTypeFontCache::GlyphEntry
 Container for information about a glyph. More...
 

Macros

#define CPSET   { 0, 0, 0, 0, 1 }
 
#define CP___   { 0, 0, 0, 0, 0 }
 

Functions

int GetCharacterHeight (FontSize size)
 Get height of a character for a given font size. More...
 
static void LoadFreeTypeFont (FontSize fs)
 Loads the freetype font. More...
 
static void * AllocateFont (size_t size)
 
static bool GetFontAAState (FontSize size)
 
void InitFreeType (bool monospace)
 (Re)initialize the freetype related things, i.e. More...
 
void UninitFreeType ()
 Free everything allocated w.r.t. More...
 

Variables

static const int ASCII_LETTERSTART = 32
 First printable ASCII letter.
 
static const int MAX_FONT_SIZE = 72
 Maximum font size.
 
static const int _default_font_height [FS_END] = {10, 6, 18, 10}
 Default heights for the different sizes of fonts. More...
 
static const int _default_font_ascender [FS_END] = { 8, 5, 15, 8}
 
FT_Library _library = NULL
 
FreeTypeSettings _freetype
 
static const byte FACE_COLOUR = 1
 
static const byte SHADOW_COLOUR = 2
 

Detailed Description

Cache for characters from fonts.

Definition in file fontcache.cpp.

Function Documentation

◆ GetCharacterHeight()

int GetCharacterHeight ( FontSize  size)

Get height of a character for a given font size.

Parameters
sizeFont size to get height of
Returns
Height of characters in the given font (pixels)

Definition at line 63 of file fontcache.cpp.

References FontCache::Get(), and FontCache::GetHeight().

Referenced by NWidgetResizeBase::SetMinimalTextLines().

◆ InitFreeType()

void InitFreeType ( bool  monospace)

(Re)initialize the freetype related things, i.e.

load the non-sprite fonts.

Parameters
monospaceWhether to initialise the monospace or regular fonts.

Definition at line 643 of file fontcache.cpp.

References FontCache::fs, and FS_BEGIN.

Referenced by MissingGlyphSearcher::FindMissingGlyphs(), and SetFallbackFont().

◆ LoadFreeTypeFont()

static void LoadFreeTypeFont ( FontSize  fs)
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'.

Parameters
fsThe font size to load.

Definition at line 324 of file fontcache.cpp.

◆ UninitFreeType()

void UninitFreeType ( )

Free everything allocated w.r.t.

fonts.

Definition at line 660 of file fontcache.cpp.

References FontCache::fs, and FS_BEGIN.

Variable Documentation

◆ _default_font_height

const int _default_font_height[FS_END] = {10, 6, 18, 10}
static

Default heights for the different sizes of fonts.

Definition at line 33 of file fontcache.cpp.