From 00350791a3f869124c80d4aef829b8e1c1167a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 7 Mar 2019 08:04:59 +0100 Subject: [PATCH] MagnumFontConverter: gracefully fail with glyph caches on OpenGL ES. --- .../MagnumFontConverter.cpp | 5 +++ .../Test/MagnumFontConverterTest.cpp | 33 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp b/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp index ad4b44951..222244c22 100644 --- a/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp +++ b/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp @@ -47,6 +47,11 @@ auto MagnumFontConverter::doFeatures() const -> Features { } std::vector>> MagnumFontConverter::doExportFontToData(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::u32string& characters) const { + if(!(cache.features() & GlyphCacheFeature::ImageDownload)) { + Error{} << "Text::MagnumFontConverter::exportFontToData(): passed glyph cache doesn't support image download"; + return {}; + } + Utility::Configuration configuration; configuration.setValue("version", 1); diff --git a/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp b/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp index 525da2208..e04c32efb 100644 --- a/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp +++ b/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp @@ -46,6 +46,7 @@ struct MagnumFontConverterTest: TestSuite::Tester { explicit MagnumFontConverterTest(); void exportFont(); + void exportFontNoGlyphCacheImageDownload(); /* Explicitly forbid system-wide plugin dependencies */ PluginManager::Manager _imageConverterManager{"nonexistent"}; @@ -54,7 +55,8 @@ struct MagnumFontConverterTest: TestSuite::Tester { }; MagnumFontConverterTest::MagnumFontConverterTest() { - addTests({&MagnumFontConverterTest::exportFont}); + addTests({&MagnumFontConverterTest::exportFont, + &MagnumFontConverterTest::exportFontNoGlyphCacheImageDownload}); /* Load the plugins directly from the build tree. Otherwise they are static and already loaded. */ @@ -147,6 +149,35 @@ void MagnumFontConverterTest::exportFont() { CORRADE_COMPARE(image->format(), PixelFormat::R8Unorm); } +void MagnumFontConverterTest::exportFontNoGlyphCacheImageDownload() { + struct MyFont: AbstractFont { + /* Supports neither file nor data opening */ + Features doFeatures() const override { return {}; } + bool doIsOpened() const override { return false; } + void doClose() override {} + + UnsignedInt doGlyphId(char32_t) override { return {}; } + Vector2 doGlyphAdvance(UnsignedInt) override { return {}; } + Containers::Pointer doLayout(const AbstractGlyphCache&, Float, const std::string&) override { + return nullptr; + } + } font; + + struct DummyGlyphCache: AbstractGlyphCache { + using AbstractGlyphCache::AbstractGlyphCache; + + GlyphCacheFeatures doFeatures() const override { return {}; } + void doSetImage(const Vector2i&, const ImageView2D&) override {} + } cache{{100, 100}}; + + Containers::Pointer converter = _fontConverterManager.instantiate("MagnumFontConverter"); + + std::ostringstream out; + Error redirectError{&out}; + CORRADE_VERIFY(!converter->exportFontToFile(font, cache, Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font"), "Wave")); + CORRADE_COMPARE(out.str(), "Text::MagnumFontConverter::exportFontToData(): passed glyph cache doesn't support image download\n"); +} + }}}} CORRADE_TEST_MAIN(Magnum::Text::Test::MagnumFontConverterTest)