per map load cache if a fonts is known as valid

This commit is contained in:
Dane Springmeyer 2014-10-01 20:59:05 -07:00
parent 687a33575c
commit 0efb6964ef

View file

@ -89,6 +89,9 @@ public:
filename_(filename),
font_library_(),
font_file_mapping_(map.get_font_file_mapping()),
font_name_cache_(),
file_sources_(),
fontsets_(),
xml_base_path_() {}
void parse_map(Map & map, xml_node const& node, std::string const& base_path);
@ -131,6 +134,7 @@ private:
std::map<std::string,parameters> datasource_templates_;
font_library font_library_;
freetype_engine::font_file_mapping_type & font_file_mapping_;
std::map<std::string,bool> font_name_cache_;
std::map<std::string,std::string> file_sources_;
std::map<std::string,font_set> fontsets_;
std::string xml_base_path_;
@ -512,24 +516,34 @@ void map_parser::parse_fontset(Map & map, xml_node const& node)
}
}
bool map_parser::parse_font(font_set &fset, xml_node const& f)
bool map_parser::parse_font(font_set & fset, xml_node const& f)
{
optional<std::string> face_name = f.get_opt_attr<std::string>("face-name");
if (face_name)
optional<std::string> has_face_name = f.get_opt_attr<std::string>("face-name");
if (has_face_name)
{
// TODO - cache results to avoid repeated opens
if (freetype_engine::can_open(*face_name,
font_library_,
font_file_mapping_,
freetype_engine::get_mapping()))
std::string face_name = *has_face_name;
bool found = false;
auto itr = font_name_cache_.find(face_name);
if (itr != font_name_cache_.end())
{
fset.add_face_name(*face_name);
found = itr->second;
}
else
{
found = freetype_engine::can_open(face_name,
font_library_,
font_file_mapping_,
freetype_engine::get_mapping());
font_name_cache_.emplace(face_name,found);
}
if (found)
{
fset.add_face_name(face_name);
return true;
}
else if (strict_)
{
throw config_error("Failed to find font face '" +
*face_name + "'");
throw config_error("Failed to find font face '" + face_name + "'");
}
}
else
@ -1523,11 +1537,21 @@ void map_parser::parse_pair_layout(group_symbolizer_properties & prop, xml_node
void map_parser::ensure_font_face(std::string const& face_name)
{
// TODO - cache results to avoid repeated opens
if (!freetype_engine::can_open(face_name,
font_library_,
font_file_mapping_,
freetype_engine::get_mapping()))
bool found = false;
auto itr = font_name_cache_.find(face_name);
if (itr != font_name_cache_.end())
{
found = itr->second;
}
else
{
found = freetype_engine::can_open(face_name,
font_library_,
font_file_mapping_,
freetype_engine::get_mapping());
font_name_cache_.emplace(face_name,found);
}
if (!found)
{
throw config_error("Failed to find font face '" +
face_name + "'");