Browse Source

Text: add init list overload for AbstractFont::fillGlyphCache().

As usual, API warts that are impossible to see until I actually get to
documenting their usage in a code snippet.
pull/651/merge
Vladimír Vondruš 1 year ago
parent
commit
e7dce086f4
  1. 4
      src/Magnum/Text/AbstractFont.cpp
  2. 3
      src/Magnum/Text/AbstractFont.h
  3. 19
      src/Magnum/Text/Test/AbstractFontTest.cpp

4
src/Magnum/Text/AbstractFont.cpp

@ -381,6 +381,10 @@ bool AbstractFont::fillGlyphCache(AbstractGlyphCache& cache, const Containers::S
return doFillGlyphCache(cache, glyphs); return doFillGlyphCache(cache, glyphs);
} }
bool AbstractFont::fillGlyphCache(AbstractGlyphCache& cache, const std::initializer_list<UnsignedInt> glyphs) {
return fillGlyphCache(cache, Containers::stridedArrayView(glyphs));
}
bool AbstractFont::doFillGlyphCache(AbstractGlyphCache&, const Containers::StridedArrayView1D<const UnsignedInt>&) { bool AbstractFont::doFillGlyphCache(AbstractGlyphCache&, const Containers::StridedArrayView1D<const UnsignedInt>&) {
CORRADE_ASSERT_UNREACHABLE("Text::AbstractFont::fillGlyphCache(): feature advertised but not implemented", {}); CORRADE_ASSERT_UNREACHABLE("Text::AbstractFont::fillGlyphCache(): feature advertised but not implemented", {});
return {}; return {};

3
src/Magnum/Text/AbstractFont.h

@ -30,6 +30,7 @@
* @brief Class @ref Magnum::Text::AbstractFont, enum @ref Magnum::Text::FontFeature, enum set @ref Magnum::Text::FontFeatures * @brief Class @ref Magnum::Text::AbstractFont, enum @ref Magnum::Text::FontFeature, enum set @ref Magnum::Text::FontFeatures
*/ */
#include <initializer_list>
#include <Corrade/PluginManager/AbstractPlugin.h> #include <Corrade/PluginManager/AbstractPlugin.h>
#include <Corrade/Utility/StlForwardString.h> /** @todo remove once file callbacks are std::string-free */ #include <Corrade/Utility/StlForwardString.h> /** @todo remove once file callbacks are std::string-free */
@ -550,6 +551,8 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* @cpp false @ce. * @cpp false @ce.
*/ */
bool fillGlyphCache(AbstractGlyphCache& cache, const Containers::StridedArrayView1D<const UnsignedInt>& glyphs); bool fillGlyphCache(AbstractGlyphCache& cache, const Containers::StridedArrayView1D<const UnsignedInt>& glyphs);
/** @overload */
bool fillGlyphCache(AbstractGlyphCache& cache, std::initializer_list<UnsignedInt> glyphs);
/** /**
* @brief Fill glyph cache with given character set * @brief Fill glyph cache with given character set

19
src/Magnum/Text/Test/AbstractFontTest.cpp

@ -1184,11 +1184,11 @@ void AbstractFontTest::fillGlyphCache() {
CORRADE_COMPARE_AS(glyphs, Containers::arrayView({ CORRADE_COMPARE_AS(glyphs, Containers::arrayView({
16u, 5u, 11u, 2u 16u, 5u, 11u, 2u
}), TestSuite::Compare::Container); }), TestSuite::Compare::Container);
called = true; ++called;
return true; return true;
} }
bool called = false; Int called = 0;
private: private:
bool _opened = false; bool _opened = false;
@ -1200,7 +1200,11 @@ void AbstractFontTest::fillGlyphCache() {
DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}};
CORRADE_VERIFY(font.fillGlyphCache(cache, Containers::arrayView({16u, 5u, 11u, 2u}))); CORRADE_VERIFY(font.fillGlyphCache(cache, Containers::arrayView({16u, 5u, 11u, 2u})));
CORRADE_VERIFY(font.called); CORRADE_COMPARE(font.called, 1);
/* Also the initializer list overload */
CORRADE_VERIFY(font.fillGlyphCache(cache, {16, 5, 11, 2}));
CORRADE_COMPARE(font.called, 2);
} }
void AbstractFontTest::fillGlyphCacheOutOfRange() { void AbstractFontTest::fillGlyphCacheOutOfRange() {
@ -1234,7 +1238,9 @@ void AbstractFontTest::fillGlyphCacheOutOfRange() {
Error redirectError{&out}; Error redirectError{&out};
DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}};
font.fillGlyphCache(cache, Containers::arrayView({0u, 15u, 3u, 16u, 80u})); font.fillGlyphCache(cache, Containers::arrayView({0u, 15u, 3u, 16u, 80u}));
font.fillGlyphCache(cache, {0, 15, 3, 16, 80});
CORRADE_COMPARE(out, CORRADE_COMPARE(out,
"Text::AbstractFont::fillGlyphCache(): index 16 out of range for 16 glyphs\n"
"Text::AbstractFont::fillGlyphCache(): index 16 out of range for 16 glyphs\n"); "Text::AbstractFont::fillGlyphCache(): index 16 out of range for 16 glyphs\n");
} }
@ -1379,6 +1385,7 @@ void AbstractFontTest::fillGlyphCacheFailed() {
DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}};
CORRADE_VERIFY(!font.fillGlyphCache(cache, Containers::ArrayView<const UnsignedInt>{})); CORRADE_VERIFY(!font.fillGlyphCache(cache, Containers::ArrayView<const UnsignedInt>{}));
CORRADE_VERIFY(!font.fillGlyphCache(cache, {}));
CORRADE_VERIFY(!font.fillGlyphCache(cache, "")); CORRADE_VERIFY(!font.fillGlyphCache(cache, ""));
} }
@ -1404,8 +1411,10 @@ void AbstractFontTest::fillGlyphCacheNotSupported() {
Error redirectError{&out}; Error redirectError{&out};
DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}};
font.fillGlyphCache(cache, Containers::arrayView({0u, 15u})); font.fillGlyphCache(cache, Containers::arrayView({0u, 15u}));
font.fillGlyphCache(cache, {0u, 15u});
font.fillGlyphCache(cache, "hello"); font.fillGlyphCache(cache, "hello");
CORRADE_COMPARE(out, CORRADE_COMPARE(out,
"Text::AbstractFont::fillGlyphCache(): feature not supported\n"
"Text::AbstractFont::fillGlyphCache(): feature not supported\n" "Text::AbstractFont::fillGlyphCache(): feature not supported\n"
"Text::AbstractFont::fillGlyphCache(): feature not supported\n"); "Text::AbstractFont::fillGlyphCache(): feature not supported\n");
} }
@ -1441,8 +1450,10 @@ void AbstractFontTest::fillGlyphCacheNotImplemented() {
Error redirectError{&out}; Error redirectError{&out};
DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}};
font.fillGlyphCache(cache, Containers::arrayView({0u})); font.fillGlyphCache(cache, Containers::arrayView({0u}));
font.fillGlyphCache(cache, {0});
font.fillGlyphCache(cache, "hello"); font.fillGlyphCache(cache, "hello");
CORRADE_COMPARE(out, CORRADE_COMPARE(out,
"Text::AbstractFont::fillGlyphCache(): feature advertised but not implemented\n"
"Text::AbstractFont::fillGlyphCache(): feature advertised but not implemented\n" "Text::AbstractFont::fillGlyphCache(): feature advertised but not implemented\n"
"Text::AbstractFont::fillGlyphCache(): feature advertised but not implemented\n"); "Text::AbstractFont::fillGlyphCache(): feature advertised but not implemented\n");
} }
@ -1465,8 +1476,10 @@ void AbstractFontTest::fillGlyphCacheNoFont() {
Error redirectError{&out}; Error redirectError{&out};
DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}};
font.fillGlyphCache(cache, Containers::arrayView({0u, 15u})); font.fillGlyphCache(cache, Containers::arrayView({0u, 15u}));
font.fillGlyphCache(cache, {0, 15});
font.fillGlyphCache(cache, "hello"); font.fillGlyphCache(cache, "hello");
CORRADE_COMPARE(out, CORRADE_COMPARE(out,
"Text::AbstractFont::fillGlyphCache(): no font opened\n"
"Text::AbstractFont::fillGlyphCache(): no font opened\n" "Text::AbstractFont::fillGlyphCache(): no font opened\n"
"Text::AbstractFont::fillGlyphCache(): no font opened\n"); "Text::AbstractFont::fillGlyphCache(): no font opened\n");
} }

Loading…
Cancel
Save