face_entity* glyph_freetype_provider::get_face_entity(const gameswf::tu_string& fontname, bool is_bold, bool is_italic) { // form hash key gameswf::tu_string key = fontname; if (is_bold) { key += "B"; } if (is_italic) { key += "I"; } // first try to find from hash gc_ptr<face_entity> fe; if (m_face_entity.get(key, &fe)) { return fe.get_ptr(); } gameswf::tu_string font_filename; if (get_fontfile(fontname, font_filename, is_bold, is_italic) == false) { log_error("can't find font file '%s'\n", fontname.c_str()); m_face_entity.add(key, NULL); return NULL; } FT_Face face = NULL; FT_New_Face(m_lib, font_filename.c_str(), 0, &face); if (face) { if (is_bold) { face->style_flags |= FT_STYLE_FLAG_BOLD; } if (is_italic) { face->style_flags |= FT_STYLE_FLAG_ITALIC; } fe = new face_entity(face); m_face_entity.add(key, fe); } else { log_error("some error opening font '%s'\n", font_filename.c_str()); } return fe.get_ptr(); }
face_entity* glyph_provider::get_face_entity(const tu_string& fontname, bool is_bold, bool is_italic) { // form hash key tu_string key = fontname; if (is_bold) { key += "B"; } if (is_italic) { key += "I"; } // first try to find from hash smart_ptr<face_entity> fe; if (m_face_entity.get(key, &fe)) { return fe.get_ptr(); } tu_string font_filename; if (get_fontfile(fontname, font_filename, is_bold, is_italic) == false) { log_error("can't find font file '%s'\n", fontname.c_str()); m_face_entity.add(key, NULL); return NULL; } FT_Face face = NULL; FT_New_Face(m_lib, font_filename.c_str(), 0, &face); if (face) { fe = new face_entity(face); m_face_entity.add(key, fe); } else { log_error("some error opening font '%s'\n", font_filename.c_str()); } return fe.get_ptr(); }