Browse Source

Text: turned AbstractFont into plugin interface.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
92c4a5a2ed
  1. 1
      doc/cmake.dox
  2. 9
      modules/FindMagnum.cmake
  3. 4
      src/Text/AbstractFont.cpp
  4. 55
      src/Text/AbstractFont.h

1
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

9
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()

4
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) {}

55
src/Text/AbstractFont.h

@ -30,6 +30,7 @@
#include <tuple>
#include <string>
#include <PluginManager/AbstractPlugin.h>
#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;
};

Loading…
Cancel
Save