|
OpenTTD Source 20251213-master-g1091fa6071
|
Font cache for basic fonts. More...
#include <fontcache.h>
Data Structures | |
| struct | FontMetrics |
Public Member Functions | |
| FontSize | GetSize () const |
| Get the FontSize of the font. | |
| FontIndex | GetIndex () const |
| FontLoadReason | GetFontLoadReason () const |
| 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)=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. | |
| virtual int | GetGlyphYOffset () |
| 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 int | GetFontBaseline (FontSize fs) |
| static void | AddFallback (FontSizes fontsizes, FontLoadReason load_reason, std::string_view name, std::span< const std::byte > os_data={}) |
| Add a fallback font, with optional OS-specific handle. | |
| template<typename T > | |
| static void | AddFallbackWithHandle (FontSizes fontsizes, FontLoadReason load_reason, std::string_view name, T &handle) |
| Add a fallback font, with OS-specific handle. | |
| static std::span< const std::unique_ptr< FontCache > > | Get () |
| Get span of all FontCaches. | |
| static FontCache * | Get (FontIndex font_index) |
| Get the font cache of a given font size. | |
| static int | GetCharacterHeight (FontSize fs) |
| static void | UpdateCharacterHeight (FontSize fs) |
| static FontIndex | GetDefaultFontIndex (FontSize fs) |
| static class FontCache * | GetDefaultFontCache (FontSize fs) |
| static FontIndex | GetFontIndexForCharacter (FontSize fs, char32_t c) |
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, 6, 15, 8} |
| Default unscaled font ascenders. | |
Protected Types | |
| using | FontCaches = std::vector< std::unique_ptr< FontCache > > |
Protected Member Functions | |
| FontCache (FontSize fs) | |
Static Protected Member Functions | |
| static void | Register (std::unique_ptr< FontCache > &&fc, FontLoadReason load_reason) |
| static void | LoadDefaultFonts (FontSize fs) |
| static void | LoadFallbackFonts (FontSize fs, FontLoadReason load_reason) |
Protected Attributes | |
| const FontSize | fs |
| The size of the font. | |
| FontIndex | font_index |
| The index of the font. | |
| FontLoadReason | load_reason |
| Reason why the font is loaded. | |
| 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 FontCaches | caches |
| static std::array< FontMetrics, FS_END > | metrics {} |
| static std::array< FontIndex, FS_END > | default_font_index {} |
Font cache for basic fonts.
Definition at line 32 of file fontcache.h.
|
protected |
Definition at line 34 of file fontcache.h.
|
inlineprotected |
Definition at line 52 of file fontcache.h.
|
static |
Add a fallback font, with optional OS-specific handle.
| fontsizes | Fontsizes to add fallback to. |
| name | Name of font to add. |
| handle | OS-specific handle or data of font. |
Definition at line 256 of file fontcache.cpp.
References fs, GetFontCacheSubSetting(), and load_reason.
Referenced by AddFallbackWithHandle().
|
inlinestatic |
Add a fallback font, with OS-specific handle.
| fontsizes | Fontsizes to add fallback to. |
| name | Name of font to add. |
| handle | OS-specific handle or data of font. |
Definition at line 86 of file fontcache.h.
References AddFallback(), and load_reason.
|
pure virtual |
Clear the font cache.
Implemented in FreeTypeFontCache, SpriteFontCache, TrueTypeFontCache, CoreTextFontCache, Win32FontCache, and MockFontCache.
|
static |
Clear cached information for the specified font caches.
| fontsizes | Font sizes to clear. |
Definition at line 345 of file fontcache.cpp.
References fs, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
Referenced by AdjustGUIZoom(), CheckBlitter(), GfxLoadSprites(), LoadStringWidthTable(), and GameOptionsWindow::OnClick().
|
inlinestatic |
Get span of all FontCaches.
Definition at line 177 of file fontcache.h.
Referenced by CustomFontGetWidth(), GetGlyph(), GetGlyphWidth(), and SurveyFont().
|
inlinestatic |
Get the font cache of a given font size.
| fs | The font size to look up. |
Definition at line 187 of file fontcache.h.
References font_index.
|
inline |
Get the ascender value of the font.
Definition at line 112 of file fontcache.h.
References ascender.
|
inlinestatic |
Definition at line 193 of file fontcache.h.
Definition at line 205 of file fontcache.h.
|
static |
Definition at line 64 of file fontcache.cpp.
|
inlinestatic |
Definition at line 200 of file fontcache.h.
|
inline |
Get the descender value of the font.
Definition at line 118 of file fontcache.h.
References descender.
|
pure virtual |
Do we need to draw a glyph shadow?
Implemented in SpriteFontCache, TrueTypeFontCache, and MockFontCache.
Referenced by DrawLayoutLine().
|
inlinestatic |
Definition at line 72 of file fontcache.h.
|
inlinestatic |
Definition at line 212 of file fontcache.h.
|
inline |
Definition at line 100 of file fontcache.h.
|
pure virtual |
Get the name of this font.
Implemented in FreeTypeFontCache, SpriteFontCache, CoreTextFontCache, Win32FontCache, and MockFontCache.
Referenced by CoreTextParagraphLayoutFactory::GetParagraphLayout(), and HFontFromFont().
|
inlinevirtual |
Get the nominal font size of the font.
Reimplemented in TrueTypeFontCache.
Definition at line 124 of file fontcache.h.
References height.
Referenced by CoreTextParagraphLayoutFactory::GetParagraphLayout().
Get the glyph (sprite) of the given key.
| key | The key to look up. |
Implemented in SpriteFontCache, TrueTypeFontCache, and MockFontCache.
Referenced by DrawLayoutLine(), and GetGlyph().
|
pure virtual |
Get the width of the glyph with the given key.
| key | The key to look up. |
Implemented in SpriteFontCache, TrueTypeFontCache, and MockFontCache.
Referenced by UniscribeRun::FallbackShape(), ICURun::FallbackShape(), FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(), GetGlyphWidth(), and UniscribeShapeRun().
|
virtual |
Definition at line 93 of file fontcache.cpp.
|
inline |
Get the height of the font.
Definition at line 106 of file fontcache.h.
References height.
Referenced by HFontFromFont().
|
inline |
Definition at line 98 of file fontcache.h.
|
inlinevirtual |
Get the native OS font handle, if there is one.
Reimplemented in FreeTypeFontCache, CoreTextFontCache, and Win32FontCache.
Definition at line 160 of file fontcache.h.
Referenced by CoreTextParagraphLayoutFactory::GetParagraphLayout(), HFontFromFont(), and ICURun::Shape().
|
inline |
Get the FontSize of the font.
Definition at line 96 of file fontcache.h.
References fs.
Referenced by DrawLayoutLine(), and FallbackParagraphLayout::NextLine().
|
static |
Initialise font caches with the base sprite font cache for all sizes.
Definition at line 117 of file fontcache.cpp.
References FONTSIZES_ALL, and fs.
|
pure virtual |
Is this a built-in sprite font?
Implemented in FreeTypeFontCache, SpriteFontCache, TrueTypeFontCache, CoreTextFontCache, and MockFontCache.
Referenced by CoreTextParagraphLayoutFactory::GetParagraphLayout(), ICURun::Shape(), and UniscribeShapeRun().
|
staticprotected |
Definition at line 263 of file fontcache.cpp.
|
staticprotected |
Definition at line 273 of file fontcache.cpp.
|
static |
(Re)initialize the font cache related things, i.e.
load the non-sprite fonts.
| fontsizes | Font sizes to be initialised. |
Definition at line 286 of file fontcache.cpp.
References StringConsumer::AnyBytesLeft(), FONTSIZES_ALL, fs, GetFontCacheSubSetting(), FontProviderManager::LoadFont(), FontCacheSettings::prefer_default, StringConsumer::ReadUntilChar(), Layouter::ResetFontCache(), StringConsumer::SKIP_ONE_SEPARATOR, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and TrueType.
Referenced by CheckForMissingGlyphs(), MissingGlyphSearcher::FindMissingGlyphs(), and openttd_main().
|
pure virtual |
Map a character into a glyph.
| key | The character. |
Implemented in FreeTypeFontCache, SpriteFontCache, CoreTextFontCache, Win32FontCache, and MockFontCache.
Referenced by UniscribeRun::FallbackShape(), ICURun::FallbackShape(), FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(), GetGlyph(), and GetGlyphWidth().
|
staticprotected |
Definition at line 231 of file fontcache.cpp.
|
static |
Free everything allocated w.r.t.
fonts.
Definition at line 361 of file fontcache.cpp.
Referenced by ShutdownGame().
|
static |
Definition at line 69 of file fontcache.cpp.
|
protected |
The ascender value of the font.
Definition at line 49 of file fontcache.h.
Referenced by GetAscender().
|
staticprotected |
Definition at line 35 of file fontcache.h.
|
static |
Default unscaled font ascenders.
Default unscaled ascenders for the different sizes of fonts.
Definition at line 29 of file fontcache.h.
|
static |
Default unscaled font heights.
Default unscaled heights for the different sizes of fonts.
Definition at line 27 of file fontcache.h.
|
staticprotected |
Definition at line 112 of file fontcache.h.
|
protected |
The descender value of the font.
Definition at line 50 of file fontcache.h.
Referenced by GetDescender().
|
protected |
The index of the font.
Definition at line 46 of file fontcache.h.
Referenced by Get(), GetGlyph(), and GetGlyphWidth().
|
protected |
The size of the font.
Definition at line 45 of file fontcache.h.
Referenced by AddFallback(), SpriteFontCache::ClearFontCache(), TrueTypeFontCache::ClearFontCache(), ClearFontCaches(), TrueTypeFontCache::GetDrawGlyphShadow(), SpriteFontCache::GetGlyph(), SpriteFontCache::GetGlyphWidth(), GetSize(), InitializeFontCaches(), LoadFontCaches(), and SpriteFontCache::MapCharToGlyph().
|
protected |
The height of the font.
Definition at line 48 of file fontcache.h.
Referenced by GetFontSize(), MockFontCache::GetGlyphWidth(), and GetHeight().
|
protected |
Reason why the font is loaded.
Definition at line 47 of file fontcache.h.
Referenced by AddFallback(), and AddFallbackWithHandle().
|
staticprotected |
Definition at line 111 of file fontcache.h.