mirror of https://github.com/mosra/magnum.git
Browse Source
Implementation is moved into `do*()` private virtual functions, public interface is doing additional sanity checks around them. Opening files is by default done in base implementation, which loads the files into memory and then calls function for opening raw data. Added interface for opening multi-file fonts from raw data, default implementation just calls single-file implementation. Function for creating glyph cache converts the text from UTF-8 to UTF-32 and then calls the implementation, removing the burden from reimplementing this in each plugin. Added unit test for file and single data opening, bumped plugin version to 0.2.pull/278/head
7 changed files with 386 additions and 16 deletions
@ -0,0 +1,118 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <Containers/Array.h> |
||||||
|
#include <TestSuite/Tester.h> |
||||||
|
#include <Utility/Directory.h> |
||||||
|
|
||||||
|
#include "Text/AbstractFont.h" |
||||||
|
|
||||||
|
#include "testConfigure.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Text { namespace Test { |
||||||
|
|
||||||
|
class AbstractFontTest: public TestSuite::Tester { |
||||||
|
public: |
||||||
|
explicit AbstractFontTest(); |
||||||
|
|
||||||
|
void openSingleData(); |
||||||
|
void openFile(); |
||||||
|
|
||||||
|
void createGlyphCache(); |
||||||
|
}; |
||||||
|
|
||||||
|
AbstractFontTest::AbstractFontTest() { |
||||||
|
addTests({&AbstractFontTest::openSingleData, |
||||||
|
&AbstractFontTest::openFile, |
||||||
|
|
||||||
|
&AbstractFontTest::createGlyphCache}); |
||||||
|
} |
||||||
|
|
||||||
|
namespace { |
||||||
|
|
||||||
|
class SingleDataFont: public Text::AbstractFont { |
||||||
|
public: |
||||||
|
Features doFeatures() const override { return Feature::OpenData; } |
||||||
|
bool doIsOpened() const override { return opened; } |
||||||
|
void doClose() override {} |
||||||
|
|
||||||
|
void doOpenSingleData(const Containers::ArrayReference<const unsigned char> data, Float) override { |
||||||
|
opened = (data.size() == 1 && data[0] == 0xa5); |
||||||
|
} |
||||||
|
|
||||||
|
void doCreateGlyphCache(GlyphCache*, const std::u32string&) override {} |
||||||
|
|
||||||
|
AbstractLayouter* doLayout(const GlyphCache*, Float, const std::string&) { |
||||||
|
return nullptr; |
||||||
|
} |
||||||
|
|
||||||
|
bool opened = false; |
||||||
|
}; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void AbstractFontTest::openSingleData() { |
||||||
|
/* doOpenData() should call doOpenSingleData() */ |
||||||
|
SingleDataFont font; |
||||||
|
const unsigned char data[] = {0xa5}; |
||||||
|
CORRADE_VERIFY(!font.isOpened()); |
||||||
|
font.openData({{{}, data}}, 3.0f); |
||||||
|
CORRADE_VERIFY(font.isOpened()); |
||||||
|
} |
||||||
|
|
||||||
|
void AbstractFontTest::openFile() { |
||||||
|
/* doOpenFile() should call doOpenSingleData() */ |
||||||
|
SingleDataFont font; |
||||||
|
CORRADE_VERIFY(!font.isOpened()); |
||||||
|
font.openFile(Utility::Directory::join(TEXT_TEST_DIR, "data.bin"), 3.0f); |
||||||
|
CORRADE_VERIFY(font.isOpened()); |
||||||
|
} |
||||||
|
|
||||||
|
void AbstractFontTest::createGlyphCache() { |
||||||
|
class CachingFont: public Text::AbstractFont { |
||||||
|
public: |
||||||
|
std::u32string cacheCharacters; |
||||||
|
|
||||||
|
private: |
||||||
|
Features doFeatures() const override { return {}; } |
||||||
|
bool doIsOpened() const override { return true; } |
||||||
|
void doClose() override {} |
||||||
|
|
||||||
|
void doCreateGlyphCache(GlyphCache*, const std::u32string& characters) override { |
||||||
|
cacheCharacters = characters; |
||||||
|
} |
||||||
|
|
||||||
|
AbstractLayouter* doLayout(const GlyphCache*, Float, const std::string&) override { |
||||||
|
return nullptr; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
CachingFont font; |
||||||
|
font.createGlyphCache(nullptr, "žluťoučký kůň"); |
||||||
|
CORRADE_COMPARE(font.cacheCharacters, U"\u017Elu\u0165ou\u010Dk\u00FD k\u016F\u0148"); |
||||||
|
} |
||||||
|
|
||||||
|
}}} |
||||||
|
|
||||||
|
CORRADE_TEST_MAIN(Magnum::Text::Test::AbstractFontTest) |
||||||
@ -0,0 +1,30 @@ |
|||||||
|
# |
||||||
|
# This file is part of Magnum. |
||||||
|
# |
||||||
|
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
# |
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
# copy of this software and associated documentation files (the "Software"), |
||||||
|
# to deal in the Software without restriction, including without limitation |
||||||
|
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
# and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
# Software is furnished to do so, subject to the following conditions: |
||||||
|
# |
||||||
|
# The above copyright notice and this permission notice shall be included |
||||||
|
# in all copies or substantial portions of the Software. |
||||||
|
# |
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
# DEALINGS IN THE SOFTWARE. |
||||||
|
# |
||||||
|
|
||||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testConfigure.h.cmake |
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/testConfigure.h) |
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
||||||
|
|
||||||
|
corrade_add_test(TextAbstractFontTest AbstractFontTest.cpp LIBRARIES Magnum MagnumText) |
||||||
@ -0,0 +1,25 @@ |
|||||||
|
/* |
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#define TEXT_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}" |
||||||
Loading…
Reference in new issue