OpenTTD Source 20250824-master-g98090fe948
fontcache.h File Reference

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

#include "provider_manager.h"
#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...
 
class  FontCacheFactory
 Factory for FontCaches. More...
 
class  FontProviderManager
 

Typedefs

typedef uint32_t GlyphID
 Glyphs are characters from a font.
 

Enumerations

enum class  FontType : uint8_t { Sprite , TrueType }
 Different types of font that can be loaded. More...
 

Functions

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.
 
bool GetFontAAState ()
 
void SetFont (FontSize fontsize, const std::string &font, uint size)
 
void InitializeUnicodeGlyphMap ()
 Initialize the glyph map.
 
void SetUnicodeGlyph (FontSize size, char32_t key, SpriteID sprite)
 Set the SpriteID for a unicode character.
 

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 18 of file fontcache.h.

Enumeration Type Documentation

◆ FontType

enum class FontType : uint8_t
strong

Different types of font that can be loaded.

Enumerator
Sprite 

Bitmap sprites from GRF files.

TrueType 

Scalable TrueType fonts.

Definition at line 214 of file fontcache.h.

Function Documentation

◆ GetDrawGlyphShadow()

bool GetDrawGlyphShadow ( FontSize  size)
inline

Definition at line 166 of file fontcache.h.

◆ GetFontAAState()

bool GetFontAAState ( )

Definition at line 107 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 211 of file fontcache.cpp.

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

Referenced by FreeTypeFontCacheFactory::LoadFont(), CoreTextFontCacheFactory::LoadFont(), and Win32FontCacheFactory::LoadFont().

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

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

Referenced by FreeTypeFontCacheFactory::LoadFont(), CoreTextFontCacheFactory::LoadFont(), and Win32FontCacheFactory::LoadFont().

◆ GetFontCacheSubSetting()

FontCacheSubSetting * GetFontCacheSubSetting ( FontSize  fs)
inline

◆ GetGlyph()

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

Get the Sprite for a glyph.

Definition at line 153 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 160 of file fontcache.h.

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

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

◆ InitializeUnicodeGlyphMap()

void InitializeUnicodeGlyphMap ( )

Initialize the glyph map.

Definition at line 104 of file spritefontcache.cpp.

References FS_BEGIN, and InitializeUnicodeGlyphMap().

Referenced by HandleBootstrap(), InitializeUnicodeGlyphMap(), and LoadSpriteTables().

◆ SetFont()

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

Definition at line 115 of file fontcache.cpp.

◆ SetUnicodeGlyph()

void SetUnicodeGlyph ( FontSize  fs,
char32_t  key,
SpriteID  sprite 
)

Set the SpriteID for a unicode character.

Parameters
fsFont size to set.
keyUnicode character to set.
spriteSpriteID of character.

Definition at line 55 of file spritefontcache.cpp.

References _char_maps.

Referenced by InitializeUnicodeGlyphMap(), and LoadFontGlyph().

Variable Documentation

◆ _fcsettings

FontCacheSettings _fcsettings
extern

Definition at line 28 of file fontcache.cpp.

◆ SPRITE_GLYPH

const GlyphID SPRITE_GLYPH = 1U << 30
static

Definition at line 19 of file fontcache.h.