refactored font engine to export symbols correctly on win32
This commit is contained in:
parent
98763057e6
commit
fce4076ad5
2 changed files with 87 additions and 82 deletions
|
@ -93,77 +93,22 @@ namespace mapnik
|
|||
typedef boost::shared_ptr<font_face> face_ptr;
|
||||
|
||||
class MAPNIK_DECL freetype_engine : public mapnik::singleton<freetype_engine,mapnik::CreateStatic>,
|
||||
private boost::noncopyable
|
||||
private boost::noncopyable
|
||||
{
|
||||
friend class mapnik::CreateStatic<freetype_engine>;
|
||||
friend class mapnik::CreateStatic<freetype_engine>;
|
||||
public:
|
||||
|
||||
static bool register_font(std::string const& file_name)
|
||||
{
|
||||
mutex::scoped_lock lock(mapnik::singleton<freetype_engine,
|
||||
mapnik::CreateStatic>::mutex_);
|
||||
FT_Face face;
|
||||
FT_Error error = FT_New_Face (library_,file_name.c_str(),0,&face);
|
||||
if ( !error )
|
||||
{
|
||||
std::string name = std::string(face->family_name) + " " + std::string(face->style_name);
|
||||
name2file_.insert(std::make_pair(name,file_name));
|
||||
FT_Done_Face(face );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static std::vector<std::string> face_names ()
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
std::map<std::string,std::string>::const_iterator itr;
|
||||
for (itr = name2file_.begin();itr!=name2file_.end();++itr)
|
||||
{
|
||||
names.push_back(itr->first);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
static face_ptr create_face(std::string const& family_name)
|
||||
{
|
||||
mutex::scoped_lock lock(mapnik::singleton<freetype_engine,
|
||||
mapnik::CreateStatic>::mutex_);
|
||||
|
||||
std::map<std::string,std::string>::iterator itr;
|
||||
itr = name2file_.find(family_name);
|
||||
if (itr != name2file_.end())
|
||||
{
|
||||
FT_Face face;
|
||||
FT_Error error = FT_New_Face (library_,itr->second.c_str(),0,&face);
|
||||
|
||||
if (!error)
|
||||
{
|
||||
return face_ptr (new font_face(face));
|
||||
}
|
||||
}
|
||||
return face_ptr();
|
||||
}
|
||||
|
||||
static bool register_font(std::string const& file_name);
|
||||
static std::vector<std::string> face_names ();
|
||||
static face_ptr create_face(std::string const& family_name);
|
||||
|
||||
private:
|
||||
freetype_engine()
|
||||
{
|
||||
FT_Error error = FT_Init_FreeType( &library_ );
|
||||
if (error)
|
||||
{
|
||||
throw std::runtime_error("can not load FreeType2 library");
|
||||
}
|
||||
}
|
||||
virtual ~freetype_engine()
|
||||
{
|
||||
FT_Done_FreeType(library_);
|
||||
}
|
||||
|
||||
freetype_engine();
|
||||
virtual ~freetype_engine();
|
||||
static FT_Library library_;
|
||||
static std::map<std::string,std::string> name2file_;
|
||||
static std::map<std::string,std::string> name2file_;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class MAPNIK_DECL face_manager : private boost::noncopyable
|
||||
{
|
||||
|
@ -171,24 +116,24 @@ namespace mapnik
|
|||
typedef std::map<std::string,face_ptr> faces;
|
||||
|
||||
public:
|
||||
face_ptr get_face(std::string const& name)
|
||||
{
|
||||
typename faces::iterator itr;
|
||||
itr = faces_.find(name);
|
||||
if (itr != faces_.end())
|
||||
{
|
||||
return itr->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
face_ptr face = font_engine_type::instance()->create_face(name);
|
||||
if (face)
|
||||
{
|
||||
faces_.insert(make_pair(name,face));
|
||||
}
|
||||
return face;
|
||||
}
|
||||
}
|
||||
face_ptr get_face(std::string const& name)
|
||||
{
|
||||
typename faces::iterator itr;
|
||||
itr = faces_.find(name);
|
||||
if (itr != faces_.end())
|
||||
{
|
||||
return itr->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
face_ptr face = font_engine_type::instance()->create_face(name);
|
||||
if (face)
|
||||
{
|
||||
faces_.insert(make_pair(name,face));
|
||||
}
|
||||
return face;
|
||||
}
|
||||
}
|
||||
private:
|
||||
faces faces_;
|
||||
};
|
||||
|
|
|
@ -22,6 +22,66 @@
|
|||
|
||||
namespace mapnik
|
||||
{
|
||||
freetype_engine::freetype_engine()
|
||||
{
|
||||
FT_Error error = FT_Init_FreeType( &library_ );
|
||||
if (error)
|
||||
{
|
||||
throw std::runtime_error("can not load FreeType2 library");
|
||||
}
|
||||
}
|
||||
|
||||
freetype_engine::~freetype_engine()
|
||||
{
|
||||
FT_Done_FreeType(library_);
|
||||
}
|
||||
|
||||
bool freetype_engine::register_font(std::string const& file_name)
|
||||
{
|
||||
mutex::scoped_lock lock(mapnik::singleton<freetype_engine,
|
||||
mapnik::CreateStatic>::mutex_);
|
||||
FT_Face face;
|
||||
FT_Error error = FT_New_Face (library_,file_name.c_str(),0,&face);
|
||||
if ( !error )
|
||||
{
|
||||
std::string name = std::string(face->family_name) + " " + std::string(face->style_name);
|
||||
name2file_.insert(std::make_pair(name,file_name));
|
||||
FT_Done_Face(face );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
std::vector<std::string> freetype_engine::face_names ()
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
std::map<std::string,std::string>::const_iterator itr;
|
||||
for (itr = name2file_.begin();itr!=name2file_.end();++itr)
|
||||
{
|
||||
names.push_back(itr->first);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
face_ptr freetype_engine::create_face(std::string const& family_name)
|
||||
{
|
||||
mutex::scoped_lock lock(mapnik::singleton<freetype_engine,
|
||||
mapnik::CreateStatic>::mutex_);
|
||||
|
||||
std::map<std::string,std::string>::iterator itr;
|
||||
itr = name2file_.find(family_name);
|
||||
if (itr != name2file_.end())
|
||||
{
|
||||
FT_Face face;
|
||||
FT_Error error = FT_New_Face (library_,itr->second.c_str(),0,&face);
|
||||
|
||||
if (!error)
|
||||
{
|
||||
return face_ptr (new font_face(face));
|
||||
}
|
||||
}
|
||||
return face_ptr();
|
||||
}
|
||||
|
||||
FT_Library freetype_engine::library_;
|
||||
std::map<std::string,std::string> freetype_engine::name2file_;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue