OpenTTD Source 20251213-master-g1091fa6071
spritefontcache.cpp File Reference

Sprite fontcache implementation. More...

#include "../stdafx.h"
#include "../fontcache.h"
#include "../gfx_layout.h"
#include "../spritecache.h"
#include "../string_func.h"
#include "../zoom_func.h"
#include "spritefontcache.h"
#include "../table/sprites.h"
#include "../table/control_codes.h"
#include "../table/unicode.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

class  SpriteFontCacheFactory
 

Functions

static SpriteID GetUnicodeGlyph (FontSize fs, char32_t key)
 Get SpriteID associated with a character.
 
void SetUnicodeGlyph (FontSize fs, char32_t key, SpriteID sprite)
 Set the SpriteID for a unicode character.
 
void InitializeUnicodeGlyphMap (FontSize fs)
 Initialize the glyph map for a font size.
 
void InitializeUnicodeGlyphMap ()
 Initialize the glyph map.
 

Variables

static const int ASCII_LETTERSTART = 32
 First printable ASCII letter.
 
static std::array< std::unordered_map< char32_t, SpriteID >, FS_END > _char_maps {}
 Glyph map for each font size.
 

Detailed Description

Sprite fontcache implementation.

Definition in file spritefontcache.cpp.

Function Documentation

◆ GetUnicodeGlyph()

static SpriteID GetUnicodeGlyph ( FontSize  fs,
char32_t  key 
)
static

Get SpriteID associated with a character.

Parameters
keyCharacter to find.
Returns
SpriteID for character, or 0 if not present.

Definition at line 33 of file spritefontcache.cpp.

References _char_maps.

Referenced by SpriteFontCache::GetGlyph(), SpriteFontCache::GetGlyphWidth(), and SpriteFontCache::MapCharToGlyph().

◆ InitializeUnicodeGlyphMap() [1/2]

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().

◆ InitializeUnicodeGlyphMap() [2/2]

void InitializeUnicodeGlyphMap ( FontSize  fs)

Initialize the glyph map for a font size.

This populates the glyph map with the baseset font sprites.

Parameters
fsFont size to initialize.

Definition at line 56 of file spritefontcache.cpp.

References _char_maps, ASCII_LETTERSTART, CLRA, FS_LARGE, FS_MONO, FS_NORMAL, FS_SMALL, and SetUnicodeGlyph().

◆ 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

◆ _char_maps

std::array<std::unordered_map<char32_t, SpriteID>, FS_END> _char_maps {}
static

Glyph map for each font size.

Definition at line 26 of file spritefontcache.cpp.

Referenced by GetUnicodeGlyph(), InitializeUnicodeGlyphMap(), and SetUnicodeGlyph().

◆ ASCII_LETTERSTART

const int ASCII_LETTERSTART = 32
static

First printable ASCII letter.

Definition at line 24 of file spritefontcache.cpp.

Referenced by InitializeUnicodeGlyphMap().