throw if we encounter a font file which lacks any referencable names (freetype family_name and style_name) making it basically invalid

This commit is contained in:
Dane Springmeyer 2011-06-24 00:51:21 +00:00
parent d403cbf4bc
commit 45965381af
2 changed files with 19 additions and 4 deletions

View file

@ -14,6 +14,8 @@ For a complete change history, see the SVN log.
Mapnik Trunk
------------
- Throw an error during registration for fonts which Freetype2 does not report a family or style name (r2985).
- Fixed quoting syntax for "table"."attribute" in PostGIS plugin (previously if table aliases were used quoting like "table.attribute" would cause query failure) (r2979).
- Added the ability to control the PostGIS feature id by suppling a key_field to reference and integer attribute name (r2979).

View file

@ -27,6 +27,7 @@
// boost
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <sstream>
namespace mapnik
{
@ -78,10 +79,22 @@ bool freetype_engine::register_font(std::string const& file_name)
FT_Done_FreeType(library);
return false;
}
std::string name = std::string(face->family_name) + " " + std::string(face->style_name);
name2file_.insert(std::make_pair(name,file_name));
FT_Done_Face(face );
FT_Done_FreeType(library);
// some fonts can lack names, skip them
// http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_FaceRec
if (face->family_name && face->style_name) {
std::string name = std::string(face->family_name) + " " + std::string(face->style_name);
name2file_.insert(std::make_pair(name,file_name));
FT_Done_Face(face);
FT_Done_FreeType(library);
return true;
} else {
FT_Done_Face(face);
FT_Done_FreeType(library);
std::ostringstream s;
s << "Error: unable to load invalid font file which lacks identifiable family and style name: '"
<< file_name << "'";
throw std::runtime_error(s.str());
}
return true;
}