⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wg_fontengine.cpp

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 CPP
字号:
// wg_fontengine.cpp//// CFontEngine implementation////// Copyright (c) 2002 Rob Wiskow// rob-dev@boxedchaos.com//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//#include "wgui_include_config.h"#include "wg_fontengine.h"#include "wg_error.h"namespace wGui {// Static membersFT_Library CFontEngine::m_FTLibrary;bool CFontEngine::m_bFTLibraryLoaded = false;CFontEngine::CFontEngine(const std::string& sFontFileName, unsigned char FontSize){	if (!m_bFTLibraryLoaded)	{		if (FT_Init_FreeType(&m_FTLibrary))		{			throw(Wg_Ex_FreeType("CFontEngine::CFontEngine : Unable to initialize FreeType library."));		}		m_bFTLibraryLoaded = true;	}	if (FT_New_Face(m_FTLibrary, sFontFileName.c_str(), 0, &m_FontFace))	{		throw(Wg_Ex_FreeType("CFontEngine::CFontEngine : Unable to create font face."));	}	if (FT_Set_Char_Size(m_FontFace, 0, FontSize * 64, 0, 0))	{		throw(Wg_Ex_FreeType("CFontEngine::CFontEngine : Unable to set character size."));	}}CFontEngine::~CFontEngine(void){	FT_Done_Face(m_FontFace);}FT_BitmapGlyphRec* CFontEngine::RenderGlyph(char Char){	std::map<char, FT_BitmapGlyphRec>::iterator glyphIter = m_CachedGlyphMap.find(Char);	if (glyphIter == m_CachedGlyphMap.end())	{		if (FT_Load_Char(m_FontFace, Char, FT_LOAD_DEFAULT))		{			throw(Wg_Ex_FreeType("CFontEngine::RenderGlyph : Unable to render glyph."));		}		FT_Glyph glyph;		if (FT_Get_Glyph(m_FontFace->glyph, &glyph))		{			throw(Wg_Ex_FreeType("CFontEngine::RenderGlyph : Unable to copy glyph."));		}		if (FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, 0, 1))		{			throw(Wg_Ex_FreeType("CFontEngine::RenderGlyph : Unable to render glyph."));		}		glyphIter = m_CachedGlyphMap.insert(std::make_pair(Char, *reinterpret_cast<FT_BitmapGlyph>(glyph))).first;	}	return &(glyphIter->second);}FT_Glyph_Metrics* CFontEngine::GetMetrics(char Char){	std::map<char, FT_Glyph_Metrics>::iterator glyphIter = m_CachedMetricsMap.find(Char);	if (glyphIter == m_CachedMetricsMap.end())	{		if (FT_Load_Char(m_FontFace, Char, FT_LOAD_DEFAULT))		{			throw(Wg_Ex_FreeType("CFontEngine::RenderGlyph : Unable to render glyph."));		}		glyphIter = m_CachedMetricsMap.insert(std::make_pair(Char, m_FontFace->glyph->metrics)).first;	}	return &(glyphIter->second);}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -