示例#1
0
/* static */
void FontUtils::GetAllRenderableCharacters(const string& font_name,
                                           vector<bool>* unichar_bitmap) {
  PangoFontInfo font_info(font_name);
  PangoCoverage* coverage = pango_font_get_coverage(
      font_info.ToPangoFont(), NULL);
  CharCoverageMapToBitmap(coverage, unichar_bitmap);
}
示例#2
0
/* static */
void FontUtils::GetAllRenderableCharacters(const vector<string>& fonts,
                                           vector<bool>* unichar_bitmap) {
  // Form the union of coverage maps from the fonts
  PangoCoverage* all_coverage = pango_coverage_new();
  tlog(1, "Processing %d fonts\n", fonts.size());
  for (int i = 0; i < fonts.size(); ++i) {
    PangoFontInfo font_info(fonts[i]);
    PangoCoverage* coverage = pango_font_get_coverage(
        font_info.ToPangoFont(), NULL);
    // Mark off characters that any font can render.
    pango_coverage_max(all_coverage, coverage);
  }
  CharCoverageMapToBitmap(all_coverage, unichar_bitmap);
  pango_coverage_unref(all_coverage);
}
示例#3
0
文件: axFont.cpp 项目: EQ4/axLib
bool axFontGlobalManager::LoadFont(const string& path, FT_Face& face)
{
	std::map<std::string, axFontStruct>::iterator it = _fontMap.find(path);

	if (it != _fontMap.end())
	{
		//cout << "Font already loaded in memory." << endl;
		FT_New_Memory_Face(_freeType,
							(FT_Byte*)it->second._data, // First byte in memory.
							it->second._size, // Size in bytes.
							0, // Face_index.        
							&face);
		return true;
	}
	else
	{
		//cout << "Init new font." << endl;
		std::ifstream file(path, std::ios::binary);
		file.seekg(0, std::ios::end);
		std::streamsize size = file.tellg();
		file.seekg(0, std::ios::beg);
		
		char* buffer = nullptr;
		try
		{
			buffer = new char[size];
		}
		catch (std::bad_alloc)
		{
			cerr << "Error new buffer." << endl;
		}

		//std::vector<unsigned char> buffer(size);

		if (file.read(buffer, size))
		{
			axFontStruct font_info(buffer, (unsigned int)size);
			_fontMap.insert(pair<std::string, axFontStruct>(path, font_info));

			FT_New_Memory_Face(_freeType,
							   (FT_Byte*)buffer, // First byte in memory.
							   size, // Size in bytes.
							   0, // Face_index.        
				               &face);

			file.close();

			return true;
		}
		else
		{
			delete buffer;
		}
		//if (InitImage(path, _texture, _size) == false)
		//{
		//	axImageStruct img_info(_texture, _size);
		//	_imageMap.insert(pair<std::string, axImageStruct>(path, img_info));
		//	return true;
		//}
	}

	return false;
}