freetype_engine - preserve original intetface via static methods + make impl methods private.
This commit is contained in:
parent
648f9698a0
commit
d1327dea88
2 changed files with 90 additions and 33 deletions
|
@ -56,34 +56,48 @@ class MAPNIK_DECL freetype_engine : public singleton<freetype_engine, CreateUsin
|
||||||
private util::noncopyable
|
private util::noncopyable
|
||||||
{
|
{
|
||||||
friend class CreateUsingNew<freetype_engine>;
|
friend class CreateUsingNew<freetype_engine>;
|
||||||
|
friend class Map;
|
||||||
public:
|
public:
|
||||||
using font_file_mapping_type = std::map<std::string,std::pair<int,std::string>>;
|
using font_file_mapping_type = std::map<std::string,std::pair<int,std::string>>;
|
||||||
using font_memory_cache_type = std::map<std::string, std::pair<std::unique_ptr<char[]>, std::size_t>>;
|
using font_memory_cache_type = std::map<std::string, std::pair<std::unique_ptr<char[]>, std::size_t>>;
|
||||||
bool is_font_file(std::string const& file_name);
|
|
||||||
/*! \brief register a font file
|
static bool is_font_file(std::string const& file_name);
|
||||||
* @param file_name path to a font file.
|
static bool register_font(std::string const& file_name);
|
||||||
* @return bool - true if at least one face was successfully registered in the file.
|
static bool register_fonts(std::string const& dir, bool recurse = false);
|
||||||
*/
|
static std::vector<std::string> face_names();
|
||||||
bool register_font(std::string const& file_name);
|
static font_file_mapping_type const& get_mapping();
|
||||||
/*! \brief register a font files
|
static font_memory_cache_type & get_cache();
|
||||||
* @param dir - path to a directory containing fonts or subdirectories.
|
static bool can_open(std::string const& face_name,
|
||||||
* @param recurse - default false, whether to search for fonts in sub directories.
|
|
||||||
* @return bool - true if at least one face was successfully registered.
|
|
||||||
*/
|
|
||||||
bool register_fonts(std::string const& dir, bool recurse = false);
|
|
||||||
std::vector<std::string> face_names();
|
|
||||||
font_file_mapping_type const& get_mapping();
|
|
||||||
font_memory_cache_type & get_cache();
|
|
||||||
bool can_open(std::string const& face_name,
|
|
||||||
font_library & library,
|
font_library & library,
|
||||||
font_file_mapping_type const& font_file_mapping,
|
font_file_mapping_type const& font_file_mapping,
|
||||||
font_file_mapping_type const& global_font_file_mapping);
|
font_file_mapping_type const& global_font_file_mapping);
|
||||||
face_ptr create_face(std::string const& face_name,
|
|
||||||
|
static face_ptr create_face(std::string const& face_name,
|
||||||
font_library & library,
|
font_library & library,
|
||||||
font_file_mapping_type const& font_file_mapping,
|
font_file_mapping_type const& font_file_mapping,
|
||||||
freetype_engine::font_memory_cache_type const& font_cache,
|
freetype_engine::font_memory_cache_type const& font_cache,
|
||||||
font_file_mapping_type const& global_font_file_mapping,
|
font_file_mapping_type const& global_font_file_mapping,
|
||||||
freetype_engine::font_memory_cache_type & global_memory_fonts);
|
freetype_engine::font_memory_cache_type & global_memory_fonts);
|
||||||
|
private:
|
||||||
|
bool is_font_file_impl(std::string const& file_name);
|
||||||
|
std::vector<std::string> face_names_impl();
|
||||||
|
font_file_mapping_type const& get_mapping_impl();
|
||||||
|
font_memory_cache_type& get_cache_impl();
|
||||||
|
bool can_open_impl(std::string const& face_name,
|
||||||
|
font_library & library,
|
||||||
|
font_file_mapping_type const& font_file_mapping,
|
||||||
|
font_file_mapping_type const& global_font_file_mapping);
|
||||||
|
|
||||||
|
face_ptr create_face_impl(std::string const& face_name,
|
||||||
|
font_library & library,
|
||||||
|
font_file_mapping_type const& font_file_mapping,
|
||||||
|
freetype_engine::font_memory_cache_type const& font_cache,
|
||||||
|
font_file_mapping_type const& global_font_file_mapping,
|
||||||
|
freetype_engine::font_memory_cache_type & global_memory_fonts);
|
||||||
|
bool register_font_impl(std::string const& file_name);
|
||||||
|
bool register_fonts_impl(std::string const& dir, bool recurse);
|
||||||
|
bool register_font_impl(std::string const& file_name, FT_LibraryRec_ * library);
|
||||||
|
bool register_fonts_impl(std::string const& dir, FT_LibraryRec_ * library, bool recurse = false);
|
||||||
bool register_font_impl(std::string const& file_name,
|
bool register_font_impl(std::string const& file_name,
|
||||||
font_library & libary,
|
font_library & libary,
|
||||||
font_file_mapping_type & font_file_mapping);
|
font_file_mapping_type & font_file_mapping);
|
||||||
|
@ -91,9 +105,6 @@ public:
|
||||||
font_library & libary,
|
font_library & libary,
|
||||||
font_file_mapping_type & font_file_mapping,
|
font_file_mapping_type & font_file_mapping,
|
||||||
bool recurse = false);
|
bool recurse = false);
|
||||||
private:
|
|
||||||
bool register_font_impl(std::string const& file_name, FT_LibraryRec_ * library);
|
|
||||||
bool register_fonts_impl(std::string const& dir, FT_LibraryRec_ * library, bool recurse = false);
|
|
||||||
#ifdef MAPNIK_THREADSAFE
|
#ifdef MAPNIK_THREADSAFE
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -77,6 +77,11 @@ unsigned long ft_read_cb(FT_Stream stream, unsigned long offset, unsigned char *
|
||||||
}
|
}
|
||||||
|
|
||||||
bool freetype_engine::register_font(std::string const& file_name)
|
bool freetype_engine::register_font(std::string const& file_name)
|
||||||
|
{
|
||||||
|
return instance().register_font_impl(file_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool freetype_engine::register_font_impl(std::string const& file_name)
|
||||||
{
|
{
|
||||||
#ifdef MAPNIK_THREADSAFE
|
#ifdef MAPNIK_THREADSAFE
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
@ -159,6 +164,11 @@ bool freetype_engine::register_font_impl(std::string const& file_name,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool freetype_engine::register_fonts(std::string const& dir, bool recurse)
|
bool freetype_engine::register_fonts(std::string const& dir, bool recurse)
|
||||||
|
{
|
||||||
|
return instance().register_fonts_impl(dir, recurse);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool freetype_engine::register_fonts_impl(std::string const& dir, bool recurse)
|
||||||
{
|
{
|
||||||
#ifdef MAPNIK_THREADSAFE
|
#ifdef MAPNIK_THREADSAFE
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
@ -214,8 +224,12 @@ bool freetype_engine::register_fonts_impl(std::string const& dir,
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string> freetype_engine::face_names()
|
std::vector<std::string> freetype_engine::face_names()
|
||||||
|
{
|
||||||
|
return instance().face_names_impl();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> freetype_engine::face_names_impl()
|
||||||
{
|
{
|
||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
for (auto const& kv : global_font_file_mapping_)
|
for (auto const& kv : global_font_file_mapping_)
|
||||||
|
@ -226,11 +240,21 @@ std::vector<std::string> freetype_engine::face_names ()
|
||||||
}
|
}
|
||||||
|
|
||||||
freetype_engine::font_file_mapping_type const& freetype_engine::get_mapping()
|
freetype_engine::font_file_mapping_type const& freetype_engine::get_mapping()
|
||||||
|
{
|
||||||
|
return instance().get_mapping_impl();
|
||||||
|
}
|
||||||
|
|
||||||
|
freetype_engine::font_file_mapping_type const& freetype_engine::get_mapping_impl()
|
||||||
{
|
{
|
||||||
return global_font_file_mapping_;
|
return global_font_file_mapping_;
|
||||||
}
|
}
|
||||||
|
|
||||||
freetype_engine::font_memory_cache_type & freetype_engine::get_cache()
|
freetype_engine::font_memory_cache_type & freetype_engine::get_cache()
|
||||||
|
{
|
||||||
|
return instance().get_cache_impl();
|
||||||
|
}
|
||||||
|
|
||||||
|
freetype_engine::font_memory_cache_type & freetype_engine::get_cache_impl()
|
||||||
{
|
{
|
||||||
return global_memory_fonts_;
|
return global_memory_fonts_;
|
||||||
}
|
}
|
||||||
|
@ -239,6 +263,14 @@ bool freetype_engine::can_open(std::string const& face_name,
|
||||||
font_library & library,
|
font_library & library,
|
||||||
font_file_mapping_type const& font_file_mapping,
|
font_file_mapping_type const& font_file_mapping,
|
||||||
font_file_mapping_type const& global_font_file_mapping)
|
font_file_mapping_type const& global_font_file_mapping)
|
||||||
|
{
|
||||||
|
return instance().can_open_impl(face_name, library, font_file_mapping, global_font_file_mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool freetype_engine::can_open_impl(std::string const& face_name,
|
||||||
|
font_library & library,
|
||||||
|
font_file_mapping_type const& font_file_mapping,
|
||||||
|
font_file_mapping_type const& global_font_file_mapping)
|
||||||
{
|
{
|
||||||
bool found_font_file = false;
|
bool found_font_file = false;
|
||||||
font_file_mapping_type::const_iterator itr = font_file_mapping.find(face_name);
|
font_file_mapping_type::const_iterator itr = font_file_mapping.find(face_name);
|
||||||
|
@ -277,7 +309,7 @@ bool freetype_engine::can_open(std::string const& face_name,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
face_ptr freetype_engine::create_face(std::string const& family_name,
|
face_ptr freetype_engine::create_face_impl(std::string const& family_name,
|
||||||
font_library & library,
|
font_library & library,
|
||||||
freetype_engine::font_file_mapping_type const& font_file_mapping,
|
freetype_engine::font_file_mapping_type const& font_file_mapping,
|
||||||
freetype_engine::font_memory_cache_type const& font_cache,
|
freetype_engine::font_memory_cache_type const& font_cache,
|
||||||
|
@ -354,6 +386,20 @@ face_ptr freetype_engine::create_face(std::string const& family_name,
|
||||||
return face_ptr();
|
return face_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
face_ptr freetype_engine::create_face(std::string const& family_name,
|
||||||
|
font_library & library,
|
||||||
|
freetype_engine::font_file_mapping_type const& font_file_mapping,
|
||||||
|
freetype_engine::font_memory_cache_type const& font_cache,
|
||||||
|
freetype_engine::font_file_mapping_type const& global_font_file_mapping,
|
||||||
|
freetype_engine::font_memory_cache_type & global_memory_fonts)
|
||||||
|
{
|
||||||
|
return instance().create_face_impl(family_name,
|
||||||
|
library,
|
||||||
|
font_file_mapping,
|
||||||
|
font_cache,
|
||||||
|
global_font_file_mapping,
|
||||||
|
global_memory_fonts);
|
||||||
|
}
|
||||||
|
|
||||||
face_manager::face_manager(font_library & library,
|
face_manager::face_manager(font_library & library,
|
||||||
freetype_engine::font_file_mapping_type const& font_file_mapping,
|
freetype_engine::font_file_mapping_type const& font_file_mapping,
|
||||||
|
@ -380,7 +426,7 @@ face_ptr face_manager::get_face(std::string const& name)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
face_ptr face = freetype_engine::instance().create_face(name,
|
face_ptr face = freetype_engine::create_face(name,
|
||||||
library_,
|
library_,
|
||||||
font_file_mapping_,
|
font_file_mapping_,
|
||||||
font_memory_cache_,
|
font_memory_cache_,
|
||||||
|
|
Loading…
Reference in a new issue