2013-11-19 20:23:37 +00:00
|
|
|
#include "bench_framework.hpp"
|
|
|
|
#include <mapnik/font_engine_freetype.hpp>
|
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
|
|
|
class test : public benchmark::test_case
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
test(mapnik::parameters const& params)
|
|
|
|
: test_case(params) {}
|
|
|
|
bool validate() const
|
|
|
|
{
|
2014-09-25 20:09:05 +00:00
|
|
|
std::size_t count = 0;
|
2017-06-01 10:23:13 +00:00
|
|
|
std::size_t expected_count = mapnik::freetype_engine::face_names().size();
|
2014-09-27 02:54:07 +00:00
|
|
|
mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
|
|
|
|
mapnik::freetype_engine::font_memory_cache_type font_cache;
|
2014-10-02 03:03:03 +00:00
|
|
|
mapnik::font_library library;
|
2017-06-01 10:23:13 +00:00
|
|
|
for (std::string const& name : mapnik::freetype_engine::face_names())
|
2014-09-25 20:09:05 +00:00
|
|
|
{
|
2017-06-01 10:23:13 +00:00
|
|
|
mapnik::face_ptr f = mapnik::freetype_engine::create_face(name,
|
2014-10-02 03:03:03 +00:00
|
|
|
library,
|
|
|
|
font_file_mapping,
|
|
|
|
font_cache,
|
2017-06-01 10:23:13 +00:00
|
|
|
mapnik::freetype_engine::get_mapping(),
|
|
|
|
mapnik::freetype_engine::get_cache());
|
2014-09-25 20:09:05 +00:00
|
|
|
if (f) ++count;
|
|
|
|
}
|
|
|
|
return count == expected_count;
|
2013-11-19 20:23:37 +00:00
|
|
|
}
|
2014-12-12 16:59:45 +00:00
|
|
|
bool operator()() const
|
2013-11-19 20:23:37 +00:00
|
|
|
{
|
2017-06-01 10:23:13 +00:00
|
|
|
std::size_t expected_count = mapnik::freetype_engine::face_names().size();
|
2013-11-19 20:23:37 +00:00
|
|
|
for (unsigned i=0;i<iterations_;++i)
|
|
|
|
{
|
2014-09-25 20:09:05 +00:00
|
|
|
std::size_t count = 0;
|
2014-09-27 02:54:07 +00:00
|
|
|
mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
|
|
|
|
mapnik::freetype_engine::font_memory_cache_type font_cache;
|
2014-10-02 03:03:03 +00:00
|
|
|
mapnik::font_library library;
|
2017-06-01 10:23:13 +00:00
|
|
|
for (std::string const& name : mapnik::freetype_engine::face_names())
|
2013-11-19 20:23:37 +00:00
|
|
|
{
|
2017-06-01 10:23:13 +00:00
|
|
|
mapnik::face_ptr f = mapnik::freetype_engine::create_face(name,
|
2014-10-02 03:03:03 +00:00
|
|
|
library,
|
|
|
|
font_file_mapping,
|
|
|
|
font_cache,
|
2017-06-01 10:23:13 +00:00
|
|
|
mapnik::freetype_engine::get_mapping(),
|
|
|
|
mapnik::freetype_engine::get_cache());
|
2013-11-19 20:23:37 +00:00
|
|
|
if (f) ++count;
|
|
|
|
}
|
2014-09-25 20:09:05 +00:00
|
|
|
if (count != expected_count) {
|
|
|
|
std::clog << "warning: face creation not working as expected\n";
|
|
|
|
}
|
2013-11-19 20:23:37 +00:00
|
|
|
}
|
2014-12-12 16:59:45 +00:00
|
|
|
return true;
|
2013-11-19 20:23:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
benchmark::handle_args(argc,argv,params);
|
2017-06-01 10:23:13 +00:00
|
|
|
bool success = mapnik::freetype_engine::register_fonts("./fonts", true);
|
2013-11-19 20:23:37 +00:00
|
|
|
if (!success) {
|
|
|
|
std::clog << "warning, did not register any new fonts!\n";
|
|
|
|
return -1;
|
2017-06-01 10:23:13 +00:00
|
|
|
}
|
|
|
|
std::size_t face_count = mapnik::freetype_engine::face_names().size();
|
2013-11-19 20:23:37 +00:00
|
|
|
test test_runner(params);
|
2014-09-25 20:09:05 +00:00
|
|
|
return run(test_runner,(boost::format("font_engine: creating %ld faces") % (face_count)).str());
|
2013-11-19 20:23:37 +00:00
|
|
|
}
|
2017-06-01 10:23:13 +00:00
|
|
|
|