Merge pull request #2241 from mapnik/freetype-new-lib

FT_New_Library/FT_Done_Library
This commit is contained in:
Dane Springmeyer 2014-05-13 16:14:38 -07:00
commit 6f176ab0bf
2 changed files with 28 additions and 4 deletions

View file

@ -44,6 +44,7 @@
#include <vector>
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<FT_MemoryRec_> memory_;
#ifdef MAPNIK_THREADSAFE
static std::mutex mutex_;
#endif

View file

@ -34,6 +34,7 @@
// stl
#include <algorithm>
#include <stdexcept>
#include <cstdlib>
// freetype2
extern "C"
@ -41,25 +42,46 @@ extern "C"
#include <ft2build.h>
#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)