OpenTTD Source: src/tests/mock_fontcache.h Source File

OpenTTD Source 14.1

mock_fontcache.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef MOCK_FONTCACHE_H
11 #define MOCK_FONTCACHE_H
12
13 #include "../stdafx.h"
14
15 #include "../fontcache.h"
16 #include "../string_func.h"
17
19 class MockFontCache : public FontCache {
20 public:
21 MockFontCache(FontSize fs) : FontCache(fs)
22 {
23 this->height = FontCache::GetDefaultFontHeight(this->fs);
24 }
25
26 void SetUnicodeGlyph(char32_t, SpriteID) override {}
27 void InitializeUnicodeGlyphMap() override {}
28 void ClearFontCache() override {}
29 const Sprite *GetGlyph(GlyphID) override { return nullptr; }
30 uint GetGlyphWidth(GlyphID) override { return this->height / 2; }
31 bool GetDrawGlyphShadow() override { return false; }
32 GlyphID MapCharToGlyph(char32_t key, [[maybe_unused]] bool allow_fallback = true) override { return key; }
33 const void *GetFontTable(uint32_t, size_t &length) override { length = 0; return nullptr; }
34 std::string GetFontName() override { return "mock"; }
35 bool IsBuiltInFont() override { return true; }
36
37 static void InitializeFontCaches()
38 {
39 for (FontSize fs = FS_BEGIN; fs != FS_END; fs++) {
40 if (FontCache::caches[fs] == nullptr) new MockFontCache(fs); /* FontCache inserts itself into to the cache. */
41 }
42 }
43 };
44
45 #endif /* MOCK_FONTCACHE_H */
MockFontCache::GetGlyphWidth
uint GetGlyphWidth(GlyphID) override
Get the width of the glyph with the given key.
Definition: mock_fontcache.h:30
FS_BEGIN
@ FS_BEGIN
First font.
Definition: gfx_type.h:209
FontCache::height
int height
The height of the font.
Definition: fontcache.h:26
MockFontCache::ClearFontCache
void ClearFontCache() override
Clear the font cache.
Definition: mock_fontcache.h:28
MockFontCache::GetGlyph
const Sprite * GetGlyph(GlyphID) override
Get the glyph (sprite) of the given key.
Definition: mock_fontcache.h:29
MockFontCache::GetDrawGlyphShadow
bool GetDrawGlyphShadow() override
Do we need to draw a glyph shadow?
Definition: mock_fontcache.h:31
GlyphID
uint32_t GlyphID
Glyphs are characters from a font.
Definition: fontcache.h:17
MockFontCache::IsBuiltInFont
bool IsBuiltInFont() override
Is this a built-in sprite font?
Definition: mock_fontcache.h:35
FontCache::fs
const FontSize fs
The size of the font.
Definition: fontcache.h:25
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
MockFontCache::GetFontTable
const void * GetFontTable(uint32_t, size_t &length) override
Read a font table from the font.
Definition: mock_fontcache.h:33
MockFontCache
Font cache for mocking basic use of fonts.
Definition: mock_fontcache.h:19
FontCache::caches
static FontCache * caches[FS_END]
All the font caches.
Definition: fontcache.h:23
FontCache
Font cache for basic fonts.
Definition: fontcache.h:21
MockFontCache::GetFontName
std::string GetFontName() override
Get the name of this font.
Definition: mock_fontcache.h:34
MockFontCache::SetUnicodeGlyph
void SetUnicodeGlyph(char32_t, SpriteID) override
Map a SpriteID to the key.
Definition: mock_fontcache.h:26
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
FontCache::FontCache
FontCache(FontSize fs)
Create a new font cache.
Definition: fontcache.cpp:35
MockFontCache::InitializeUnicodeGlyphMap
void InitializeUnicodeGlyphMap() override
Initialize the glyph map.
Definition: mock_fontcache.h:27