Пример #1
0
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;	
}
Пример #2
0
static const char *locate_font(const std::string& path)
{
	builtin_fonts_t::iterator j = builtin_fonts.find(path);
	if (j != builtin_fonts.end() || path == "")
	{
		return path.c_str();
	}
	else
	{
		static FileSpecifier file;
		if (file.SetNameWithPath(path.c_str()))
			return file.GetPath();
		else
			return "";
	}
}