+ #1177 via @springmeyer

(TODO: check if loading the whole font file is required for registering)
This commit is contained in:
artemp 2013-06-03 09:15:37 +01:00
parent 19ce56b051
commit f4d2fbac43

View File

@ -30,6 +30,7 @@
#include <mapnik/pixel_position.hpp>
#include <mapnik/font_util.hpp>
#include <mapnik/util/fs.hpp>
#include <mapnik/utils.hpp>
// boost
#include <boost/algorithm/string.hpp>
@ -102,7 +103,24 @@ bool freetype_engine::register_font(std::string const& file_name)
// see the FT_FaceRec in freetype.h
for ( int i = 0; face == 0 || i < num_faces; i++ ) {
// if face is null then this is the first face
error = FT_New_Face (library,file_name.c_str(),i,&face);
try
{
#ifdef _WINDOWS
std::ifstream is(mapnik::utf8_to_utf16(file_name), std::ios::binary);
#else
std::ifstream is(file_name.c_str() , std::ios::binary);
#endif
std::string buffer((std::istreambuf_iterator<char>(is)),
std::istreambuf_iterator<char>());
if (buffer.size() <= 0)
{
break;
}
error = FT_New_Memory_Face (library,
(FT_Byte const*) buffer.c_str(),
buffer.size(),
i,
&face);
if (error)
{
break;
@ -135,6 +153,9 @@ bool freetype_engine::register_font(std::string const& file_name)
MAPNIK_LOG_DEBUG(font_engine_freetype) << "freetype_engine: " << s.str();
}
} catch (std::exception const&) {
break;
}
}
if (face)
FT_Done_Face(face);
@ -234,7 +255,11 @@ face_ptr freetype_engine::create_face(std::string const& family_name)
#ifdef MAPNIK_THREADSAFE
mutex::scoped_lock lock(mutex_);
#endif
#ifdef _WINDOWS
std::ifstream is(mapnik::utf8_to_utf16(itr->second.second), std::ios::binary);
#else
std::ifstream is(itr->second.second.c_str() , std::ios::binary);
#endif
std::string buffer((std::istreambuf_iterator<char>(is)),
std::istreambuf_iterator<char>());
std::pair<std::map<std::string,std::string>::iterator,bool> result