OpenTTD Source 20260206-master-g4d4e37dbf1
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 int ScaleFontTrad (int value)
 Scale traditional pixel dimensions to font zoom level, for drawing sprite fonts.
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()

SpriteID GetUnicodeGlyph ( FontSize fs,
char32_t key )
static

Get SpriteID associated with a character.

Parameters
fsThe font size of the character.
keyCharacter to find.
Returns
SpriteID for character, or 0 if not present.

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

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

◆ ScaleFontTrad()

int ScaleFontTrad ( int value)
static

Scale traditional pixel dimensions to font zoom level, for drawing sprite fonts.

Parameters
valuePixel amount at #ZOOM_BASE (traditional "normal" interface size).
Returns
Pixel amount at _font_zoom (current interface size).

Definition at line 31 of file spritefontcache.cpp.

References _font_zoom, and UnScaleByZoom().

Referenced by SpriteFontCache::ClearFontCache(), SpriteFontCache::GetGlyphWidth(), and SpriteFontCache::SpriteFontCache().

◆ 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

◆ _char_maps

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

Glyph map for each font size.

Definition at line 36 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().