OpenTTD Source 20260421-master-gc2fbc6fdeb
fontcache.h File Reference

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

#include <any>
#include "gfx_type.h"
#include "provider_manager.h"
#include "spritecache_type.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.
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 19 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 231 of file fontcache.h.

Function Documentation

◆ GetDrawGlyphShadow()

bool GetDrawGlyphShadow ( FontSize size)
inline

Definition at line 184 of file fontcache.h.

◆ GetFontAAState()

bool GetFontAAState ( )

Definition at line 108 of file fontcache.cpp.

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

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

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

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

References Large, Monospace, Normal, and Small.

Referenced by FontCache::AddFallback(), ConFont(), GetFontCacheFontName(), GetFontCacheFontSize(), and FontCache::LoadFontCaches().

◆ GetGlyph()

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

Get the Sprite for a glyph.

Parameters
sizeThe font size to look in.
keyThe key to look up.
Returns
The sprite.

Definition at line 166 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.

Parameters
sizeThe font size to look in.
keyThe key to look up.
Returns
The sprite's width.

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

References Begin, End, and InitializeUnicodeGlyphMap().

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

◆ SetFont()

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

Definition at line 116 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 57 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 20 of file fontcache.h.