Changeset - r28096:1c7cbc1e05d5
[Not reviewed]
master
0 2 1
Peter Nelson - 13 months ago 2023-11-02 11:15:41
peter1138@openttd.org
Add: MockFontCache for testing GUI code that only needs to know font sizes.
3 files changed with 47 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/fontcache.h
Show inline comments
 
@@ -19,9 +19,8 @@ static const GlyphID SPRITE_GLYPH = 1U <
 

	
 
/** Font cache for basic fonts. */
 
class FontCache {
 
private:
 
protected:
 
	static FontCache *caches[FS_END]; ///< All the font caches.
 
protected:
 
	FontCache *parent;                ///< The parent of this font cache.
 
	const FontSize fs;                ///< The size of the font.
 
	int height;                       ///< The height of the font.
src/tests/CMakeLists.txt
Show inline comments
 
add_test_files(
 
    landscape_partial_pixel_z.cpp
 
    math_func.cpp
 
    mock_fontcache.h
 
    string_func.cpp
 
    strings_func.cpp
 
    test_main.cpp
src/tests/mock_fontcache.h
Show inline comments
 
new file 100644
 
/*
 
 * This file is part of OpenTTD.
 
 * 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.
 
 * 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.
 
 * 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/>.
 
 */
 

	
 
/** @file mock_fontcache.h Mock font cache implementation definition. */
 

	
 
#ifndef MOCK_FONTCACHE_H
 
#define MOCK_FONTCACHE_H
 

	
 
#include "../stdafx.h"
 

	
 
#include "../fontcache.h"
 
#include "../string_func.h"
 

	
 
/** Font cache for mocking basic use of fonts. */
 
class MockFontCache : public FontCache {
 
public:
 
	MockFontCache(FontSize fs) : FontCache(fs)
 
	{
 
		this->height = FontCache::GetDefaultFontHeight(this->fs);
 
	}
 

	
 
	void SetUnicodeGlyph(char32_t, SpriteID) override {}
 
	void InitializeUnicodeGlyphMap() override {}
 
	void ClearFontCache() override {}
 
	const Sprite *GetGlyph(GlyphID) override { return nullptr; }
 
	uint GetGlyphWidth(GlyphID) override { return this->height / 2; }
 
	bool GetDrawGlyphShadow() override { return false; }
 
	GlyphID MapCharToGlyph(char32_t key) override { return key; }
 
	const void *GetFontTable(uint32_t, size_t &length) override { length = 0; return nullptr; }
 
	std::string GetFontName() override { return "mock"; }
 
	bool IsBuiltInFont() override { return true; }
 

	
 
	static void InitializeFontCaches()
 
	{
 
		for (FontSize fs = FS_BEGIN; fs != FS_END; fs++) {
 
			if (FontCache::caches[fs] == nullptr) new MockFontCache(fs); /* FontCache inserts itself into to the cache. */
 
		}
 
	}
 
};
 

	
 
#endif /* MOCK_FONTCACHE_H */
0 comments (0 inline, 0 general)