freetype_engine : revert back to original APIs usage.

This reverts commit 1c101c3243.
This commit is contained in:
artemp 2017-06-01 12:23:13 +02:00
parent 98fa7699f3
commit 9f19fa8943
11 changed files with 57 additions and 62 deletions

View file

@ -10,39 +10,39 @@ public:
bool validate() const
{
std::size_t count = 0;
std::size_t expected_count = mapnik::freetype_engine::instance().face_names().size();
std::size_t expected_count = mapnik::freetype_engine::face_names().size();
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::instance().face_names())
for (std::string const& name : mapnik::freetype_engine::face_names())
{
mapnik::face_ptr f = mapnik::freetype_engine::instance().create_face(name,
mapnik::face_ptr f = mapnik::freetype_engine::create_face(name,
library,
font_file_mapping,
font_cache,
mapnik::freetype_engine::instance().get_mapping(),
mapnik::freetype_engine::instance().get_cache());
mapnik::freetype_engine::get_mapping(),
mapnik::freetype_engine::get_cache());
if (f) ++count;
}
return count == expected_count;
}
bool operator()() const
{
std::size_t expected_count = mapnik::freetype_engine::instance().face_names().size();
std::size_t expected_count = mapnik::freetype_engine::face_names().size();
for (unsigned i=0;i<iterations_;++i)
{
std::size_t count = 0;
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::instance().face_names())
for (std::string const& name : mapnik::freetype_engine::face_names())
{
mapnik::face_ptr f = mapnik::freetype_engine::instance().create_face(name,
mapnik::face_ptr f = mapnik::freetype_engine::create_face(name,
library,
font_file_mapping,
font_cache,
mapnik::freetype_engine::instance().get_mapping(),
mapnik::freetype_engine::instance().get_cache());
mapnik::freetype_engine::get_mapping(),
mapnik::freetype_engine::get_cache());
if (f) ++count;
}
if (count != expected_count) {
@ -57,12 +57,13 @@ int main(int argc, char** argv)
{
mapnik::parameters params;
benchmark::handle_args(argc,argv,params);
bool success = mapnik::freetype_engine::instance().register_fonts("./fonts", true);
bool success = mapnik::freetype_engine::register_fonts("./fonts", true);
if (!success) {
std::clog << "warning, did not register any new fonts!\n";
return -1;
}
std::size_t face_count = mapnik::freetype_engine::instance().face_names().size();
std::size_t face_count = mapnik::freetype_engine::face_names().size();
test test_runner(params);
return run(test_runner,(boost::format("font_engine: creating %ld faces") % (face_count)).str());
}

View file

@ -10,14 +10,14 @@ public:
: test_case(params) {}
bool validate() const
{
return mapnik::freetype_engine::instance().register_fonts("./fonts", true);
return mapnik::freetype_engine::register_fonts("./fonts", true);
}
bool operator()() const
{
unsigned long count = 0;
for (unsigned i=0;i<iterations_;++i)
{
mapnik::freetype_engine::instance().register_fonts("./fonts", true);
mapnik::freetype_engine::register_fonts("./fonts", true);
count++;
}
return true;

View file

@ -99,7 +99,7 @@ int main(int argc, char** argv)
std::clog << "please provide a name for this test\n";
return -1;
}
mapnik::freetype_engine::instance().register_fonts("./fonts/",true);
mapnik::freetype_engine::register_fonts("./fonts/",true);
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
{
test test_runner(params);

View file

@ -156,7 +156,7 @@ int main(int argc, char** argv)
std::clog << "please provide a name for this test\n";
return -1;
}
mapnik::freetype_engine::instance().register_fonts("./fonts/",true);
mapnik::freetype_engine::register_fonts("./fonts/",true);
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
{
test test_runner(params);

View file

@ -55,7 +55,7 @@ int main ( int, char** )
try {
std::cout << " running demo ... \n";
datasource_cache::instance().register_datasources("plugins/input/");
freetype_engine::instance().register_font("fonts/dejavu-fonts-ttf-2.37/ttf/DejaVuSans.ttf");
freetype_engine::register_font("fonts/dejavu-fonts-ttf-2.37/ttf/DejaVuSans.ttf");
Map m(800,600);
m.set_background(parse_color("white"));

View file

@ -485,10 +485,4 @@ face_set_ptr face_manager::get_face_set(std::string const& name, boost::optional
}
}
#ifdef MAPNIK_THREADSAFE
//std::mutex freetype_engine::mutex_;
#endif
//freetype_engine::font_file_mapping_type freetype_engine::global_font_file_mapping_;
//freetype_engine::font_memory_cache_type freetype_engine::global_memory_fonts_;
}

View file

@ -536,10 +536,10 @@ bool map_parser::parse_font(font_set & fset, xml_node const& f)
}
else
{
found = freetype_engine::instance().can_open(face_name,
found = freetype_engine::can_open(face_name,
font_library_,
font_file_mapping_,
freetype_engine::instance().get_mapping());
freetype_engine::get_mapping());
font_name_cache_.emplace(face_name,found);
}
if (found)
@ -1599,10 +1599,10 @@ void map_parser::ensure_font_face(std::string const& face_name)
}
else
{
found = freetype_engine::instance().can_open(face_name,
found = freetype_engine::can_open(face_name,
font_library_,
font_file_mapping_,
freetype_engine::instance().get_mapping());
freetype_engine::get_mapping());
font_name_cache_.emplace(face_name,found);
}
if (!found)

View file

@ -291,7 +291,7 @@ bool Map::register_fonts(std::string const& dir, bool recurse)
bool Map::load_fonts()
{
bool result = false;
auto const& global_mapping = freetype_engine::instance().get_mapping();
auto const& global_mapping = freetype_engine::get_mapping();
for (auto const& kv : font_file_mapping_) // for every face-name -> idx/filepath
{
auto const& file_path = kv.second.second;

View file

@ -20,8 +20,8 @@ SECTION("registration") {
mapnik::logger::severity_type original_severity = logger.get_severity();
// grab references to global statics of registered/cached fonts
auto const& global_mapping = mapnik::freetype_engine::instance().get_mapping();
auto const& global_cache = mapnik::freetype_engine::instance().get_cache();
auto const& global_mapping = mapnik::freetype_engine::get_mapping();
auto const& global_cache = mapnik::freetype_engine::get_cache();
// mapnik.Map object has parallel structure for localized fonts
mapnik::Map m(1,1);
@ -62,11 +62,11 @@ SECTION("registration") {
std::vector<std::string> face_names;
std::string foo("foo");
// fake directories
REQUIRE( !mapnik::freetype_engine::instance().register_fonts(foo , true ) );
face_names = mapnik::freetype_engine::instance().face_names();
REQUIRE( !mapnik::freetype_engine::register_fonts(foo , true ) );
face_names = mapnik::freetype_engine::face_names();
REQUIRE( face_names.size() == 0 );
REQUIRE( !mapnik::freetype_engine::instance().register_fonts(foo) );
face_names = mapnik::freetype_engine::instance().face_names();
REQUIRE( !mapnik::freetype_engine::register_fonts(foo) );
face_names = mapnik::freetype_engine::face_names();
REQUIRE( face_names.size() == 0 );
// directories without fonts
@ -76,31 +76,31 @@ SECTION("registration") {
// an empty directory will not return true
// we need to register at least one font and not fail on any
// to return true
REQUIRE( mapnik::freetype_engine::instance().register_font(src) == false );
REQUIRE( mapnik::freetype_engine::instance().register_fonts(src, true) == false );
REQUIRE( mapnik::freetype_engine::instance().face_names().size() == 0 );
REQUIRE( mapnik::freetype_engine::register_font(src) == false );
REQUIRE( mapnik::freetype_engine::register_fonts(src, true) == false );
REQUIRE( mapnik::freetype_engine::face_names().size() == 0 );
// bogus, emtpy file that looks like font
REQUIRE( mapnik::freetype_engine::instance().register_font("test/data/fonts/fake.ttf") == false );
REQUIRE( mapnik::freetype_engine::instance().register_fonts("test/data/fonts/fake.ttf") == false );
REQUIRE( mapnik::freetype_engine::instance().face_names().size() == 0 );
REQUIRE( mapnik::freetype_engine::register_font("test/data/fonts/fake.ttf") == false );
REQUIRE( mapnik::freetype_engine::register_fonts("test/data/fonts/fake.ttf") == false );
REQUIRE( mapnik::freetype_engine::face_names().size() == 0 );
REQUIRE( mapnik::freetype_engine::instance().register_font("test/data/fonts/intentionally-broken.ttf") == false );
REQUIRE( mapnik::freetype_engine::instance().register_fonts("test/data/fonts/intentionally-broken.ttf") == false );
REQUIRE( mapnik::freetype_engine::instance().face_names().size() == 0 );
REQUIRE( mapnik::freetype_engine::register_font("test/data/fonts/intentionally-broken.ttf") == false );
REQUIRE( mapnik::freetype_engine::register_fonts("test/data/fonts/intentionally-broken.ttf") == false );
REQUIRE( mapnik::freetype_engine::face_names().size() == 0 );
// now restore the original severity
logger.set_severity(original_severity);
// single dejavu font in separate location
std::string dejavu_bold_oblique("test/data/fonts/DejaVuSansMono-BoldOblique.ttf");
REQUIRE( mapnik::freetype_engine::instance().register_font(dejavu_bold_oblique) );
face_names = mapnik::freetype_engine::instance().face_names();
REQUIRE( mapnik::freetype_engine::register_font(dejavu_bold_oblique) );
face_names = mapnik::freetype_engine::face_names();
REQUIRE( face_names.size() == 1 );
// now, inspect font mapping and confirm the correct 'DejaVu Sans Mono Bold Oblique' is registered
using font_file_mapping = std::map<std::string, std::pair<int,std::string> >;
font_file_mapping const& name2file = mapnik::freetype_engine::instance().get_mapping();
font_file_mapping const& name2file = mapnik::freetype_engine::get_mapping();
bool found_dejavu = false;
for (auto const& item : name2file)
{
@ -114,8 +114,8 @@ SECTION("registration") {
REQUIRE( found_dejavu );
// recurse to find all dejavu fonts
REQUIRE( mapnik::freetype_engine::instance().register_fonts(fontdir, true) );
face_names = mapnik::freetype_engine::instance().face_names();
REQUIRE( mapnik::freetype_engine::register_fonts(fontdir, true) );
face_names = mapnik::freetype_engine::face_names();
REQUIRE( face_names.size() == 22 );
// we should have re-registered 'DejaVu Sans Mono Bold Oblique' again,
@ -148,21 +148,21 @@ SECTION("registration") {
// check that we can correctly read a .ttc containing
// multiple valid faces
// https://github.com/mapnik/mapnik/issues/2274
REQUIRE( mapnik::freetype_engine::instance().register_font("test/data/fonts/NotoSans-Regular.ttc") );
face_names = mapnik::freetype_engine::instance().face_names();
REQUIRE( mapnik::freetype_engine::register_font("test/data/fonts/NotoSans-Regular.ttc") );
face_names = mapnik::freetype_engine::face_names();
REQUIRE( face_names.size() == 24 );
// now blindly register as many system fonts as possible
// the goal here to make sure we don't crash
// linux
mapnik::freetype_engine::instance().register_fonts("/usr/share/fonts/", true);
mapnik::freetype_engine::instance().register_fonts("/usr/local/share/fonts/", true);
mapnik::freetype_engine::register_fonts("/usr/share/fonts/", true);
mapnik::freetype_engine::register_fonts("/usr/local/share/fonts/", true);
// osx
mapnik::freetype_engine::instance().register_fonts("/Library/Fonts/", true);
mapnik::freetype_engine::instance().register_fonts("/System/Library/Fonts/", true);
mapnik::freetype_engine::register_fonts("/Library/Fonts/", true);
mapnik::freetype_engine::register_fonts("/System/Library/Fonts/", true);
// windows
mapnik::freetype_engine::instance().register_fonts("C:\\Windows\\Fonts", true);
face_names = mapnik::freetype_engine::instance().face_names();
mapnik::freetype_engine::register_fonts("C:\\Windows\\Fonts", true);
face_names = mapnik::freetype_engine::face_names();
REQUIRE( face_names.size() > 22 );
}
catch (std::exception const & ex)

View file

@ -174,7 +174,7 @@ int main(int argc, char** argv)
}
#endif
mapnik::freetype_engine::instance().register_fonts(vm["fonts"].as<std::string>(), true);
mapnik::freetype_engine::register_fonts(vm["fonts"].as<std::string>(), true);
mapnik::datasource_cache::instance().register_datasources(vm["plugins"].as<std::string>());
boost::filesystem::path output_dir(vm["output-dir"].as<std::string>());

View file

@ -104,7 +104,7 @@ int main (int argc,char** argv)
}
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
mapnik::freetype_engine::instance().register_fonts("./fonts",true);
mapnik::freetype_engine::register_fonts("./fonts",true);
mapnik::Map map(600,400);
mapnik::load_map(map,xml_file,true);
map.zoom_all();