Browse Source

MagnumFontConverter: gracefully fail with glyph caches on OpenGL ES.

pull/325/head
Vladimír Vondruš 7 years ago
parent
commit
00350791a3
  1. 5
      src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp
  2. 33
      src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp

5
src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp

@ -47,6 +47,11 @@ auto MagnumFontConverter::doFeatures() const -> Features {
}
std::vector<std::pair<std::string, Containers::Array<char>>> 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);

33
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<Trade::AbstractImageConverter> _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<AbstractLayouter> 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<AbstractFontConverter> 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)

Loading…
Cancel
Save