OpenTTD Source 20241224-master-gf74b0cf984
fontcache.h File Reference

Functions to read fonts from files and cache them. More...

#include "string_type.h"
#include "spritecache.h"

Go to the source code of this file.

Data Structures

class  FontCache
 Font cache for basic fonts. More...
 
struct  FontCacheSubSetting
 Settings for a single font. More...
 
struct  FontCacheSettings
 Settings for the four different fonts. More...
 

Typedefs

typedef uint32_t GlyphID
 Glyphs are characters from a font.
 

Functions

void SetUnicodeGlyph (FontSize size, char32_t key, SpriteID sprite)
 Map a SpriteID to the font size and key.
 
void InitializeUnicodeGlyphMap ()
 Initialize the glyph map.
 
void ClearFontCache ()
 
const SpriteGetGlyph (FontSize size, char32_t key)
 Get the Sprite for a glyph.
 
uint GetGlyphWidth (FontSize size, char32_t key)
 Get the width of a glyph.
 
bool GetDrawGlyphShadow (FontSize size)
 
FontCacheSubSettingGetFontCacheSubSetting (FontSize fs)
 Get the settings of a given font size.
 
uint GetFontCacheFontSize (FontSize fs)
 Get the scalable font size to use for a FontSize.
 
std::string GetFontCacheFontName (FontSize fs)
 Get font to use for a given font size.
 
void InitFontCache (bool monospace)
 (Re)initialize the font cache related things, i.e.
 
void UninitFontCache ()
 Free everything allocated w.r.t.
 
bool GetFontAAState ()
 
void SetFont (FontSize fontsize, const std::string &font, uint size)
 

Variables

static const GlyphID SPRITE_GLYPH = 1U << 30
 
FontCacheSettings _fcsettings
 

Detailed Description

Functions to read fonts from files and cache them.

Definition in file fontcache.h.

Typedef Documentation

◆ GlyphID

typedef uint32_t GlyphID

Glyphs are characters from a font.

Definition at line 17 of file fontcache.h.

Function Documentation

◆ ClearFontCache()

void ClearFontCache ( )
inline

Definition at line 165 of file fontcache.h.

◆ GetDrawGlyphShadow()

bool GetDrawGlyphShadow ( FontSize  size)
inline

Definition at line 186 of file fontcache.h.

◆ GetFontAAState()

bool GetFontAAState ( )

Definition at line 93 of file fontcache.cpp.

◆ GetFontCacheFontName()

std::string GetFontCacheFontName ( FontSize  fs)

Get font to use for a given font size.

Parameters
fsFont size.
Returns
If configured, the font name to use, or the path of the default TrueType font if sprites are not preferred.

Definition at line 206 of file fontcache.cpp.

References GetDefaultTruetypeFontFile(), GetFontCacheSubSetting(), FontCacheSettings::prefer_sprite, and settings.

Referenced by LoadCoreTextFont(), LoadFreeTypeFont(), and LoadWin32Font().

◆ GetFontCacheFontSize()

uint GetFontCacheFontSize ( FontSize  fs)

Get the scalable font size to use for a FontSize.

Parameters
fsFontSize to get the scalable font size for.
Returns
Scalable font size to use.

Definition at line 162 of file fontcache.cpp.

References GetFontCacheSubSetting(), IsDefaultFont(), and FontCacheSubSetting::size.

Referenced by LoadCoreTextFont(), LoadFreeTypeFont(), and LoadWin32Font().

◆ GetFontCacheSubSetting()

FontCacheSubSetting * GetFontCacheSubSetting ( FontSize  fs)
inline

Get the settings of a given font size.

Parameters
fsThe font size to look up.
Returns
The settings.

Definition at line 216 of file fontcache.h.

References FS_LARGE, FS_MONO, FS_NORMAL, FS_SMALL, FontCacheSettings::large, FontCacheSettings::medium, FontCacheSettings::mono, and FontCacheSettings::small.

Referenced by GetFontCacheFontName(), GetFontCacheFontSize(), LoadCoreTextFont(), LoadFreeTypeFont(), and LoadWin32Font().

◆ GetGlyph()

const Sprite * GetGlyph ( FontSize  size,
char32_t  key 
)
inline

Get the Sprite for a glyph.

Definition at line 173 of file fontcache.h.

References FontCache::Get(), FontCache::GetGlyph(), and FontCache::MapCharToGlyph().

Referenced by DrawCharCentered().

◆ GetGlyphWidth()

uint GetGlyphWidth ( FontSize  size,
char32_t  key 
)
inline

Get the width of a glyph.

Definition at line 180 of file fontcache.h.

References FontCache::Get(), FontCache::GetGlyphWidth(), and FontCache::MapCharToGlyph().

Referenced by GetCharacterWidth(), LoadStringWidthTable(), and SpriteFontGetWidth().

◆ InitFontCache()

void InitFontCache ( bool  monospace)

(Re)initialize the font cache related things, i.e.

load the non-sprite fonts.

Parameters
monospaceWhether to initialise the monospace or regular fonts.

Definition at line 218 of file fontcache.cpp.

References FS_BEGIN, FS_MONO, FontCache::Get(), FontCache::HasParent(), LoadCoreTextFont(), LoadFreeTypeFont(), and LoadWin32Font().

Referenced by CheckForMissingGlyphs(), MissingGlyphSearcher::FindMissingGlyphs(), GameOptionsWindow::OnClick(), openttd_main(), and SetFallbackFont().

◆ InitializeUnicodeGlyphMap()

void InitializeUnicodeGlyphMap ( )
inline

Initialize the glyph map.

Definition at line 158 of file fontcache.h.

References FS_BEGIN, FontCache::Get(), and FontCache::InitializeUnicodeGlyphMap().

Referenced by HandleBootstrap(), and LoadSpriteTables().

◆ SetFont()

void SetFont ( FontSize  fontsize,
const std::string &  font,
uint  size 
)

Definition at line 101 of file fontcache.cpp.

◆ SetUnicodeGlyph()

void SetUnicodeGlyph ( FontSize  size,
char32_t  key,
SpriteID  sprite 
)
inline

Map a SpriteID to the font size and key.

Definition at line 152 of file fontcache.h.

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

Referenced by LoadFontGlyph().

◆ UninitFontCache()

void UninitFontCache ( )

Free everything allocated w.r.t.

fonts.

Definition at line 241 of file fontcache.cpp.

References FS_BEGIN, FontCache::Get(), FontCache::HasParent(), and UninitFreeType().

Referenced by ShutdownGame().

Variable Documentation

◆ _fcsettings

FontCacheSettings _fcsettings
extern

Definition at line 29 of file fontcache.cpp.

◆ SPRITE_GLYPH

const GlyphID SPRITE_GLYPH = 1U << 30
static

Definition at line 18 of file fontcache.h.