OpenTTD Source: FontCache Class Reference

OpenTTD Source 15.3

Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes
FontCache Class Referenceabstract

Font cache for basic fonts. More...

`#include <fontcache.h>`

Inheritance diagram for FontCache:

## Public Member Functions
FontSize | GetSize () const
| Get the FontSize of the font.
int | GetHeight () const
| Get the height of the font.
int | GetAscender () const
| Get the ascender value of the font.
int | GetDescender () const
| Get the descender value of the font.
virtual int | GetFontSize () const
| Get the nominal font size of the font.
virtual void | ClearFontCache ()=0
| Clear the font cache.
virtual const Sprite * | GetGlyph (GlyphID key)=0
| Get the glyph (sprite) of the given key.
virtual uint | GetGlyphWidth (GlyphID key)=0
| Get the width of the glyph with the given key.
virtual bool | GetDrawGlyphShadow ()=0
| Do we need to draw a glyph shadow?
virtual GlyphID | MapCharToGlyph (char32_t key, bool fallback=true)=0
| Map a character into a glyph.
virtual const void * | GetOSHandle ()
| Get the native OS font handle, if there is one.
virtual std::string | GetFontName ()=0
| Get the name of this font.
bool | HasParent ()
| Check whether the font cache has a parent.
virtual bool | IsBuiltInFont ()=0
| Is this a built-in sprite font?

## Static Public Member Functions
static void | InitializeFontCaches ()
| Initialise font caches with the base sprite font cache for all sizes.
static void | UninitializeFontCaches ()
| Free everything allocated w.r.t.
static void | LoadFontCaches (FontSizes fontsizes)
| (Re)initialize the font cache related things, i.e.
static void | ClearFontCaches (FontSizes fontsizes)
| Clear cached information for the specified font caches.
static int | GetDefaultFontHeight (FontSize fs)
static FontCache * | Get (FontSize fs)
| Get the font cache of a given font size.
static std::string | GetName (FontSize fs)
| Get the font name of a given font size.

## Static Public Attributes
static const int | DEFAULT_FONT_HEIGHT [FS_END] = {10, 6, 18, 10}
| Default unscaled font heights.
static const int | DEFAULT_FONT_ASCENDER [FS_END] = {8, 5, 15, 8}
| Default unscaled font ascenders.

## Protected Member Functions
| FontCache (FontSize fs)

## Static Protected Member Functions
static void | Register (std::unique_ptr< FontCache > &&fc)
| Register a FontCache for its font size.

## Protected Attributes
std::unique_ptr< FontCache > | parent
| The parent of this font cache.
const FontSize | fs
| The size of the font.
int | height = 0
| The height of the font.
int | ascender = 0
| The ascender value of the font.
int | descender = 0
| The descender value of the font.

## Static Protected Attributes
static std::array< std::unique_ptr< FontCache >, FS_END > | caches {}
| All the font caches.

## Detailed Description

Font cache for basic fonts.

Definition at line 22 of file fontcache.h.

## Constructor & Destructor Documentation

## ◆ FontCache()

FontCache::FontCache | ( | FontSize | fs | ) |
| inlineprotected

Definition at line 31 of file fontcache.h.

## Member Function Documentation

## ◆ ClearFontCache()

virtual void FontCache::ClearFontCache | ( |  | ) |
| pure virtual

Clear the font cache.

Implemented in FreeTypeFontCache, SpriteFontCache, TrueTypeFontCache, CoreTextFontCache, Win32FontCache, and MockFontCache.

Referenced by ClearFontCaches().

## ◆ ClearFontCaches()

void FontCache::ClearFontCaches | ( | FontSizes | fontsizes | ) |
| static

Clear cached information for the specified font caches.

Parameters

  fontsizes | Font sizes to clear.

Definition at line 257 of file fontcache.cpp.

References ClearFontCache(), fs, and Get().

Referenced by AdjustGUIZoom(), CheckBlitter(), GfxLoadSprites(), LoadStringWidthTable(), and GameOptionsWindow::OnClick().

## ◆ Get()

static FontCache * FontCache::Get | ( | FontSize | fs | ) |
| inlinestatic

Get the font cache of a given font size.

Parameters

  fs | The font size to look up.

Returns
  The font cache.

Definition at line 130 of file fontcache.h.

References caches, and fs.

Referenced by ClearFontCaches(), MissingGlyphSearcher::FindMissingGlyphs(), GetCharacterHeight(), GetGlyph(), GetGlyphWidth(), GetName(), InitializeFontCaches(), LoadFontCaches(), and SurveyFont().

## ◆ GetAscender()

int FontCache::GetAscender | ( |  | ) | const
| inline

Get the ascender value of the font.

Returns
  The ascender value of the font.

Definition at line 65 of file fontcache.h.

References ascender.

Referenced by FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun().

## ◆ GetDefaultFontHeight()

int FontCache::GetDefaultFontHeight | ( | FontSize | fs | ) |
| static

Definition at line 61 of file fontcache.cpp.

## ◆ GetDescender()

int FontCache::GetDescender | ( |  | ) | const
| inline

Get the descender value of the font.

Returns
  The descender value of the font.

Definition at line 71 of file fontcache.h.

References descender.

## ◆ GetDrawGlyphShadow()

virtual bool FontCache::GetDrawGlyphShadow | ( |  | ) |
| pure virtual

Do we need to draw a glyph shadow?

Returns
  True if it has to be done, otherwise false.

Implemented in SpriteFontCache, TrueTypeFontCache, and MockFontCache.

Referenced by DrawLayoutLine().

## ◆ GetFontName()

virtual std::string FontCache::GetFontName | ( |  | ) |
| pure virtual

Get the name of this font.

Returns
  The name of the font.

Implemented in FreeTypeFontCache, SpriteFontCache, CoreTextFontCache, Win32FontCache, and MockFontCache.

Referenced by GetName(), HFontFromFont(), and SurveyFont().

## ◆ GetFontSize()

virtual int FontCache::GetFontSize | ( |  | ) | const
| inlinevirtual

Get the nominal font size of the font.

Returns
  The nominal font size.

Reimplemented in TrueTypeFontCache.

Definition at line 77 of file fontcache.h.

References height.

## ◆ GetGlyph()

virtual const Sprite * FontCache::GetGlyph | ( | GlyphID | key | ) |
| pure virtual

Get the glyph (sprite) of the given key.

Parameters

  key | The key to look up.

Returns
  The sprite.

Implemented in SpriteFontCache, TrueTypeFontCache, and MockFontCache.

Referenced by DrawLayoutLine(), and GetGlyph().

## ◆ GetGlyphWidth()

virtual uint FontCache::GetGlyphWidth | ( | GlyphID | key | ) |
| pure virtual

Get the width of the glyph with the given key.

Parameters

  key | The key to look up.

Returns
  The width.

Implemented in SpriteFontCache, TrueTypeFontCache, and MockFontCache.

Referenced by FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(), GetGlyphWidth(), and UniscribeShapeRun().

## ◆ GetHeight()

int FontCache::GetHeight | ( |  | ) | const
| inline

Get the height of the font.

Returns
  The height of the font.

Definition at line 59 of file fontcache.h.

References height.

Referenced by FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(), GetCharacterHeight(), HFontFromFont(), and UniscribeShapeRun().

## ◆ GetName()

std::string FontCache::GetName | ( | FontSize | fs | ) |
| static

Get the font name of a given font size.

Parameters

  fs | The font size to look up.

Returns
  The font name.

Definition at line 71 of file fontcache.cpp.

References fs, Get(), and GetFontName().

## ◆ GetOSHandle()

virtual const void * FontCache::GetOSHandle | ( |  | ) |
| inlinevirtual

Get the native OS font handle, if there is one.

Returns
  Opaque OS font handle.

Reimplemented in FreeTypeFontCache, CoreTextFontCache, and Win32FontCache.

Definition at line 114 of file fontcache.h.

Referenced by HFontFromFont().

## ◆ GetSize()

FontSize FontCache::GetSize | ( |  | ) | const
| inline

Get the FontSize of the font.

Returns
  The FontSize.

Definition at line 53 of file fontcache.h.

References fs.

Referenced by DrawLayoutLine(), FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(), FallbackParagraphLayout::NextLine(), and UniscribeShapeRun().

## ◆ HasParent()

bool FontCache::HasParent | ( |  | ) |
| inline

Check whether the font cache has a parent.

Definition at line 141 of file fontcache.h.

Referenced by LoadFontCaches().

## ◆ InitializeFontCaches()

void FontCache::InitializeFontCaches | ( |  | ) |
| static

Initialise font caches with the base sprite font cache for all sizes.

Definition at line 98 of file fontcache.cpp.

References fs, FS_BEGIN, Get(), FontProviderManager::LoadFont(), Register(), and Sprite.

Referenced by LoadFontCaches().

## ◆ IsBuiltInFont()

virtual bool FontCache::IsBuiltInFont | ( |  | ) |
| pure virtual

Is this a built-in sprite font?

Implemented in FreeTypeFontCache, SpriteFontCache, TrueTypeFontCache, CoreTextFontCache, and MockFontCache.

Referenced by FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun().

## ◆ LoadFontCaches()

void FontCache::LoadFontCaches | ( | FontSizes | fontsizes | ) |
| static

(Re)initialize the font cache related things, i.e.

load the non-sprite fonts.

Parameters

  fontsizes | Font sizes to be initialised.

Definition at line 237 of file fontcache.cpp.

References caches, fs, Get(), HasParent(), InitializeFontCaches(), FontProviderManager::LoadFont(), parent, Register(), Layouter::ResetFontCache(), and TrueType.

Referenced by CheckForMissingGlyphs(), MissingGlyphSearcher::FindMissingGlyphs(), GameOptionsWindow::OnClick(), and openttd_main().

## ◆ MapCharToGlyph()

virtual GlyphID FontCache::MapCharToGlyph | ( | char32_t | key,
|  | bool | fallback = `true`
| ) |  |
| pure virtual

Map a character into a glyph.

Parameters

  key | The character.
  fallback | Allow fallback to the parent font.

Returns
  The glyph ID used to draw the character.

Implemented in FreeTypeFontCache, SpriteFontCache, CoreTextFontCache, Win32FontCache, and MockFontCache.

Referenced by FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(), MissingGlyphSearcher::FindMissingGlyphs(), GetGlyph(), GetGlyphWidth(), and UniscribeShapeRun().

## ◆ Register()

void FontCache::Register | ( | std::unique_ptr< FontCache > && | fc | ) |
| staticprotected

Register a FontCache for its font size.

Parameters

  fc | FontCache to register.

Definition at line 223 of file fontcache.cpp.

References caches, fs, and parent.

Referenced by InitializeFontCaches(), and LoadFontCaches().

## ◆ UninitializeFontCaches()

void FontCache::UninitializeFontCaches | ( |  | ) |
| static

Free everything allocated w.r.t.

fonts.

Definition at line 267 of file fontcache.cpp.

References caches.

Referenced by ShutdownGame().

## Field Documentation

## ◆ ascender

int FontCache::ascender = 0
| protected

The ascender value of the font.

Definition at line 28 of file fontcache.h.

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

## ◆ caches

std::array< std::unique_ptr< FontCache >, FS_END > FontCache::caches {}
| staticprotected

All the font caches.

Definition at line 93 of file fontcache.h.

Referenced by Get(), LoadFontCaches(), Register(), and UninitializeFontCaches().

## ◆ DEFAULT_FONT_ASCENDER

const int FontCache::DEFAULT_FONT_ASCENDER = {8, 5, 15, 8}
| static

Default unscaled font ascenders.

Default unscaled ascenders for the different sizes of fonts.

Definition at line 26 of file fontcache.h.

## ◆ DEFAULT_FONT_HEIGHT

const int FontCache::DEFAULT_FONT_HEIGHT = {10, 6, 18, 10}
| static

Default unscaled font heights.

Default unscaled heights for the different sizes of fonts.

Definition at line 24 of file fontcache.h.

## ◆ descender

int FontCache::descender = 0
| protected

The descender value of the font.

Definition at line 29 of file fontcache.h.

Referenced by GetDescender().

## ◆ fs

const FontSize FontCache::fs
| protected

The size of the font.

Definition at line 26 of file fontcache.h.

Referenced by SpriteFontCache::ClearFontCache(), TrueTypeFontCache::ClearFontCache(), ClearFontCaches(), Get(), TrueTypeFontCache::GetDrawGlyphShadow(), SpriteFontCache::GetGlyph(), SpriteFontCache::GetGlyphWidth(), GetName(), GetSize(), InitializeFontCaches(), LoadFontCaches(), SpriteFontCache::MapCharToGlyph(), and Register().

## ◆ height

int FontCache::height = 0
| protected

The height of the font.

Definition at line 27 of file fontcache.h.

Referenced by SpriteFontCache::ClearFontCache(), GetFontSize(), MockFontCache::GetGlyphWidth(), GetHeight(), and SpriteFontCache::SpriteFontCache().

## ◆ parent

std::unique_ptr<FontCache> FontCache::parent
| protected

The parent of this font cache.

Definition at line 25 of file fontcache.h.

Referenced by TrueTypeFontCache::GetGlyph(), TrueTypeFontCache::GetGlyphWidth(), LoadFontCaches(), FreeTypeFontCache::MapCharToGlyph(), CoreTextFontCache::MapCharToGlyph(), Win32FontCache::MapCharToGlyph(), and Register().

The documentation for this class was generated from the following files:

- src/fontcache.h
- src/fontcache.cpp