From 92c4a5a2ed61407e52a7b44fea42ccf71ff85f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 10:55:01 +0100 Subject: [PATCH] Text: turned AbstractFont into plugin interface. --- doc/cmake.dox | 1 + modules/FindMagnum.cmake | 9 ++++++- src/Text/AbstractFont.cpp | 4 +-- src/Text/AbstractFont.h | 55 +++++++++++++++++++++++++++++++++------ 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/doc/cmake.dox b/doc/cmake.dox index 5a6907707..274ab26ce 100644 --- a/doc/cmake.dox +++ b/doc/cmake.dox @@ -43,6 +43,7 @@ variables: - `MAGNUM_FOUND` -- Whether the library was found - `MAGNUM_LIBRARIES` -- %Magnum library and dependent libraries - `MAGNUM_INCLUDE_DIRS` -- Root include dir and include dirs of dependencies +- `MAGNUM_PLUGINS_FONT_DIR` -- Directory with font plugins - `MAGNUM_PLUGINS_IMPORTER_DIR` -- Directory with importer plugins However, this command will try to find only the base library, not the optional diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 0f815fc4a..e1e9561ad 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -7,6 +7,7 @@ # MAGNUM_LIBRARIES - Magnum library and dependent libraries # MAGNUM_INCLUDE_DIRS - Root include dir and include dirs of # dependencies +# MAGNUM_PLUGINS_FONT_DIR - Directory with font plugins # MAGNUM_PLUGINS_IMPORTER_DIR - Directory with importer plugins # This command will try to find only the base library, not the optional # components. The base library depends on Corrade, OpenGL and GLEW @@ -60,6 +61,8 @@ # dependencies) # MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory # MAGNUM_PLUGINS_INSTALL_DIR - Plugin installation directory +# MAGNUM_PLUGINS_FONT_INSTALL_DIR - Font plugin installation +# directory # MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR - Importer plugin installation # directory # MAGNUM_CMAKE_MODULE_INSTALL_DIR - Installation dir for CMake @@ -319,6 +322,7 @@ endif() # Installation dirs set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) set(MAGNUM_PLUGINS_INSTALL_DIR ${MAGNUM_LIBRARY_INSTALL_DIR}/magnum) +set(MAGNUM_PLUGINS_FONT_INSTALL_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/fonts) set(MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/importers) set(MAGNUM_CMAKE_MODULE_INSTALL_DIR ${CMAKE_ROOT}/Modules) set(MAGNUM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/Magnum) @@ -328,14 +332,17 @@ mark_as_advanced(FORCE MAGNUM_INCLUDE_DIR MAGNUM_LIBRARY_INSTALL_DIR MAGNUM_PLUGINS_INSTALL_DIR + MAGNUM_PLUGINS_FONT_INSTALL_DIR MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR MAGNUM_CMAKE_MODULE_INSTALL_DIR MAGNUM_INCLUDE_INSTALL_DIR MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR) -# Importer plugins dir +# Plugin directories if(NOT WIN32) + set(MAGNUM_PLUGINS_FONT_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/fonts) set(MAGNUM_PLUGINS_IMPORTER_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/importers) else() + set(MAGNUM_PLUGINS_FONT_DIR fonts) set(MAGNUM_PLUGINS_IMPORTER_DIR importers) endif() diff --git a/src/Text/AbstractFont.cpp b/src/Text/AbstractFont.cpp index 049341ab9..74f116ad3 100644 --- a/src/Text/AbstractFont.cpp +++ b/src/Text/AbstractFont.cpp @@ -26,9 +26,9 @@ namespace Magnum { namespace Text { -AbstractFont::AbstractFont(Float size): _size(size) {} +AbstractFont::AbstractFont(): _size(0.0f) {} -AbstractFont::~AbstractFont() {} +AbstractFont::AbstractFont(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)), _size(0.0f) {} AbstractLayouter::AbstractLayouter(): _glyphCount(0) {} diff --git a/src/Text/AbstractFont.h b/src/Text/AbstractFont.h index cedfef2c9..df2d06437 100644 --- a/src/Text/AbstractFont.h +++ b/src/Text/AbstractFont.h @@ -30,6 +30,7 @@ #include #include +#include #include "Magnum.h" #include "Texture.h" @@ -39,17 +40,51 @@ namespace Magnum { namespace Text { /** -@brief Base for fonts +@brief Base for font plugins + +@section AbstractFont-usage Usage + +First step is to open the font using open(), next step is to prerender all the +glyphs which will be used in text rendering later, see GlyphCache for more +information. See TextRenderer for information about text rendering. + +@section AbstractFont-subclassing Subclassing + +Plugin implements functions open(), close(), createGlyphCache() and layout(). */ -class MAGNUM_TEXT_EXPORT AbstractFont { - AbstractFont(const AbstractFont&) = delete; - AbstractFont(AbstractFont&&) = delete; - AbstractFont& operator=(const AbstractFont&) = delete; - AbstractFont& operator=(const AbstractFont&&) = delete; +class MAGNUM_TEXT_EXPORT AbstractFont: public Corrade::PluginManager::AbstractPlugin { + PLUGIN_INTERFACE("cz.mosra.magnum.Text.AbstractFont/0.1") public: - explicit AbstractFont(Float size); - virtual ~AbstractFont() = 0; + /** @brief Default constructor */ + explicit AbstractFont(); + + /** @brief Plugin manager constructor */ + explicit AbstractFont(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin); + + /** + * @brief Open font from file + * @param filename Font file + * @param size Font size + * + * Closes previous file, if it was opened, and tries to open given + * file. Returns `true` on success, `false` otherwise. + */ + virtual bool open(const std::string& filename, Float size) = 0; + + /** + * @brief Open font from memory + * @param data Font data + * @param dataSize Font data size + * @param size Font size + * + * Closes previous file, if it was opened, and tries to open given + * file. Returns `true` on success, `false` otherwise. + */ + virtual bool open(const unsigned char* data, std::size_t dataSize, Float size) = 0; + + /** @brief Close font */ + virtual void close() = 0; /** @brief Font size */ inline Float size() const { return _size; } @@ -73,7 +108,11 @@ class MAGNUM_TEXT_EXPORT AbstractFont { */ virtual AbstractLayouter* layout(const GlyphCache* const cache, const Float size, const std::string& text) = 0; + #ifdef DOXYGEN_GENERATING_OUTPUT private: + #else + protected: + #endif Float _size; };