2012-05-18 18:17:54 +00:00
|
|
|
#include <boost/version.hpp>
|
2013-06-03 02:28:24 +00:00
|
|
|
#include <mapnik/util/fs.hpp>
|
2010-07-15 23:09:33 +00:00
|
|
|
|
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
#include <mapnik/font_engine_freetype.hpp>
|
2013-05-25 00:21:55 +00:00
|
|
|
#include <vector>
|
2013-05-25 23:04:40 +00:00
|
|
|
#include <algorithm>
|
2010-07-15 23:09:33 +00:00
|
|
|
|
2013-05-26 00:55:41 +00:00
|
|
|
#include "utils.hpp"
|
|
|
|
|
2013-05-25 00:21:55 +00:00
|
|
|
int main(int argc, char** argv)
|
2010-07-15 23:09:33 +00:00
|
|
|
{
|
2013-05-25 00:21:55 +00:00
|
|
|
std::vector<std::string> args;
|
|
|
|
for (int i=1;i<argc;++i)
|
|
|
|
{
|
|
|
|
args.push_back(argv[i]);
|
|
|
|
}
|
|
|
|
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
try
|
|
|
|
{
|
2013-05-26 00:55:41 +00:00
|
|
|
|
|
|
|
BOOST_TEST(set_working_dir(args));
|
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
std::string fontdir("fonts/");
|
2010-07-15 23:09:33 +00:00
|
|
|
|
2013-06-03 02:28:24 +00:00
|
|
|
BOOST_TEST( mapnik::util::exists( fontdir ) );
|
|
|
|
BOOST_TEST( mapnik::util::is_directory( fontdir ) );
|
2010-07-15 23:09:33 +00:00
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
std::vector<std::string> face_names;
|
2010-07-15 23:09:33 +00:00
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
std::string foo("foo");
|
2010-07-15 23:09:33 +00:00
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
// fake directories
|
|
|
|
BOOST_TEST( !mapnik::freetype_engine::register_fonts(foo , true ) );
|
|
|
|
face_names = mapnik::freetype_engine::face_names();
|
|
|
|
BOOST_TEST( face_names.size() == 0 );
|
|
|
|
BOOST_TEST( !mapnik::freetype_engine::register_fonts(foo) );
|
|
|
|
face_names = mapnik::freetype_engine::face_names();
|
|
|
|
BOOST_TEST( face_names.size() == 0 );
|
2012-03-23 22:07:28 +00:00
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
// directories without fonts
|
|
|
|
std::string src("src");
|
|
|
|
// an empty directory will not return true
|
|
|
|
// we need to register at least one font and not fail on any
|
|
|
|
// to return true
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::register_font(src) == false );
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::register_fonts(src, true) == false );
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
|
2012-03-23 22:07:28 +00:00
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
// bogus, emtpy file that looks like font
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/fake.ttf") == false );
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/fake.ttf") == false );
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
|
2012-03-23 22:07:28 +00:00
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/intentionally-broken.ttf") == false );
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/intentionally-broken.ttf") == false );
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
|
2010-07-15 23:09:33 +00:00
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
// register unifont, since we know it sits in the root fonts/ dir
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir) );
|
|
|
|
face_names = mapnik::freetype_engine::face_names();
|
|
|
|
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
|
|
|
|
BOOST_TEST( face_names.size() > 0 );
|
|
|
|
BOOST_TEST( face_names.size() == 1 );
|
2010-07-15 23:09:33 +00:00
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
// re-register unifont, should not have any affect
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, false) );
|
|
|
|
face_names = mapnik::freetype_engine::face_names();
|
|
|
|
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
|
|
|
|
BOOST_TEST( face_names.size() == 1 );
|
2010-07-15 23:09:33 +00:00
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
// register a single dejavu font
|
|
|
|
std::string dejavu_bold_oblique("tests/data/fonts/DejaVuSansMono-BoldOblique.ttf");
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::register_font(dejavu_bold_oblique) );
|
|
|
|
face_names = mapnik::freetype_engine::face_names();
|
|
|
|
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
|
|
|
|
BOOST_TEST( face_names.size() == 2 );
|
2010-07-15 23:09:33 +00:00
|
|
|
|
2012-12-06 23:15:21 +00:00
|
|
|
// recurse to find all dejavu fonts
|
|
|
|
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, true) );
|
|
|
|
face_names = mapnik::freetype_engine::face_names();
|
|
|
|
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
|
|
|
|
BOOST_TEST( face_names.size() == 22 );
|
|
|
|
}
|
|
|
|
catch (std::exception const & ex)
|
|
|
|
{
|
|
|
|
std::clog << "C++ fonts registration problem: " << ex.what() << "\n";
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
2012-04-17 05:33:37 +00:00
|
|
|
|
|
|
|
if (!::boost::detail::test_errors()) {
|
2013-05-25 00:21:55 +00:00
|
|
|
if (quiet) std::clog << "\x1b[1;32m.\x1b[0m";
|
|
|
|
else std::clog << "C++ fonts registration: \x1b[1;32m✓ \x1b[0m\n";
|
2012-05-18 18:17:54 +00:00
|
|
|
#if BOOST_VERSION >= 104600
|
2012-05-15 18:45:55 +00:00
|
|
|
::boost::detail::report_errors_remind().called_report_errors_function = true;
|
2012-05-18 18:17:54 +00:00
|
|
|
#endif
|
2012-04-17 05:33:37 +00:00
|
|
|
} else {
|
|
|
|
return ::boost::report_errors();
|
|
|
|
}
|
2010-07-15 23:09:33 +00:00
|
|
|
}
|