Merge branch 'master' of github.com:mapnik/mapnik

This commit is contained in:
kunitoki 2013-04-08 11:32:10 +02:00
commit 1bcb9784ab
5 changed files with 104 additions and 24 deletions

View File

@ -708,6 +708,39 @@ struct test12
}
};
#include <mapnik/font_engine_freetype.hpp>
#include <boost/format.hpp>
struct test13
{
unsigned iter_;
unsigned threads_;
test13(unsigned iterations,
unsigned threads)
: iter_(iterations),
threads_(threads)
{}
bool validate()
{
return true;
}
void operator()()
{
mapnik::freetype_engine engine;
unsigned long count = 0;
for (unsigned i=0;i<iter_;++i)
{
BOOST_FOREACH( std::string const& name, mapnik::freetype_engine::face_names())
{
mapnik::face_ptr f = engine.create_face(name);
if (f) ++count;
}
}
}
};
int main( int argc, char** argv)
{
if (argc > 0) {
@ -864,6 +897,12 @@ int main( int argc, char** argv)
benchmark(runner,"clipping polygon with mapnik::polygon_clipper");
}
{
mapnik::freetype_engine::register_fonts("./fonts", true);
unsigned face_count = mapnik::freetype_engine::face_names().size();
test13 runner(1000,10);
benchmark(runner, (boost::format("font_engihe: created %ld faces in ") % (face_count * 1000 * 10)).str());
}
std::cout << "...benchmark done\n";
return 0;
}

View File

@ -146,6 +146,7 @@ private:
static boost::mutex mutex_;
#endif
static std::map<std::string,std::pair<int,std::string> > name2file_;
static std::map<std::string, std::string> memory_fonts_;
};
template <typename T>

View File

@ -114,11 +114,11 @@ bool freetype_engine::register_font(std::string const& file_name)
if (face->family_name && face->style_name)
{
std::string name = std::string(face->family_name) + " " + std::string(face->style_name);
// skip fonts with leading . in name
// skip fonts with leading . in the name
if (!boost::algorithm::starts_with(name,"."))
{
success = true;
name2file_.insert(std::make_pair(name, std::make_pair(i,file_name)));
success = true;
}
}
else
@ -210,18 +210,41 @@ std::map<std::string,std::pair<int,std::string> > const& freetype_engine::get_ma
face_ptr freetype_engine::create_face(std::string const& family_name)
{
std::map<std::string, std::pair<int,std::string> >::iterator itr;
std::map<std::string, std::pair<int,std::string> >::const_iterator itr;
itr = name2file_.find(family_name);
if (itr != name2file_.end())
{
FT_Face face;
FT_Error error = FT_New_Face (library_,
itr->second.second.c_str(),
itr->second.first,
&face);
if (!error)
std::map<std::string,std::string>::const_iterator mem_font_itr = memory_fonts_.find(itr->second.second);
if (mem_font_itr != memory_fonts_.end()) // memory font
{
return boost::make_shared<font_face>(face);
FT_Error error = FT_New_Memory_Face(library_,
(FT_Byte const*) mem_font_itr->second.c_str(), //buffer
mem_font_itr->second.size(), // size
itr->second.first, // face index
&face);
if (!error) return boost::make_shared<font_face>(face);
}
else
{
// load font into memory
std::ifstream is(itr->second.second.c_str() , std::ios::binary);
std::string buffer((std::istreambuf_iterator<char>(is)),
std::istreambuf_iterator<char>());
FT_Error error = FT_New_Memory_Face (library_,
(FT_Byte const*) buffer.c_str(),
buffer.size(),
itr->second.first,
&face);
if (!error)
{
memory_fonts_.insert(std::make_pair(itr->second.second, buffer));
return boost::make_shared<font_face>(face);
}
}
}
return face_ptr();
@ -659,6 +682,8 @@ void text_renderer<T>::render_id(mapnik::value_integer feature_id,
boost::mutex freetype_engine::mutex_;
#endif
std::map<std::string,std::pair<int,std::string> > freetype_engine::name2file_;
std::map<std::string,std::string> freetype_engine::memory_fonts_;
template text_renderer<image_32>::text_renderer(image_32&,
face_manager<freetype_engine>&,
halo_rasterizer_e,

View File

@ -12,17 +12,17 @@ namespace sys = boost::system;
int main( int, char*[] )
{
std::string blank;
std::string should_throw;
boost::optional<std::string> type;
try
{
blank = "./tests/cpp_tests/data/blank.jpg";
BOOST_TEST( fs::exists( blank ) );
type = mapnik::type_from_filename(blank);
should_throw = "./tests/cpp_tests/data/blank.jpg";
BOOST_TEST( fs::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw);
BOOST_TEST( type );
try
{
std::auto_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(blank,*type));
std::auto_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type));
BOOST_TEST( false );
}
catch (std::exception const&)
@ -30,13 +30,13 @@ int main( int, char*[] )
BOOST_TEST( true );
}
blank = "./tests/cpp_tests/data/blank.png";
BOOST_TEST( fs::exists( blank ) );
type = mapnik::type_from_filename(blank);
should_throw = "./tests/cpp_tests/data/blank.png";
BOOST_TEST( fs::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw);
BOOST_TEST( type );
try
{
std::auto_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(blank,*type));
std::auto_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type));
BOOST_TEST( false );
}
catch (std::exception const&)
@ -44,19 +44,34 @@ int main( int, char*[] )
BOOST_TEST( true );
}
blank = "./tests/cpp_tests/data/blank.tiff";
BOOST_TEST( fs::exists( blank ) );
type = mapnik::type_from_filename(blank);
should_throw = "./tests/cpp_tests/data/blank.tiff";
BOOST_TEST( fs::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw);
BOOST_TEST( type );
try
{
std::auto_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(blank,*type));
std::auto_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type));
BOOST_TEST( false );
}
catch (std::exception const&)
{
BOOST_TEST( true );
}
should_throw = "./tests/data/images/xcode-CgBI.png";
BOOST_TEST( fs::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw);
BOOST_TEST( type );
try
{
std::auto_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type));
BOOST_TEST( false );
}
catch (std::exception const&)
{
BOOST_TEST( true );
}
}
catch (std::exception const & ex)
{

View File

@ -4,8 +4,8 @@ import sys
try:
import nose
except ImportError:
sys.stderr.write("Unable to run python tests: the third party 'nose' module is required\nTo install 'nose' do:\n\tsudo pip install nose (or on debian systems: apt-get install python-nose\n")
except ImportError, e:
sys.stderr.write("Unable to run python tests: the third party 'nose' module is required\nTo install 'nose' do:\n\tsudo pip install nose (or on debian systems: apt-get install python-nose): %s\n" % e)
sys.exit(1)
from python_tests.utilities import TodoPlugin