Browse Source

Move Feature[s] enums from inside plugin classes outside.

Too annoyingly long to type. Also added a debug output operator for the
FontConverterFeature enums, for some reason there were none.
dpi-change-events
Vladimír Vondruš 8 years ago
parent
commit
19dd7a0176
  1. 10
      doc/changelog.dox
  2. 16
      src/Magnum/Audio/AbstractImporter.cpp
  3. 73
      src/Magnum/Audio/AbstractImporter.h
  4. 38
      src/Magnum/Audio/Test/AbstractImporterTest.cpp
  5. 30
      src/Magnum/Text/AbstractFont.cpp
  6. 181
      src/Magnum/Text/AbstractFont.h
  7. 64
      src/Magnum/Text/AbstractFontConverter.cpp
  8. 261
      src/Magnum/Text/AbstractFontConverter.h
  9. 41
      src/Magnum/Text/Test/AbstractFontConverterTest.cpp
  10. 84
      src/Magnum/Text/Test/AbstractFontTest.cpp
  11. 4
      src/Magnum/Text/Test/RendererGLTest.cpp
  12. 38
      src/Magnum/Trade/AbstractImageConverter.cpp
  13. 166
      src/Magnum/Trade/AbstractImageConverter.h
  14. 28
      src/Magnum/Trade/AbstractImporter.cpp
  15. 194
      src/Magnum/Trade/AbstractImporter.h
  16. 70
      src/Magnum/Trade/Test/AbstractImageConverterTest.cpp
  17. 362
      src/Magnum/Trade/Test/AbstractImporterTest.cpp
  18. 2
      src/MagnumPlugins/AnyAudioImporter/AnyImporter.cpp
  19. 2
      src/MagnumPlugins/AnyAudioImporter/AnyImporter.h
  20. 4
      src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp
  21. 2
      src/MagnumPlugins/AnyImageConverter/AnyImageConverter.h
  22. 2
      src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp
  23. 2
      src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h
  24. 2
      src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp
  25. 2
      src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h
  26. 2
      src/MagnumPlugins/MagnumFont/MagnumFont.cpp
  27. 2
      src/MagnumPlugins/MagnumFont/MagnumFont.h
  28. 4
      src/MagnumPlugins/MagnumFont/Test/MagnumFontTest.cpp
  29. 4
      src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp
  30. 2
      src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.h
  31. 4
      src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp
  32. 2
      src/MagnumPlugins/ObjImporter/ObjImporter.cpp
  33. 2
      src/MagnumPlugins/ObjImporter/ObjImporter.h
  34. 2
      src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp
  35. 2
      src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h
  36. 2
      src/MagnumPlugins/TgaImporter/TgaImporter.cpp
  37. 2
      src/MagnumPlugins/TgaImporter/TgaImporter.h
  38. 2
      src/MagnumPlugins/WavAudioImporter/WavImporter.cpp
  39. 2
      src/MagnumPlugins/WavAudioImporter/WavImporter.h

10
doc/changelog.dox

@ -291,6 +291,16 @@ See also:
@cpp Platform::Sdl2Application::Configuration::isMouseLocked() @ce is
deprecated in favor of the new @ref Platform::Sdl2Application::setCursor()
together with @ref Platform::Sdl2Application::Cursor::HiddenLocked
- @cpp Audio::AbstractImporter::Features @ce,
@cpp Text::AbstractFont::Features @ce,
@cpp Text::AbstractFontConverter::Features @ce,
@cpp Trade::AbstractImporter::Features @ce,
@cpp Trade::AbstractImageConverter::Features @ce enum sets and their
corresponding `Feature` enums are deprecated in favor of
@ref Audio::ImporterFeatures, @ref Text::FontFeatures,
@ref Text::FontConverterFeatures, @ref Trade::ImporterFeatures,
@ref Trade::ImageConverterFeatures enum sets and their corresponding enums
placed directly in the namespace to have them shorter and unambiguous
@subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs

16
src/Magnum/Audio/AbstractImporter.cpp

@ -81,7 +81,7 @@ AbstractImporter::AbstractImporter(PluginManager::Manager<AbstractImporter>& man
AbstractImporter::AbstractImporter(PluginManager::AbstractManager& manager, const std::string& plugin): PluginManager::AbstractManagingPlugin<AbstractImporter>{manager, plugin} {}
bool AbstractImporter::openData(Containers::ArrayView<const char> data) {
CORRADE_ASSERT(features() & Feature::OpenData,
CORRADE_ASSERT(features() & ImporterFeature::OpenData,
"Audio::AbstractImporter::openData(): feature not supported", {});
close();
@ -100,7 +100,7 @@ bool AbstractImporter::openFile(const std::string& filename) {
}
void AbstractImporter::doOpenFile(const std::string& filename) {
CORRADE_ASSERT(features() & Feature::OpenData, "Audio::AbstractImporter::openFile(): not implemented", );
CORRADE_ASSERT(features() & ImporterFeature::OpenData, "Audio::AbstractImporter::openFile(): not implemented", );
/* Open file */
if(!Utility::Directory::exists(filename)) {
@ -136,12 +136,12 @@ Containers::Array<char> AbstractImporter::data() {
return out;
}
Debug& operator<<(Debug& debug, const AbstractImporter::Feature value) {
debug << "Audio::AbstractImporter::Feature" << Debug::nospace;
Debug& operator<<(Debug& debug, const ImporterFeature value) {
debug << "Audio::ImporterFeature" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case AbstractImporter::Feature::v: return debug << "::" #v;
#define _c(v) case ImporterFeature::v: return debug << "::" #v;
_c(OpenData)
#undef _c
/* LCOV_EXCL_STOP */
@ -150,9 +150,9 @@ Debug& operator<<(Debug& debug, const AbstractImporter::Feature value) {
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const AbstractImporter::Features value) {
return Containers::enumSetDebugOutput(debug, value, "Audio::AbstractImporter::Features{}", {
AbstractImporter::Feature::OpenData});
Debug& operator<<(Debug& debug, const ImporterFeatures value) {
return Containers::enumSetDebugOutput(debug, value, "Audio::ImporterFeatures{}", {
ImporterFeature::OpenData});
}
}}

73
src/Magnum/Audio/AbstractImporter.h

@ -36,6 +36,33 @@
namespace Magnum { namespace Audio {
/**
@brief Features supported by an audio importer
@m_since_latest
@see @ref ImporterFeatures, @ref AbstractImporter::features()
*/
enum class ImporterFeature: UnsignedByte {
/** Opening files from raw data using @ref AbstractImporter::openData() */
OpenData = 1 << 0
};
/**
@brief Features supported by an audio importer
@m_since_latest
@see @ref AbstractImporter::features()
*/
typedef Containers::EnumSet<ImporterFeature> ImporterFeatures;
CORRADE_ENUMSET_OPERATORS(ImporterFeatures)
/** @debugoperatorenum{ImporterFeatures} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, ImporterFeature value);
/** @debugoperatorenum{ImporterFeatures} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, ImporterFeatures value);
/**
@brief Base for audio importer plugins
@ -64,8 +91,8 @@ checked by the implementation:
- Functions @ref doOpenData() and @ref doOpenFile() are called after the
previous file was closed, function @ref doClose() is called only if there
is any file opened.
- Function @ref doOpenData() is called only if @ref Feature::OpenData is
supported.
- Function @ref doOpenData() is called only if @ref ImporterFeature::OpenData
is supported.
- All `do*()` implementations working on opened file are called only if
there is any file opened.
@ -81,22 +108,17 @@ checked by the implementation:
*/
class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractManagingPlugin<AbstractImporter> {
public:
/**
* @brief Features supported by this importer
*
* @see @ref Features, @ref features()
#ifdef MAGNUM_BUILD_DEPRECATED
/** @brief @copybrief ImporterFeature
* @m_deprecated_since_latest Use @ref ImporterFeature instead.
*/
enum class Feature: UnsignedByte {
/** Opening files from raw data using @ref openData() */
OpenData = 1 << 0
};
typedef CORRADE_DEPRECATED("use ImporterFeature instead") ImporterFeature Feature;
/**
* @brief Features supported by this importer
*
* @see @ref features()
/** @brief @copybrief ImporterFeatures
* @m_deprecated_since_latest Use @ref ImporterFeatures instead.
*/
typedef Containers::EnumSet<Feature> Features;
typedef CORRADE_DEPRECATED("use ImporterFeatures instead") ImporterFeatures Features;
#endif
/**
* @brief Plugin interface
@ -136,7 +158,7 @@ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractManagi
explicit AbstractImporter(PluginManager::AbstractManager& manager, const std::string& plugin);
/** @brief Features supported by this importer */
Features features() const { return doFeatures(); }
ImporterFeatures features() const { return doFeatures(); }
/** @brief Whether any file is opened */
bool isOpened() const { return doIsOpened(); }
@ -145,8 +167,8 @@ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractManagi
* @brief Open raw data
*
* Closes previous file, if it was opened, and tries to open given
* file. Available only if @ref Feature::OpenData is supported. Returns
* @cpp true @ce on success, @cpp false @ce otherwise.
* file. Available only if @ref ImporterFeature::OpenData is supported.
* Returns @cpp true @ce on success, @cpp false @ce otherwise.
* @see @ref features(), @ref openFile()
*/
bool openData(Containers::ArrayView<const char> data);
@ -178,7 +200,7 @@ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractManagi
private:
/** @brief Implementation for @ref features() */
virtual Features doFeatures() const = 0;
virtual ImporterFeatures doFeatures() const = 0;
/** @brief Implementation for @ref isOpened() */
virtual bool doIsOpened() const = 0;
@ -189,8 +211,9 @@ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractManagi
/**
* @brief Implementation for @ref openFile()
*
* If @ref Feature::OpenData is supported, default implementation opens
* the file and calls @ref doOpenData() with its contents.
* If @ref ImporterFeature::OpenData is supported, default
* implementation opens the file and calls @ref doOpenData() with its
* contents.
*/
virtual void doOpenFile(const std::string& filename);
@ -207,14 +230,6 @@ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractManagi
virtual Containers::Array<char> doData() = 0;
};
CORRADE_ENUMSET_OPERATORS(AbstractImporter::Features)
/** @debugoperatorclassenum{AbstractImporter,AbstractImporter::Feature} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, AbstractImporter::Feature value);
/** @debugoperatorclassenum{AbstractImporter,AbstractImporter::Features} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, AbstractImporter::Features value);
}}
#endif

38
src/Magnum/Audio/Test/AbstractImporterTest.cpp

@ -94,7 +94,7 @@ AbstractImporterTest::AbstractImporterTest() {
void AbstractImporterTest::construct() {
struct: AbstractImporter {
Features doFeatures() const override { return {}; }
ImporterFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -103,7 +103,7 @@ void AbstractImporterTest::construct() {
Containers::Array<char> doData() override { return nullptr; }
} importer;
CORRADE_COMPARE(importer.features(), AbstractImporter::Features{});
CORRADE_COMPARE(importer.features(), ImporterFeatures{});
CORRADE_VERIFY(!importer.isOpened());
importer.close();
@ -112,7 +112,7 @@ void AbstractImporterTest::construct() {
void AbstractImporterTest::openData() {
struct: AbstractImporter {
Features doFeatures() const override { return Feature::OpenData; }
ImporterFeatures doFeatures() const override { return ImporterFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override { _opened = false; }
@ -138,7 +138,7 @@ void AbstractImporterTest::openData() {
void AbstractImporterTest::openFileAsData() {
struct: AbstractImporter {
Features doFeatures() const override { return Feature::OpenData; }
ImporterFeatures doFeatures() const override { return ImporterFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override { _opened = false; }
@ -164,7 +164,7 @@ void AbstractImporterTest::openFileAsData() {
void AbstractImporterTest::openFileAsDataNotFound() {
struct Importer: AbstractImporter {
Features doFeatures() const override { return Feature::OpenData; }
ImporterFeatures doFeatures() const override { return ImporterFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override { _opened = false; }
@ -189,7 +189,7 @@ void AbstractImporterTest::openFileAsDataNotFound() {
void AbstractImporterTest::openFileNotImplemented() {
struct Importer: AbstractImporter {
Features doFeatures() const override { return {}; }
ImporterFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -207,7 +207,7 @@ void AbstractImporterTest::openFileNotImplemented() {
void AbstractImporterTest::openDataNotSupported() {
struct: AbstractImporter {
Features doFeatures() const override { return {}; }
ImporterFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -225,7 +225,7 @@ void AbstractImporterTest::openDataNotSupported() {
void AbstractImporterTest::openDataNotImplemented() {
struct: AbstractImporter {
Features doFeatures() const override { return Feature::OpenData; }
ImporterFeatures doFeatures() const override { return ImporterFeature::OpenData; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -243,7 +243,7 @@ void AbstractImporterTest::openDataNotImplemented() {
void AbstractImporterTest::format() {
struct: AbstractImporter {
Features doFeatures() const override { return {}; }
ImporterFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -257,7 +257,7 @@ void AbstractImporterTest::format() {
void AbstractImporterTest::formatNoFile() {
struct: AbstractImporter {
Features doFeatures() const override { return {}; }
ImporterFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -275,7 +275,7 @@ void AbstractImporterTest::formatNoFile() {
void AbstractImporterTest::frequency() {
struct: AbstractImporter {
Features doFeatures() const override { return {}; }
ImporterFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -289,7 +289,7 @@ void AbstractImporterTest::frequency() {
void AbstractImporterTest::frequencyNoFile() {
struct: AbstractImporter {
Features doFeatures() const override { return {}; }
ImporterFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -307,7 +307,7 @@ void AbstractImporterTest::frequencyNoFile() {
void AbstractImporterTest::data() {
struct: AbstractImporter {
Features doFeatures() const override { return {}; }
ImporterFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -325,7 +325,7 @@ void AbstractImporterTest::data() {
void AbstractImporterTest::dataNoFile() {
struct: AbstractImporter {
Features doFeatures() const override { return {}; }
ImporterFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -343,7 +343,7 @@ void AbstractImporterTest::dataNoFile() {
void AbstractImporterTest::dataCustomDeleter() {
struct: AbstractImporter {
Features doFeatures() const override { return {}; }
ImporterFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -364,15 +364,15 @@ void AbstractImporterTest::dataCustomDeleter() {
void AbstractImporterTest::debugFeature() {
std::ostringstream out;
Debug{&out} << AbstractImporter::Feature::OpenData << AbstractImporter::Feature(0xf0);
CORRADE_COMPARE(out.str(), "Audio::AbstractImporter::Feature::OpenData Audio::AbstractImporter::Feature(0xf0)\n");
Debug{&out} << ImporterFeature::OpenData << ImporterFeature(0xf0);
CORRADE_COMPARE(out.str(), "Audio::ImporterFeature::OpenData Audio::ImporterFeature(0xf0)\n");
}
void AbstractImporterTest::debugFeatures() {
std::ostringstream out;
Debug{&out} << AbstractImporter::Feature::OpenData << AbstractImporter::Features{};
CORRADE_COMPARE(out.str(), "Audio::AbstractImporter::Feature::OpenData Audio::AbstractImporter::Features{}\n");
Debug{&out} << ImporterFeature::OpenData << ImporterFeatures{};
CORRADE_COMPARE(out.str(), "Audio::ImporterFeature::OpenData Audio::ImporterFeatures{}\n");
}
}}}}

30
src/Magnum/Text/AbstractFont.cpp

@ -85,7 +85,7 @@ AbstractFont::AbstractFont(PluginManager::AbstractManager& manager, const std::s
void AbstractFont::setFileCallback(Containers::Optional<Containers::ArrayView<const char>>(*callback)(const std::string&, InputFileCallbackPolicy, void*), void* const userData) {
CORRADE_ASSERT(!isOpened(), "Text::AbstractFont::setFileCallback(): can't be set while a font is opened", );
CORRADE_ASSERT(features() & (Feature::FileCallback|Feature::OpenData), "Text::AbstractFont::setFileCallback(): font plugin supports neither loading from data nor via callbacks, callbacks can't be used", );
CORRADE_ASSERT(features() & (FontFeature::FileCallback|FontFeature::OpenData), "Text::AbstractFont::setFileCallback(): font plugin supports neither loading from data nor via callbacks, callbacks can't be used", );
_fileCallback = callback;
_fileCallbackUserData = userData;
@ -95,7 +95,7 @@ void AbstractFont::setFileCallback(Containers::Optional<Containers::ArrayView<co
void AbstractFont::doSetFileCallback(Containers::Optional<Containers::ArrayView<const char>>(*)(const std::string&, InputFileCallbackPolicy, void*), void*) {}
bool AbstractFont::openData(Containers::ArrayView<const char> data, const Float size) {
CORRADE_ASSERT(features() & Feature::OpenData,
CORRADE_ASSERT(features() & FontFeature::OpenData,
"Text::AbstractFont::openData(): feature not supported", false);
/* We accept empty data here (instead of checking for them and failing so
@ -139,13 +139,13 @@ bool AbstractFont::openFile(const std::string& filename, const Float size) {
/* If file loading callbacks are not set or the font implementation
supports handling them directly, call into the implementation */
if(!_fileCallback || (doFeatures() & Feature::FileCallback)) {
if(!_fileCallback || (doFeatures() & FontFeature::FileCallback)) {
metrics = doOpenFile(filename, size);
/* Otherwise, if loading from data is supported, use the callback and pass
the data through to openData(). Mark the file as ready to be closed once
opening is finished. */
} else if(doFeatures() & Feature::OpenData) {
} else if(doFeatures() & FontFeature::OpenData) {
/* This needs to be duplicated here and in the doOpenFile()
implementation in order to support both following cases:
- plugins that don't support FileCallback but have their own
@ -176,7 +176,7 @@ bool AbstractFont::openFile(const std::string& filename, const Float size) {
}
auto AbstractFont::doOpenFile(const std::string& filename, const Float size) -> Metrics {
CORRADE_ASSERT(features() & Feature::OpenData, "Text::AbstractFont::openFile(): not implemented", {});
CORRADE_ASSERT(features() & FontFeature::OpenData, "Text::AbstractFont::openFile(): not implemented", {});
Metrics metrics;
@ -248,7 +248,7 @@ Vector2 AbstractFont::glyphAdvance(const UnsignedInt glyph) {
void AbstractFont::fillGlyphCache(AbstractGlyphCache& cache, const std::string& characters) {
CORRADE_ASSERT(isOpened(),
"Text::AbstractFont::fillGlyphCache(): no font opened", );
CORRADE_ASSERT(!(features() & Feature::PreparedGlyphCache),
CORRADE_ASSERT(!(features() & FontFeature::PreparedGlyphCache),
"Text::AbstractFont::fillGlyphCache(): feature not supported", );
doFillGlyphCache(cache, Utility::Unicode::utf32(characters));
@ -261,7 +261,7 @@ void AbstractFont::doFillGlyphCache(AbstractGlyphCache&, const std::u32string&)
Containers::Pointer<AbstractGlyphCache> AbstractFont::createGlyphCache() {
CORRADE_ASSERT(isOpened(),
"Text::AbstractFont::createGlyphCache(): no font opened", nullptr);
CORRADE_ASSERT(features() & Feature::PreparedGlyphCache,
CORRADE_ASSERT(features() & FontFeature::PreparedGlyphCache,
"Text::AbstractFont::createGlyphCache(): feature not supported", nullptr);
return doCreateGlyphCache();
@ -278,12 +278,12 @@ Containers::Pointer<AbstractLayouter> AbstractFont::layout(const AbstractGlyphCa
return doLayout(cache, size, text);
}
Debug& operator<<(Debug& debug, const AbstractFont::Feature value) {
debug << "Text::AbstractFont::Feature" << Debug::nospace;
Debug& operator<<(Debug& debug, const FontFeature value) {
debug << "Text::FontFeature" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case AbstractFont::Feature::v: return debug << "::" #v;
#define _c(v) case FontFeature::v: return debug << "::" #v;
_c(OpenData)
_c(FileCallback)
_c(PreparedGlyphCache)
@ -294,11 +294,11 @@ Debug& operator<<(Debug& debug, const AbstractFont::Feature value) {
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const AbstractFont::Features value) {
return Containers::enumSetDebugOutput(debug, value, "Text::AbstractFont::Features{}", {
AbstractFont::Feature::OpenData,
AbstractFont::Feature::FileCallback,
AbstractFont::Feature::PreparedGlyphCache});
Debug& operator<<(Debug& debug, const FontFeatures value) {
return Containers::enumSetDebugOutput(debug, value, "Text::FontFeatures{}", {
FontFeature::OpenData,
FontFeature::FileCallback,
FontFeature::PreparedGlyphCache});
}
AbstractLayouter::AbstractLayouter(UnsignedInt glyphCount): _glyphCount(glyphCount) {}

181
src/Magnum/Text/AbstractFont.h

@ -44,6 +44,63 @@
namespace Magnum { namespace Text {
/**
@brief Features supported by a font implementation
@m_since_latest
@see @ref FontFeatures, @ref AbstractFont::features()
*/
enum class FontFeature: UnsignedByte {
/** Opening fonts from raw data using @ref AbstractFont::openData() */
OpenData = 1 << 0,
/**
* Specifying callbacks for loading additional files referenced from the
* main file using @ref AbstractFont::setFileCallback(). If the font
* doesn't expose this feature, the format is either single-file or loading
* via callbacks is not supported.
*
* See @ref Text-AbstractFont-usage-callbacks and particular font plugin
* documentation for more information.
* @m_since{2019,10}
*/
FileCallback = 1 << 1,
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* The format is multi-file, thus @ref AbstractFont::openSingleData()
* convenience function cannot be used.
* @m_deprecated_since{2019,10} Obsolete, use file callbacks
* instead.
*/
MultiFile CORRADE_DEPRECATED_ENUM("obsolete, use file callbacks instead") = FileCallback,
#endif
/**
* The font contains prepared glyph cache.
*
* @see @ref AbstractFont::fillGlyphCache(),
* @ref AbstractFont::createGlyphCache()
*/
PreparedGlyphCache = 1 << 2
};
/**
@brief Set of features supported by a font implementation
@m_since_latest
@see @ref AbstractFont::features()
*/
typedef Containers::EnumSet<FontFeature> FontFeatures;
CORRADE_ENUMSET_OPERATORS(FontFeatures)
/** @debugoperatorenum{FontFeature} */
MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, FontFeature value);
/** @debugoperatorenum{FontFeatures} */
MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, FontFeatures value);
/**
@brief Base for font plugins
@ -68,13 +125,13 @@ information about actual text rendering.
Besides loading data directly from the filesystem using @ref openFile() like
shown above, it's possible to use @ref openData() to import data from memory.
Note that the particular importer implementation must support
@ref Feature::OpenData for this method to work.
@ref FontFeature::OpenData for this method to work.
Some font formats consist of more than one file and in that case you may want
to intercept those references and load them in a custom way as well. For font
plugins that advertise support for this with @ref Feature::FileCallback this is
done by specifying a file loading callback using @ref setFileCallback(). The
callback gets a filename, @ref InputFileCallbackPolicy and an user
plugins that advertise support for this with @ref FontFeature::FileCallback
this is done by specifying a file loading callback using @ref setFileCallback().
The callback gets a filename, @ref InputFileCallbackPolicy and an user
pointer as parameters; returns a non-owning view on the loaded data or a
@ref Corrade::Containers::NullOpt "Containers::NullOpt" to indicate the file
loading failed. For example, loading a memory-mapped font could look like
@ -85,12 +142,12 @@ correctly.
@snippet MagnumText.cpp AbstractFont-usage-callbacks
For importers that don't support @ref Feature::FileCallback directly, the base
@ref openFile() implementation will use the file callback to pass the loaded
data through to @ref openData(), in case the importer supports at least
@ref Feature::OpenData. If the importer supports neither @ref Feature::FileCallback
nor @ref Feature::OpenData, @ref setFileCallback() doesn't allow the callbacks
to be set.
For importers that don't support @ref FontFeature::FileCallback directly, the
base @ref openFile() implementation will use the file callback to pass the
loaded data through to @ref openData(), in case the importer supports at least
@ref FontFeature::OpenData. If the importer supports neither
@ref FontFeature::FileCallback nor @ref FontFeature::OpenData,
@ref setFileCallback() doesn't allow the callbacks to be set.
The input file callback signature is the same for @ref Text::AbstractFont and
@ref Trade::AbstractImporter to allow code reuse.
@ -107,56 +164,26 @@ checked by the implementation:
- Functions @ref doOpenData() and @ref doOpenFile() are called after the
previous file was closed, function @ref doClose() is called only if there
is any file opened.
- Function @ref doOpenData() is called only if @ref Feature::OpenData is
- Function @ref doOpenData() is called only if @ref FontFeature::OpenData is
supported.
- The @ref doSetFileCallback() function is called only if
@ref Feature::FileCallback is supported and there is no file opened.
@ref FontFeature::FileCallback is supported and there is no file opened.
- All `do*()` implementations working on opened file are called only if
there is any file opened.
*/
class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
public:
/**
* @brief Features supported by this font implementation
*
* @see @ref Features, @ref features()
*/
enum class Feature: UnsignedByte {
/** Opening fonts from raw data using @ref openData() */
OpenData = 1 << 0,
/**
* Specifying callbacks for loading additional files referenced
* from the main file using @ref setFileCallback(). If the font
* doesn't expose this feature, the format is either single-file or
* loading via callbacks is not supported.
*
* See @ref Text-AbstractFont-usage-callbacks and particular font
* plugin documentation for more information.
* @m_since{2019,10}
*/
FileCallback = 1 << 1,
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* The format is multi-file, thus @ref openSingleData() convenience
* function cannot be used.
* @m_deprecated_since{2019,10} Obsolete, use file callbacks
* instead.
/** @brief @copybrief FontFeature
* @m_deprecated_since_latest Use @ref FontFeature instead.
*/
MultiFile CORRADE_DEPRECATED_ENUM("obsolete, use file callbacks instead") = FileCallback,
#endif
typedef CORRADE_DEPRECATED("use FontFeature instead") FontFeature Feature;
/**
* The font contains prepared glyph cache.
*
* @see @ref fillGlyphCache(), @ref createGlyphCache()
/** @brief @copybrief FontFeatures
* @m_deprecated_since_latest Use @ref FontFeatures instead.
*/
PreparedGlyphCache = 1 << 2
};
/** @brief Set of features supported by this font implementation */
typedef Containers::EnumSet<Feature> Features;
typedef CORRADE_DEPRECATED("use FontFeatures instead") FontFeatures Features;
#endif
/**
* @brief Plugin interface
@ -193,7 +220,7 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
explicit AbstractFont(PluginManager::AbstractManager& manager, const std::string& plugin);
/** @brief Features supported by this font */
Features features() const { return doFeatures(); }
FontFeatures features() const { return doFeatures(); }
/**
* @brief File opening callback function
@ -215,22 +242,22 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* @brief Set file opening callback
* @m_since{2019,10}
*
* In case the font plugin supports @ref Feature::FileCallback, files
* opened through @ref openFile() will be loaded through the provided
* callback. Besides that, all external files referenced by the
* top-level file will be loaded through the callback function as well,
* usually on demand. The callback function gets a filename,
* In case the font plugin supports @ref FontFeature::FileCallback,
* files opened through @ref openFile() will be loaded through the
* provided callback. Besides that, all external files referenced by
* the top-level file will be loaded through the callback function as
* well, usually on demand. The callback function gets a filename,
* @ref InputFileCallbackPolicy and the @p userData pointer as input
* and returns a non-owning view on the loaded data as output or a
* @ref Corrade::Containers::NullOpt if loading failed --- because
* empty files might also be valid in some circumstances, @cpp nullptr @ce
* can't be used to indicate a failure.
*
* In case the font plugin doesn't support @ref Feature::FileCallback but
* supports at least @ref Feature::OpenData, a file opened through
* @ref openFile() will be internally loaded through the provided
* callback and then passed to @ref openData(). First the file is
* loaded with @ref InputFileCallbackPolicy::LoadTemporary passed to
* In case the font plugin doesn't support @ref FontFeature::FileCallback
* but supports at least @ref FontFeature::OpenData, a file opened
* through @ref openFile() will be internally loaded through the
* provided callback and then passed to @ref openData(). First the file
* is loaded with @ref InputFileCallbackPolicy::LoadTemporary passed to
* the callback, then the returned memory view is passed to
* @ref openData() (sidestepping the potential @ref openFile()
* implementation of that particular font plugin) and after that the
@ -241,8 +268,8 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
*
* In case @p callback is @cpp nullptr @ce, the current callback (if
* any) is reset. This function expects that the font plugin supports
* either @ref Feature::FileCallback or @ref Feature::OpenData. If an
* font plugin supports neither, callbacks can't be used.
* either @ref FontFeature::FileCallback or @ref FontFeature::OpenData.
* If a font plugin supports neither, callbacks can't be used.
*
* It's expected that this function is called *before* a file is
* opened. It's also expected that the loaded data are kept in scope
@ -292,8 +319,8 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* @param size Font size
*
* Closes previous file, if it was opened, and tries to open given
* file. Available only if @ref Feature::OpenData is supported. Returns
* @cpp true @ce on success, @cpp false @ce otherwise.
* file. Available only if @ref FontFeature::OpenData is supported.
* Returns @cpp true @ce on success, @cpp false @ce otherwise.
* @see @ref features(), @ref openFile()
*/
bool openData(Containers::ArrayView<const char> data, Float size);
@ -318,8 +345,8 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* @param size Font size
*
* Closes previous file, if it was opened, and tries to open given
* file. If the plugin has @ref Feature::MultiFile, the function will
* use additional files in given path, all sharing common basename
* file. If the plugin has @ref FontFeature::MultiFile, the function
* will use additional files in given path, all sharing common basename
* derived from @p filename. Returns @cpp true @ce on success,
* @cpp false @ce otherwise.
*/
@ -393,9 +420,9 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* @param characters UTF-8 characters to render
*
* Fills the cache with given characters. Fonts having
* @ref Feature::PreparedGlyphCache do not support partial glyph cache
* filling, use @ref createGlyphCache() instead. Expects that a font is
* opened.
* @ref FontFeature::PreparedGlyphCache do not support partial glyph
* cache filling, use @ref createGlyphCache() instead. Expects that a
* font is opened.
*/
void fillGlyphCache(AbstractGlyphCache& cache, const std::string& characters);
@ -403,7 +430,7 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* @brief Create glyph cache
*
* Configures and fills glyph cache with the contents of whole font.
* Available only if @ref Feature::PreparedGlyphCache is supported.
* Available only if @ref FontFeature::PreparedGlyphCache is supported.
* Other fonts support only partial glyph cache filling, see
* @ref fillGlyphCache(). Expects that a font is opened.
*/
@ -465,7 +492,7 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* @brief Implementation for @ref openFile()
*
* Return metrics of opened font on successful opening, zeros
* otherwise. If @ref Feature::OpenData is supported, default
* otherwise. If @ref FontFeature::OpenData is supported, default
* implementation opens the file and calls @ref doOpenData() with its
* contents. It is allowed to call this function from your
* @ref doOpenFile() implementation --- in particular, this
@ -473,7 +500,7 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* @ref setFileCallback().
*
* This function is not called when file callbacks are set through
* @ref setFileCallback() and @ref Feature::FileCallback is not
* @ref setFileCallback() and @ref FontFeature::FileCallback is not
* supported --- instead, file is loaded though the callback and data
* passed through to @ref doOpenData().
*/
@ -481,7 +508,7 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
private:
/** @brief Implementation for @ref features() */
virtual Features doFeatures() const = 0;
virtual FontFeatures doFeatures() const = 0;
/**
* @brief Implementation for @ref setFileCallback()
@ -541,14 +568,6 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
Float _size{}, _ascent{}, _descent{}, _lineHeight{};
};
CORRADE_ENUMSET_OPERATORS(AbstractFont::Features)
/** @debugoperatorclassenum{AbstractFont,AbstractFont::Feature} */
MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, AbstractFont::Feature value);
/** @debugoperatorclassenum{AbstractFont,AbstractFont::Features} */
MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, AbstractFont::Features value);
/**
@brief Base for text layouters

64
src/Magnum/Text/AbstractFontConverter.cpp

@ -27,6 +27,7 @@
#include <algorithm>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/EnumSet.hpp>
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Directory.h>
@ -98,14 +99,14 @@ AbstractFontConverter::AbstractFontConverter() = default;
AbstractFontConverter::AbstractFontConverter(PluginManager::AbstractManager& manager, const std::string& plugin): PluginManager::AbstractPlugin{manager, plugin} {}
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::exportFontToData(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::string& characters) const {
CORRADE_ASSERT(features() >= (Feature::ExportFont|Feature::ConvertData),
CORRADE_ASSERT(features() >= (FontConverterFeature::ExportFont|FontConverterFeature::ConvertData),
"Text::AbstractFontConverter::exportFontToData(): feature not supported", {});
return doExportFontToData(font, cache, filename, uniqueUnicode(characters));
}
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::doExportFontToData(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::u32string& characters) const {
CORRADE_ASSERT(!(features() & Feature::MultiFile),
CORRADE_ASSERT(!(features() & FontConverterFeature::MultiFile),
"Text::AbstractFontConverter::exportFontToData(): feature advertised but not implemented", {});
std::vector<std::pair<std::string, Containers::Array<char>>> out;
@ -114,9 +115,9 @@ std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConvert
}
Containers::Array<char> AbstractFontConverter::exportFontToSingleData(AbstractFont& font, AbstractGlyphCache& cache, const std::string& characters) const {
CORRADE_ASSERT(features() >= (Feature::ExportFont|Feature::ConvertData),
CORRADE_ASSERT(features() >= (FontConverterFeature::ExportFont|FontConverterFeature::ConvertData),
"Text::AbstractFontConverter::exportFontToSingleData(): feature not supported", nullptr);
CORRADE_ASSERT(!(features() & Feature::MultiFile),
CORRADE_ASSERT(!(features() & FontConverterFeature::MultiFile),
"Text::AbstractFontConverter::exportFontToSingleData(): the format is not single-file", nullptr);
return doExportFontToSingleData(font, cache, uniqueUnicode(characters));
@ -129,14 +130,14 @@ Containers::Array<char> AbstractFontConverter::doExportFontToSingleData(Abstract
}
bool AbstractFontConverter::exportFontToFile(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::string& characters) const {
CORRADE_ASSERT(features() & Feature::ExportFont,
CORRADE_ASSERT(features() & FontConverterFeature::ExportFont,
"Text::AbstractFontConverter::exportFontToFile(): feature not supported", false);
return doExportFontToFile(font, cache, filename, uniqueUnicode(characters));
}
bool AbstractFontConverter::doExportFontToFile(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::u32string& characters) const {
CORRADE_ASSERT(features() & Feature::ConvertData,
CORRADE_ASSERT(features() & FontConverterFeature::ConvertData,
"Text::AbstractFontConverter::exportFontToFile(): not implemented", false);
/* Export all data */
@ -152,14 +153,14 @@ bool AbstractFontConverter::doExportFontToFile(AbstractFont& font, AbstractGlyph
}
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::exportGlyphCacheToData(AbstractGlyphCache& cache, const std::string& filename) const {
CORRADE_ASSERT(features() >= (Feature::ExportGlyphCache|Feature::ConvertData),
CORRADE_ASSERT(features() >= (FontConverterFeature::ExportGlyphCache|FontConverterFeature::ConvertData),
"Text::AbstractFontConverter::exportGlyphCacheToData(): feature not supported", {});
return doExportGlyphCacheToData(cache, filename);
}
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::doExportGlyphCacheToData(AbstractGlyphCache& cache, const std::string& filename) const {
CORRADE_ASSERT(!(features() & Feature::MultiFile),
CORRADE_ASSERT(!(features() & FontConverterFeature::MultiFile),
"Text::AbstractFontConverter::exportGlyphCacheToData(): feature advertised but not implemented", {});
std::vector<std::pair<std::string, Containers::Array<char>>> out;
@ -168,9 +169,9 @@ std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConvert
}
Containers::Array<char> AbstractFontConverter::exportGlyphCacheToSingleData(AbstractGlyphCache& cache) const {
CORRADE_ASSERT(features() >= (Feature::ExportGlyphCache|Feature::ConvertData),
CORRADE_ASSERT(features() >= (FontConverterFeature::ExportGlyphCache|FontConverterFeature::ConvertData),
"Text::AbstractFontConverter::exportGlyphCacheToSingleData(): feature not supported", nullptr);
CORRADE_ASSERT(!(features() & Feature::MultiFile),
CORRADE_ASSERT(!(features() & FontConverterFeature::MultiFile),
"Text::AbstractFontConverter::exportGlyphCacheToSingleData(): the format is not single-file", nullptr);
return doExportGlyphCacheToSingleData(cache);
@ -183,14 +184,14 @@ Containers::Array<char> AbstractFontConverter::doExportGlyphCacheToSingleData(Ab
}
bool AbstractFontConverter::exportGlyphCacheToFile(AbstractGlyphCache& cache, const std::string& filename) const {
CORRADE_ASSERT(features() & Feature::ExportGlyphCache,
CORRADE_ASSERT(features() & FontConverterFeature::ExportGlyphCache,
"Text::AbstractFontConverter::exportGlyphCacheToFile(): feature not supported", false);
return doExportGlyphCacheToFile(cache, filename);
}
bool AbstractFontConverter::doExportGlyphCacheToFile(AbstractGlyphCache& cache, const std::string& filename) const {
CORRADE_ASSERT(features() & Feature::ConvertData,
CORRADE_ASSERT(features() & FontConverterFeature::ConvertData,
"Text::AbstractFontConverter::exportGlyphCacheToFile(): not implemented", false);
/* Export all data */
@ -206,7 +207,7 @@ bool AbstractFontConverter::doExportGlyphCacheToFile(AbstractGlyphCache& cache,
}
Containers::Pointer<AbstractGlyphCache> AbstractFontConverter::importGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayView<const char>>>& data) const {
CORRADE_ASSERT(features() >= (Feature::ImportGlyphCache|Feature::ConvertData),
CORRADE_ASSERT(features() >= (FontConverterFeature::ImportGlyphCache|FontConverterFeature::ConvertData),
"Text::AbstractFontConverter::importGlyphCacheFromData(): feature not supported", nullptr);
CORRADE_ASSERT(!data.empty(),
"Text::AbstractFontConverter::importGlyphCacheFromData(): no data passed", nullptr);
@ -215,7 +216,7 @@ Containers::Pointer<AbstractGlyphCache> AbstractFontConverter::importGlyphCacheF
}
Containers::Pointer<AbstractGlyphCache> AbstractFontConverter::doImportGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayView<const char>>>& data) const {
CORRADE_ASSERT(!(features() & Feature::MultiFile),
CORRADE_ASSERT(!(features() & FontConverterFeature::MultiFile),
"Text::AbstractFontConverter::importGlyphCacheFromData(): feature advertised but not implemented", nullptr);
CORRADE_ASSERT(data.size() == 1,
"Text::AbstractFontConverter::importGlyphCacheFromData(): expected just one file for single-file format", nullptr);
@ -224,9 +225,9 @@ Containers::Pointer<AbstractGlyphCache> AbstractFontConverter::doImportGlyphCach
}
Containers::Pointer<AbstractGlyphCache> AbstractFontConverter::importGlyphCacheFromSingleData(Containers::ArrayView<const char> data) const {
CORRADE_ASSERT(features() >= (Feature::ImportGlyphCache|Feature::ConvertData),
CORRADE_ASSERT(features() >= (FontConverterFeature::ImportGlyphCache|FontConverterFeature::ConvertData),
"Text::AbstractFontConverter::importGlyphCacheFromSingleData(): feature not supported", nullptr);
CORRADE_ASSERT(!(features() & Feature::MultiFile),
CORRADE_ASSERT(!(features() & FontConverterFeature::MultiFile),
"Text::AbstractFontConverter::importGlyphCacheFromSingleData(): the format is not single-file", nullptr);
return doImportGlyphCacheFromSingleData(data);
@ -239,14 +240,14 @@ Containers::Pointer<AbstractGlyphCache> AbstractFontConverter::doImportGlyphCach
}
Containers::Pointer<AbstractGlyphCache> AbstractFontConverter::importGlyphCacheFromFile(const std::string& filename) const {
CORRADE_ASSERT(features() & Feature::ImportGlyphCache,
CORRADE_ASSERT(features() & FontConverterFeature::ImportGlyphCache,
"Text::AbstractFontConverter::importGlyphCacheFromFile(): feature not supported", nullptr);
return doImportGlyphCacheFromFile(filename);
}
Containers::Pointer<AbstractGlyphCache> AbstractFontConverter::doImportGlyphCacheFromFile(const std::string& filename) const {
CORRADE_ASSERT(features() & Feature::ConvertData && !(features() & Feature::MultiFile),
CORRADE_ASSERT(features() & FontConverterFeature::ConvertData && !(features() & FontConverterFeature::MultiFile),
"Text::AbstractFontConverter::importGlyphCacheFromFile(): not implemented", nullptr);
/* Open file */
@ -258,4 +259,31 @@ Containers::Pointer<AbstractGlyphCache> AbstractFontConverter::doImportGlyphCach
return doImportGlyphCacheFromSingleData(Utility::Directory::read(filename));
}
Debug& operator<<(Debug& debug, const FontConverterFeature value) {
debug << "Text::FontConverterFeature" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case FontConverterFeature::v: return debug << "::" #v;
_c(ExportFont)
_c(ExportGlyphCache)
_c(ImportGlyphCache)
_c(ConvertData)
_c(MultiFile)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(Containers::enumCastUnderlyingType(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const FontConverterFeatures value) {
return Containers::enumSetDebugOutput(debug, value, "Text::FontConverterFeatures{}", {
FontConverterFeature::ExportFont,
FontConverterFeature::ExportGlyphCache,
FontConverterFeature::ImportGlyphCache,
FontConverterFeature::ConvertData,
FontConverterFeature::MultiFile});
}
}}

261
src/Magnum/Text/AbstractFontConverter.h

@ -49,6 +49,76 @@
namespace Magnum { namespace Text {
/**
@brief Features supported by a font converter
@m_since_latest
@see @ref FontConverterFeatures, @ref AbstractFontConverter::features()
*/
enum class FontConverterFeature: UnsignedByte {
/**
* Exporting font using @ref AbstractFontConverter::exportFontToFile(),
* @ref AbstractFontConverter::exportFontToData() or
* @ref AbstractFontConverter::exportFontToSingleData()
* @see @ref FontConverterFeature::ConvertData
*/
ExportFont = 1 << 0,
/**
* Export glyph cache using
* @ref AbstractFontConverter::exportGlyphCacheToFile(),
* @ref AbstractFontConverter::exportGlyphCacheToData() or
* @ref AbstractFontConverter::exportGlyphCacheToSingleData()
* @see @ref FontConverterFeature::ConvertData
*/
ExportGlyphCache = 1 << 1,
/**
* Import glyph cache using
* @ref AbstractFontConverter::importGlyphCacheFromFile(),
* @ref AbstractFontConverter::importGlyphCacheFromData() or
* @ref AbstractFontConverter::importGlyphCacheFromSingleData()
* @see @ref FontConverterFeature::ConvertData
*/
ImportGlyphCache = 1 << 2,
/**
* Convert from/to data using
* @ref AbstractFontConverter::exportFontToData(),
* @ref AbstractFontConverter::exportFontToSingleData(),
* @ref AbstractFontConverter::exportGlyphCacheToData(),
* @ref AbstractFontConverter::exportGlyphCacheToSingleData(),
* @ref AbstractFontConverter::importGlyphCacheFromData() or
* @ref AbstractFontConverter::importGlyphCacheFromSingleData()
*/
ConvertData = 1 << 4,
/**
* The format is multi-file, thus
* @ref AbstractFontConverter::exportFontToSingleData(),
* @ref AbstractFontConverter::exportGlyphCacheToSingleData() and
* @ref AbstractFontConverter::importGlyphCacheFromSingleData() convenience
* functions cannot be used.
*/
MultiFile = 1 << 5
};
/**
@brief Features supported by a font converter
@m_since_latest
@see @ref AbstractFontConverter::features()
*/
typedef Containers::EnumSet<FontConverterFeature> FontConverterFeatures;
CORRADE_ENUMSET_OPERATORS(FontConverterFeatures)
/** @debugoperatorenum{FontConverterFeature} */
MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, FontConverterFeature value);
/** @debugoperatorenum{FontConverterFeatures} */
MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, FontConverterFeatures value);
/**
@brief Base for font converter plugins
@ -69,13 +139,14 @@ characters.
You don't need to do most of the redundant sanity checks, these things are
checked by the implementation:
- Functions `doExportFontTo*()` are called only if @ref Feature::ExportFont
is supported, functions `doExportGlyphCacheTo*()` are called only if
@ref Feature::ExportGlyphCache is supported.
- Functions `doExportFontTo*()` are called only if
@ref FontConverterFeature::ExportFont is supported, functions
`doExportGlyphCacheTo*()` are called only if
@ref FontConverterFeature::ExportGlyphCache is supported.
- Functions `doImportGlyphCacheFrom*()` are called only if
@ref Feature::ImportGlyphCache is supported.
@ref FontConverterFeature::ImportGlyphCache is supported.
- Functions `doExport*To*Data()` and `doImport*From*Data()` are called only
if @ref Feature::ConvertData is supported.
if @ref FontConverterFeature::ConvertData is supported.
- Function `doImport*FromData()` is called only if there is at least one data
array passed.
@ -86,55 +157,17 @@ checked by the implementation:
*/
class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPlugin {
public:
/**
* @brief Features supported by this converter
*
* @see @ref Features, @ref features()
*/
enum class Feature: UnsignedByte {
/**
* Exporting font using @ref exportFontToFile(), @ref exportFontToData()
* or @ref exportFontToSingleData()
* @see @ref Feature::ConvertData
*/
ExportFont = 1 << 0,
/**
* Export glyph cache using @ref exportGlyphCacheToFile(),
* @ref exportGlyphCacheToData() or @ref exportGlyphCacheToSingleData()
* @see @ref Feature::ConvertData
*/
ExportGlyphCache = 1 << 1,
/**
* Import glyph cache using @ref importGlyphCacheFromFile(),
* @ref importGlyphCacheFromData() or @ref importGlyphCacheFromSingleData()
* @see @ref Feature::ConvertData
*/
ImportGlyphCache = 1 << 2,
/**
* Convert from/to data using @ref exportFontToData(),
* @ref exportFontToSingleData(), @ref exportGlyphCacheToData(),
* @ref exportGlyphCacheToSingleData(), @ref importGlyphCacheFromData()
* or @ref importGlyphCacheFromSingleData()
#ifdef MAGNUM_BUILD_DEPRECATED
/** @brief @copybrief FontConverterFeature
* @m_deprecated_since_latest Use @ref FontConverterFeature instead.
*/
ConvertData = 1 << 4,
typedef CORRADE_DEPRECATED("use FontConverterFeature instead") FontConverterFeature Feature;
/**
* The format is multi-file, thus @ref exportFontToSingleData(),
* @ref exportGlyphCacheToSingleData() and @ref importGlyphCacheFromSingleData()
* convenience functions cannot be used.
/** @brief @copybrief FontConverterFeatures
* @m_deprecated_since_latest Use @ref FontConverterFeatures instead.
*/
MultiFile = 1 << 5
};
/**
* @brief Features supported by this converter
*
* @see @ref features()
*/
typedef Containers::EnumSet<Feature> Features;
typedef CORRADE_DEPRECATED("use FontConverterFeatures instead") FontConverterFeatures Features;
#endif
/**
* @brief Plugin interface
@ -171,7 +204,7 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
explicit AbstractFontConverter(PluginManager::AbstractManager& manager, const std::string& plugin);
/** @brief Features supported by this converter */
Features features() const { return doFeatures(); }
FontConverterFeatures features() const { return doFeatures(); }
/**
* @brief Export font to raw data
@ -180,12 +213,13 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* @param filename Output filename
* @param characters Characters to export
*
* Available only if @ref Feature::ConvertData and @ref Feature::ExportFont
* is supported. Returns pairs of filename and data on success, empty
* vector otherwise. All data will be sharing common basename derived
* from @p filename. If the plugin doesn't have @ref Feature::MultiFile,
* only one pair is returned, thus using @ref exportFontToSingleData()
* might be more convenient in that case.
* Available only if @ref FontConverterFeature::ConvertData and
* @ref FontConverterFeature::ExportFont is supported. Returns pairs of
* filename and data on success, empty vector otherwise. All data will
* be sharing common basename derived from @p filename. If the plugin
* doesn't have @ref FontConverterFeature::MultiFile, only one pair is
* returned, thus using @ref exportFontToSingleData() might be more
* convenient in that case.
* @see @ref features(), @ref exportFontToFile(),
* @ref exportGlyphCacheToData()
*/
@ -194,10 +228,11 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
/**
* @brief Export font to single raw data
*
* Available only if @ref Feature::ConvertData and @ref Feature::ExportFont
* is supported and the plugin doesn't have @ref Feature::MultiFile.
* Returns data on success, zero-sized array otherwise. See
* @ref exportFontToData() for more information.
* Available only if @ref FontConverterFeature::ConvertData and
* @ref FontConverterFeature::ExportFont is supported and the plugin
* doesn't have @ref FontConverterFeature::MultiFile. Returns data on
* success, zero-sized array otherwise. See @ref exportFontToData() for
* more information.
* @see @ref features(), @ref exportFontToFile(),
* @ref exportGlyphCacheToSingleData()
*/
@ -206,11 +241,12 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
/**
* @brief Export font to file
*
* Available only if @ref Feature::ExportFont is supported. If the
* plugin has @ref Feature::MultiFile, the function will create more
* than one file in given path, all sharing common basename derived
* from @p filename. Returns @cpp true @ce on success, @cpp false @ce
* otherwise. See @ref exportFontToData() for more information.
* Available only if @ref FontConverterFeature::ExportFont is
* supported. If the plugin has @ref FontConverterFeature::MultiFile,
* the function will create more than one file in given path, all
* sharing common basename derived from @p filename. Returns
* @cpp true @ce on success, @cpp false @ce otherwise. See
* @ref exportFontToData() for more information.
* @see @ref features(), @ref exportFontToData(),
* @ref exportGlyphCacheToFile()
*/
@ -221,11 +257,12 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* @param cache Populated glyph cache
* @param filename Output filename
*
* Available only if @ref Feature::ConvertData and @ref Feature::ExportGlyphCache
* is supported. Returns pairs of filename and data on success, empty
* vector otherwise. All data will be sharing common basename derived
* from @p filename. If the plugin doesn't have @ref Feature::MultiFile,
* only one pair is returned, thus using @ref exportGlyphCacheToSingleData()
* Available only if @ref FontConverterFeature::ConvertData and
* @ref FontConverterFeature::ExportGlyphCache is supported. Returns
* pairs of filename and data on success, empty vector otherwise. All
* data will be sharing common basename derived from @p filename. If
* the plugin doesn't have @ref FontConverterFeature::MultiFile, only
* one pair is returned, thus using @ref exportGlyphCacheToSingleData()
* might be more convenient in that case.
*
* All glyphs from given cache will be exported. If you want to export
@ -238,9 +275,10 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
/**
* @brief Export glyph cache to single raw data
*
* Available only if @ref Feature::ConvertData and @ref Feature::ExportGlyphCache
* is supported and the plugin doesn't have @ref Feature::MultiFile.
* Returns data on success, zero-sized array otherwise. See
* Available only if @ref FontConverterFeature::ConvertData and
* @ref FontConverterFeature::ExportGlyphCache is supported and the
* plugin doesn't have @ref FontConverterFeature::MultiFile. Returns
* data on success, zero-sized array otherwise. See
* @ref exportGlyphCacheToData() for more information.
* @see @ref features(), @ref exportGlyphCacheToFile(),
* @ref importGlyphCacheFromSingleData()
@ -250,11 +288,11 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
/**
* @brief Export glyph cache to file
*
* Available only if @ref Feature::ExportGlyphCache is supported. If
* the plugin has @ref Feature::MultiFile, the function will create
* more than one file in given path, all sharing common basename
* derived from @p filename. Returns @cpp true @ce on success,
* @cpp false @ce otherwise.
* Available only if @ref FontConverterFeature::ExportGlyphCache is
* supported. If the plugin has @ref FontConverterFeature::MultiFile,
* the function will create more than one file in given path, all
* sharing common basename derived from @p filename. Returns
* @cpp true @ce on success, @cpp false @ce otherwise.
* @see @ref features(), @ref exportGlyphCacheToData(),
* @ref exportFontToFile()
*/
@ -264,11 +302,12 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* @brief Import glyph cache from raw data
* @param data Pairs of filename and file data
*
* Available only if @ref Feature::ConvertData and @ref Feature::ImportGlyphCache
* is supported. Returns imported cache on success, @cpp nullptr @ce
* otherwise. If the plugin doesn't have @ref Feature::MultiFile, only
* one file is needed, thus using @ref importGlyphCacheFromSingleData()
* might be more convenient in that case.
* Available only if @ref FontConverterFeature::ConvertData and
* @ref FontConverterFeature::ImportGlyphCache is supported. Returns
* imported cache on success, @cpp nullptr @ce otherwise. If the plugin
* doesn't have @ref FontConverterFeature::MultiFile, only one file is
* needed, thus using @ref importGlyphCacheFromSingleData() might be
* more convenient in that case.
* @see @ref features(), @ref importGlyphCacheFromFile(),
* @ref exportGlyphCacheToData()
*/
@ -277,9 +316,10 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
/**
* @brief Import glyph cache from single raw data
*
* Available only if @ref Feature::ConvertData and @ref Feature::ImportGlyphCache
* is supported and the plugin doesn't have @ref Feature::MultiFile.
* Returns imported cache on success, @cpp nullptr @ce otherwise. See
* Available only if @ref FontConverterFeature::ConvertData and
* @ref FontConverterFeature::ImportGlyphCache is supported and the
* plugin doesn't have @ref FontConverterFeature::MultiFile. Returns
* imported cache on success, @cpp nullptr @ce otherwise. See
* @ref importGlyphCacheFromData() for multi-file conversion.
* @see @ref features(), @ref importGlyphCacheFromFile(),
* @ref exportFontToSingleData()
@ -289,11 +329,11 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
/**
* @brief Import glyph cache from file
*
* Available only if @ref Feature::ImportGlyphCache is supported. If
* the plugin has @ref Feature::MultiFile, the function will use
* additional files in given path, all sharing common basename derived
* from @p filename. Returns imported cache on success, @cpp nullptr @ce
* otherwise.
* Available only if @ref FontConverterFeature::ImportGlyphCache is
* supported. If the plugin has @ref FontConverterFeature::MultiFile,
* the function will use additional files in given path, all sharing
* common basename derived from @p filename. Returns imported cache on
* success, @cpp nullptr @ce otherwise.
* @see @ref features(), @ref importGlyphCacheFromData(),
* @ref exportGlyphCacheToFile()
*/
@ -301,13 +341,13 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
private:
/** @brief Implementation for @ref features() */
virtual Features doFeatures() const = 0;
virtual FontConverterFeatures doFeatures() const = 0;
/**
* @brief Implementation for @ref exportFontToData()
*
* If the plugin doesn't have @ref Feature::MultiFile, default
* implementation calls @ref doExportFontToSingleData().
* If the plugin doesn't have @ref FontConverterFeature::MultiFile,
* default implementation calls @ref doExportFontToSingleData().
*/
virtual std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::u32string& characters) const;
@ -317,17 +357,17 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
/**
* @brief Implementation for @ref exportFontToFile()
*
* If @ref Feature::ConvertData is supported, default implementation
* calls @ref doExportFontToData() and saves the result to given
* file(s).
* If @ref FontConverterFeature::ConvertData is supported, default
* implementation calls @ref doExportFontToData() and saves the result
* to given file(s).
*/
virtual bool doExportFontToFile(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::u32string& characters) const;
/**
* @brief Implementation for @ref exportGlyphCacheToData()
*
* If the plugin doesn't have @ref Feature::MultiFile, default
* implementation calls @ref doExportGlyphCacheToSingleData().
* If the plugin doesn't have @ref FontConverterFeature::MultiFile,
* default implementation calls @ref doExportGlyphCacheToSingleData().
*/
virtual std::vector<std::pair<std::string, Containers::Array<char>>> doExportGlyphCacheToData(AbstractGlyphCache& cache, const std::string& filename) const;
@ -337,17 +377,17 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
/**
* @brief Implementation for @ref exportGlyphCacheToFile()
*
* If @ref Feature::ConvertData is supported, default implementation
* calls @ref doExportGlyphCacheToData() and saves the result to given
* file(s).
* If @ref FontConverterFeature::ConvertData is supported, default
* implementation calls @ref doExportGlyphCacheToData() and saves the
* result to given file(s).
*/
virtual bool doExportGlyphCacheToFile(AbstractGlyphCache& cache, const std::string& filename) const;
/**
* @brief Implementation for @ref importGlyphCacheFromData()
*
* If the plugin doesn't have @ref Feature::MultiFile, default
* implementation calls @ref doImportGlyphCacheFromSingleData().
* If the plugin doesn't have @ref FontConverterFeature::MultiFile,
* default implementation calls @ref doImportGlyphCacheFromSingleData().
*/
virtual Containers::Pointer<AbstractGlyphCache> doImportGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayView<const char>>>& data) const;
@ -357,15 +397,14 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
/**
* @brief Implementation for @ref importGlyphCacheFromFile()
*
* If @ref Feature::ConvertData is supported and the plugin doesn't
* have @ref Feature::MultiFile, default implementation opens the file
* and calls @ref doImportGlyphCacheFromSingleData() with its contents.
* If @ref FontConverterFeature::ConvertData is supported and the
* plugin doesn't have @ref FontConverterFeature::MultiFile, default
* implementation opens the file and calls
* @ref doImportGlyphCacheFromSingleData() with its contents.
*/
virtual Containers::Pointer<AbstractGlyphCache> doImportGlyphCacheFromFile(const std::string& filename) const;
};
CORRADE_ENUMSET_OPERATORS(AbstractFontConverter::Features)
}}
#endif

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

@ -23,6 +23,7 @@
DEALINGS IN THE SOFTWARE.
*/
#include <sstream>
#include <Corrade/Containers/Array.h>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/TestSuite/Compare/FileToString.h>
@ -53,6 +54,9 @@ struct AbstractFontConverterTest: TestSuite::Tester {
void importGlyphCacheFromSingleData();
void importGlyphCacheFromFile();
void debugFeature();
void debugFeatures();
};
AbstractFontConverterTest::AbstractFontConverterTest() {
@ -67,14 +71,17 @@ AbstractFontConverterTest::AbstractFontConverterTest() {
&AbstractFontConverterTest::exportGlyphCacheToFileFailed,
&AbstractFontConverterTest::importGlyphCacheFromSingleData,
&AbstractFontConverterTest::importGlyphCacheFromFile});
&AbstractFontConverterTest::importGlyphCacheFromFile,
&AbstractFontConverterTest::debugFeature,
&AbstractFontConverterTest::debugFeatures});
/* Create testing dir */
Utility::Directory::mkpath(TEXT_TEST_OUTPUT_DIR);
}
struct DummyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -99,7 +106,7 @@ void AbstractFontConverterTest::convertGlyphs() {
GlyphExporter(std::u32string& characters): _characters(characters) {}
private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont; }
FontConverterFeatures doFeatures() const override { return FontConverterFeature::ConvertData|FontConverterFeature::ExportFont; }
Containers::Array<char> doExportFontToSingleData(AbstractFont&, AbstractGlyphCache&, const std::u32string& characters) const override {
_characters = characters;
@ -118,7 +125,7 @@ void AbstractFontConverterTest::convertGlyphs() {
void AbstractFontConverterTest::exportFontToSingleData() {
class SingleDataExporter: public Text::AbstractFontConverter {
private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont; }
FontConverterFeatures doFeatures() const override { return FontConverterFeature::ConvertData|FontConverterFeature::ExportFont; }
Containers::Array<char> doExportFontToSingleData(AbstractFont&, AbstractGlyphCache&, const std::u32string&) const override {
Containers::Array<char> data(1);
@ -139,7 +146,7 @@ void AbstractFontConverterTest::exportFontToSingleData() {
void AbstractFontConverterTest::exportFontToFile() {
class DataExporter: public Text::AbstractFontConverter {
private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont|Feature::MultiFile; }
FontConverterFeatures doFeatures() const override { return FontConverterFeature::ConvertData|FontConverterFeature::ExportFont|FontConverterFeature::MultiFile; }
std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont&, AbstractGlyphCache&, const std::string& filename, const std::u32string&) const override {
/* Why the hell GCC 4.9 fails to do proper move so I need to
@ -167,7 +174,7 @@ void AbstractFontConverterTest::exportFontToFile() {
void AbstractFontConverterTest::exportFontToFileFailed() {
struct: AbstractFontConverter {
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont|Feature::MultiFile; }
FontConverterFeatures doFeatures() const override { return FontConverterFeature::ConvertData|FontConverterFeature::ExportFont|FontConverterFeature::MultiFile; }
std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont&, AbstractGlyphCache&, const std::string&, const std::u32string&) const override { return {}; }
} exporter;
@ -177,7 +184,7 @@ void AbstractFontConverterTest::exportFontToFileFailed() {
void AbstractFontConverterTest::exportGlyphCacheToSingleData() {
struct: Text::AbstractFontConverter {
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportGlyphCache; }
FontConverterFeatures doFeatures() const override { return FontConverterFeature::ConvertData|FontConverterFeature::ExportGlyphCache; }
Containers::Array<char> doExportGlyphCacheToSingleData(AbstractGlyphCache&) const override {
return Containers::Array<char>{Containers::InPlaceInit, {'\xee'}};
@ -196,7 +203,7 @@ void AbstractFontConverterTest::exportGlyphCacheToSingleData() {
void AbstractFontConverterTest::exportGlyphCacheToFile() {
class DataExporter: public Text::AbstractFontConverter {
private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportGlyphCache|Feature::MultiFile; }
FontConverterFeatures doFeatures() const override { return FontConverterFeature::ConvertData|FontConverterFeature::ExportGlyphCache|FontConverterFeature::MultiFile; }
std::vector<std::pair<std::string, Containers::Array<char>>> doExportGlyphCacheToData(AbstractGlyphCache&, const std::string& filename) const override {
/* Why the hell GCC 4.9 fails to do proper move so I need to
@ -224,7 +231,7 @@ void AbstractFontConverterTest::exportGlyphCacheToFile() {
void AbstractFontConverterTest::exportGlyphCacheToFileFailed() {
struct: Text::AbstractFontConverter {
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportGlyphCache|Feature::MultiFile; }
FontConverterFeatures doFeatures() const override { return FontConverterFeature::ConvertData|FontConverterFeature::ExportGlyphCache|FontConverterFeature::MultiFile; }
std::vector<std::pair<std::string, Containers::Array<char>>> doExportGlyphCacheToData(AbstractGlyphCache&, const std::string&) const override { return {}; }
} exporter;
@ -235,7 +242,7 @@ void AbstractFontConverterTest::exportGlyphCacheToFileFailed() {
class SingleGlyphCacheDataImporter: public Text::AbstractFontConverter {
private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ImportGlyphCache; }
FontConverterFeatures doFeatures() const override { return FontConverterFeature::ConvertData|FontConverterFeature::ImportGlyphCache; }
Containers::Pointer<AbstractGlyphCache> doImportGlyphCacheFromSingleData(const Containers::ArrayView<const char> data) const override {
if(data.size() == 1 && data[0] == '\xa5')
@ -259,6 +266,20 @@ void AbstractFontConverterTest::importGlyphCacheFromFile() {
CORRADE_COMPARE(cache->textureSize(), (Vector2i{123, 345}));
}
void AbstractFontConverterTest::debugFeature() {
std::ostringstream out;
Debug{&out} << FontConverterFeature::ExportFont << FontConverterFeature(0xf0);
CORRADE_COMPARE(out.str(), "Text::FontConverterFeature::ExportFont Text::FontConverterFeature(0xf0)\n");
}
void AbstractFontConverterTest::debugFeatures() {
std::ostringstream out;
Debug{&out} << (FontConverterFeature::ExportFont|FontConverterFeature::ImportGlyphCache) << FontConverterFeatures{};
CORRADE_COMPARE(out.str(), "Text::FontConverterFeature::ExportFont|Text::FontConverterFeature::ImportGlyphCache Text::FontConverterFeatures{}\n");
}
}}}}
CORRADE_TEST_MAIN(Magnum::Text::Test::AbstractFontConverterTest)

84
src/Magnum/Text/Test/AbstractFontTest.cpp

@ -153,7 +153,7 @@ AbstractFontTest::AbstractFontTest() {
void AbstractFontTest::construct() {
struct: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -164,7 +164,7 @@ void AbstractFontTest::construct() {
}
} font;
CORRADE_COMPARE(font.features(), AbstractFont::Features{});
CORRADE_COMPARE(font.features(), FontFeatures{});
CORRADE_VERIFY(!font.isOpened());
font.close();
@ -173,7 +173,7 @@ void AbstractFontTest::construct() {
void AbstractFontTest::openData() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override {}
@ -203,7 +203,7 @@ void AbstractFontTest::openData() {
void AbstractFontTest::openFileAsData() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override {}
@ -233,7 +233,7 @@ void AbstractFontTest::openFileAsData() {
void AbstractFontTest::openFileAsDataNotFound() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::OpenData; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -253,7 +253,7 @@ void AbstractFontTest::openFileAsDataNotFound() {
void AbstractFontTest::openFileNotImplemented() {
struct: AbstractFont {
/* Supports neither file nor data opening */
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -273,7 +273,7 @@ void AbstractFontTest::openFileNotImplemented() {
void AbstractFontTest::openDataNotSupported() {
struct: AbstractFont {
/* Supports neither file nor data opening */
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -292,7 +292,7 @@ void AbstractFontTest::openDataNotSupported() {
void AbstractFontTest::openDataNotImplemented() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::OpenData; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -312,7 +312,7 @@ void AbstractFontTest::openDataNotImplemented() {
#ifdef MAGNUM_BUILD_DEPRECATED
void AbstractFontTest::openSingleDataDeprecated() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override {}
@ -344,7 +344,7 @@ void AbstractFontTest::openSingleDataDeprecated() {
void AbstractFontTest::openMultiDataDeprecated() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override {}
@ -382,7 +382,7 @@ void AbstractFontTest::openMultiDataDeprecated() {
void AbstractFontTest::setFileCallback() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData|Feature::FileCallback; }
FontFeatures doFeatures() const override { return FontFeature::OpenData|FontFeature::FileCallback; }
bool doIsOpened() const override { return false; }
void doClose() override {}
void doSetFileCallback(Containers::Optional<Containers::ArrayView<const char>>(*)(const std::string&, InputFileCallbackPolicy, void*), void* userData) override {
@ -408,7 +408,7 @@ void AbstractFontTest::setFileCallback() {
void AbstractFontTest::setFileCallbackTemplate() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData|Feature::FileCallback; }
FontFeatures doFeatures() const override { return FontFeature::OpenData|FontFeature::FileCallback; }
bool doIsOpened() const override { return false; }
void doClose() override {}
void doSetFileCallback(Containers::Optional<Containers::ArrayView<const char>>(*)(const std::string&, InputFileCallbackPolicy, void*), void*) override {
@ -440,7 +440,7 @@ void AbstractFontTest::setFileCallbackTemplate() {
void AbstractFontTest::setFileCallbackTemplateNull() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData|Feature::FileCallback; }
FontFeatures doFeatures() const override { return FontFeature::OpenData|FontFeature::FileCallback; }
bool doIsOpened() const override { return false; }
void doClose() override {}
void doSetFileCallback(Containers::Optional<Containers::ArrayView<const char>>(*callback)(const std::string&, InputFileCallbackPolicy, void*), void* userData) override {
@ -465,7 +465,7 @@ void AbstractFontTest::setFileCallbackTemplateNull() {
void AbstractFontTest::setFileCallbackTemplateConst() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData|Feature::FileCallback; }
FontFeatures doFeatures() const override { return FontFeature::OpenData|FontFeature::FileCallback; }
bool doIsOpened() const override { return false; }
void doClose() override {}
void doSetFileCallback(Containers::Optional<Containers::ArrayView<const char>>(*)(const std::string&, InputFileCallbackPolicy, void*), void*) override {
@ -493,7 +493,7 @@ void AbstractFontTest::setFileCallbackTemplateConst() {
void AbstractFontTest::setFileCallbackFileOpened() {
struct: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -515,7 +515,7 @@ void AbstractFontTest::setFileCallbackFileOpened() {
void AbstractFontTest::setFileCallbackNotImplemented() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::FileCallback; }
FontFeatures doFeatures() const override { return FontFeature::FileCallback; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -538,7 +538,7 @@ void AbstractFontTest::setFileCallbackNotImplemented() {
void AbstractFontTest::setFileCallbackNotSupported() {
struct: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -561,7 +561,7 @@ void AbstractFontTest::setFileCallbackNotSupported() {
void AbstractFontTest::setFileCallbackOpenFileDirectly() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::FileCallback|Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::FileCallback|FontFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override { _opened = false; }
@ -604,7 +604,7 @@ void AbstractFontTest::setFileCallbackOpenFileDirectly() {
void AbstractFontTest::setFileCallbackOpenFileThroughBaseImplementation() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::FileCallback|Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::FileCallback|FontFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override { _opened = false; }
@ -662,7 +662,7 @@ void AbstractFontTest::setFileCallbackOpenFileThroughBaseImplementation() {
void AbstractFontTest::setFileCallbackOpenFileThroughBaseImplementationFailed() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::FileCallback|Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::FileCallback|FontFeature::OpenData; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -694,7 +694,7 @@ void AbstractFontTest::setFileCallbackOpenFileThroughBaseImplementationFailed()
void AbstractFontTest::setFileCallbackOpenFileAsData() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override { _opened = false; }
@ -753,7 +753,7 @@ void AbstractFontTest::setFileCallbackOpenFileAsData() {
void AbstractFontTest::setFileCallbackOpenFileAsDataFailed() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::OpenData; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -785,7 +785,7 @@ void AbstractFontTest::setFileCallbackOpenFileAsDataFailed() {
void AbstractFontTest::properties() {
struct: AbstractFont {
Features doFeatures() const override { return Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::OpenData; }
bool doIsOpened() const override { return _opened; }
void doClose() override {}
@ -812,7 +812,7 @@ void AbstractFontTest::properties() {
void AbstractFontTest::propertiesNoFont() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -838,7 +838,7 @@ void AbstractFontTest::propertiesNoFont() {
void AbstractFontTest::glyphId() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -854,7 +854,7 @@ void AbstractFontTest::glyphId() {
void AbstractFontTest::glyphIdNoFont() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -873,7 +873,7 @@ void AbstractFontTest::glyphIdNoFont() {
void AbstractFontTest::glyphAdvance() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -889,7 +889,7 @@ void AbstractFontTest::glyphAdvance() {
void AbstractFontTest::glyphAdvanceNoFont() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -920,7 +920,7 @@ void AbstractFontTest::layout() {
};
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -938,7 +938,7 @@ void AbstractFontTest::layout() {
void AbstractFontTest::layoutNoFont() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -956,7 +956,7 @@ void AbstractFontTest::layoutNoFont() {
void AbstractFontTest::fillGlyphCache() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -983,7 +983,7 @@ void AbstractFontTest::fillGlyphCache() {
void AbstractFontTest::fillGlyphCacheNotSupported() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return Feature::PreparedGlyphCache; }
FontFeatures doFeatures() const override { return FontFeature::PreparedGlyphCache; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -1001,7 +1001,7 @@ void AbstractFontTest::fillGlyphCacheNotSupported() {
void AbstractFontTest::fillGlyphCacheNotImplemented() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -1019,7 +1019,7 @@ void AbstractFontTest::fillGlyphCacheNotImplemented() {
void AbstractFontTest::fillGlyphCacheNoFont() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -1037,7 +1037,7 @@ void AbstractFontTest::fillGlyphCacheNoFont() {
void AbstractFontTest::createGlyphCache() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return Feature::PreparedGlyphCache; }
FontFeatures doFeatures() const override { return FontFeature::PreparedGlyphCache; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -1063,7 +1063,7 @@ void AbstractFontTest::createGlyphCache() {
void AbstractFontTest::createGlyphCacheNotSupported() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -1080,7 +1080,7 @@ void AbstractFontTest::createGlyphCacheNotSupported() {
void AbstractFontTest::createGlyphCacheNotImplemented() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return Feature::PreparedGlyphCache; }
FontFeatures doFeatures() const override { return FontFeature::PreparedGlyphCache; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -1097,7 +1097,7 @@ void AbstractFontTest::createGlyphCacheNotImplemented() {
void AbstractFontTest::createGlyphCacheNoFont() {
struct MyFont: AbstractFont {
Features doFeatures() const override { return Feature::PreparedGlyphCache; }
FontFeatures doFeatures() const override { return FontFeature::PreparedGlyphCache; }
bool doIsOpened() const override { return false; }
void doClose() override {}
@ -1115,15 +1115,15 @@ void AbstractFontTest::createGlyphCacheNoFont() {
void AbstractFontTest::debugFeature() {
std::ostringstream out;
Debug{&out} << AbstractFont::Feature::OpenData << AbstractFont::Feature(0xf0);
CORRADE_COMPARE(out.str(), "Text::AbstractFont::Feature::OpenData Text::AbstractFont::Feature(0xf0)\n");
Debug{&out} << FontFeature::OpenData << FontFeature(0xf0);
CORRADE_COMPARE(out.str(), "Text::FontFeature::OpenData Text::FontFeature(0xf0)\n");
}
void AbstractFontTest::debugFeatures() {
std::ostringstream out;
Debug{&out} << (AbstractFont::Feature::OpenData|AbstractFont::Feature::PreparedGlyphCache) << AbstractFont::Features{};
CORRADE_COMPARE(out.str(), "Text::AbstractFont::Feature::OpenData|Text::AbstractFont::Feature::PreparedGlyphCache Text::AbstractFont::Features{}\n");
Debug{&out} << (FontFeature::OpenData|FontFeature::PreparedGlyphCache) << FontFeatures{};
CORRADE_COMPARE(out.str(), "Text::FontFeature::OpenData|Text::FontFeature::PreparedGlyphCache Text::FontFeatures{}\n");
}
}}}}

4
src/Magnum/Text/Test/RendererGLTest.cpp

@ -71,7 +71,7 @@ class TestLayouter: public Text::AbstractLayouter {
};
class TestFont: public Text::AbstractFont {
Features doFeatures() const override { return Feature::OpenData; }
FontFeatures doFeatures() const override { return FontFeature::OpenData; }
bool doIsOpened() const override { return true; }
void doClose() override {}
@ -340,7 +340,7 @@ void RendererGLTest::multiline() {
explicit Font(): _opened(false) {}
private:
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return _opened; }
void doClose() override { _opened = false; }

38
src/Magnum/Trade/AbstractImageConverter.cpp

@ -86,7 +86,7 @@ AbstractImageConverter::AbstractImageConverter(PluginManager::Manager<AbstractIm
AbstractImageConverter::AbstractImageConverter(PluginManager::AbstractManager& manager, const std::string& plugin): PluginManager::AbstractManagingPlugin<AbstractImageConverter>{manager, plugin} {}
Containers::Optional<Image2D> AbstractImageConverter::exportToImage(const ImageView2D& image) {
CORRADE_ASSERT(features() & Feature::ConvertImage,
CORRADE_ASSERT(features() & ImageConverterFeature::ConvertImage,
"Trade::AbstractImageConverter::exportToImage(): feature not supported", {});
Containers::Optional<Image2D> out = doExportToImage(image);
@ -99,7 +99,7 @@ Containers::Optional<Image2D> AbstractImageConverter::doExportToImage(const Imag
}
Containers::Optional<CompressedImage2D> AbstractImageConverter::exportToCompressedImage(const ImageView2D& image) {
CORRADE_ASSERT(features() & Feature::ConvertCompressedImage,
CORRADE_ASSERT(features() & ImageConverterFeature::ConvertCompressedImage,
"Trade::AbstractImageConverter::exportToCompressedImage(): feature not supported", {});
Containers::Optional<CompressedImage2D> out = doExportToCompressedImage(image);
@ -112,7 +112,7 @@ Containers::Optional<CompressedImage2D> AbstractImageConverter::doExportToCompre
}
Containers::Array<char> AbstractImageConverter::exportToData(const ImageView2D& image) {
CORRADE_ASSERT(features() & Feature::ConvertData,
CORRADE_ASSERT(features() & ImageConverterFeature::ConvertData,
"Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr);
Containers::Array<char> out = doExportToData(image);
@ -125,7 +125,7 @@ Containers::Array<char> AbstractImageConverter::doExportToData(const ImageView2D
}
Containers::Array<char> AbstractImageConverter::exportToData(const CompressedImageView2D& image) {
CORRADE_ASSERT(features() & Feature::ConvertCompressedData,
CORRADE_ASSERT(features() & ImageConverterFeature::ConvertCompressedData,
"Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr);
Containers::Array<char> out = doExportToData(image);
@ -142,14 +142,14 @@ Containers::Array<char> AbstractImageConverter::exportToData(const ImageData2D&
}
bool AbstractImageConverter::exportToFile(const ImageView2D& image, const std::string& filename) {
CORRADE_ASSERT(features() & Feature::ConvertFile,
CORRADE_ASSERT(features() & ImageConverterFeature::ConvertFile,
"Trade::AbstractImageConverter::exportToFile(): feature not supported", {});
return doExportToFile(image, filename);
}
bool AbstractImageConverter::doExportToFile(const ImageView2D& image, const std::string& filename) {
CORRADE_ASSERT(features() >= Feature::ConvertData, "Trade::AbstractImageConverter::exportToFile(): feature advertised but not implemented", false);
CORRADE_ASSERT(features() >= ImageConverterFeature::ConvertData, "Trade::AbstractImageConverter::exportToFile(): feature advertised but not implemented", false);
const auto data = doExportToData(image);
if(!data) return false;
@ -164,14 +164,14 @@ bool AbstractImageConverter::doExportToFile(const ImageView2D& image, const std:
}
bool AbstractImageConverter::exportToFile(const CompressedImageView2D& image, const std::string& filename) {
CORRADE_ASSERT(features() & Feature::ConvertCompressedFile,
CORRADE_ASSERT(features() & ImageConverterFeature::ConvertCompressedFile,
"Trade::AbstractImageConverter::exportToFile(): feature not supported", {});
return doExportToFile(image, filename);
}
bool AbstractImageConverter::doExportToFile(const CompressedImageView2D& image, const std::string& filename) {
CORRADE_ASSERT(features() >= Feature::ConvertCompressedData, "Trade::AbstractImageConverter::exportToFile(): feature advertised but not implemented", false);
CORRADE_ASSERT(features() >= ImageConverterFeature::ConvertCompressedData, "Trade::AbstractImageConverter::exportToFile(): feature advertised but not implemented", false);
const auto data = doExportToData(image);
if(!data) return false;
@ -189,12 +189,12 @@ bool AbstractImageConverter::exportToFile(const ImageData2D& image, const std::s
return image.isCompressed() ? exportToFile(CompressedImageView2D(image), filename) : exportToFile(ImageView2D(image), filename);
}
Debug& operator<<(Debug& debug, const AbstractImageConverter::Feature value) {
debug << "Trade::AbstractImageConverter::Feature" << Debug::nospace;
Debug& operator<<(Debug& debug, const ImageConverterFeature value) {
debug << "Trade::ImageConverterFeature" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case AbstractImageConverter::Feature::v: return debug << "::" #v;
#define _c(v) case ImageConverterFeature::v: return debug << "::" #v;
_c(ConvertImage)
_c(ConvertCompressedImage)
_c(ConvertFile)
@ -208,15 +208,15 @@ Debug& operator<<(Debug& debug, const AbstractImageConverter::Feature value) {
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const AbstractImageConverter::Features value) {
return Containers::enumSetDebugOutput(debug, value, "Trade::AbstractImageConverter::Features{}", {
AbstractImageConverter::Feature::ConvertImage,
AbstractImageConverter::Feature::ConvertCompressedImage,
AbstractImageConverter::Feature::ConvertData,
AbstractImageConverter::Feature::ConvertCompressedData,
Debug& operator<<(Debug& debug, const ImageConverterFeatures value) {
return Containers::enumSetDebugOutput(debug, value, "Trade::ImageConverterFeatures{}", {
ImageConverterFeature::ConvertImage,
ImageConverterFeature::ConvertCompressedImage,
ImageConverterFeature::ConvertData,
ImageConverterFeature::ConvertCompressedData,
/* These are implied by Convert[Compressed]Data, so have to be last */
AbstractImageConverter::Feature::ConvertFile,
AbstractImageConverter::Feature::ConvertCompressedFile});
ImageConverterFeature::ConvertFile,
ImageConverterFeature::ConvertCompressedFile});
}
}}

166
src/Magnum/Trade/AbstractImageConverter.h

@ -37,6 +37,68 @@
namespace Magnum { namespace Trade {
/**
@brief Features supported by an image converter
@m_since_latest
@see @ref ImageConverterFeatures, @ref AbstractImageConverter::features()
*/
enum class ImageConverterFeature: UnsignedByte {
/**
* Conversion to image with different format with
* @ref AbstractImageConverter::exportToImage()
*/
ConvertImage = 1 << 0,
/**
* Conversion to compressed image with
* @ref AbstractImageConverter::exportToCompressedImage()
*/
ConvertCompressedImage = 1 << 1,
/**
* Exporting to file with
* @ref AbstractImageConverter::exportToFile(const ImageView2D&, const std::string&)
*/
ConvertFile = 1 << 2,
/**
* Exporting to file with
* @ref AbstractImageConverter::exportToFile(const CompressedImageView2D&, const std::string&)
*/
ConvertCompressedFile = 1 << 3,
/**
* Exporting to raw data with
* @ref AbstractImageConverter::exportToData(const ImageView2D&).
* Implies @ref ImageConverterFeature::ConvertFile.
*/
ConvertData = ConvertFile|(1 << 4),
/**
* Exporting compressed image to raw data with
* @ref AbstractImageConverter::exportToData(const CompressedImageView2D&).
* Implies @ref ImageConverterFeature::ConvertCompressedFile.
*/
ConvertCompressedData = ConvertCompressedFile|(1 << 4)
};
/**
@brief Features supported by an image converter
@m_since_latest
@see @ref AbstractImageConverter::features()
*/
typedef Containers::EnumSet<ImageConverterFeature> ImageConverterFeatures;
CORRADE_ENUMSET_OPERATORS(ImageConverterFeatures)
/** @debugoperatorenum{ImageConverterFeature} */
MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, ImageConverterFeature value);
/** @debugoperatorenum{ImageConverterFeatures} */
MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, ImageConverterFeatures value);
/**
@brief Base for image converter plugins
@ -65,14 +127,13 @@ You don't need to do most of the redundant sanity checks, these things are
checked by the implementation:
- The function @ref doExportToImage() is called only if
@ref Feature::ConvertImage
is supported.
@ref ImageConverterFeature::ConvertImage is supported.
- The function @ref doExportToCompressedImage() is called only if
@ref Feature::ConvertCompressedImage is supported.
@ref ImageConverterFeature::ConvertCompressedImage is supported.
- The function @ref doExportToData(const ImageView2D&) is called only if
@ref Feature::ConvertData is supported.
@ref ImageConverterFeature::ConvertData is supported.
- The function @ref doExportToData(const CompressedImageView2D&) is called
only if @ref Feature::ConvertCompressedData is supported.
only if @ref ImageConverterFeature::ConvertCompressedData is supported.
@m_class{m-block m-warning}
@ -86,44 +147,17 @@ checked by the implementation:
*/
class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::AbstractManagingPlugin<AbstractImageConverter> {
public:
/**
* @brief Features supported by this converter
*
* @see @ref Features, @ref features()
*/
enum class Feature: UnsignedByte {
/** Conversion to image with different format with @ref exportToImage() */
ConvertImage = 1 << 0,
/** Conversion to compressed image with @ref exportToCompressedImage() */
ConvertCompressedImage = 1 << 1,
/** Exporting to file with @ref exportToFile(const ImageView2D&, const std::string&) */
ConvertFile = 1 << 2,
/** Exporting to file with @ref exportToFile(const CompressedImageView2D&, const std::string&) */
ConvertCompressedFile = 1 << 3,
/**
* Exporting to raw data with @ref exportToData(const ImageView2D&).
* Implies @ref Feature::ConvertFile.
#ifdef MAGNUM_BUILD_DEPRECATED
/** @brief @copybrief ImageConverterFeature
* @m_deprecated_since_latest Use @ref ImageConverterFeature instead.
*/
ConvertData = ConvertFile|(1 << 4),
typedef CORRADE_DEPRECATED("use ImageConverterFeature instead") ImageConverterFeature Feature;
/**
* Exporting compressed image to raw data with
* @ref exportToData(const CompressedImageView2D&). Implies
* @ref Feature::ConvertCompressedFile.
/** @brief @copybrief ImageConverterFeatures
* @m_deprecated_since_latest Use @ref ImageConverterFeatures instead.
*/
ConvertCompressedData = ConvertCompressedFile|(1 << 4)
};
/**
* @brief Features supported by this converter
*
* @see @ref features()
*/
typedef Containers::EnumSet<Feature> Features;
typedef CORRADE_DEPRECATED("use ImageConverterFeatures instead") ImageConverterFeatures Features;
#endif
/**
* @brief Plugin interface
@ -163,13 +197,14 @@ class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::Abstract
explicit AbstractImageConverter(PluginManager::AbstractManager& manager, const std::string& plugin);
/** @brief Features supported by this converter */
Features features() const { return doFeatures(); }
ImageConverterFeatures features() const { return doFeatures(); }
/**
* @brief Convert image to different format
*
* Available only if @ref Feature::ConvertImage is supported. Returns
* converted image on success, @ref Containers::NullOpt otherwise.
* Available only if @ref ImageConverterFeature::ConvertImage is
* supported. Returns converted image on success,
* @ref Containers::NullOpt otherwise.
* @see @ref features(), @ref exportToData(), @ref exportToFile()
*/
Containers::Optional<Image2D> exportToImage(const ImageView2D& image);
@ -177,8 +212,9 @@ class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::Abstract
/**
* @brief Convert image to compressed format
*
* Available only if @ref Feature::ConvertCompressedImage is supported.
* Returns converted image on success, @ref Containers::NullOpt otherwise.
* Available only if @ref ImageConverterFeature::ConvertCompressedImage
* is supported. Returns converted image on success,
* @ref Containers::NullOpt otherwise.
* @see @ref features(), @ref exportToData(), @ref exportToFile()
*/
Containers::Optional<CompressedImage2D> exportToCompressedImage(const ImageView2D& image);
@ -186,8 +222,8 @@ class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::Abstract
/**
* @brief Export image to raw data
*
* Available only if @ref Feature::ConvertData is supported. Returns
* data on success, zero-sized array otherwise.
* Available only if @ref ImageConverterFeature::ConvertData is
* supported. Returns data on success, zero-sized array otherwise.
* @see @ref features(), @ref exportToImage(),
* @ref exportToFile(const ImageView2D&, const std::string&)
*/
@ -196,8 +232,8 @@ class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::Abstract
/**
* @brief Export compressed image to raw data
*
* Available only if @ref Feature::ConvertCompressedData is supported.
* Returns data on success, zero-sized array otherwise.
* Available only if @ref ImageConverterFeature::ConvertCompressedData
* is supported. Returns data on success, zero-sized array otherwise.
* @see @ref features(), @ref exportToCompressedImage(),
* @ref exportToFile(const CompressedImageView2D&, const std::string&)
*/
@ -216,9 +252,9 @@ class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::Abstract
/**
* @brief Export image to file
*
* Available only if @ref Feature::ConvertFile or
* @ref Feature::ConvertData is supported. Returns `true` on success,
* `false` otherwise.
* Available only if @ref ImageConverterFeature::ConvertFile or
* @ref ImageConverterFeature::ConvertData is supported. Returns
* @cpp true @ce on success, @cpp false @ce otherwise.
* @see @ref features(), @ref exportToImage(),
* @ref exportToData(const ImageView2D&)
*/
@ -227,9 +263,9 @@ class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::Abstract
/**
* @brief Export compressed image to file
*
* Available only if @ref Feature::ConvertCompressedFile or
* @ref Feature::ConvertCompressedData is supported. Returns `true` on
* success, `false` otherwise.
* Available only if @ref ImageConverterFeature::ConvertCompressedFile
* or @ref ImageConverterFeature::ConvertCompressedData is supported.
* Returns @cpp true @ce on success, @cpp false @ce otherwise.
* @see @ref features(), @ref exportToCompressedImage(),
* @ref exportToData(const CompressedImageView2D&)
*/
@ -247,7 +283,7 @@ class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::Abstract
private:
/** @brief Implementation of @ref features() */
virtual Features doFeatures() const = 0;
virtual ImageConverterFeatures doFeatures() const = 0;
/** @brief Implementation of @ref exportToImage() */
virtual Containers::Optional<Image2D> doExportToImage(const ImageView2D& image);
@ -264,30 +300,22 @@ class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::Abstract
/**
* @brief Implementation of @ref exportToFile(const ImageView2D&, const std::string&)
*
* If @ref Feature::ConvertData is supported, default implementation
* calls @ref doExportToData(const ImageView2D&) and saves the result
* to given file.
* If @ref ImageConverterFeature::ConvertData is supported, default
* implementation calls @ref doExportToData(const ImageView2D&) and
* saves the result to given file.
*/
virtual bool doExportToFile(const ImageView2D& image, const std::string& filename);
/**
* @brief Implementation of @ref exportToFile(const CompressedImageView2D&, const std::string&)
*
* If @ref Feature::ConvertCompressedData is supported, default
* implementation calls @ref doExportToData(const CompressedImageView2D&)
* If @ref ImageConverterFeature::ConvertCompressedData is supported,
* default implementation calls @ref doExportToData(const CompressedImageView2D&)
* and saves the result to given file.
*/
virtual bool doExportToFile(const CompressedImageView2D& image, const std::string& filename);
};
CORRADE_ENUMSET_OPERATORS(AbstractImageConverter::Features)
/** @debugoperatorclassenum{AbstractImageConverter,AbstractImageConverter::Feature} */
MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, AbstractImageConverter::Feature value);
/** @debugoperatorclassenum{AbstractImageConverter,AbstractImageConverter::Features} */
MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, AbstractImageConverter::Features value);
}}
#endif

28
src/Magnum/Trade/AbstractImporter.cpp

@ -96,7 +96,7 @@ AbstractImporter::AbstractImporter(PluginManager::AbstractManager& manager, cons
void AbstractImporter::setFileCallback(Containers::Optional<Containers::ArrayView<const char>>(*callback)(const std::string&, InputFileCallbackPolicy, void*), void* const userData) {
CORRADE_ASSERT(!isOpened(), "Trade::AbstractImporter::setFileCallback(): can't be set while a file is opened", );
CORRADE_ASSERT(features() & (Feature::FileCallback|Feature::OpenData), "Trade::AbstractImporter::setFileCallback(): importer supports neither loading from data nor via callbacks, callbacks can't be used", );
CORRADE_ASSERT(features() & (ImporterFeature::FileCallback|ImporterFeature::OpenData), "Trade::AbstractImporter::setFileCallback(): importer supports neither loading from data nor via callbacks, callbacks can't be used", );
_fileCallback = callback;
_fileCallbackUserData = userData;
@ -106,7 +106,7 @@ void AbstractImporter::setFileCallback(Containers::Optional<Containers::ArrayVie
void AbstractImporter::doSetFileCallback(Containers::Optional<Containers::ArrayView<const char>>(*)(const std::string&, InputFileCallbackPolicy, void*), void*) {}
bool AbstractImporter::openData(Containers::ArrayView<const char> data) {
CORRADE_ASSERT(features() & Feature::OpenData,
CORRADE_ASSERT(features() & ImporterFeature::OpenData,
"Trade::AbstractImporter::openData(): feature not supported", {});
/* We accept empty data here (instead of checking for them and failing so
@ -122,7 +122,7 @@ void AbstractImporter::doOpenData(Containers::ArrayView<const char>) {
}
bool AbstractImporter::openState(const void* state, const std::string& filePath) {
CORRADE_ASSERT(features() & Feature::OpenState,
CORRADE_ASSERT(features() & ImporterFeature::OpenState,
"Trade::AbstractImporter::openState(): feature not supported", {});
close();
@ -139,13 +139,13 @@ bool AbstractImporter::openFile(const std::string& filename) {
/* If file loading callbacks are not set or the importer supports handling
them directly, call into the implementation */
if(!_fileCallback || (doFeatures() & Feature::FileCallback)) {
if(!_fileCallback || (doFeatures() & ImporterFeature::FileCallback)) {
doOpenFile(filename);
/* Otherwise, if loading from data is supported, use the callback and pass
the data through to openData(). Mark the file as ready to be closed once
opening is finished. */
} else if(doFeatures() & Feature::OpenData) {
} else if(doFeatures() & ImporterFeature::OpenData) {
/* This needs to be duplicated here and in the doOpenFile()
implementation in order to support both following cases:
- plugins that don't support FileCallback but have their own
@ -171,7 +171,7 @@ bool AbstractImporter::openFile(const std::string& filename) {
}
void AbstractImporter::doOpenFile(const std::string& filename) {
CORRADE_ASSERT(features() & Feature::OpenData, "Trade::AbstractImporter::openFile(): not implemented", );
CORRADE_ASSERT(features() & ImporterFeature::OpenData, "Trade::AbstractImporter::openFile(): not implemented", );
/* If callbacks are set, use them. This is the same implementation as in
openFile(), see the comment there for details. */
@ -640,12 +640,12 @@ const void* AbstractImporter::importerState() const {
const void* AbstractImporter::doImporterState() const { return nullptr; }
Debug& operator<<(Debug& debug, const AbstractImporter::Feature value) {
debug << "Trade::AbstractImporter::Feature" << Debug::nospace;
Debug& operator<<(Debug& debug, const ImporterFeature value) {
debug << "Trade::ImporterFeature" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case AbstractImporter::Feature::v: return debug << "::" #v;
#define _c(v) case ImporterFeature::v: return debug << "::" #v;
_c(OpenData)
_c(OpenState)
_c(FileCallback)
@ -656,11 +656,11 @@ Debug& operator<<(Debug& debug, const AbstractImporter::Feature value) {
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const AbstractImporter::Features value) {
return Containers::enumSetDebugOutput(debug, value, "Trade::AbstractImporter::Features{}", {
AbstractImporter::Feature::OpenData,
AbstractImporter::Feature::OpenState,
AbstractImporter::Feature::FileCallback});
Debug& operator<<(Debug& debug, const ImporterFeatures value) {
return Containers::enumSetDebugOutput(debug, value, "Trade::ImporterFeatures{}", {
ImporterFeature::OpenData,
ImporterFeature::OpenState,
ImporterFeature::FileCallback});
}
}}

194
src/Magnum/Trade/AbstractImporter.h

@ -44,6 +44,47 @@
namespace Magnum { namespace Trade {
/**
@brief Features supported by an importer
@m_since_latest
@see @ref ImporterFeatures, @ref AbstractImporter::features()
*/
enum class ImporterFeature: UnsignedByte {
/** Opening files from raw data using @ref AbstractImporter::openData() */
OpenData = 1 << 0,
/** Opening already loaded state using @ref AbstractImporter::openState() */
OpenState = 1 << 1,
/**
* Specifying callbacks for loading additional files referenced
* from the main file using @ref AbstractImporter::setFileCallback(). If
* the importer * doesn't expose this feature, the format is either
* single-file or loading via callbacks is not supported.
*
* See @ref Trade-AbstractImporter-usage-callbacks and particular importer
* documentation for more information.
*/
FileCallback = 1 << 2
};
/**
@brief Set of features supported by an importer
@m_since_latest
@see @ref AbstractImporter::features()
*/
typedef Containers::EnumSet<ImporterFeature> ImporterFeatures;
CORRADE_ENUMSET_OPERATORS(ImporterFeatures)
/** @debugoperatorenum{ImporterFeatures} */
MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, ImporterFeature value);
/** @debugoperatorenum{ImporterFeatures} */
MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, ImporterFeatures value);
#ifdef MAGNUM_BUILD_DEPRECATED
/** @brief @copybrief InputFileCallbackPolicy
* @m_deprecated_since{2019,10} Use @ref InputFileCallbackPolicy instead.
@ -73,14 +114,15 @@ See @ref plugins for more information about general plugin usage and
Besides loading data directly from the filesystem using @ref openFile() like
shown above, it's possible to use @ref openData() to import data from memory.
Note that the particular importer implementation must support
@ref Feature::OpenData for this method to work.
@ref ImporterFeature::OpenData for this method to work.
Complex scene files often reference other files such as images and in that case
you may want to intercept those references and load them in a custom way as
well. For importers that advertise support for this with @ref Feature::FileCallback
this is done by specifying a file loading callback using @ref setFileCallback().
The callback gets a filename, @ref InputFileCallbackPolicy and an user
pointer as parameters; returns a non-owning view on the loaded data or a
well. For importers that advertise support for this with
@ref ImporterFeature::FileCallback this is done by specifying a file loading
callback using @ref setFileCallback(). The callback gets a filename,
@ref InputFileCallbackPolicy and an user pointer as parameters; returns a
non-owning view on the loaded data or a
@ref Corrade::Containers::NullOpt "Containers::NullOpt" to indicate the file
loading failed. For example, loading a scene from memory-mapped files could
look like below. Note that the file loading callback affects @ref openFile() as
@ -90,12 +132,12 @@ correctly.
@snippet MagnumTrade.cpp AbstractImporter-usage-callbacks
For importers that don't support @ref Feature::FileCallback directly, the base
@ref openFile() implementation will use the file callback to pass the loaded
data through to @ref openData(), in case the importer supports at least
@ref Feature::OpenData. If the importer supports neither @ref Feature::FileCallback
nor @ref Feature::OpenData, @ref setFileCallback() doesn't allow the callbacks
to be set.
For importers that don't support @ref ImporterFeature::FileCallback directly,
the base @ref openFile() implementation will use the file callback to pass the
loaded data through to @ref openData(), in case the importer supports at least
@ref ImporterFeature::OpenData. If the importer supports neither
@ref ImporterFeature::FileCallback nor @ref ImporterFeature::OpenData,
@ref setFileCallback() doesn't allow the callbacks to be set.
The input file callback signature is the same for @ref Trade::AbstractImporter
and @ref Text::AbstractFont to allow code reuse.
@ -127,9 +169,9 @@ expose internal state through various accessors:
imported by @ref texture()
Besides exposing internal state, importers that support the
@ref Feature::OpenState feature can also attach to existing importer state
using @ref openState(). See documentation of a particular importer for details
about concrete types returned and accepted by these functions.
@ref ImporterFeature::OpenState feature can also attach to existing importer
state using @ref openState(). See documentation of a particular importer for
details about concrete types returned and accepted by these functions.
@subsection Trade-AbstractImporter-usage-casting Polymorphic imported data types
@ -170,11 +212,11 @@ functions, at least one of @ref doOpenData() / @ref doOpenFile() /
@ref doOpenState() functions, function @ref doClose() and one or more tuples of
data access functions, based on what features are supported in given format.
In order to support @ref Feature::FileCallback, the importer needs to properly
use the callbacks to both load the top-level file in @ref doOpenFile() and also
load any external files when needed. The @ref doOpenFile() can delegate back
into the base implementation, but it should remember at least the base file
path to pass correct paths to subsequent file callbacks. The
In order to support @ref ImporterFeature::FileCallback, the importer needs to
properly use the callbacks to both load the top-level file in @ref doOpenFile()
and also load any external files when needed. The @ref doOpenFile() can
delegate back into the base implementation, but it should remember at least the
base file path to pass correct paths to subsequent file callbacks. The
@ref doSetFileCallback() can be overriden in case it's desired to respond to
file loading callback setup, but doesn't have to be.
@ -190,12 +232,13 @@ checked by the implementation:
- The @ref doOpenData(), @ref doOpenFile() and @ref doOpenState() functions
are called after the previous file was closed, function @ref doClose() is
called only if there is any file opened.
- The @ref doOpenData() function is called only if @ref Feature::OpenData is
supported.
- The @ref doOpenState() function is called only if @ref Feature::OpenState
is supported.
- The @ref doOpenData() function is called only if
@ref ImporterFeature::OpenData is supported.
- The @ref doOpenState() function is called only if
@ref ImporterFeature::OpenState is supported.
- The @ref doSetFileCallback() function is called only if
@ref Feature::FileCallback is supported and there is no file opened.
@ref ImporterFeature::FileCallback is supported and there is no file
opened.
- All `do*()` implementations working on an opened file are called only if
there is any file opened.
- All `do*()` implementations taking data ID as parameter are called only if
@ -223,36 +266,17 @@ checked by the implementation:
*/
class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagingPlugin<AbstractImporter> {
public:
/**
* @brief Features supported by this importer
*
* @see @ref Features, @ref features()
#ifdef MAGNUM_BUILD_DEPRECATED
/** @brief @copybrief ImporterFeature
* @m_deprecated_since_latest Use @ref ImporterFeature instead.
*/
enum class Feature: UnsignedByte {
/** Opening files from raw data using @ref openData() */
OpenData = 1 << 0,
/** Opening already loaded state using @ref openState() */
OpenState = 1 << 1,
typedef CORRADE_DEPRECATED("use ImporterFeature instead") ImporterFeature Feature;
/**
* Specifying callbacks for loading additional files referenced
* from the main file using @ref setFileCallback(). If the importer
* doesn't expose this feature, the format is either single-file or
* loading via callbacks is not supported.
*
* See @ref Trade-AbstractImporter-usage-callbacks and particular
* importer documentation for more information.
/** @brief @copybrief ImporterFeatures
* @m_deprecated_since_latest Use @ref ImporterFeatures instead.
*/
FileCallback = 1 << 2
};
/**
* @brief Set of features supported by this importer
*
* @see @ref features()
*/
typedef Containers::EnumSet<Feature> Features;
typedef CORRADE_DEPRECATED("use ImporterFeature instead") ImporterFeatures Features;
#endif
/**
* @brief Plugin interface
@ -292,7 +316,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
explicit AbstractImporter(PluginManager::AbstractManager& manager, const std::string& plugin);
/** @brief Features supported by this importer */
Features features() const { return doFeatures(); }
ImporterFeatures features() const { return doFeatures(); }
/**
* @brief File opening callback function
@ -311,22 +335,22 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
/**
* @brief Set file opening callback
*
* In case the importer supports @ref Feature::FileCallback, files
* opened through @ref openFile() will be loaded through the provided
* callback. Besides that, all external files referenced by the
* top-level file will be loaded through the callback function as well,
* usually on demand. The callback function gets a filename,
* In case the importer supports @ref ImporterFeature::FileCallback,
* files opened through @ref openFile() will be loaded through the
* provided callback. Besides that, all external files referenced by
* the top-level file will be loaded through the callback function as
* well, usually on demand. The callback function gets a filename,
* @ref InputFileCallbackPolicy and the @p userData pointer as input
* and returns a non-owning view on the loaded data as output or a
* @ref Corrade::Containers::NullOpt if loading failed --- because
* empty files might also be valid in some circumstances, @cpp nullptr @ce
* can't be used to indicate a failure.
*
* In case the importer doesn't support @ref Feature::FileCallback but
* supports at least @ref Feature::OpenData, a file opened through
* @ref openFile() will be internally loaded through the provided
* callback and then passed to @ref openData(). First the file is
* loaded with @ref InputFileCallbackPolicy::LoadTemporary passed to
* In case the importer doesn't support @ref ImporterFeature::FileCallback
* but supports at least @ref ImporterFeature::OpenData, a file opened
* through @ref openFile() will be internally loaded through the
* provided callback and then passed to @ref openData(). First the file
* is loaded with @ref InputFileCallbackPolicy::LoadTemporary passed to
* the callback, then the returned memory view is passed to
* @ref openData() (sidestepping the potential @ref openFile()
* implementation of that particular importer) and after that the
@ -337,8 +361,9 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
*
* In case @p callback is @cpp nullptr @ce, the current callback (if
* any) is reset. This function expects that the importer supports
* either @ref Feature::FileCallback or @ref Feature::OpenData. If an
* importer supports neither, callbacks can't be used.
* either @ref ImporterFeature::FileCallback or
* @ref ImporterFeature::OpenData. If an importer supports neither,
* callbacks can't be used.
*
* It's expected that this function is called *before* a file is
* opened. It's also expected that the loaded data are kept in scope
@ -385,9 +410,9 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
* @brief Open raw data
*
* Closes previous file, if it was opened, and tries to open given raw
* data. Available only if @ref Feature::OpenData is supported. Returns
* @cpp true @ce on success, @cpp false @ce otherwise. The @p data is
* not expected to be alive after the function exits.
* data. Available only if @ref ImporterFeature::OpenData is supported.
* Returns @cpp true @ce on success, @cpp false @ce otherwise. The
* @p data is not expected to be alive after the function exits.
* @see @ref features(), @ref openFile()
*/
bool openData(Containers::ArrayView<const char> data);
@ -399,8 +424,9 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
* textures and materials.
*
* Closes previous file, if it was opened, and tries to open given
* state. Available only if @ref Feature::OpenState is supported. Returns
* @cpp true @ce on success, @cpp false @ce otherwise.
* state. Available only if @ref ImporterFeature::OpenState is
* supported. Returns @cpp true @ce on success, @cpp false @ce
* otherwise.
*
* See documentation of a particular plugin for more information about
* type and contents of the @p state parameter.
@ -414,9 +440,10 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
* Closes previous file, if it was opened, and tries to open given
* file. Returns @cpp true @ce on success, @cpp false @ce otherwise.
* If file loading callbacks are set via @ref setFileCallback() and
* @ref Feature::OpenData is supported, this function uses the callback
* to load the file and passes the memory view to @ref openData()
* instead. See @ref setFileCallback() for more information.
* @ref ImporterFeature::OpenData is supported, this function uses the
* callback to load the file and passes the memory view to
* @ref openData() instead. See @ref setFileCallback() for more
* information.
* @see @ref features(), @ref openData()
*/
bool openFile(const std::string& filename);
@ -906,14 +933,15 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
/**
* @brief Implementation for @ref openFile()
*
* If @ref Feature::OpenData is supported, default implementation opens
* the file and calls @ref doOpenData() with its contents. It is
* allowed to call this function from your @ref doOpenFile()
* implementation --- in particular, this implementation will also
* correctly handle callbacks set through @ref setFileCallback().
* If @ref ImporterFeature::OpenData is supported, default
* implementation opens the file and calls @ref doOpenData() with its
* contents. It is allowed to call this function from your
* @ref doOpenFile() implementation --- in particular, this
* implementation will also correctly handle callbacks set through
* @ref setFileCallback().
*
* This function is not called when file callbacks are set through
* @ref setFileCallback() and @ref Feature::FileCallback is not
* @ref setFileCallback() and @ref ImporterFeature::FileCallback is not
* supported --- instead, file is loaded though the callback and data
* passed through to @ref doOpenData().
*/
@ -921,7 +949,7 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
private:
/** @brief Implementation for @ref features() */
virtual Features doFeatures() const = 0;
virtual ImporterFeatures doFeatures() const = 0;
/**
* @brief Implementation for @ref setFileCallback()
@ -1294,14 +1322,6 @@ template<class Callback, class T> void AbstractImporter::setFileCallback(Callbac
}
#endif
CORRADE_ENUMSET_OPERATORS(AbstractImporter::Features)
/** @debugoperatorclassenum{AbstractImporter,AbstractImporter::Feature} */
MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, AbstractImporter::Feature value);
/** @debugoperatorclassenum{AbstractImporter,AbstractImporter::Features} */
MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, AbstractImporter::Features value);
}}
#endif

70
src/Magnum/Trade/Test/AbstractImageConverterTest.cpp

@ -138,11 +138,11 @@ AbstractImageConverterTest::AbstractImageConverterTest() {
void AbstractImageConverterTest::construct() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return {}; }
ImageConverterFeatures doFeatures() const override { return {}; }
};
Converter converter;
CORRADE_COMPARE(converter.features(), AbstractImageConverter::Features{});
CORRADE_COMPARE(converter.features(), ImageConverterFeatures{});
}
void AbstractImageConverterTest::constructWithPluginManagerReference() {
@ -151,17 +151,17 @@ void AbstractImageConverterTest::constructWithPluginManagerReference() {
explicit Converter(PluginManager::Manager<AbstractImageConverter>& manager): AbstractImageConverter{manager} {}
private:
Features doFeatures() const override { return {}; }
ImageConverterFeatures doFeatures() const override { return {}; }
};
PluginManager::Manager<AbstractImageConverter> manager;
Converter converter{manager};
CORRADE_COMPARE(converter.features(), AbstractImageConverter::Features{});
CORRADE_COMPARE(converter.features(), ImageConverterFeatures{});
}
void AbstractImageConverterTest::exportToImage() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertImage; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertImage; }
Containers::Optional<Image2D> doExportToImage(const ImageView2D& image) override {
return Image2D{PixelFormat::RGBA8Unorm, image.size(), Containers::Array<char>{96}};
}
@ -176,7 +176,7 @@ void AbstractImageConverterTest::exportToImage() {
void AbstractImageConverterTest::exportToImageNotSupported() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return {}; }
ImageConverterFeatures doFeatures() const override { return {}; }
};
std::ostringstream out;
@ -189,7 +189,7 @@ void AbstractImageConverterTest::exportToImageNotSupported() {
void AbstractImageConverterTest::exportToImageNotImplemented() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertImage; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertImage; }
};
std::ostringstream out;
@ -202,7 +202,7 @@ void AbstractImageConverterTest::exportToImageNotImplemented() {
void AbstractImageConverterTest::exportToImageCustomDeleter() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertImage; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertImage; }
Containers::Optional<Image2D> doExportToImage(const ImageView2D&) override {
return Image2D{PixelFormat::RGBA8Unorm, {}, Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}};
}
@ -218,7 +218,7 @@ void AbstractImageConverterTest::exportToImageCustomDeleter() {
void AbstractImageConverterTest::exportToCompressedImage() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertCompressedImage; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedImage; }
Containers::Optional<CompressedImage2D> doExportToCompressedImage(const ImageView2D& image) override {
return CompressedImage2D{CompressedPixelFormat::Bc1RGBAUnorm, image.size(), Containers::Array<char>{64}};
}
@ -233,7 +233,7 @@ void AbstractImageConverterTest::exportToCompressedImage() {
void AbstractImageConverterTest::exportToCompressedImageNotSupported() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return {}; }
ImageConverterFeatures doFeatures() const override { return {}; }
};
std::ostringstream out;
@ -246,7 +246,7 @@ void AbstractImageConverterTest::exportToCompressedImageNotSupported() {
void AbstractImageConverterTest::exportToCompressedImageNotImplemented() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertCompressedImage; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedImage; }
};
std::ostringstream out;
@ -259,7 +259,7 @@ void AbstractImageConverterTest::exportToCompressedImageNotImplemented() {
void AbstractImageConverterTest::exportToCompressedImageCustomDeleter() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertCompressedImage; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedImage; }
Containers::Optional<CompressedImage2D> doExportToCompressedImage(const ImageView2D&) override {
return CompressedImage2D{CompressedPixelFormat::Bc1RGBAUnorm, {}, Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}}};
}
@ -275,7 +275,7 @@ void AbstractImageConverterTest::exportToCompressedImageCustomDeleter() {
void AbstractImageConverterTest::exportToData() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; }
Containers::Array<char> doExportToData(const ImageView2D& image) override {
return Containers::Array<char>{nullptr, std::size_t(image.size().product())};
}
@ -288,7 +288,7 @@ void AbstractImageConverterTest::exportToData() {
void AbstractImageConverterTest::exportToDataNotSupported() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return {}; }
ImageConverterFeatures doFeatures() const override { return {}; }
};
std::ostringstream out;
@ -301,7 +301,7 @@ void AbstractImageConverterTest::exportToDataNotSupported() {
void AbstractImageConverterTest::exportToDataNotImplemented() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; }
};
std::ostringstream out;
@ -314,7 +314,7 @@ void AbstractImageConverterTest::exportToDataNotImplemented() {
void AbstractImageConverterTest::exportToDataCustomDeleter() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; }
Containers::Array<char> doExportToData(const ImageView2D&) override {
return Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}};
}
@ -330,7 +330,7 @@ void AbstractImageConverterTest::exportToDataCustomDeleter() {
void AbstractImageConverterTest::exportCompressedToData() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertCompressedData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedData; }
Containers::Array<char> doExportToData(const CompressedImageView2D& image) override {
return Containers::Array<char>{nullptr, std::size_t(image.size().product())};
}
@ -343,7 +343,7 @@ void AbstractImageConverterTest::exportCompressedToData() {
void AbstractImageConverterTest::exportCompressedToDataNotSupported() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return {}; }
ImageConverterFeatures doFeatures() const override { return {}; }
};
std::ostringstream out;
@ -356,7 +356,7 @@ void AbstractImageConverterTest::exportCompressedToDataNotSupported() {
void AbstractImageConverterTest::exportCompressedToDataNotImplemented() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; }
};
std::ostringstream out;
@ -369,7 +369,7 @@ void AbstractImageConverterTest::exportCompressedToDataNotImplemented() {
void AbstractImageConverterTest::exportCompressedToDataCustomDeleter() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertCompressedData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedData; }
Containers::Array<char> doExportToData(const CompressedImageView2D&) override {
return Containers::Array<char>{nullptr, 0, [](char*, std::size_t) {}};
}
@ -385,7 +385,7 @@ void AbstractImageConverterTest::exportCompressedToDataCustomDeleter() {
class ImageDataExporter: public Trade::AbstractImageConverter {
private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ConvertCompressedData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData|ImageConverterFeature::ConvertCompressedData; }
Containers::Array<char> doExportToData(const ImageView2D&) override {
/* DirectInit / InPlaceInit is unfortunately causing a custom
@ -426,7 +426,7 @@ void AbstractImageConverterTest::exportImageDataToData() {
void AbstractImageConverterTest::exportToFile() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; }
bool doExportToFile(const ImageView2D& image, const std::string& filename) override {
return Utility::Directory::write(filename, Containers::Array<char>{Containers::InPlaceInit,
{char(image.size().x()), char(image.size().y())}});
@ -444,7 +444,7 @@ void AbstractImageConverterTest::exportToFile() {
void AbstractImageConverterTest::exportToFileThroughData() {
class DataExporter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; }
Containers::Array<char> doExportToData(const ImageView2D& image) override {
return Containers::Array<char>{Containers::InPlaceInit,
@ -465,7 +465,7 @@ void AbstractImageConverterTest::exportToFileThroughData() {
void AbstractImageConverterTest::exportToFileThroughDataNotWritable() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertData; }
Containers::Array<char> doExportToData(const ImageView2D& image) override {
return Containers::Array<char>{Containers::InPlaceInit,
@ -485,7 +485,7 @@ void AbstractImageConverterTest::exportToFileThroughDataNotWritable() {
void AbstractImageConverterTest::exportToFileNotSupported() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return {}; }
ImageConverterFeatures doFeatures() const override { return {}; }
};
std::ostringstream out;
@ -498,7 +498,7 @@ void AbstractImageConverterTest::exportToFileNotSupported() {
void AbstractImageConverterTest::exportToFileNotImplemented() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertFile; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertFile; }
};
std::ostringstream out;
@ -511,7 +511,7 @@ void AbstractImageConverterTest::exportToFileNotImplemented() {
void AbstractImageConverterTest::exportCompressedToFile() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertCompressedFile; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedFile; }
bool doExportToFile(const CompressedImageView2D& image, const std::string& filename) override {
return Utility::Directory::write(filename, Containers::Array<char>{Containers::InPlaceInit,
{char(image.size().x()), char(image.size().y())}});
@ -526,7 +526,7 @@ void AbstractImageConverterTest::exportCompressedToFile() {
void AbstractImageConverterTest::exportCompressedToFileThroughData() {
class DataExporter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertCompressedData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedData; }
Containers::Array<char> doExportToData(const CompressedImageView2D& image) override {
return Containers::Array<char>{Containers::InPlaceInit,
@ -546,7 +546,7 @@ void AbstractImageConverterTest::exportCompressedToFileThroughData() {
void AbstractImageConverterTest::exportCompressedToFileThroughDataNotWritable() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertCompressedData; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedData; }
Containers::Array<char> doExportToData(const CompressedImageView2D& image) override {
return Containers::Array<char>{Containers::InPlaceInit,
@ -566,7 +566,7 @@ void AbstractImageConverterTest::exportCompressedToFileThroughDataNotWritable()
void AbstractImageConverterTest::exportCompressedToFileNotSupported() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return {}; }
ImageConverterFeatures doFeatures() const override { return {}; }
};
std::ostringstream out;
@ -579,7 +579,7 @@ void AbstractImageConverterTest::exportCompressedToFileNotSupported() {
void AbstractImageConverterTest::exportCompressedToFileNotImplemented() {
class Converter: public AbstractImageConverter {
Features doFeatures() const override { return Feature::ConvertCompressedFile; }
ImageConverterFeatures doFeatures() const override { return ImageConverterFeature::ConvertCompressedFile; }
};
std::ostringstream out;
@ -611,15 +611,15 @@ void AbstractImageConverterTest::exportImageDataToFile() {
void AbstractImageConverterTest::debugFeature() {
std::ostringstream out;
Debug{&out} << AbstractImageConverter::Feature::ConvertCompressedImage << AbstractImageConverter::Feature(0xf0);
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::Feature::ConvertCompressedImage Trade::AbstractImageConverter::Feature(0xf0)\n");
Debug{&out} << ImageConverterFeature::ConvertCompressedImage << ImageConverterFeature(0xf0);
CORRADE_COMPARE(out.str(), "Trade::ImageConverterFeature::ConvertCompressedImage Trade::ImageConverterFeature(0xf0)\n");
}
void AbstractImageConverterTest::debugFeatures() {
std::ostringstream out;
Debug{&out} << (AbstractImageConverter::Feature::ConvertData|AbstractImageConverter::Feature::ConvertCompressedFile) << AbstractImageConverter::Features{};
CORRADE_COMPARE(out.str(), "Trade::AbstractImageConverter::Feature::ConvertData|Trade::AbstractImageConverter::Feature::ConvertCompressedFile Trade::AbstractImageConverter::Features{}\n");
Debug{&out} << (ImageConverterFeature::ConvertData|ImageConverterFeature::ConvertCompressedFile) << ImageConverterFeatures{};
CORRADE_COMPARE(out.str(), "Trade::ImageConverterFeature::ConvertData|Trade::ImageConverterFeature::ConvertCompressedFile Trade::ImageConverterFeatures{}\n");
}
}}}}

362
src/Magnum/Trade/Test/AbstractImporterTest.cpp

File diff suppressed because it is too large Load Diff

2
src/MagnumPlugins/AnyAudioImporter/AnyImporter.cpp

@ -39,7 +39,7 @@ AnyImporter::AnyImporter(PluginManager::AbstractManager& manager, const std::str
AnyImporter::~AnyImporter() = default;
auto AnyImporter::doFeatures() const -> Features { return {}; }
ImporterFeatures AnyImporter::doFeatures() const { return {}; }
bool AnyImporter::doIsOpened() const { return !!_in; }

2
src/MagnumPlugins/AnyAudioImporter/AnyImporter.h

@ -111,7 +111,7 @@ class MAGNUM_ANYAUDIOIMPORTER_EXPORT AnyImporter: public AbstractImporter {
~AnyImporter();
private:
MAGNUM_ANYAUDIOIMPORTER_LOCAL Features doFeatures() const override;
MAGNUM_ANYAUDIOIMPORTER_LOCAL ImporterFeatures doFeatures() const override;
MAGNUM_ANYAUDIOIMPORTER_LOCAL bool doIsOpened() const override;
MAGNUM_ANYAUDIOIMPORTER_LOCAL void doClose() override;
MAGNUM_ANYAUDIOIMPORTER_LOCAL void doOpenFile(const std::string& filename) override;

4
src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp

@ -40,8 +40,8 @@ AnyImageConverter::AnyImageConverter(PluginManager::AbstractManager& manager, co
AnyImageConverter::~AnyImageConverter() = default;
auto AnyImageConverter::doFeatures() const -> Features {
return Feature::ConvertFile|Feature::ConvertCompressedFile;
ImageConverterFeatures AnyImageConverter::doFeatures() const {
return ImageConverterFeature::ConvertFile|ImageConverterFeature::ConvertCompressedFile;
}
bool AnyImageConverter::doExportToFile(const ImageView2D& image, const std::string& filename) {

2
src/MagnumPlugins/AnyImageConverter/AnyImageConverter.h

@ -115,7 +115,7 @@ class MAGNUM_ANYIMAGECONVERTER_EXPORT AnyImageConverter: public AbstractImageCon
~AnyImageConverter();
private:
MAGNUM_ANYIMAGECONVERTER_LOCAL Features doFeatures() const override;
MAGNUM_ANYIMAGECONVERTER_LOCAL ImageConverterFeatures doFeatures() const override;
MAGNUM_ANYIMAGECONVERTER_LOCAL bool doExportToFile(const ImageView2D& image, const std::string& filename) override;
MAGNUM_ANYIMAGECONVERTER_LOCAL bool doExportToFile(const CompressedImageView2D& image, const std::string& filename) override;
};

2
src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp

@ -41,7 +41,7 @@ AnyImageImporter::AnyImageImporter(PluginManager::AbstractManager& manager, cons
AnyImageImporter::~AnyImageImporter() = default;
auto AnyImageImporter::doFeatures() const -> Features { return Feature::OpenData; }
ImporterFeatures AnyImageImporter::doFeatures() const { return ImporterFeature::OpenData; }
bool AnyImageImporter::doIsOpened() const { return !!_in; }

2
src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h

@ -136,7 +136,7 @@ class MAGNUM_ANYIMAGEIMPORTER_EXPORT AnyImageImporter: public AbstractImporter {
~AnyImageImporter();
private:
MAGNUM_ANYIMAGEIMPORTER_LOCAL Features doFeatures() const override;
MAGNUM_ANYIMAGEIMPORTER_LOCAL ImporterFeatures doFeatures() const override;
MAGNUM_ANYIMAGEIMPORTER_LOCAL bool doIsOpened() const override;
MAGNUM_ANYIMAGEIMPORTER_LOCAL void doClose() override;
MAGNUM_ANYIMAGEIMPORTER_LOCAL void doOpenFile(const std::string& filename) override;

2
src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp

@ -51,7 +51,7 @@ AnySceneImporter::AnySceneImporter(PluginManager::AbstractManager& manager, cons
AnySceneImporter::~AnySceneImporter() = default;
auto AnySceneImporter::doFeatures() const -> Features { return {}; }
ImporterFeatures AnySceneImporter::doFeatures() const { return {}; }
bool AnySceneImporter::doIsOpened() const { return !!_in; }

2
src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h

@ -138,7 +138,7 @@ class MAGNUM_ANYSCENEIMPORTER_EXPORT AnySceneImporter: public AbstractImporter {
~AnySceneImporter();
private:
MAGNUM_ANYSCENEIMPORTER_LOCAL Features doFeatures() const override;
MAGNUM_ANYSCENEIMPORTER_LOCAL ImporterFeatures doFeatures() const override;
MAGNUM_ANYSCENEIMPORTER_LOCAL bool doIsOpened() const override;
MAGNUM_ANYSCENEIMPORTER_LOCAL void doClose() override;
MAGNUM_ANYSCENEIMPORTER_LOCAL void doOpenFile(const std::string& filename) override;

2
src/MagnumPlugins/MagnumFont/MagnumFont.cpp

@ -74,7 +74,7 @@ MagnumFont::MagnumFont(PluginManager::AbstractManager& manager, const std::strin
MagnumFont::~MagnumFont() { close(); }
auto MagnumFont::doFeatures() const -> Features { return Feature::OpenData|Feature::FileCallback|Feature::PreparedGlyphCache; }
FontFeatures MagnumFont::doFeatures() const { return FontFeature::OpenData|FontFeature::FileCallback|FontFeature::PreparedGlyphCache; }
bool MagnumFont::doIsOpened() const { return _opened && _opened->image; }

2
src/MagnumPlugins/MagnumFont/MagnumFont.h

@ -157,7 +157,7 @@ class MAGNUM_MAGNUMFONT_EXPORT MagnumFont: public AbstractFont {
~MagnumFont();
private:
MAGNUM_MAGNUMFONT_LOCAL Features doFeatures() const override;
MAGNUM_MAGNUMFONT_LOCAL FontFeatures doFeatures() const override;
MAGNUM_MAGNUMFONT_LOCAL bool doIsOpened() const override;
MAGNUM_MAGNUMFONT_LOCAL Metrics doOpenData(Containers::ArrayView<const char> data, Float) override;
MAGNUM_MAGNUMFONT_LOCAL Metrics doOpenFile(const std::string& filename, Float) override;

4
src/MagnumPlugins/MagnumFont/Test/MagnumFontTest.cpp

@ -141,7 +141,7 @@ void MagnumFontTest::layout() {
void MagnumFontTest::fileCallbackImage() {
Containers::Pointer<AbstractFont> font = _fontManager.instantiate("MagnumFont");
CORRADE_VERIFY(font->features() & AbstractFont::Feature::FileCallback);
CORRADE_VERIFY(font->features() & FontFeature::FileCallback);
std::unordered_map<std::string, Containers::Array<char>> files;
files["not/a/path/font.conf"] = Utility::Directory::read(Utility::Directory::join(MAGNUMFONT_TEST_DIR, "font.conf"));
@ -162,7 +162,7 @@ void MagnumFontTest::fileCallbackImage() {
void MagnumFontTest::fileCallbackImageNotFound() {
Containers::Pointer<AbstractFont> font = _fontManager.instantiate("MagnumFont");
CORRADE_VERIFY(font->features() & AbstractFont::Feature::FileCallback);
CORRADE_VERIFY(font->features() & FontFeature::FileCallback);
font->setFileCallback([](const std::string&, InputFileCallbackPolicy, void*) {
return Containers::Optional<Containers::ArrayView<const char>>{};

4
src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp

@ -45,8 +45,8 @@ MagnumFontConverter::MagnumFontConverter() = default;
MagnumFontConverter::MagnumFontConverter(PluginManager::AbstractManager& manager, const std::string& plugin): AbstractFontConverter{manager, plugin} {}
auto MagnumFontConverter::doFeatures() const -> Features {
return Feature::ExportFont|Feature::ConvertData|Feature::MultiFile;
FontConverterFeatures MagnumFontConverter::doFeatures() const {
return FontConverterFeature::ExportFont|FontConverterFeature::ConvertData|FontConverterFeature::MultiFile;
}
std::vector<std::pair<std::string, Containers::Array<char>>> MagnumFontConverter::doExportFontToData(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::u32string& characters) const {

2
src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.h

@ -98,7 +98,7 @@ class MAGNUM_MAGNUMFONTCONVERTER_EXPORT MagnumFontConverter: public Text::Abstra
explicit MagnumFontConverter(PluginManager::AbstractManager& manager, const std::string& plugin);
private:
MAGNUM_MAGNUMFONTCONVERTER_LOCAL Features doFeatures() const override;
MAGNUM_MAGNUMFONTCONVERTER_LOCAL FontConverterFeatures doFeatures() const override;
MAGNUM_MAGNUMFONTCONVERTER_LOCAL std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont& font, AbstractGlyphCache& cache, const std::string& filename, const std::u32string& characters) const override;
};

4
src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp

@ -88,7 +88,7 @@ void MagnumFontConverterTest::exportFont() {
_opened = true;
return {16.0f, 25.0f, -10.0f, 39.7333f};
}
Features doFeatures() const { return {}; }
FontFeatures doFeatures() const { return {}; }
Containers::Pointer<AbstractLayouter> doLayout(const AbstractGlyphCache&, Float, const std::string&) { return nullptr; }
UnsignedInt doGlyphId(const char32_t character) {
@ -152,7 +152,7 @@ void MagnumFontConverterTest::exportFont() {
void MagnumFontConverterTest::exportFontNoGlyphCacheImageDownload() {
struct MyFont: AbstractFont {
/* Supports neither file nor data opening */
Features doFeatures() const override { return {}; }
FontFeatures doFeatures() const override { return {}; }
bool doIsOpened() const override { return false; }
void doClose() override {}

2
src/MagnumPlugins/ObjImporter/ObjImporter.cpp

@ -96,7 +96,7 @@ ObjImporter::ObjImporter(PluginManager::AbstractManager& manager, const std::str
ObjImporter::~ObjImporter() = default;
auto ObjImporter::doFeatures() const -> Features { return Feature::OpenData; }
ImporterFeatures ObjImporter::doFeatures() const { return ImporterFeature::OpenData; }
void ObjImporter::doClose() { _file.reset(); }

2
src/MagnumPlugins/ObjImporter/ObjImporter.h

@ -107,7 +107,7 @@ class MAGNUM_OBJIMPORTER_EXPORT ObjImporter: public AbstractImporter {
private:
struct File;
MAGNUM_OBJIMPORTER_LOCAL Features doFeatures() const override;
MAGNUM_OBJIMPORTER_LOCAL ImporterFeatures doFeatures() const override;
MAGNUM_OBJIMPORTER_LOCAL bool doIsOpened() const override;
MAGNUM_OBJIMPORTER_LOCAL void doOpenData(Containers::ArrayView<const char> data) override;

2
src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp

@ -43,7 +43,7 @@ TgaImageConverter::TgaImageConverter() = default;
TgaImageConverter::TgaImageConverter(PluginManager::AbstractManager& manager, const std::string& plugin): AbstractImageConverter{manager, plugin} {}
auto TgaImageConverter::doFeatures() const -> Features { return Feature::ConvertData; }
ImageConverterFeatures TgaImageConverter::doFeatures() const { return ImageConverterFeature::ConvertData; }
Containers::Array<char> TgaImageConverter::doExportToData(const ImageView2D& image) {
/* Initialize data buffer */

2
src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h

@ -97,7 +97,7 @@ class MAGNUM_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractImageCon
explicit TgaImageConverter(PluginManager::AbstractManager& manager, const std::string& plugin);
private:
Features MAGNUM_TGAIMAGECONVERTER_LOCAL doFeatures() const override;
ImageConverterFeatures MAGNUM_TGAIMAGECONVERTER_LOCAL doFeatures() const override;
Containers::Array<char> MAGNUM_TGAIMAGECONVERTER_LOCAL doExportToData(const ImageView2D& image) override;
};

2
src/MagnumPlugins/TgaImporter/TgaImporter.cpp

@ -46,7 +46,7 @@ TgaImporter::TgaImporter(PluginManager::AbstractManager& manager, const std::str
TgaImporter::~TgaImporter() = default;
auto TgaImporter::doFeatures() const -> Features { return Feature::OpenData; }
ImporterFeatures TgaImporter::doFeatures() const { return ImporterFeature::OpenData; }
bool TgaImporter::doIsOpened() const { return _in; }

2
src/MagnumPlugins/TgaImporter/TgaImporter.h

@ -105,7 +105,7 @@ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter {
~TgaImporter();
private:
Features MAGNUM_TGAIMPORTER_LOCAL doFeatures() const override;
ImporterFeatures MAGNUM_TGAIMPORTER_LOCAL doFeatures() const override;
bool MAGNUM_TGAIMPORTER_LOCAL doIsOpened() const override;
void MAGNUM_TGAIMPORTER_LOCAL doOpenData(Containers::ArrayView<const char> data) override;
void MAGNUM_TGAIMPORTER_LOCAL doClose() override;

2
src/MagnumPlugins/WavAudioImporter/WavImporter.cpp

@ -43,7 +43,7 @@ WavImporter::WavImporter() = default;
WavImporter::WavImporter(PluginManager::AbstractManager& manager, const std::string& plugin): AbstractImporter{manager, plugin} {}
auto WavImporter::doFeatures() const -> Features { return Feature::OpenData; }
ImporterFeatures WavImporter::doFeatures() const { return ImporterFeature::OpenData; }
bool WavImporter::doIsOpened() const { return !!_data; }

2
src/MagnumPlugins/WavAudioImporter/WavImporter.h

@ -118,7 +118,7 @@ class MAGNUM_WAVAUDIOIMPORTER_EXPORT WavImporter: public AbstractImporter {
explicit WavImporter(PluginManager::AbstractManager& manager, const std::string& plugin);
private:
MAGNUM_WAVAUDIOIMPORTER_LOCAL Features doFeatures() const override;
MAGNUM_WAVAUDIOIMPORTER_LOCAL ImporterFeatures doFeatures() const override;
MAGNUM_WAVAUDIOIMPORTER_LOCAL bool doIsOpened() const override;
MAGNUM_WAVAUDIOIMPORTER_LOCAL void doOpenData(Containers::ArrayView<const char> data) override;
MAGNUM_WAVAUDIOIMPORTER_LOCAL void doClose() override;

Loading…
Cancel
Save