From 8b748ace7dac4a21e531ebabb74e7e53dc5a5c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 7 Mar 2019 08:04:25 +0100 Subject: [PATCH] Text: properly report failures from AbstractFontConverter. --- doc/changelog.dox | 4 +++ src/Magnum/Text/AbstractFontConverter.cpp | 4 +++ .../Text/Test/AbstractFontConverterTest.cpp | 25 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/doc/changelog.dox b/doc/changelog.dox index 1c54ad05c..05e48c6c3 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -174,6 +174,10 @@ See also: - Properly zero-initializing the UTF-8 buffer in @ref Platform::GlfwApplication::textInputEvent() (see [mosra/magnum#324](https://github.com/mosra/magnum/pull/324)) +- @ref Trade::AbstractFontConverter::exportFontToFile() and + @ref Trade::AbstractFontConverter::exportGlyphCacheToFile() now properly + returns failure when the underlying data export function returns an empty + list of files - Updated the `base-qt` bootstrap project to correctly reset state tracker when going from and back to Qt code, and to use the framebuffer provided by Qt instead of @ref GL::defaultFramebuffer (see diff --git a/src/Magnum/Text/AbstractFontConverter.cpp b/src/Magnum/Text/AbstractFontConverter.cpp index 7b5d7abf7..fb2cc886b 100644 --- a/src/Magnum/Text/AbstractFontConverter.cpp +++ b/src/Magnum/Text/AbstractFontConverter.cpp @@ -121,6 +121,8 @@ bool AbstractFontConverter::doExportFontToFile(AbstractFont& font, AbstractGlyph /* Export all data */ const auto data = doExportFontToData(font, cache, filename, characters); + if(data.empty()) return false; + for(const auto& d: data) if(!Utility::Directory::write(d.first, d.second)) { Error() << "Text::AbstractFontConverter::exportFontToFile(): cannot write to file" << d.first; return false; @@ -173,6 +175,8 @@ bool AbstractFontConverter::doExportGlyphCacheToFile(AbstractGlyphCache& cache, /* Export all data */ const auto data = doExportGlyphCacheToData(cache, filename); + if(data.empty()) return false; + for(const auto& d: data) if(!Utility::Directory::write(d.first, d.second)) { Error() << "Text::AbstractFontConverter::exportGlyphCacheToFile(): cannot write to file" << d.first; return false; diff --git a/src/Magnum/Text/Test/AbstractFontConverterTest.cpp b/src/Magnum/Text/Test/AbstractFontConverterTest.cpp index 70d8f3c71..41c4a8f4d 100644 --- a/src/Magnum/Text/Test/AbstractFontConverterTest.cpp +++ b/src/Magnum/Text/Test/AbstractFontConverterTest.cpp @@ -44,9 +44,11 @@ struct AbstractFontConverterTest: TestSuite::Tester { void exportFontToSingleData(); void exportFontToFile(); + void exportFontToFileFailed(); void exportGlyphCacheToSingleData(); void exportGlyphCacheToFile(); + void exportGlyphCacheToFileFailed(); void importGlyphCacheFromSingleData(); void importGlyphCacheFromFile(); @@ -57,9 +59,11 @@ AbstractFontConverterTest::AbstractFontConverterTest() { &AbstractFontConverterTest::exportFontToSingleData, &AbstractFontConverterTest::exportFontToFile, + &AbstractFontConverterTest::exportFontToFileFailed, &AbstractFontConverterTest::exportGlyphCacheToSingleData, &AbstractFontConverterTest::exportGlyphCacheToFile, + &AbstractFontConverterTest::exportGlyphCacheToFileFailed, &AbstractFontConverterTest::importGlyphCacheFromSingleData, &AbstractFontConverterTest::importGlyphCacheFromFile}); @@ -160,6 +164,16 @@ void AbstractFontConverterTest::exportFontToFile() { "\xfe\xed", TestSuite::Compare::FileToString); } +void AbstractFontConverterTest::exportFontToFileFailed() { + struct: AbstractFontConverter { + Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont|Feature::MultiFile; } + + std::vector>> doExportFontToData(AbstractFont&, AbstractGlyphCache&, const std::string&, const std::u32string&) const override { return {}; } + } exporter; + + CORRADE_VERIFY(!exporter.exportFontToFile(dummyFont, dummyGlyphCache, "nonexistent.dat", {})); +} + void AbstractFontConverterTest::exportGlyphCacheToSingleData() { struct: Text::AbstractFontConverter { Features doFeatures() const override { return Feature::ConvertData|Feature::ExportGlyphCache; } @@ -207,6 +221,17 @@ void AbstractFontConverterTest::exportGlyphCacheToFile() { "\xfe\xed", TestSuite::Compare::FileToString); } +void AbstractFontConverterTest::exportGlyphCacheToFileFailed() { + struct: Text::AbstractFontConverter { + Features doFeatures() const override { return Feature::ConvertData|Feature::ExportGlyphCache|Feature::MultiFile; } + + std::vector>> doExportGlyphCacheToData(AbstractGlyphCache&, const std::string&) const override { return {}; } + } exporter; + + /* doExportGlyphCacheToFile() should call doExportGlyphCacheToData() */ + CORRADE_VERIFY(!exporter.exportGlyphCacheToFile(dummyGlyphCache, "nonexistent.dat")); +} + class SingleGlyphCacheDataImporter: public Text::AbstractFontConverter { private: Features doFeatures() const override { return Feature::ConvertData|Feature::ImportGlyphCache; }