Browse Source

Text: properly report failures from AbstractFontConverter.

pull/325/head
Vladimír Vondruš 7 years ago
parent
commit
8b748ace7d
  1. 4
      doc/changelog.dox
  2. 4
      src/Magnum/Text/AbstractFontConverter.cpp
  3. 25
      src/Magnum/Text/Test/AbstractFontConverterTest.cpp

4
doc/changelog.dox

@ -174,6 +174,10 @@ See also:
- Properly zero-initializing the UTF-8 buffer in - Properly zero-initializing the UTF-8 buffer in
@ref Platform::GlfwApplication::textInputEvent() (see @ref Platform::GlfwApplication::textInputEvent() (see
[mosra/magnum#324](https://github.com/mosra/magnum/pull/324)) [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 - 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 when going from and back to Qt code, and to use the framebuffer provided by
Qt instead of @ref GL::defaultFramebuffer (see Qt instead of @ref GL::defaultFramebuffer (see

4
src/Magnum/Text/AbstractFontConverter.cpp

@ -121,6 +121,8 @@ bool AbstractFontConverter::doExportFontToFile(AbstractFont& font, AbstractGlyph
/* Export all data */ /* Export all data */
const auto data = doExportFontToData(font, cache, filename, characters); 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)) { for(const auto& d: data) if(!Utility::Directory::write(d.first, d.second)) {
Error() << "Text::AbstractFontConverter::exportFontToFile(): cannot write to file" << d.first; Error() << "Text::AbstractFontConverter::exportFontToFile(): cannot write to file" << d.first;
return false; return false;
@ -173,6 +175,8 @@ bool AbstractFontConverter::doExportGlyphCacheToFile(AbstractGlyphCache& cache,
/* Export all data */ /* Export all data */
const auto data = doExportGlyphCacheToData(cache, filename); const auto data = doExportGlyphCacheToData(cache, filename);
if(data.empty()) return false;
for(const auto& d: data) if(!Utility::Directory::write(d.first, d.second)) { for(const auto& d: data) if(!Utility::Directory::write(d.first, d.second)) {
Error() << "Text::AbstractFontConverter::exportGlyphCacheToFile(): cannot write to file" << d.first; Error() << "Text::AbstractFontConverter::exportGlyphCacheToFile(): cannot write to file" << d.first;
return false; return false;

25
src/Magnum/Text/Test/AbstractFontConverterTest.cpp

@ -44,9 +44,11 @@ struct AbstractFontConverterTest: TestSuite::Tester {
void exportFontToSingleData(); void exportFontToSingleData();
void exportFontToFile(); void exportFontToFile();
void exportFontToFileFailed();
void exportGlyphCacheToSingleData(); void exportGlyphCacheToSingleData();
void exportGlyphCacheToFile(); void exportGlyphCacheToFile();
void exportGlyphCacheToFileFailed();
void importGlyphCacheFromSingleData(); void importGlyphCacheFromSingleData();
void importGlyphCacheFromFile(); void importGlyphCacheFromFile();
@ -57,9 +59,11 @@ AbstractFontConverterTest::AbstractFontConverterTest() {
&AbstractFontConverterTest::exportFontToSingleData, &AbstractFontConverterTest::exportFontToSingleData,
&AbstractFontConverterTest::exportFontToFile, &AbstractFontConverterTest::exportFontToFile,
&AbstractFontConverterTest::exportFontToFileFailed,
&AbstractFontConverterTest::exportGlyphCacheToSingleData, &AbstractFontConverterTest::exportGlyphCacheToSingleData,
&AbstractFontConverterTest::exportGlyphCacheToFile, &AbstractFontConverterTest::exportGlyphCacheToFile,
&AbstractFontConverterTest::exportGlyphCacheToFileFailed,
&AbstractFontConverterTest::importGlyphCacheFromSingleData, &AbstractFontConverterTest::importGlyphCacheFromSingleData,
&AbstractFontConverterTest::importGlyphCacheFromFile}); &AbstractFontConverterTest::importGlyphCacheFromFile});
@ -160,6 +164,16 @@ void AbstractFontConverterTest::exportFontToFile() {
"\xfe\xed", TestSuite::Compare::FileToString); "\xfe\xed", TestSuite::Compare::FileToString);
} }
void AbstractFontConverterTest::exportFontToFileFailed() {
struct: AbstractFontConverter {
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont|Feature::MultiFile; }
std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont&, AbstractGlyphCache&, const std::string&, const std::u32string&) const override { return {}; }
} exporter;
CORRADE_VERIFY(!exporter.exportFontToFile(dummyFont, dummyGlyphCache, "nonexistent.dat", {}));
}
void AbstractFontConverterTest::exportGlyphCacheToSingleData() { void AbstractFontConverterTest::exportGlyphCacheToSingleData() {
struct: Text::AbstractFontConverter { struct: Text::AbstractFontConverter {
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportGlyphCache; } Features doFeatures() const override { return Feature::ConvertData|Feature::ExportGlyphCache; }
@ -207,6 +221,17 @@ void AbstractFontConverterTest::exportGlyphCacheToFile() {
"\xfe\xed", TestSuite::Compare::FileToString); "\xfe\xed", TestSuite::Compare::FileToString);
} }
void AbstractFontConverterTest::exportGlyphCacheToFileFailed() {
struct: Text::AbstractFontConverter {
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportGlyphCache|Feature::MultiFile; }
std::vector<std::pair<std::string, Containers::Array<char>>> 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 { class SingleGlyphCacheDataImporter: public Text::AbstractFontConverter {
private: private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ImportGlyphCache; } Features doFeatures() const override { return Feature::ConvertData|Feature::ImportGlyphCache; }

Loading…
Cancel
Save