📄 wg__fontengine_8cpp-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>wg_fontengine.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> </center><hr><h1>wg_fontengine.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_fontengine.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CFontEngine implementation</span>00004 <span class="comment">//</span>00005 <span class="comment">//</span>00006 <span class="comment">// Copyright (c) 2002 Rob Wiskow</span>00007 <span class="comment">// rob-dev@boxedchaos.com</span>00008 <span class="comment">//</span>00009 <span class="comment">// This library is free software; you can redistribute it and/or</span>00010 <span class="comment">// modify it under the terms of the GNU Lesser General Public</span>00011 <span class="comment">// License as published by the Free Software Foundation; either</span>00012 <span class="comment">// version 2.1 of the License, or (at your option) any later version.</span>00013 <span class="comment">//</span>00014 <span class="comment">// This library is distributed in the hope that it will be useful,</span>00015 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>00016 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>00017 <span class="comment">// Lesser General Public License for more details.</span>00018 <span class="comment">//</span>00019 <span class="comment">// You should have received a copy of the GNU Lesser General Public</span>00020 <span class="comment">// License along with this library; if not, write to the Free Software</span>00021 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>00022 <span class="comment">//</span>00023 00024 00025 <span class="preprocessor">#include "wgui_include_config.h"</span>00026 <span class="preprocessor">#include "wg_fontengine.h"</span>00027 <span class="preprocessor">#include "wg_error.h"</span>00028 00029 00030 <span class="keyword">namespace </span>wGui {00031 00032 <span class="comment">// Static members</span><a name="l00033"></a><a class="code" href="classwGui_1_1CFontEngine.html#q0">00033</a> FT_Library CFontEngine::m_FTLibrary;<a name="l00034"></a><a class="code" href="classwGui_1_1CFontEngine.html#q1">00034</a> <span class="keywordtype">bool</span> CFontEngine::m_bFTLibraryLoaded = <span class="keyword">false</span>;00035 00036 <a name="l00037"></a><a class="code" href="classwGui_1_1CFontEngine.html#a0">00037</a> CFontEngine::CFontEngine(<span class="keyword">const</span> std::string& sFontFileName, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> FontSize)00038 {00039 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CFontEngine.html#q1">m_bFTLibraryLoaded</a>)00040 {00041 <span class="keywordflow">if</span> (FT_Init_FreeType(&<a class="code" href="classwGui_1_1CFontEngine.html#q0">m_FTLibrary</a>))00042 {00043 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__FreeType.html">Wg_Ex_FreeType</a>(<span class="stringliteral">"CFontEngine::CFontEngine : Unable to initialize FreeType library."</span>));00044 }00045 <a class="code" href="classwGui_1_1CFontEngine.html#q1">m_bFTLibraryLoaded</a> = <span class="keyword">true</span>;00046 }00047 <span class="keywordflow">if</span> (FT_New_Face(<a class="code" href="classwGui_1_1CFontEngine.html#q0">m_FTLibrary</a>, sFontFileName.c_str(), 0, &<a class="code" href="classwGui_1_1CFontEngine.html#n0">m_FontFace</a>))00048 {00049 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__FreeType.html">Wg_Ex_FreeType</a>(<span class="stringliteral">"CFontEngine::CFontEngine : Unable to create font face."</span>));00050 }00051 <span class="keywordflow">if</span> (FT_Set_Char_Size(<a class="code" href="classwGui_1_1CFontEngine.html#n0">m_FontFace</a>, 0, FontSize * 64, 0, 0))00052 {00053 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__FreeType.html">Wg_Ex_FreeType</a>(<span class="stringliteral">"CFontEngine::CFontEngine : Unable to set character size."</span>));00054 }00055 }00056 00057 <a name="l00058"></a><a class="code" href="classwGui_1_1CFontEngine.html#a1">00058</a> CFontEngine::~CFontEngine(<span class="keywordtype">void</span>)00059 {00060 00061 FT_Done_Face(<a class="code" href="classwGui_1_1CFontEngine.html#n0">m_FontFace</a>);00062 }00063 <a name="l00064"></a><a class="code" href="classwGui_1_1CFontEngine.html#a2">00064</a> FT_BitmapGlyphRec* CFontEngine::RenderGlyph(<span class="keywordtype">char</span> Char)00065 {00066 std::map<char, FT_BitmapGlyphRec>::iterator glyphIter = <a class="code" href="classwGui_1_1CFontEngine.html#n1">m_CachedGlyphMap</a>.find(Char);00067 <span class="keywordflow">if</span> (glyphIter == <a class="code" href="classwGui_1_1CFontEngine.html#n1">m_CachedGlyphMap</a>.end())00068 {00069 <span class="keywordflow">if</span> (FT_Load_Char(<a class="code" href="classwGui_1_1CFontEngine.html#n0">m_FontFace</a>, Char, FT_LOAD_DEFAULT))00070 {00071 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__FreeType.html">Wg_Ex_FreeType</a>(<span class="stringliteral">"CFontEngine::RenderGlyph : Unable to render glyph."</span>));00072 }00073 FT_Glyph glyph;00074 <span class="keywordflow">if</span> (FT_Get_Glyph(<a class="code" href="classwGui_1_1CFontEngine.html#n0">m_FontFace</a>->glyph, &glyph))00075 {00076 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__FreeType.html">Wg_Ex_FreeType</a>(<span class="stringliteral">"CFontEngine::RenderGlyph : Unable to copy glyph."</span>));00077 }00078 <span class="keywordflow">if</span> (FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, 0, 1))00079 {00080 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__FreeType.html">Wg_Ex_FreeType</a>(<span class="stringliteral">"CFontEngine::RenderGlyph : Unable to render glyph."</span>));00081 }00082 glyphIter = <a class="code" href="classwGui_1_1CFontEngine.html#n1">m_CachedGlyphMap</a>.insert(std::make_pair(Char, *reinterpret_cast<FT_BitmapGlyph>(glyph))).first;00083 }00084 <span class="keywordflow">return</span> &(glyphIter->second);00085 }00086 <a name="l00087"></a><a class="code" href="classwGui_1_1CFontEngine.html#a3">00087</a> FT_Glyph_Metrics* CFontEngine::GetMetrics(<span class="keywordtype">char</span> Char)00088 {00089 std::map<char, FT_Glyph_Metrics>::iterator glyphIter = <a class="code" href="classwGui_1_1CFontEngine.html#n2">m_CachedMetricsMap</a>.find(Char);00090 <span class="keywordflow">if</span> (glyphIter == <a class="code" href="classwGui_1_1CFontEngine.html#n2">m_CachedMetricsMap</a>.end())00091 {00092 <span class="keywordflow">if</span> (FT_Load_Char(<a class="code" href="classwGui_1_1CFontEngine.html#n0">m_FontFace</a>, Char, FT_LOAD_DEFAULT))00093 {00094 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__FreeType.html">Wg_Ex_FreeType</a>(<span class="stringliteral">"CFontEngine::RenderGlyph : Unable to render glyph."</span>));00095 }00096 glyphIter = <a class="code" href="classwGui_1_1CFontEngine.html#n2">m_CachedMetricsMap</a>.insert(std::make_pair(Char, <a class="code" href="classwGui_1_1CFontEngine.html#n0">m_FontFace</a>->glyph->metrics)).first;00097 }00098 <span class="keywordflow">return</span> &(glyphIter->second);00099 }00100 00101 }</pre></div><hr><address style="align: right;"><small>Generated on Sat Oct 25 12:43:22 2003 for wGui by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -