static TTF_Font *load_ttf_font(const std::string& path, uint16 style, int16 size) { // already loaded? increment reference counter and return pointer ttf_font_key_t search_key(path, style, size); ttf_font_list_t::iterator it = ttf_font_list.find(search_key); if (it != ttf_font_list.end()) { TTF_Font *font = it->second.first; it->second.second++; return font; } TTF_Font *font = 0; builtin_fonts_t::iterator j = builtin_fonts.find(path); if (j != builtin_fonts.end()) { font = TTF_OpenFontRW(SDL_RWFromConstMem(j->second.data, j->second.size), 0, size); } else { short SavedType, SavedError = get_game_error(&SavedType); FileSpecifier fileSpec(path); OpenedFile file; if (fileSpec.Open(file)) { font = TTF_OpenFontRW(file.TakeRWops(), 1, size); } set_game_error(SavedType, SavedError); } if (font) { int ttf_style = TTF_STYLE_NORMAL; if (style & styleBold) ttf_style |= TTF_STYLE_BOLD; if (style & styleItalic) ttf_style |= TTF_STYLE_ITALIC; TTF_SetFontStyle(font, ttf_style); #ifdef TTF_HINTING_LIGHT if (environment_preferences->smooth_text) TTF_SetFontHinting(font, TTF_HINTING_LIGHT); else TTF_SetFontHinting(font, TTF_HINTING_MONO); #endif ttf_font_key_t key(path, style, size); ref_counted_ttf_font_t value(font, 1); ttf_font_list[key] = value; } return font; }
void ttf_font_info::_unload() { for (int i = 0; i < styleUnderline; ++i) { ttf_font_list_t::iterator it = ttf_font_list.find(m_keys[i]); if (it != ttf_font_list.end()) { --(it->second.second); if (it->second.second <= 0) { TTF_CloseFont(it->second.first); ttf_font_list.erase(m_keys[i]); } } m_styles[i] = 0; } delete this; }
static TTF_Font *load_ttf_font(const std::string& path, uint16 style, int16 size) { // already loaded? increment reference counter and return pointer ttf_font_key_t search_key(path, style, size); ttf_font_list_t::iterator it = ttf_font_list.find(search_key); if (it != ttf_font_list.end()) { TTF_Font *font = it->second.first; it->second.second++; return font; } TTF_Font *font = 0; TTF_Init(); // Load AlephOne Default Font. path is "mono" // Japanese Font cannot render as embeded font. // If Fonts.ttf is missing, Load from System Font const string fontPath[] = { FONT_PATH, #if defined(__WIN32__) // Path to the below Windows directory // for Windows 7 (Meiryo Bold) "C:/Windows/winsxs/x86_microsoft-windows-f..truetype-meiryobold_31bf3856ad364e35_6.1.7600.16385_none_cd23f5e0d8f9c6fa/meiryob.ttc", "C:/Windows/winsxs/amd64_microsoft-windows-f..truetype-meiryobold_31bf3856ad364e35_6.1.7600.16385_none_2942916491573830/meiryob.ttc", // for Windows Vista "C:/Windows/Fonts/meiryob.ttc", // for less than Windows XP (MS Gothic) "C:/Windows/fonts/msgothic.ttc", //#elif defined(__MACOS__) #else // for MacOS (Hiragino Kaku Gothic Pro W6) "/System/Library/Fonts/ヒラギノ角ゴ ProN W6.otf", "/System/Library/Fonts/Hiragino Kaku Gothic Pro W6.otf", "/System/Library/Fonts/Cache/HiraginoKakuGothicProNW6.otf" // for iOS //#else // for Linux "/usr/share/fonts/truetype/vlgothic/VL-Gothic-Regular.ttf", "/usr/X11R6/lib/X11/fonts/TrueType/VL-Gothic-Regular.ttf", "/usr/X11/lib/X11/fonts/truetype/VL-Gothic-Regular.ttf", "/usr/share/fonts/truetype/takao/TakaoExGothic.ttf" "/usr/share/fonts/ja-ipafonts/ipag.ttc", "/usr/share/fonts/TrueType/mika.ttf", "/usr/X11R6/lib/X11/fonts/TrueType/mika.ttf", "/usr/X11R6/lib/X11/fonts/truetype/sazanami-gothic.ttf", "/usr/X11/lib/X11/fonts/truetype/sazanami-gothic.ttf", "/usr/share/fonts/TrueType/sazanami-gothic.ttf", "/usr/X11R6/lib/X11/fonts/TrueType/sazanami-gothic.ttf", "/usr/share/fonts/truetype/sazanami-gothic.ttf", "/usr/share/fonts/TrueType/FS-Gothic-gs.ttf", "/usr/X11R6/lib/X11/fonts/TrueType/FS-Gothic.ttf", "/usr/share/fonts/TrueType/gt200001.ttf", "/usr/X11R6/lib/X11/fonts/TrueType/gt200001.ttf", #endif }; for ( int i=0; i < sizeof(fontPath)/sizeof(fontPath[0]); i++ ) { const char* file = fontPath[i].c_str(); font = TTF_OpenFont(file , size); if ( !font ) { continue; } else { break; } } if( !font ){ fprintf(stderr, "cannot open font! died\n"); exit(1); } if (font) { int ttf_style = TTF_STYLE_NORMAL; if (style & styleBold) ttf_style |= TTF_STYLE_BOLD; if (style & styleItalic) ttf_style |= TTF_STYLE_ITALIC; TTF_SetFontStyle(font, ttf_style); #ifdef TTF_HINTING_LIGHT if (environment_preferences->smooth_text) TTF_SetFontHinting(font, TTF_HINTING_LIGHT); else TTF_SetFontHinting(font, TTF_HINTING_MONO); #endif ttf_font_key_t key(path, style, size); ref_counted_ttf_font_t value(font, 1); ttf_font_list[key] = value; } return font; }