simplify code in create_face
This commit is contained in:
parent
11d8f40342
commit
4541a2207b
1 changed files with 20 additions and 25 deletions
|
@ -267,7 +267,6 @@ face_ptr freetype_engine::create_face(std::string const& family_name,
|
||||||
// look for font registered on specific map
|
// look for font registered on specific map
|
||||||
if (itr != font_file_mapping.end())
|
if (itr != font_file_mapping.end())
|
||||||
{
|
{
|
||||||
found_font_file = true;
|
|
||||||
auto mem_font_itr = font_cache.find(itr->second.second);
|
auto mem_font_itr = font_cache.find(itr->second.second);
|
||||||
// if map has font already in memory, use it
|
// if map has font already in memory, use it
|
||||||
if (mem_font_itr != font_cache.end())
|
if (mem_font_itr != font_cache.end())
|
||||||
|
@ -278,37 +277,34 @@ face_ptr freetype_engine::create_face(std::string const& family_name,
|
||||||
}
|
}
|
||||||
// we don't add to cache here because the map and its font_cache
|
// we don't add to cache here because the map and its font_cache
|
||||||
// must be immutable during rendering for predictable thread safety
|
// must be immutable during rendering for predictable thread safety
|
||||||
|
found_font_file = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// otherwise search global registry
|
// otherwise search global registry
|
||||||
itr = global_font_file_mapping_.find(family_name);
|
itr = global_font_file_mapping_.find(family_name);
|
||||||
if (itr != global_font_file_mapping_.end())
|
if (itr != global_font_file_mapping_.end())
|
||||||
{
|
|
||||||
found_font_file = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found_font_file)
|
|
||||||
{
|
{
|
||||||
auto mem_font_itr = global_memory_fonts_.find(itr->second.second);
|
auto mem_font_itr = global_memory_fonts_.find(itr->second.second);
|
||||||
// if font already in memory, use it
|
// if font already in memory, use it
|
||||||
if (mem_font_itr != global_memory_fonts_.end())
|
if (mem_font_itr != global_memory_fonts_.end())
|
||||||
{
|
{
|
||||||
face_ptr face = library.face_from_memory(mem_font_itr->second.first.get(),
|
return library.face_from_memory(mem_font_itr->second.first.get(),
|
||||||
mem_font_itr->second.second,
|
mem_font_itr->second.second,
|
||||||
itr->second.first);
|
itr->second.first);
|
||||||
if (face) return face;
|
|
||||||
}
|
}
|
||||||
else
|
found_font_file = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if we found file file but it is not yet in memory
|
||||||
|
if (found_font_file)
|
||||||
{
|
{
|
||||||
// otherwise load into memory and cache globally
|
|
||||||
#ifdef MAPNIK_THREADSAFE
|
|
||||||
mapnik::scoped_lock lock(mutex_);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mapnik::util::file file(itr->second.second);
|
mapnik::util::file file(itr->second.second);
|
||||||
if (file.open())
|
if (file.open())
|
||||||
{
|
{
|
||||||
|
#ifdef MAPNIK_THREADSAFE
|
||||||
|
mapnik::scoped_lock lock(mutex_);
|
||||||
|
#endif
|
||||||
auto result = global_memory_fonts_.emplace(itr->second.second, std::make_pair(std::move(file.data()),file.size()));
|
auto result = global_memory_fonts_.emplace(itr->second.second, std::make_pair(std::move(file.data()),file.size()));
|
||||||
face_ptr face = library.face_from_memory(result.first->second.first.get(),
|
face_ptr face = library.face_from_memory(result.first->second.first.get(),
|
||||||
result.first->second.second,
|
result.first->second.second,
|
||||||
|
@ -321,7 +317,6 @@ face_ptr freetype_engine::create_face(std::string const& family_name,
|
||||||
return face;
|
return face;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return face_ptr();
|
return face_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue