//  // // # # ### # # -= Nuclex Project =-  // // ## # # # ## ## NuclexFreeType.cpp - FreeType plugin impl.  // // ### # # ###  // // # ### # ### The plugin implementation for nuclex  // // # ## # # ## ##  // // # # ### # # R1 (C)2002-2004 Markus Ewald -> License.txt  // //  // #include "FreeTypePlugin/FreeTypePlugin.h" #include "FreeTypePlugin/Text/FreeTypeFontCodec.h" #include "Nuclex/Text/TextServer.h" #include "Nuclex/Kernel.h" using namespace Nuclex; namespace { //  // //  FreeTypeInitTerm  // //  // /// FreeType global initialization class /** Initializes global DLL data */ class FreeTypeInitTerm { public: /// Constructor /** Initializes global data when the dll enters a process */ FreeTypeInitTerm() { FT_Error Error = ::FT_Init_FreeType(&m_FTLibrary); if(Error) { Kernel::logMessage( Kernel::MT_WARNING, "FreeType library could not be initialized. FreeType support disabled." ); return; } Kernel::logMessage(Kernel::MT_INFO, "FreeType initialized successfully."); } /// Destructor /** Destroys global data when the dll leaves a process */ ~FreeTypeInitTerm() { ::FT_Done_FreeType(m_FTLibrary); m_FTLibrary = NULL; } FT_Library getFTLibrary() const { return m_FTLibrary; } private: FT_Library m_FTLibrary; } _FreeTypeInitTerm; } // namespace // ####################################################################### // // # Nuclex::Text::getFreeTypeLibrary() # // // ####################################################################### // FREETYPEPLUGIN_API FT_Library Nuclex::Text::getFreeTypeLibrary() { return _FreeTypeInitTerm.getFTLibrary(); } // ####################################################################### // // # Nuclex::Text::getFreeTypeMutex() # // // ####################################################################### // FREETYPEPLUGIN_API Mutex &Nuclex::Text::getFreeTypeMutex() { static Mutex FreeTypeMutex; return FreeTypeMutex; } // ############################################################################################# // // # NuclexVersion() # // // ############################################################################################# // /** Retrieve the version number of the nuclex framework the plugin was compiled against @return The framework version against which the plugin was compiled */ extern "C" FREETYPEPLUGIN_API int nuclexPluginVersion() { return NUCLEX_VERSION; } // ############################################################################################# // // # NuclexRegister() # // // ############################################################################################# // /** Register the plugin to a nuclex kernel instance @param pKernel Kernel to register to */ extern "C" FREETYPEPLUGIN_API void nuclexPluginRegister(Kernel *pKernel) { pKernel->getTextServer()->addCodec( "FreeType", shared_ptr(new Text::FreeTypeFontCodec()) ); } // ############################################################################################# // // # NuclexUnregister() # // // ############################################################################################# // /** Unregister the plugin from a nuclex kernel instance @param pKernel Kernel to unregister from */ extern "C" FREETYPEPLUGIN_API void nuclexPluginUnregister(Kernel *pKernel) { try { pKernel->getTextServer()->removeCodec("FreeType"); } catch(...) { Kernel::logMessage( Kernel::MT_ERROR, "An exception occured while removing the freetype codec" ); } }