From e7dce086f4b0459a766286845338ed2a5a1a871e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 14 Feb 2025 11:48:34 +0100 Subject: [PATCH] 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. --- src/Magnum/Text/AbstractFont.cpp | 4 ++++ src/Magnum/Text/AbstractFont.h | 3 +++ src/Magnum/Text/Test/AbstractFontTest.cpp | 19 ++++++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Magnum/Text/AbstractFont.cpp b/src/Magnum/Text/AbstractFont.cpp index 5077beda1..b4d43c86e 100644 --- a/src/Magnum/Text/AbstractFont.cpp +++ b/src/Magnum/Text/AbstractFont.cpp @@ -381,6 +381,10 @@ bool AbstractFont::fillGlyphCache(AbstractGlyphCache& cache, const Containers::S return doFillGlyphCache(cache, glyphs); } +bool AbstractFont::fillGlyphCache(AbstractGlyphCache& cache, const std::initializer_list glyphs) { + return fillGlyphCache(cache, Containers::stridedArrayView(glyphs)); +} + bool AbstractFont::doFillGlyphCache(AbstractGlyphCache&, const Containers::StridedArrayView1D&) { CORRADE_ASSERT_UNREACHABLE("Text::AbstractFont::fillGlyphCache(): feature advertised but not implemented", {}); return {}; diff --git a/src/Magnum/Text/AbstractFont.h b/src/Magnum/Text/AbstractFont.h index f41f017dc..65ac0616d 100644 --- a/src/Magnum/Text/AbstractFont.h +++ b/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 */ +#include #include #include /** @todo remove once file callbacks are std::string-free */ @@ -550,6 +551,8 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin { * @cpp false @ce. */ bool fillGlyphCache(AbstractGlyphCache& cache, const Containers::StridedArrayView1D& glyphs); + /** @overload */ + bool fillGlyphCache(AbstractGlyphCache& cache, std::initializer_list glyphs); /** * @brief Fill glyph cache with given character set diff --git a/src/Magnum/Text/Test/AbstractFontTest.cpp b/src/Magnum/Text/Test/AbstractFontTest.cpp index 23709842f..78fd0beb6 100644 --- a/src/Magnum/Text/Test/AbstractFontTest.cpp +++ b/src/Magnum/Text/Test/AbstractFontTest.cpp @@ -1184,11 +1184,11 @@ void AbstractFontTest::fillGlyphCache() { CORRADE_COMPARE_AS(glyphs, Containers::arrayView({ 16u, 5u, 11u, 2u }), TestSuite::Compare::Container); - called = true; + ++called; return true; } - bool called = false; + Int called = 0; private: bool _opened = false; @@ -1200,7 +1200,11 @@ void AbstractFontTest::fillGlyphCache() { DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; 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() { @@ -1234,7 +1238,9 @@ void AbstractFontTest::fillGlyphCacheOutOfRange() { Error redirectError{&out}; DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; font.fillGlyphCache(cache, Containers::arrayView({0u, 15u, 3u, 16u, 80u})); + font.fillGlyphCache(cache, {0, 15, 3, 16, 80}); 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"); } @@ -1379,6 +1385,7 @@ void AbstractFontTest::fillGlyphCacheFailed() { DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; CORRADE_VERIFY(!font.fillGlyphCache(cache, Containers::ArrayView{})); + CORRADE_VERIFY(!font.fillGlyphCache(cache, {})); CORRADE_VERIFY(!font.fillGlyphCache(cache, "")); } @@ -1404,8 +1411,10 @@ void AbstractFontTest::fillGlyphCacheNotSupported() { Error redirectError{&out}; DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; font.fillGlyphCache(cache, Containers::arrayView({0u, 15u})); + font.fillGlyphCache(cache, {0u, 15u}); font.fillGlyphCache(cache, "hello"); CORRADE_COMPARE(out, + "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}; DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; font.fillGlyphCache(cache, Containers::arrayView({0u})); + font.fillGlyphCache(cache, {0}); font.fillGlyphCache(cache, "hello"); 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"); } @@ -1465,8 +1476,10 @@ void AbstractFontTest::fillGlyphCacheNoFont() { Error redirectError{&out}; DummyGlyphCache cache{PixelFormat::R8Unorm, {100, 100}}; font.fillGlyphCache(cache, Containers::arrayView({0u, 15u})); + font.fillGlyphCache(cache, {0, 15}); font.fillGlyphCache(cache, "hello"); CORRADE_COMPARE(out, + "Text::AbstractFont::fillGlyphCache(): no font opened\n" "Text::AbstractFont::fillGlyphCache(): no font opened\n" "Text::AbstractFont::fillGlyphCache(): no font opened\n"); }