From 45965381aff2031463d1475ac5738dd789e5a954 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Fri, 24 Jun 2011 00:51:21 +0000 Subject: [PATCH] throw if we encounter a font file which lacks any referencable names (freetype family_name and style_name) making it basically invalid --- CHANGELOG | 2 ++ src/font_engine_freetype.cpp | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 83553778d..3ca6f42ce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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). diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index 54f75151b..e1ed26d78 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -27,6 +27,7 @@ // boost #include #include +#include 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; }