+ fix memory font loading

This commit is contained in:
artemp 2013-04-11 10:57:33 +01:00
parent 5de4636be8
commit 37b74f1e15

View file

@ -231,19 +231,25 @@ face_ptr freetype_engine::create_face(std::string const& family_name)
else
{
// load font into memory
#ifdef MAPNIK_THREADSAFE
mutex::scoped_lock lock(mutex_);
#endif
std::ifstream is(itr->second.second.c_str() , std::ios::binary);
std::string buffer((std::istreambuf_iterator<char>(is)),
std::istreambuf_iterator<char>());
std::pair<std::map<std::string,std::string>::iterator,bool> result
= memory_fonts_.insert(std::make_pair(itr->second.second, buffer));
FT_Error error = FT_New_Memory_Face (library_,
(FT_Byte const*) buffer.c_str(),
(FT_Byte const*) result.first->second.c_str(),
buffer.size(),
itr->second.first,
&face);
if (!error)
if (!error) return boost::make_shared<font_face>(face);
else
{
memory_fonts_.insert(std::make_pair(itr->second.second, buffer));
return boost::make_shared<font_face>(face);
// we can't load font, erase it.
memory_fonts_.erase(result.first);
}
}
}