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/>.
8 /** @file mock_fontcache.h Mock font cache implementation definition. */
10 #ifndef MOCK_FONTCACHE_H
11 #define MOCK_FONTCACHE_H
13 #include "../stdafx.h"
15 #include "../fontcache.h"
16 #include "../string_func.h"
18 /** Font cache for mocking basic use of fonts. */
19 class MockFontCache
: public FontCache
{
21 MockFontCache(FontSize fs
) : FontCache(fs
)
23 this->height
= FontCache::GetDefaultFontHeight(this->fs
);
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 std::string
GetFontName() override
{ return "mock"; }
34 bool IsBuiltInFont() override
{ return true; }
36 static void InitializeFontCaches()
38 for (FontSize fs
= FS_BEGIN
; fs
!= FS_END
; fs
++) {
39 if (FontCache::caches
[fs
] == nullptr) new MockFontCache(fs
); /* FontCache inserts itself into to the cache. */
44 #endif /* MOCK_FONTCACHE_H */