OpenTTD Source 20260208-master-g43af8e94d0
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef MOCK_FONTCACHE_H
11#define MOCK_FONTCACHE_H
12
13#include "../fontcache.h"
14#include "../string_func.h"
15
17class MockFontCache : public FontCache {
18public:
19 MockFontCache(FontSize fs) : FontCache(fs)
20 {
21 this->height = FontCache::GetDefaultFontHeight(this->fs);
22 }
23
24 void ClearFontCache() override {}
25 const Sprite *GetGlyph(GlyphID) override { return nullptr; }
26 uint GetGlyphWidth(GlyphID) override { return this->height / 2; }
27 bool GetDrawGlyphShadow() override { return false; }
28 GlyphID MapCharToGlyph(char32_t key, [[maybe_unused]] bool allow_fallback = true) override { return key; }
29 std::string GetFontName() override { return "mock"; }
30 bool IsBuiltInFont() override { return true; }
31
32 static void InitializeFontCaches()
33 {
34 for (FontSize fs = FS_BEGIN; fs != FS_END; fs++) {
35 if (FontCache::Get(fs) != nullptr) continue;
36 FontCache::Register(std::make_unique<MockFontCache>(fs));
37 }
38 }
39};
40
41#endif /* MOCK_FONTCACHE_H */
int height
The height of the font.
Definition fontcache.h:27
static void Register(std::unique_ptr< FontCache > &&fc)
Register a FontCache for its font size.
const FontSize fs
The size of the font.
Definition fontcache.h:26
static FontCache * Get(FontSize fs)
Get the font cache of a given font size.
Definition fontcache.h:130
static void InitializeFontCaches()
Initialise font caches with the base sprite font cache for all sizes.
Definition fontcache.cpp:98
GlyphID MapCharToGlyph(char32_t key, bool allow_fallback=true) override
Map a character into a glyph.
std::string GetFontName() override
Get the name of this font.
uint GetGlyphWidth(GlyphID) override
Get the width of the glyph with the given key.
void ClearFontCache() override
Clear the font cache.
const Sprite * GetGlyph(GlyphID) override
Get the glyph (sprite) of the given key.
bool GetDrawGlyphShadow() override
Do we need to draw a glyph shadow?
bool IsBuiltInFont() override
Is this a built-in sprite font?
Functions to read fonts from files and cache them.
FontSize
Available font sizes.
Definition gfx_type.h:248
@ FS_BEGIN
First font.
Definition gfx_type.h:255
Functions related to low-level strings.
Data structure describing a sprite.