OpenTTD Source 20251213-master-g1091fa6071
fontcache.h File Reference

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

#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  FontCache::FontMetrics
 
struct  FontCacheSubSetting
 Settings for a single font. More...
 
struct  FontCacheSubSetting::FontCacheFallback
 
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.
 
using FontIndex = uint8_t
 

Enumerations

enum class  FontLoadReason : uint8_t {
  Default , Configured , LanguageFallback , MissingFallback ,
  End
}
 
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.
 
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 FontIndex INVALID_FONT_INDEX = std::numeric_limits<FontIndex>::max()
 
FontCacheSettings _fcsettings
 

Detailed Description

Functions to read fonts from files and cache them.

Definition in file fontcache.h.

Typedef Documentation

◆ FontIndex

using FontIndex = uint8_t

Definition at line 19 of file fontcache.h.

◆ GlyphID

typedef uint32_t GlyphID

Glyphs are characters from a font.

Definition at line 18 of file fontcache.h.

Enumeration Type Documentation

◆ FontLoadReason

enum class FontLoadReason : uint8_t
strong

Definition at line 23 of file fontcache.h.

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

Function Documentation

◆ GetFontAAState()

bool GetFontAAState ( )

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

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

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

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

Referenced by FreeTypeFontCacheFactory::LoadFont(), Win32FontCacheFactory::LoadFont(), and CoreTextFontCacheFactory::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 280 of file fontcache.h.

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

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

◆ GetGlyph()

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

Get the Sprite for a glyph.

Definition at line 231 of file fontcache.h.

References FontCache::font_index, 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 240 of file fontcache.h.

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

Referenced by GetCharacterWidth(), and LoadStringWidthTable().

◆ InitializeUnicodeGlyphMap()

void InitializeUnicodeGlyphMap ( )

Initialize the glyph map.

Definition at line 96 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 133 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 46 of file spritefontcache.cpp.

References _char_maps.

Referenced by InitializeUnicodeGlyphMap(), and LoadFontGlyph().

Variable Documentation

◆ _fcsettings

FontCacheSettings _fcsettings
extern

Definition at line 31 of file fontcache.cpp.

◆ INVALID_FONT_INDEX

const FontIndex INVALID_FONT_INDEX = std::numeric_limits<FontIndex>::max()
static

Definition at line 21 of file fontcache.h.