mirror of
https://github.com/mapbox/node-fontnik.git
synced 2026-02-01 16:47:18 +00:00
font_engine : use FT_New_Library/FT_Done_Library with custom memor
management, ref https://github.com/mapnik/mapnik/pull/2241
This commit is contained in:
parent
89928bd842
commit
4cc24439cb
@ -37,22 +37,40 @@
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
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 fontserver {
|
||||
|
||||
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) {
|
||||
std::ostringstream runtime_error;
|
||||
runtime_error << "Could not load FreeType2 library: FT_Error " << error;
|
||||
throw std::runtime_error(runtime_error.str());
|
||||
}
|
||||
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) {
|
||||
|
||||
@ -38,9 +38,11 @@ extern "C"
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
// #include FT_STROKER_H
|
||||
#include FT_MODULE_H
|
||||
}
|
||||
|
||||
struct FT_LibraryRec_;
|
||||
struct FT_MemoryRec_;
|
||||
|
||||
namespace fontserver {
|
||||
|
||||
@ -75,6 +77,8 @@ public:
|
||||
face_ptr create_face(std::string const& family_name);
|
||||
private:
|
||||
FT_LibraryRec_ *library_;
|
||||
std::unique_ptr<FT_MemoryRec_> memory_;
|
||||
|
||||
static std::mutex mutex_;
|
||||
static std::map<std::string, std::pair<int, std::string>> name2file_;
|
||||
static std::map<std::string, std::string> memory_fonts_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user