remove state from freetype_engine - now fully static
This commit is contained in:
parent
940c4a321d
commit
ad7e619ba3
10 changed files with 81 additions and 68 deletions
|
@ -11,12 +11,17 @@ public:
|
|||
{
|
||||
std::size_t count = 0;
|
||||
std::size_t expected_count = mapnik::freetype_engine::face_names().size();
|
||||
mapnik::freetype_engine engine;
|
||||
mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
|
||||
mapnik::freetype_engine::font_memory_cache_type font_cache;
|
||||
mapnik::font_library library;
|
||||
for (std::string const& name : mapnik::freetype_engine::face_names())
|
||||
{
|
||||
mapnik::face_ptr f = engine.create_face(name,engine.get_library(),font_file_mapping,font_cache);
|
||||
mapnik::face_ptr f = mapnik::freetype_engine::create_face(name,
|
||||
library,
|
||||
font_file_mapping,
|
||||
font_cache,
|
||||
mapnik::freetype_engine::get_mapping(),
|
||||
mapnik::freetype_engine::get_cache());
|
||||
if (f) ++count;
|
||||
}
|
||||
return count == expected_count;
|
||||
|
@ -27,12 +32,17 @@ public:
|
|||
for (unsigned i=0;i<iterations_;++i)
|
||||
{
|
||||
std::size_t count = 0;
|
||||
mapnik::freetype_engine engine;
|
||||
mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
|
||||
mapnik::freetype_engine::font_memory_cache_type font_cache;
|
||||
mapnik::font_library library;
|
||||
for (std::string const& name : mapnik::freetype_engine::face_names())
|
||||
{
|
||||
mapnik::face_ptr f = engine.create_face(name,engine.get_library(),font_file_mapping,font_cache);
|
||||
mapnik::face_ptr f = mapnik::freetype_engine::create_face(name,
|
||||
library,
|
||||
font_file_mapping,
|
||||
font_cache,
|
||||
mapnik::freetype_engine::get_mapping(),
|
||||
mapnik::freetype_engine::get_cache());
|
||||
if (f) ++count;
|
||||
}
|
||||
if (count != expected_count) {
|
||||
|
|
|
@ -78,18 +78,18 @@ void check_object_status_and_throw_exception(T const& object)
|
|||
class cairo_face : private mapnik::noncopyable
|
||||
{
|
||||
public:
|
||||
cairo_face(std::shared_ptr<freetype_engine> const& engine, face_ptr const& face);
|
||||
cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face);
|
||||
~cairo_face();
|
||||
cairo_font_face_t * face() const;
|
||||
private:
|
||||
class handle
|
||||
{
|
||||
public:
|
||||
handle(std::shared_ptr<freetype_engine> const& engine, face_ptr const& face)
|
||||
: engine_(engine), face_(face) {}
|
||||
handle(std::shared_ptr<font_library> const& library, face_ptr const& face)
|
||||
: library_(library), face_(face) {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<freetype_engine> engine_;
|
||||
std::shared_ptr<font_library> library_;
|
||||
face_ptr face_;
|
||||
};
|
||||
|
||||
|
@ -109,12 +109,12 @@ using cairo_face_ptr = std::shared_ptr<cairo_face>;
|
|||
class cairo_face_manager : private mapnik::noncopyable
|
||||
{
|
||||
public:
|
||||
cairo_face_manager(std::shared_ptr<freetype_engine> engine);
|
||||
cairo_face_manager(std::shared_ptr<font_library> library);
|
||||
cairo_face_ptr get_face(face_ptr face);
|
||||
|
||||
private:
|
||||
using cairo_face_cache = std::map<face_ptr,cairo_face_ptr>;
|
||||
std::shared_ptr<freetype_engine> font_engine_;
|
||||
std::shared_ptr<font_library> font_library_;
|
||||
cairo_face_cache cache_;
|
||||
};
|
||||
|
||||
|
|
|
@ -70,13 +70,13 @@ public:
|
|||
static bool register_fonts(std::string const& dir, bool recurse = false);
|
||||
static std::vector<std::string> face_names();
|
||||
static font_file_mapping_type const& get_mapping();
|
||||
static font_memory_cache_type & get_cache();
|
||||
static face_ptr create_face(std::string const& family_name,
|
||||
font_library & library,
|
||||
font_file_mapping_type const& font_file_mapping,
|
||||
freetype_engine::font_memory_cache_type const& font_cache);
|
||||
stroker_ptr create_stroker();
|
||||
virtual ~freetype_engine();
|
||||
freetype_engine();
|
||||
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);
|
||||
static bool register_font_impl(std::string const& file_name,
|
||||
font_library & libary,
|
||||
font_file_mapping_type & font_file_mapping);
|
||||
|
@ -84,14 +84,11 @@ public:
|
|||
font_library & libary,
|
||||
font_file_mapping_type & font_file_mapping,
|
||||
bool recurse = false);
|
||||
font_library & get_library()
|
||||
{
|
||||
return library_;
|
||||
}
|
||||
virtual ~freetype_engine();
|
||||
freetype_engine();
|
||||
private:
|
||||
static bool register_font_impl(std::string const& file_name, FT_LibraryRec_ * library);
|
||||
static bool register_fonts_impl(std::string const& dir, FT_LibraryRec_ * library, bool recurse = false);
|
||||
font_library library_;
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
static std::mutex mutex_;
|
||||
#endif
|
||||
|
@ -104,28 +101,20 @@ class MAPNIK_DECL face_manager : private mapnik::noncopyable
|
|||
using face_ptr_cache_type = std::map<std::string, face_ptr>;
|
||||
|
||||
public:
|
||||
face_manager(freetype_engine & engine,
|
||||
face_manager(font_library & library,
|
||||
freetype_engine::font_file_mapping_type const& font_file_mapping,
|
||||
freetype_engine::font_memory_cache_type const& font_cache)
|
||||
: engine_(engine),
|
||||
stroker_(engine_.create_stroker()),
|
||||
face_ptr_cache_(),
|
||||
library_(engine_.get_library()),
|
||||
font_file_mapping_(font_file_mapping),
|
||||
font_memory_cache_(font_cache) {}
|
||||
|
||||
freetype_engine::font_memory_cache_type const& font_cache);
|
||||
face_ptr get_face(std::string const& name);
|
||||
face_set_ptr get_face_set(std::string const& name);
|
||||
face_set_ptr get_face_set(font_set const& fset);
|
||||
face_set_ptr get_face_set(std::string const& name, boost::optional<font_set> fset);
|
||||
inline stroker_ptr get_stroker() { return stroker_; }
|
||||
private:
|
||||
freetype_engine & engine_;
|
||||
stroker_ptr stroker_;
|
||||
face_ptr_cache_type face_ptr_cache_;
|
||||
font_library & library_;
|
||||
freetype_engine::font_file_mapping_type const& font_file_mapping_;
|
||||
freetype_engine::font_memory_cache_type const& font_memory_cache_;
|
||||
stroker_ptr stroker_;
|
||||
};
|
||||
|
||||
using face_manager_freetype = face_manager;
|
||||
|
|
|
@ -55,8 +55,8 @@ struct renderer_common : private mapnik::noncopyable
|
|||
double scale_factor_;
|
||||
attributes vars_;
|
||||
// TODO: dirty hack for cairo renderer, figure out how to remove this
|
||||
std::shared_ptr<freetype_engine> shared_font_engine_;
|
||||
freetype_engine & font_engine_;
|
||||
std::shared_ptr<font_library> shared_font_library_;
|
||||
font_library & font_library_;
|
||||
face_manager_freetype font_manager_;
|
||||
box2d<double> query_extent_;
|
||||
view_transform t_;
|
||||
|
|
|
@ -57,8 +57,8 @@ struct virtual_renderer_common : private mapnik::noncopyable
|
|||
height_(common.height_),
|
||||
scale_factor_(common.scale_factor_),
|
||||
vars_(common.vars_),
|
||||
shared_font_engine_(common.shared_font_engine_),
|
||||
font_engine_(*shared_font_engine_),
|
||||
shared_font_library_(common.shared_font_library_),
|
||||
font_library_(*shared_font_library_),
|
||||
font_manager_(common.font_manager_),
|
||||
query_extent_(common.query_extent_),
|
||||
t_(common.t_),
|
||||
|
@ -69,8 +69,8 @@ struct virtual_renderer_common : private mapnik::noncopyable
|
|||
double & scale_factor_;
|
||||
attributes & vars_;
|
||||
// TODO: dirty hack for cairo renderer, figure out how to remove this
|
||||
std::shared_ptr<freetype_engine> & shared_font_engine_;
|
||||
freetype_engine & font_engine_;
|
||||
std::shared_ptr<font_library> & shared_font_library_;
|
||||
font_library & font_library_;
|
||||
face_manager_freetype & font_manager_;
|
||||
box2d<double> & query_extent_;
|
||||
view_transform & t_;
|
||||
|
|
|
@ -32,12 +32,12 @@
|
|||
#include <valarray>
|
||||
namespace mapnik {
|
||||
|
||||
cairo_face::cairo_face(std::shared_ptr<freetype_engine> const& engine, face_ptr const& face)
|
||||
cairo_face::cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face)
|
||||
: face_(face)
|
||||
{
|
||||
static cairo_user_data_key_t key;
|
||||
c_face_ = cairo_ft_font_face_create_for_ft_face(face->get_face(), FT_LOAD_NO_HINTING);
|
||||
cairo_font_face_set_user_data(c_face_, &key, new handle(engine, face), destroy);
|
||||
cairo_font_face_set_user_data(c_face_, &key, new handle(library, face), destroy);
|
||||
}
|
||||
|
||||
cairo_face::~cairo_face()
|
||||
|
@ -508,8 +508,8 @@ void cairo_context::add_text(glyph_positions_ptr path,
|
|||
|
||||
}
|
||||
|
||||
cairo_face_manager::cairo_face_manager(std::shared_ptr<freetype_engine> font_engine)
|
||||
: font_engine_(font_engine)
|
||||
cairo_face_manager::cairo_face_manager(std::shared_ptr<font_library> font_library)
|
||||
: font_library_(font_library)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -524,7 +524,7 @@ cairo_face_ptr cairo_face_manager::get_face(face_ptr face)
|
|||
}
|
||||
else
|
||||
{
|
||||
entry = std::make_shared<cairo_face>(font_engine_, face);
|
||||
entry = std::make_shared<cairo_face>(font_library_, face);
|
||||
cache_.emplace(face, entry);
|
||||
}
|
||||
return entry;
|
||||
|
|
|
@ -58,7 +58,7 @@ cairo_renderer<T>::cairo_renderer(Map const& m,
|
|||
m_(m),
|
||||
context_(cairo),
|
||||
common_(m, attributes(), offset_x, offset_y, m.width(), m.height(), scale_factor),
|
||||
face_manager_(common_.shared_font_engine_)
|
||||
face_manager_(common_.shared_font_library_)
|
||||
{
|
||||
setup(m);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ cairo_renderer<T>::cairo_renderer(Map const& m,
|
|||
m_(m),
|
||||
context_(cairo),
|
||||
common_(m, req, vars, offset_x, offset_y, req.width(), req.height(), scale_factor),
|
||||
face_manager_(common_.shared_font_engine_)
|
||||
face_manager_(common_.shared_font_library_)
|
||||
{
|
||||
setup(m);
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ cairo_renderer<T>::cairo_renderer(Map const& m,
|
|||
m_(m),
|
||||
context_(cairo),
|
||||
common_(m, attributes(), offset_x, offset_y, m.width(), m.height(), scale_factor, detector),
|
||||
face_manager_(common_.shared_font_engine_)
|
||||
face_manager_(common_.shared_font_library_)
|
||||
{
|
||||
setup(m);
|
||||
}
|
||||
|
|
|
@ -52,9 +52,7 @@ extern "C"
|
|||
namespace mapnik
|
||||
{
|
||||
|
||||
freetype_engine::freetype_engine()
|
||||
: library_() {}
|
||||
|
||||
freetype_engine::freetype_engine() {}
|
||||
freetype_engine::~freetype_engine() {}
|
||||
|
||||
bool freetype_engine::is_font_file(std::string const& file_name)
|
||||
|
@ -256,11 +254,17 @@ freetype_engine::font_file_mapping_type const& freetype_engine::get_mapping()
|
|||
return global_font_file_mapping_;
|
||||
}
|
||||
|
||||
freetype_engine::font_memory_cache_type & freetype_engine::get_cache()
|
||||
{
|
||||
return global_memory_fonts_;
|
||||
}
|
||||
|
||||
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_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)
|
||||
{
|
||||
bool found_font_file = false;
|
||||
font_file_mapping_type::const_iterator itr = font_file_mapping.find(family_name);
|
||||
|
@ -277,7 +281,6 @@ face_ptr freetype_engine::create_face(std::string const& family_name,
|
|||
static_cast<FT_Long>(mem_font_itr->second.second), // size
|
||||
itr->second.first, // face index
|
||||
&face);
|
||||
|
||||
if (!error) return std::make_shared<font_face>(face);
|
||||
}
|
||||
// we don't add to cache here because the map and its font_cache
|
||||
|
@ -287,8 +290,8 @@ face_ptr freetype_engine::create_face(std::string const& family_name,
|
|||
else
|
||||
{
|
||||
// otherwise search global registry
|
||||
itr = global_font_file_mapping_.find(family_name);
|
||||
if (itr != global_font_file_mapping_.end())
|
||||
itr = global_font_file_mapping.find(family_name);
|
||||
if (itr != global_font_file_mapping.end())
|
||||
{
|
||||
auto mem_font_itr = global_memory_fonts_.find(itr->second.second);
|
||||
// if font already in memory, use it
|
||||
|
@ -300,7 +303,6 @@ face_ptr freetype_engine::create_face(std::string const& family_name,
|
|||
static_cast<FT_Long>(mem_font_itr->second.second), // size
|
||||
itr->second.first, // face index
|
||||
&face);
|
||||
|
||||
if (!error) return std::make_shared<font_face>(face);
|
||||
}
|
||||
found_font_file = true;
|
||||
|
@ -334,16 +336,22 @@ face_ptr freetype_engine::create_face(std::string const& family_name,
|
|||
return face_ptr();
|
||||
}
|
||||
|
||||
stroker_ptr freetype_engine::create_stroker()
|
||||
{
|
||||
FT_Stroker s;
|
||||
FT_Error error = FT_Stroker_New(library_.get(), &s);
|
||||
if (!error)
|
||||
{
|
||||
return std::make_shared<stroker>(s);
|
||||
}
|
||||
return stroker_ptr();
|
||||
}
|
||||
|
||||
face_manager::face_manager(font_library & library,
|
||||
freetype_engine::font_file_mapping_type const& font_file_mapping,
|
||||
freetype_engine::font_memory_cache_type const& font_cache)
|
||||
: face_ptr_cache_(),
|
||||
library_(library),
|
||||
font_file_mapping_(font_file_mapping),
|
||||
font_memory_cache_(font_cache)
|
||||
{
|
||||
FT_Stroker s;
|
||||
FT_Error error = FT_Stroker_New(library_.get(), &s);
|
||||
if (!error)
|
||||
{
|
||||
stroker_ = std::make_shared<stroker>(s);
|
||||
}
|
||||
}
|
||||
|
||||
face_ptr face_manager::get_face(std::string const& name)
|
||||
{
|
||||
|
@ -354,7 +362,12 @@ face_ptr face_manager::get_face(std::string const& name)
|
|||
}
|
||||
else
|
||||
{
|
||||
face_ptr face = engine_.create_face(name,library_,font_file_mapping_,font_memory_cache_);
|
||||
face_ptr face = freetype_engine::create_face(name,
|
||||
library_,
|
||||
font_file_mapping_,
|
||||
font_memory_cache_,
|
||||
freetype_engine::get_mapping(),
|
||||
freetype_engine::get_cache());
|
||||
if (face)
|
||||
{
|
||||
face_ptr_cache_.emplace(name,face);
|
||||
|
|
|
@ -87,7 +87,8 @@ public:
|
|||
map_parser(Map & map, bool strict, std::string const& filename = "") :
|
||||
strict_(strict),
|
||||
filename_(filename),
|
||||
font_manager_(font_engine_,map.get_font_file_mapping(),map.get_font_memory_cache()),
|
||||
font_library_(),
|
||||
font_manager_(font_library_,map.get_font_file_mapping(),map.get_font_memory_cache()),
|
||||
xml_base_path_()
|
||||
{}
|
||||
|
||||
|
@ -129,7 +130,7 @@ private:
|
|||
bool strict_;
|
||||
std::string filename_;
|
||||
std::map<std::string,parameters> datasource_templates_;
|
||||
freetype_engine font_engine_;
|
||||
font_library font_library_;
|
||||
face_manager_freetype font_manager_;
|
||||
std::map<std::string,std::string> file_sources_;
|
||||
std::map<std::string,font_set> fontsets_;
|
||||
|
|
|
@ -36,9 +36,9 @@ renderer_common::renderer_common(Map const& map, unsigned width, unsigned height
|
|||
height_(height),
|
||||
scale_factor_(scale_factor),
|
||||
vars_(vars),
|
||||
shared_font_engine_(std::make_shared<freetype_engine>()),
|
||||
font_engine_(*shared_font_engine_),
|
||||
font_manager_(font_engine_,map.get_font_file_mapping(),map.get_font_memory_cache()),
|
||||
shared_font_library_(std::make_shared<font_library>()),
|
||||
font_library_(*shared_font_library_),
|
||||
font_manager_(font_library_,map.get_font_file_mapping(),map.get_font_memory_cache()),
|
||||
query_extent_(),
|
||||
t_(t),
|
||||
detector_(detector)
|
||||
|
|
Loading…
Reference in a new issue