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
@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

4
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;

25
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<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() {
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<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 {
private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ImportGlyphCache; }

Loading…
Cancel
Save