From f0fd0aa8ce3f377289f32ebeb80f03d47f9977df Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 13 May 2014 12:43:59 +0100 Subject: [PATCH 1/2] font_engine : use FT_New_Library/FT_Done_Library with custom memory management (ref #2209 #2210) --- include/mapnik/font_engine_freetype.hpp | 4 +++- src/font_engine_freetype.cpp | 28 ++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) 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) From 92bf9782f8894e2e53c6ffb8845f175556c146f5 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 13 May 2014 15:25:05 -0700 Subject: [PATCH 2/2] scons: fix path remove to be less aggressive --- SConstruct | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index 65a9f3ba7..09ccd4db6 100644 --- a/SConstruct +++ b/SConstruct @@ -193,7 +193,7 @@ def shortest_name(libs): def rm_path(item,set,_env): for i in _env[set]: - if item in i: + if i.startswith(item): _env[set].remove(i) def sort_paths(items,priority):