diff --git a/include/mapnik/font_engine_freetype.hpp b/include/mapnik/font_engine_freetype.hpp index 02c639749..cc7c572a9 100644 --- a/include/mapnik/font_engine_freetype.hpp +++ b/include/mapnik/font_engine_freetype.hpp @@ -44,6 +44,7 @@ #include struct FT_LibraryRec_; +struct FT_MemoryRec_; namespace mapnik { @@ -78,7 +79,8 @@ public: virtual ~freetype_engine(); freetype_engine(); private: - FT_LibraryRec_ *library_; + FT_LibraryRec_ * library_; + std::unique_ptr memory_; #ifdef MAPNIK_THREADSAFE static std::mutex mutex_; #endif diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index ee7926cab..cd8fcc75a 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -34,6 +34,7 @@ // stl #include #include +#include // freetype2 extern "C" @@ -41,25 +42,46 @@ extern "C" #include #include FT_FREETYPE_H #include FT_STROKER_H +#include FT_MODULE_H +} + +void* _Alloc_Func(FT_Memory memory, long size) +{ + return std::malloc(size); +} + +void _Free_Func(FT_Memory memory, void *block) +{ + std::free(block); +} + +void* _Realloc_Func(FT_Memory memory, long cur_size, long new_size, void* block) +{ + return std::realloc(block, new_size); } namespace mapnik { freetype_engine::freetype_engine() : - library_(nullptr) + library_(nullptr), + memory_(new FT_MemoryRec_) { - FT_Error error = FT_Init_FreeType( &library_ ); + memory_->alloc = _Alloc_Func; + memory_->free = _Free_Func; + memory_->realloc = _Realloc_Func; + FT_Error error = FT_New_Library( &*memory_, &library_ ); if (error) { throw std::runtime_error("can not load FreeType2 library"); } + FT_Add_Default_Modules(library_); } freetype_engine::~freetype_engine() { - FT_Done_FreeType(library_); + FT_Done_Library(library_); } bool freetype_engine::is_font_file(std::string const& file_name)