adding support for multiple fonts in one font file, for instance .ttc

This commit is contained in:
cpsandbox 2012-01-08 21:55:18 -08:00
parent 1b3d2324de
commit e75f00cdf4

View file

@ -79,7 +79,12 @@ bool freetype_engine::register_font(std::string const& file_name)
}
FT_Face face;
error = FT_New_Face (library,file_name.c_str(),0,&face);
// fome font files have multiple fonts in a file
// the count is in the 'root' face library[0]
// see the FT_FaceRec in freetype.h
for ( int i = 0; face == 0 || i < face->num_faces; i++ ) {
// if face is null then this is the first face
error = FT_New_Face (library,file_name.c_str(),i,&face);
if (error)
{
FT_Done_FreeType(library);
@ -91,8 +96,8 @@ bool freetype_engine::register_font(std::string const& file_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;
//FT_Done_FreeType(library);
//return true;
} else {
FT_Done_Face(face);
FT_Done_FreeType(library);
@ -101,6 +106,8 @@ bool freetype_engine::register_font(std::string const& file_name)
<< file_name << "'";
throw std::runtime_error(s.str());
}
}
FT_Done_FreeType(library);
return true;
}