From 9c356d052c7eda264d4f89da91ea34bf39023f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 31 Oct 2013 15:17:02 +0100 Subject: [PATCH] Plugins: remove the need for FreeTypeFont in MagnumFontConverter test. --- .../MagnumFontConverter/Test/CMakeLists.txt | 4 +- .../Test/MagnumFontConverterTest.cpp | 44 +++++++++++++------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt b/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt index a6b28e93e..91b3d9470 100644 --- a/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt +++ b/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt @@ -25,12 +25,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/magnumFontConverterTestConfigure.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/magnumFontConverterTestConfigure.h) -include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../FreeTypeFont/Test/ - ${CMAKE_CURRENT_BINARY_DIR}/../../MagnumFont/Test/ +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../MagnumFont/Test/ ${CMAKE_CURRENT_BINARY_DIR}) corrade_add_test(MagnumFontConverterTest MagnumFontConverterTest.cpp LIBRARIES MagnumFontConverterTestLib - FreeTypeFontTestLib TgaImporterTestLib ${GL_TEST_LIBRARIES}) diff --git a/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp b/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp index 9e00c415c..d75fbb48a 100644 --- a/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp +++ b/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp @@ -31,11 +31,10 @@ #include #include -#include "FreeTypeFont/FreeTypeFont.h" +#include "Text/AbstractFont.h" #include "MagnumFontConverter/MagnumFontConverter.h" #include "TgaImporter/TgaImporter.h" -#include "freeTypeFontTestConfigure.h" #include "magnumFontTestConfigure.h" #include "magnumFontConverterTestConfigure.h" @@ -45,19 +44,11 @@ class MagnumFontConverterTest: public Magnum::Test::AbstractOpenGLTester { public: explicit MagnumFontConverterTest(); - ~MagnumFontConverterTest(); - void exportFont(); }; MagnumFontConverterTest::MagnumFontConverterTest() { addTests({&MagnumFontConverterTest::exportFont}); - - FreeTypeFont::initialize(); -} - -MagnumFontConverterTest::~MagnumFontConverterTest() { - FreeTypeFont::finalize(); } void MagnumFontConverterTest::exportFont() { @@ -65,9 +56,36 @@ void MagnumFontConverterTest::exportFont() { Utility::Directory::rm(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.conf")); Utility::Directory::rm(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.tga")); - /* Open font */ - FreeTypeFont font; - CORRADE_VERIFY(font.openFile(Utility::Directory::join(FREETYPEFONT_TEST_DIR, "Oxygen.ttf"), 16.0f)); + /* Fake font with fake cache */ + class FakeFont: public Text::AbstractFont { + public: + explicit FakeFont() { _size = 16.0f; } + + private: + void doClose() {} + bool doIsOpened() const { return true; } + Features doFeatures() const { return {}; } + AbstractLayouter* doLayout(const GlyphCache&, Float, const std::string&) { return nullptr; } + + UnsignedInt doGlyphId(const char32_t character) { + switch(character) { + case 'W': return 2; + case 'e': return 1; + } + + return 0; + } + + Vector2 doGlyphAdvance(const UnsignedInt glyph) { + switch(glyph) { + case 0: return {8, 0}; + case 1: return {12, 0}; + case 2: return {23, 0}; + } + + CORRADE_ASSERT_UNREACHABLE(); + } + } font; /* Create fake cache */ MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg);