From 9f19fa8943428653b52479215ec3c6cf945d9cf7 Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 1 Jun 2017 12:23:13 +0200 Subject: [PATCH] freetype_engine : revert back to original APIs usage. This reverts commit 1c101c324371d514ecfa87866ee4ad7773b61db8. --- benchmark/test_face_ptr_creation.cpp | 27 ++++++----- benchmark/test_font_registration.cpp | 4 +- benchmark/test_rendering.cpp | 2 +- benchmark/test_rendering_shared_map.cpp | 2 +- demo/c++/rundemo.cpp | 2 +- src/font_engine_freetype.cpp | 6 --- src/load_map.cpp | 12 ++--- src/map.cpp | 4 +- test/standalone/font_registration_test.cpp | 56 +++++++++++----------- test/visual/run.cpp | 2 +- utils/mapnik-render/mapnik-render.cpp | 2 +- 11 files changed, 57 insertions(+), 62 deletions(-) diff --git a/benchmark/test_face_ptr_creation.cpp b/benchmark/test_face_ptr_creation.cpp index 0123fffc2..186b2ee0f 100644 --- a/benchmark/test_face_ptr_creation.cpp +++ b/benchmark/test_face_ptr_creation.cpp @@ -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 idx/filepath { - auto const& file_path = kv.second.second; + auto const& file_path = kv.second.second; // do not attemp to re-cache in memory if (font_memory_cache_.find(file_path) != font_memory_cache_.end()) { diff --git a/test/standalone/font_registration_test.cpp b/test/standalone/font_registration_test.cpp index a40e7d4bd..a5ba0b271 100644 --- a/test/standalone/font_registration_test.cpp +++ b/test/standalone/font_registration_test.cpp @@ -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 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 >; - 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) diff --git a/test/visual/run.cpp b/test/visual/run.cpp index f935307f4..587727906 100644 --- a/test/visual/run.cpp +++ b/test/visual/run.cpp @@ -174,7 +174,7 @@ int main(int argc, char** argv) } #endif - mapnik::freetype_engine::instance().register_fonts(vm["fonts"].as(), true); + mapnik::freetype_engine::register_fonts(vm["fonts"].as(), true); mapnik::datasource_cache::instance().register_datasources(vm["plugins"].as()); boost::filesystem::path output_dir(vm["output-dir"].as()); diff --git a/utils/mapnik-render/mapnik-render.cpp b/utils/mapnik-render/mapnik-render.cpp index e6ce02590..c172995c7 100644 --- a/utils/mapnik-render/mapnik-render.cpp +++ b/utils/mapnik-render/mapnik-render.cpp @@ -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();