aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/a05720.html
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2018-08-11 20:21:34 +0200
committerneodarz <neodarz@neodarz.net>2018-08-11 20:21:34 +0200
commit0ea5fc66924303d1bf73ba283a383e2aadee02f2 (patch)
tree2568e71a7ccc44ec23b8bb3f0ff97fb6bf2ed709 /docs/doxygen/nel/a05720.html
downloadnevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.tar.xz
nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.zip
Initial commit
Diffstat (limited to 'docs/doxygen/nel/a05720.html')
-rw-r--r--docs/doxygen/nel/a05720.html623
1 files changed, 623 insertions, 0 deletions
diff --git a/docs/doxygen/nel/a05720.html b/docs/doxygen/nel/a05720.html
new file mode 100644
index 00000000..05e00802
--- /dev/null
+++ b/docs/doxygen/nel/a05720.html
@@ -0,0 +1,623 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
+<title>NeL: font_generator.cpp Source File</title>
+<link href="doxygen.css" rel="stylesheet" type="text/css">
+</head><body>
+<!-- Generated by Doxygen 1.3.6 -->
+<div class="qindex"> <form class="search" action="search.php" method="get">
+<a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a> | <span class="search"><u>S</u>earch&nbsp;for&nbsp;<input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
+<h1>font_generator.cpp</h1><a href="a04297.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
+00007 <span class="comment">/* Copyright, 2000 Nevrax Ltd.</span>
+00008 <span class="comment"> *</span>
+00009 <span class="comment"> * This file is part of NEVRAX NEL.</span>
+00010 <span class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</span>
+00011 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
+00012 <span class="comment"> * the Free Software Foundation; either version 2, or (at your option)</span>
+00013 <span class="comment"> * any later version.</span>
+00014 <span class="comment"></span>
+00015 <span class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</span>
+00016 <span class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</span>
+00017 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
+00018 <span class="comment"> * General Public License for more details.</span>
+00019 <span class="comment"></span>
+00020 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
+00021 <span class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</span>
+00022 <span class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</span>
+00023 <span class="comment"> * MA 02111-1307, USA.</span>
+00024 <span class="comment"> */</span>
+00025
+00026 <span class="preprocessor">#include "<a class="code" href="a05015.html">std3d.h</a>"</span>
+00027
+00028 <span class="preprocessor">#include &lt;string&gt;</span>
+00029
+00030 <span class="preprocessor">#include "<a class="code" href="a05167.html">nel/misc/types_nl.h</a>"</span>
+00031 <span class="preprocessor">#include "<a class="code" href="a04199.html">nel/misc/debug.h</a>"</span>
+00032 <span class="preprocessor">#include "<a class="code" href="a04164.html">nel/misc/common.h</a>"</span>
+00033 <span class="preprocessor">#include "<a class="code" href="a04745.html">nel/misc/path.h</a>"</span>
+00034
+00035 <span class="preprocessor">#include "<a class="code" href="a04298.html">3d/font_generator.h</a>"</span>
+00036
+00037 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
+00038
+00039 <span class="preprocessor">#ifndef NL_DONT_USE_EXTERNAL_CODE</span>
+00040 <span class="preprocessor"></span>
+00041 <span class="preprocessor">#include &lt;freetype/freetype.h&gt;</span>
+00042
+00043 <span class="comment">// for freetype 2.0</span>
+00044 <span class="preprocessor">#ifdef FTERRORS_H</span>
+00045 <span class="preprocessor"></span><span class="preprocessor">#undef FTERRORS_H</span>
+00046 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+00047 <span class="preprocessor"></span>
+00048 <span class="comment">// for freetype 2.0.1</span>
+00049 <span class="preprocessor">#ifdef __FTERRORS_H__</span>
+00050 <span class="preprocessor"></span><span class="preprocessor">#undef __FTERRORS_H__</span>
+00051 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
+00052 <span class="preprocessor"></span>
+<a name="l00053"></a><a class="code" href="a04297.html#a0">00053</a> <span class="preprocessor">#define FT_ERRORDEF( e, v, s ) { e, s },</span>
+<a name="l00054"></a><a class="code" href="a04297.html#a1">00054</a> <span class="preprocessor"></span><span class="preprocessor">#define FT_ERROR_START_LIST {</span>
+<a name="l00055"></a><a class="code" href="a04297.html#a2">00055</a> <span class="preprocessor"></span><span class="preprocessor">#define FT_ERROR_END_LIST { 0, 0 } };</span>
+00056 <span class="preprocessor"></span>
+00057 <span class="keyword">const</span> <span class="keyword">struct</span>
+00058 <span class="keyword"></span>{
+<a name="l00059"></a><a class="code" href="a04297.html#a3">00059</a> <span class="keywordtype">int</span> <a class="code" href="a04297.html#a3">err_code</a>;
+<a name="l00060"></a><a class="code" href="a04297.html#a4">00060</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="a04297.html#a4">err_msg</a>;
+00061 } <a class="code" href="a04297.html#a5">ft_errors</a>[] =
+00062
+00063 <span class="preprocessor">#include &lt;freetype/fterrors.h&gt;</span>
+00064
+00065 <span class="keyword">using</span> <span class="keyword">namespace </span>NLMISC;
+00066
+00067 <span class="keyword">namespace </span>NL3D {
+00068
+<a name="l00069"></a><a class="code" href="a02541.html#NL3D_1_1CFontGeneratorv1">00069</a> FT_Library CFontGenerator::_Library;
+<a name="l00070"></a><a class="code" href="a02541.html#NL3D_1_1CFontGeneratorv2">00070</a> <span class="keywordtype">bool</span> CFontGenerator::_LibraryInit = <span class="keyword">false</span>;
+<a name="l00071"></a><a class="code" href="a02541.html#NL3D_1_1CFontGeneratorv0">00071</a> <a class="code" href="a04558.html#a11">uint32</a> CFontGenerator::_FontGeneratorCounterUID = 1;
+00072
+<a name="l00073"></a><a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">00073</a> <span class="keyword">const</span> <span class="keywordtype">char</span> *CFontGenerator::getFT2Error(FT_Error fte)
+00074 {
+00075 NL_ALLOC_CONTEXT (FreeTyp);
+00076
+00077 <span class="keyword">static</span> <span class="keywordtype">char</span> ukn[1024];
+00078
+00079 <span class="keywordflow">for</span> (<a class="code" href="a04558.html#a11">uint32</a> i = 0; <a class="code" href="a04297.html#a5">ft_errors</a>[i].err_code != 0 || <a class="code" href="a04297.html#a5">ft_errors</a>[i].err_msg != 0; i++)
+00080 {
+00081 <span class="keywordflow">if</span> (<a class="code" href="a04297.html#a5">ft_errors</a>[i].err_code == fte)
+00082 <span class="keywordflow">return</span> <a class="code" href="a04297.html#a5">ft_errors</a>[i].err_msg;
+00083 }
+00084 <a class="code" href="a05378.html#a259">smprintf</a> (ukn, 1024, <span class="stringliteral">"Unknown freetype2 error, errcode: 0x%x"</span>, fte);
+00085 <span class="keywordflow">return</span> ukn;
+00086 }
+00087
+00088
+00089
+00090 <span class="comment">/*</span>
+00091 <span class="comment"> * Constructor</span>
+00092 <span class="comment"> */</span>
+<a name="l00093"></a><a class="code" href="a02541.html#NL3D_1_1CFontGeneratora0">00093</a> CFontGenerator::CFontGenerator (<span class="keyword">const</span> std::string &amp;fontFileName, <span class="keyword">const</span> std::string &amp;fontExFileName)
+00094 {
+00095 NL_ALLOC_CONTEXT (FreeTyp);
+00096
+00097 <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr2">_UID</a> = <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorv0">_FontGeneratorCounterUID</a>;
+00098 _FontGeneratorCounterUID++;
+00099 <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr1">_FontFileName</a> = fontFileName;
+00100
+00101 FT_Error error;
+00102
+00103 <span class="keywordflow">if</span> (!<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorv2">_LibraryInit</a>)
+00104 {
+00105 error = FT_Init_FreeType (&amp;<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorv1">_Library</a>);
+00106 <span class="keywordflow">if</span> (error)
+00107 {
+00108 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"FT_Init_FreeType() failed: %s"</span>, <a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">getFT2Error</a>(error));
+00109 }
+00110 <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorv2">_LibraryInit</a> = <span class="keyword">true</span>;
+00111 }
+00112
+00113 error = FT_New_Face (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorv1">_Library</a>, fontFileName.c_str (), 0, &amp;<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>);
+00114 <span class="keywordflow">if</span> (error)
+00115 {
+00116 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"FT_New_Face() failed with file '%s': %s"</span>, fontFileName.c_str(), <a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">getFT2Error</a>(error));
+00117 }
+00118
+00119 string fontEx = fontExFileName;
+00120 <span class="keywordflow">if</span> (fontEx == <span class="stringliteral">""</span>)
+00121 {
+00122 <span class="comment">// try to see if the ex filename exists based on the fontExFileName</span>
+00123 fontEx = CPath::lookup(CFile::getFilenameWithoutExtension (fontFileName)+<span class="stringliteral">".afm"</span>, <span class="keyword">false</span>, <span class="keyword">false</span>);
+00124 }
+00125
+00126 <span class="keywordflow">if</span> (fontEx != <span class="stringliteral">""</span>)
+00127 {
+00128 error = FT_Attach_File (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>, fontEx.c_str ());
+00129 <span class="keywordflow">if</span> (error)
+00130 {
+00131 <a class="code" href="a04199.html#a2">nlwarning</a> (<span class="stringliteral">"FT_Attach_File() failed with file '%s': %s"</span>, fontEx.c_str(), <a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">getFT2Error</a>(error));
+00132 }
+00133 }
+00134
+00135 error = FT_Select_Charmap (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>, ft_encoding_unicode);
+00136 <span class="keywordflow">if</span> (error)
+00137 {
+00138 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"FT_Select_Charmap() failed with file '%s': %s"</span>, fontFileName.c_str(), <a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">getFT2Error</a>(error));
+00139 }
+00140 }
+00141
+<a name="l00142"></a><a class="code" href="a02541.html#NL3D_1_1CFontGeneratora6">00142</a> CFontGenerator::~CFontGenerator ()
+00143 {
+00144 }
+00145
+<a name="l00146"></a><a class="code" href="a02541.html#NL3D_1_1CFontGeneratora4">00146</a> <span class="keywordtype">void</span> CFontGenerator::getSizes (<a class="code" href="a05167.html#a18">ucchar</a> c, <a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a587">size</a>, <a class="code" href="a04558.html#a11">uint32</a> &amp;<a class="code" href="a04223.html#a632">width</a>, <a class="code" href="a04558.html#a11">uint32</a> &amp;<a class="code" href="a04223.html#a633">height</a>)
+00147 {
+00148 NL_ALLOC_CONTEXT (FreeTyp);
+00149
+00150 FT_Error error;
+00151
+00152 error = FT_Set_Pixel_Sizes (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>, <a class="code" href="a04223.html#a587">size</a>, <a class="code" href="a04223.html#a587">size</a>);
+00153 <span class="keywordflow">if</span> (error)
+00154 {
+00155 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"FT_Set_Pixel_Sizes() failed: %s"</span>, <a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">getFT2Error</a>(error));
+00156 }
+00157
+00158 <span class="comment">// retrieve glyph index from character code</span>
+00159 FT_UInt glyph_index = FT_Get_Char_Index (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>, c);
+00160
+00161 <span class="comment">// load glyph image into the slot (erase previous one)</span>
+00162 error = FT_Load_Glyph (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>, glyph_index, FT_LOAD_DEFAULT);
+00163 <span class="keywordflow">if</span> (error)
+00164 {
+00165 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"FT_Load_Glyph() failed: %s"</span>, <a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">getFT2Error</a>(error));
+00166 }
+00167
+00168 <span class="comment">// convert 24.6 fixed point into integer</span>
+00169 <a class="code" href="a04223.html#a632">width</a> = <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>-&gt;glyph-&gt;metrics.width &gt;&gt; 6;
+00170 <a class="code" href="a04223.html#a633">height</a> = <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>-&gt;glyph-&gt;metrics.height &gt;&gt; 6;
+00171 }
+00172
+<a name="l00173"></a><a class="code" href="a02541.html#NL3D_1_1CFontGeneratora1">00173</a> <a class="code" href="a04558.html#a7">uint8</a> *CFontGenerator::getBitmap (<a class="code" href="a05167.html#a18">ucchar</a> c, <a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a587">size</a>, <a class="code" href="a04558.html#a11">uint32</a> &amp;<a class="code" href="a04223.html#a632">width</a>, <a class="code" href="a04558.html#a11">uint32</a> &amp;<a class="code" href="a04223.html#a633">height</a>, <a class="code" href="a04558.html#a11">uint32</a> &amp;pitch, <a class="code" href="a04558.html#a10">sint32</a> &amp;left, <a class="code" href="a04558.html#a10">sint32</a> &amp;top, <a class="code" href="a04558.html#a10">sint32</a> &amp;advx, <a class="code" href="a04558.html#a11">uint32</a> &amp;glyphIndex)
+00174 {
+00175 NL_ALLOC_CONTEXT (FreeTyp);
+00176
+00177 FT_Error error;
+00178
+00179 error = FT_Set_Pixel_Sizes (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>, <a class="code" href="a04223.html#a587">size</a>, <a class="code" href="a04223.html#a587">size</a>);
+00180 <span class="keywordflow">if</span> (error)
+00181 {
+00182 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"FT_Set_Pixel_Sizes() failed: %s"</span>, <a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">getFT2Error</a>(error));
+00183 }
+00184
+00185 <span class="comment">// retrieve glyph index from character code</span>
+00186 FT_UInt glyph_index = FT_Get_Char_Index (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>, c);
+00187
+00188 <span class="comment">// load glyph image into the slot (erase previous one)</span>
+00189 error = FT_Load_Glyph (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>, glyph_index, FT_LOAD_DEFAULT);
+00190 <span class="keywordflow">if</span> (error)
+00191 {
+00192 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"FT_Load_Glyph() failed: %s"</span>, <a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">getFT2Error</a>(error));
+00193 }
+00194
+00195 <span class="keywordflow">if</span> (<a class="code" href="a04223.html#a587">size</a> == 0)
+00196 {
+00197 <a class="code" href="a04223.html#a632">width</a> = 0;
+00198 <a class="code" href="a04223.html#a633">height</a> = 0;
+00199 pitch = 0;
+00200 left = 0;
+00201 top = 0;
+00202 advx = 0;
+00203 glyphIndex = glyph_index;
+00204 <span class="keywordflow">return</span> NULL;
+00205 }
+00206
+00207 <span class="comment">// convert to an anti-aliased bitmap</span>
+00208 error = FT_Render_Glyph (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>-&gt;glyph, ft_render_mode_normal);
+00209 <span class="keywordflow">if</span> (error)
+00210 {
+00211 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"FT_Render_Glyph() failed: %s"</span>, <a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">getFT2Error</a>(error));
+00212 }
+00213
+00214 <a class="code" href="a04223.html#a632">width</a> = <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>-&gt;glyph-&gt;bitmap.width;
+00215 <a class="code" href="a04223.html#a633">height</a> = <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>-&gt;glyph-&gt;bitmap.rows;
+00216 pitch = <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>-&gt;glyph-&gt;bitmap.pitch;
+00217
+00218 left = <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>-&gt;glyph-&gt;bitmap_left;
+00219 top = <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>-&gt;glyph-&gt;bitmap_top;
+00220
+00221 advx = <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>-&gt;glyph-&gt;advance.x &gt;&gt; 6;
+00222
+00223 glyphIndex = glyph_index;
+00224
+00225 <span class="keywordflow">return</span> (<a class="code" href="a04558.html#a7">uint8</a> *) <a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>-&gt;glyph-&gt;bitmap.buffer;
+00226 }
+00227
+00228
+00229
+<a name="l00230"></a><a class="code" href="a02541.html#NL3D_1_1CFontGeneratora3">00230</a> <span class="keywordtype">void</span> CFontGenerator::getKerning (<a class="code" href="a05167.html#a18">ucchar</a> left, <a class="code" href="a05167.html#a18">ucchar</a> right, <a class="code" href="a04558.html#a10">sint32</a> &amp;kernx)
+00231 {
+00232 NL_ALLOC_CONTEXT (FreeTyp);
+00233
+00234 <span class="keywordflow">if</span> (!FT_HAS_KERNING(<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>))
+00235 {
+00236 kernx = 0;
+00237 }
+00238 <span class="keywordflow">else</span>
+00239 {
+00240 FT_Vector kerning;
+00241 FT_Error error = FT_Get_Kerning (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>, left, right, ft_kerning_default, &amp;kerning);
+00242 <span class="keywordflow">if</span> (error)
+00243 {
+00244 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"FT_Get_Kerning() failed: %s"</span>, <a class="code" href="a02541.html#NL3D_1_1CFontGeneratord0">getFT2Error</a>(error));
+00245 }
+00246 kernx = kerning.x;
+00247 }
+00248 }
+00249
+00250
+00251
+<a name="l00252"></a><a class="code" href="a02541.html#NL3D_1_1CFontGeneratora2">00252</a> <a class="code" href="a04558.html#a11">uint32</a> CFontGenerator::getCharIndex (<a class="code" href="a05167.html#a18">ucchar</a> c)
+00253 {
+00254 NL_ALLOC_CONTEXT (FreeTyp);
+00255
+00256 <span class="keywordflow">return</span> FT_Get_Char_Index (<a class="code" href="a02541.html#NL3D_1_1CFontGeneratorr0">_Face</a>, c);
+00257 }
+00258
+00259 } <span class="comment">// NL3D</span>
+00260
+00261 <span class="preprocessor">#else // NL_DONT_USE_EXTERNAL_CODE</span>
+00262 <span class="preprocessor"></span>
+00263 <span class="preprocessor">#include &lt;windows.h&gt;</span>
+00264
+00265 <span class="keyword">using</span> <span class="keyword">namespace </span>NLMISC;
+00266
+00267 <span class="keyword">namespace </span><a class="code" href="a06846.html">NL3D</a> {
+00268
+00269 HBITMAP Dib;
+00270 <a class="code" href="a04558.html#a11">uint32</a> *Buffer;
+00271 HDC hdcDib;
+00272 <span class="keywordtype">int</span> Width = 100;
+00273 <span class="keywordtype">int</span> Height = 100;
+00274
+00275 <span class="comment">/*</span>
+00276 <span class="comment"> * Constructor</span>
+00277 <span class="comment"> */</span>
+00278 CFontGenerator::CFontGenerator (<span class="keyword">const</span> std::string &amp;fontFileName, <span class="keyword">const</span> std::string &amp;fontExFileName)
+00279 {
+00280
+00281 <span class="comment">// HWND win=(HWND)winHack;</span>
+00282 <span class="comment">// WindowHandle = win;</span>
+00283 <span class="comment">// Format = format;</span>
+00284 <span class="comment">// RECT rect;</span>
+00285 <span class="comment">// BOOL ret = GetClientRect( WindowHandle, &amp;rect);</span>
+00286 <span class="comment">// assert (ret);</span>
+00287
+00288 <span class="comment">// uint f = AddFontResource ("");</span>
+00289 <span class="comment">// nlassert (f);</span>
+00290
+00291 BITMAPINFO info;
+00292 info.bmiHeader.biWidth = Width;
+00293 info.bmiHeader.biHeight= -Height;
+00294 info.bmiHeader.biSize = <span class="keyword">sizeof</span> (BITMAPINFOHEADER);
+00295 info.bmiHeader.biPlanes = 1;
+00296 info.bmiHeader.biBitCount = 32;
+00297 info.bmiHeader.biCompression = BI_RGB;
+00298 info.bmiHeader.biSizeImage = 4*Width*Height;
+00299 info.bmiHeader.biXPelsPerMeter = 1;
+00300 info.bmiHeader.biYPelsPerMeter = 1;
+00301 info.bmiHeader.biClrUsed = 0;
+00302 info.bmiHeader.biClrImportant = 0;
+00303
+00304 HDC hdc = GetDC (NULL);
+00305 <a class="code" href="a04199.html#a6">nlassert</a> (hdc);
+00306 Dib = CreateDIBSection (hdc, &amp;info, DIB_RGB_COLORS, (<span class="keywordtype">void</span>**)&amp;Buffer, NULL, NULL);
+00307
+00308 hdcDib = CreateCompatibleDC (hdc);
+00309 <a class="code" href="a04199.html#a6">nlassert</a> (hdcDib);
+00310
+00311
+00312 ReleaseDC (NULL, hdc);
+00313
+00314 SetTextAlign (hdcDib, TA_TOP | TA_LEFT | TA_NOUPDATECP);
+00315 SetBkColor (hdcDib, RGB (0,0,0));
+00316 SetTextColor (hdcDib, RGB (255, 255, 255));
+00317
+00318 <span class="comment">/*FT_Error error;</span>
+00319 <span class="comment"></span>
+00320 <span class="comment"> if (!_LibraryInit)</span>
+00321 <span class="comment"> {</span>
+00322 <span class="comment"> error = FT_Init_FreeType (&amp;_Library);</span>
+00323 <span class="comment"> if (error)</span>
+00324 <span class="comment"> {</span>
+00325 <span class="comment"> nlerror ("FT_Init_FreeType() failed: %s", getFT2Error(error));</span>
+00326 <span class="comment"> }</span>
+00327 <span class="comment"> _LibraryInit = true;</span>
+00328 <span class="comment"> }</span>
+00329 <span class="comment"></span>
+00330 <span class="comment"> error = FT_New_Face (_Library, fontFileName.c_str (), 0, &amp;_Face);</span>
+00331 <span class="comment"> if (error)</span>
+00332 <span class="comment"> {</span>
+00333 <span class="comment"> nlerror ("FT_New_Face() failed with file '%s': %s", fontFileName.c_str(), getFT2Error(error));</span>
+00334 <span class="comment"> }</span>
+00335 <span class="comment"></span>
+00336 <span class="comment"> if (fontExFileName != "")</span>
+00337 <span class="comment"> {</span>
+00338 <span class="comment"> error = FT_Attach_File (_Face, fontExFileName.c_str ());</span>
+00339 <span class="comment"> if (error)</span>
+00340 <span class="comment"> {</span>
+00341 <span class="comment"> nlwarning ("FT_Attach_File() failed with file '%s': %s", fontExFileName.c_str(), getFT2Error(error));</span>
+00342 <span class="comment"> }</span>
+00343 <span class="comment"> }*/</span>
+00344 }
+00345
+00346 CFontGenerator::~CFontGenerator ()
+00347 {
+00348 DeleteObject (Dib);
+00349
+00350 DeleteDC (hdcDib);
+00351 }
+00352
+00353 <span class="keywordtype">void</span> CFontGenerator::getSizes (<a class="code" href="a05167.html#a18">ucchar</a> c, <a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a587">size</a>, <a class="code" href="a04558.html#a11">uint32</a> &amp;<a class="code" href="a04223.html#a632">width</a>, <a class="code" href="a04558.html#a11">uint32</a> &amp;<a class="code" href="a04223.html#a633">height</a>)
+00354 {
+00355 <span class="comment">/* FT_Error error;</span>
+00356 <span class="comment"></span>
+00357 <span class="comment"> error = FT_Set_Pixel_Sizes (_Face, size, size);</span>
+00358 <span class="comment"> if (error)</span>
+00359 <span class="comment"> {</span>
+00360 <span class="comment"> nlerror ("FT_Set_Pixel_Sizes() failed: %s", getFT2Error(error));</span>
+00361 <span class="comment"> }</span>
+00362 <span class="comment"></span>
+00363 <span class="comment"> // retrieve glyph index from character code</span>
+00364 <span class="comment"> FT_UInt glyph_index = FT_Get_Char_Index (_Face, c);</span>
+00365 <span class="comment"></span>
+00366 <span class="comment"> // load glyph image into the slot (erase previous one)</span>
+00367 <span class="comment"> error = FT_Load_Glyph (_Face, glyph_index, FT_LOAD_DEFAULT);</span>
+00368 <span class="comment"> if (error)</span>
+00369 <span class="comment"> {</span>
+00370 <span class="comment"> nlerror ("FT_Load_Glyph() failed: %s", getFT2Error(error));</span>
+00371 <span class="comment"> }</span>
+00372 <span class="comment"></span>
+00373 <span class="comment"> // convert 24.6 fixed point into integer</span>
+00374 <span class="comment"> width = _Face-&gt;glyph-&gt;metrics.width &gt;&gt; 6;</span>
+00375 <span class="comment"> height = _Face-&gt;glyph-&gt;metrics.height &gt;&gt; 6;</span>
+00376 <span class="comment"> */</span>
+00377 }
+00378
+00379 HFONT hFont = NULL;
+00380 <a class="code" href="a04558.html#a11">uint32</a> CurrentFontSize = 0;
+00381
+00382 <a class="code" href="a04558.html#a7">uint8</a> *CFontGenerator::getBitmap (<a class="code" href="a05167.html#a18">ucchar</a> c, <a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a587">size</a>, <a class="code" href="a04558.html#a11">uint32</a> &amp;<a class="code" href="a04223.html#a632">width</a>, <a class="code" href="a04558.html#a11">uint32</a> &amp;<a class="code" href="a04223.html#a633">height</a>, <a class="code" href="a04558.html#a11">uint32</a> &amp;pitch, <a class="code" href="a04558.html#a10">sint32</a> &amp;left, <a class="code" href="a04558.html#a10">sint32</a> &amp;top, <a class="code" href="a04558.html#a10">sint32</a> &amp;advx, <a class="code" href="a04558.html#a11">uint32</a> &amp;glyphIndex)
+00383 {
+00384 <span class="comment">/* FT_Error error;</span>
+00385 <span class="comment"></span>
+00386 <span class="comment"> error = FT_Set_Pixel_Sizes (_Face, size, size);</span>
+00387 <span class="comment"> if (error)</span>
+00388 <span class="comment"> {</span>
+00389 <span class="comment"> nlerror ("FT_Set_Pixel_Sizes() failed: %s", getFT2Error(error));</span>
+00390 <span class="comment"> }</span>
+00391 <span class="comment"></span>
+00392 <span class="comment"> // retrieve glyph index from character code</span>
+00393 <span class="comment"> FT_UInt glyph_index = FT_Get_Char_Index (_Face, c);</span>
+00394 <span class="comment"></span>
+00395 <span class="comment"> // load glyph image into the slot (erase previous one)</span>
+00396 <span class="comment"> error = FT_Load_Glyph (_Face, glyph_index, FT_LOAD_DEFAULT);</span>
+00397 <span class="comment"> if (error)</span>
+00398 <span class="comment"> {</span>
+00399 <span class="comment"> nlerror ("FT_Load_Glyph() failed: %s", getFT2Error(error));</span>
+00400 <span class="comment"> }</span>
+00401 <span class="comment"></span>
+00402 <span class="comment"> if (size == 0)</span>
+00403 <span class="comment"> {</span>
+00404 <span class="comment"> width = 0;</span>
+00405 <span class="comment"> height = 0;</span>
+00406 <span class="comment"> pitch = 0;</span>
+00407 <span class="comment"> left = 0;</span>
+00408 <span class="comment"> top = 0;</span>
+00409 <span class="comment"> advx = 0;</span>
+00410 <span class="comment"> glyphIndex = glyph_index;</span>
+00411 <span class="comment"> return NULL;</span>
+00412 <span class="comment"> }</span>
+00413 <span class="comment"></span>
+00414 <span class="comment"> // convert to an anti-aliased bitmap</span>
+00415 <span class="comment"> error = FT_Render_Glyph (_Face-&gt;glyph, ft_render_mode_normal);</span>
+00416 <span class="comment"> if (error)</span>
+00417 <span class="comment"> {</span>
+00418 <span class="comment"> nlerror ("FT_Render_Glyph() failed: %s", getFT2Error(error));</span>
+00419 <span class="comment"> }</span>
+00420 <span class="comment"></span>
+00421 <span class="comment"> width = _Face-&gt;glyph-&gt;bitmap.width;</span>
+00422 <span class="comment"> height = _Face-&gt;glyph-&gt;bitmap.rows;</span>
+00423 <span class="comment"> pitch = _Face-&gt;glyph-&gt;bitmap.pitch;</span>
+00424 <span class="comment"></span>
+00425 <span class="comment"> left = _Face-&gt;glyph-&gt;bitmap_left;</span>
+00426 <span class="comment"> top = _Face-&gt;glyph-&gt;bitmap_top;</span>
+00427 <span class="comment"></span>
+00428 <span class="comment"> advx = _Face-&gt;glyph-&gt;advance.x &gt;&gt; 6;</span>
+00429 <span class="comment"></span>
+00430 <span class="comment"> glyphIndex = glyph_index;</span>
+00431 <span class="comment"></span>
+00432 <span class="comment"> return (uint8 *) _Face-&gt;glyph-&gt;bitmap.buffer;</span>
+00433 <span class="comment">*/</span>
+00434
+00435 <span class="keywordflow">if</span> (<a class="code" href="a04223.html#a587">size</a> == 0)
+00436 {
+00437 <a class="code" href="a04223.html#a632">width</a> = 0;
+00438 <a class="code" href="a04223.html#a633">height</a> = 0;
+00439 pitch = 0;
+00440 left = 0;
+00441 top = 0;
+00442 advx = 0;
+00443 glyphIndex = 0;
+00444 <span class="keywordflow">return</span> NULL;
+00445 }
+00446
+00447 <span class="comment">// Create the font</span>
+00448 <span class="keywordflow">if</span> (hFont == NULL || CurrentFontSize != <a class="code" href="a04223.html#a587">size</a>)
+00449 {
+00450 <span class="keywordflow">if</span> (hFont != NULL)
+00451 {
+00452 DeleteObject (hFont);
+00453 }
+00454
+00455 hFont=CreateFont
+00456 (
+00457 <a class="code" href="a04223.html#a587">size</a>, <span class="comment">// logical height of font</span>
+00458 0, <span class="comment">// logical average character width</span>
+00459 0, <span class="comment">// angle of escapement</span>
+00460 0, <span class="comment">// base-line orientation angle</span>
+00461 FW_DONTCARE, <span class="comment">//FW_NORMAL, // font weight</span>
+00462 FALSE, <span class="comment">// italic attribute flag</span>
+00463 FALSE, <span class="comment">// underline attribute flag</span>
+00464 FALSE, <span class="comment">// strikeout attribute flag</span>
+00465 DEFAULT_CHARSET, <span class="comment">// character set identifier</span>
+00466 OUT_DEVICE_PRECIS, <span class="comment">// output precision</span>
+00467 CLIP_DEFAULT_PRECIS, <span class="comment">// clipping precision</span>
+00468 DEFAULT_QUALITY, <span class="comment">// output quality</span>
+00469 DEFAULT_PITCH|FF_DONTCARE, <span class="comment">// pitch and family</span>
+00470 <span class="stringliteral">"Arial Unicode MS Normal"</span> <span class="comment">// pointer to typeface name string</span>
+00471 );
+00472 <a class="code" href="a04199.html#a6">nlassert</a> (hFont);
+00473
+00474 CurrentFontSize = <a class="code" href="a04223.html#a587">size</a>;
+00475 }
+00476
+00477 SelectObject (hdcDib, hFont);
+00478 SelectObject (hdcDib, Dib);
+00479
+00480 <span class="keyword">const</span> <span class="keywordtype">char</span> cc = (<span class="keywordtype">char</span>) c;
+00481
+00482 RECT rect;
+00483 rect.bottom = Height;
+00484 rect.top = 0;
+00485 rect.left = 0;
+00486 rect.right = Width;
+00487
+00488 <span class="keywordtype">int</span> <a class="code" href="a04223.html#a643">res</a> = DrawText (hdcDib, &amp;cc, 1, &amp;rect, DT_LEFT | DT_TOP);
+00489
+00490 POINT point;
+00491 point.y = <a class="code" href="a04223.html#a643">res</a>;
+00492
+00493 <span class="keywordtype">int</span> <a class="code" href="a04223.html#a575">w</a> = <a class="code" href="a04223.html#a643">res</a>;
+00494 BOOL rey = GetCharWidth32 (hdcDib, (<a class="code" href="a04558.html#a7">uint8</a>) cc, (<a class="code" href="a04558.html#a7">uint8</a>) cc, &amp;w);
+00495 <a class="code" href="a04199.html#a6">nlassert</a> (rey);
+00496 point.x = <a class="code" href="a04223.html#a575">w</a>;
+00497
+00498 <span class="comment">// ABC abc;</span>
+00499 <span class="comment">// BOOL rey = GetCharABCWidths (hdcDib, (uint8) cc, (uint8) cc, &amp;abc);</span>
+00500 <span class="comment">// nlassert (rey);</span>
+00501 <span class="comment">// point.x = abc.abcA;</span>
+00502
+00503 SIZE <a class="code" href="a04223.html#a626">s</a>;
+00504 GetTextExtentPoint32 (hdcDib, &amp;cc, 1, &amp;s);
+00505
+00506 BOOL ret = LPtoDP (hdcDib, &amp;point, 1);
+00507 <a class="code" href="a04199.html#a6">nlassert</a> (ret);
+00508
+00509 <span class="keyword">static</span> <a class="code" href="a04558.html#a7">uint8</a> buf[100*100];
+00510
+00511 <a class="code" href="a04558.html#a10">sint32</a> _top = 0, _left = point.x;
+00512 <a class="code" href="a04558.html#a10">sint32</a> right = 0, bottom = point.y;
+00513 <span class="keywordtype">bool</span> emptyLine;
+00514 <span class="keywordflow">for</span> (<a class="code" href="a04558.html#a14">sint</a> <a class="code" href="a04223.html#a573">y</a> = 0; <a class="code" href="a04223.html#a573">y</a> &lt; point.y; <a class="code" href="a04223.html#a573">y</a>++)
+00515 {
+00516 emptyLine = <span class="keyword">true</span>;
+00517 <span class="keywordflow">for</span> (<a class="code" href="a04558.html#a14">sint</a> <a class="code" href="a04223.html#a572">x</a> = 0; <a class="code" href="a04223.html#a572">x</a> &lt; point.x; <a class="code" href="a04223.html#a572">x</a>++)
+00518 {
+00519 buf[<a class="code" href="a04223.html#a573">y</a>*100+<a class="code" href="a04223.html#a572">x</a>] = (<a class="code" href="a04558.html#a7">uint8</a>) Buffer[<a class="code" href="a04223.html#a573">y</a>*100+<a class="code" href="a04223.html#a572">x</a>];
+00520 <span class="keywordflow">if</span> (buf[<a class="code" href="a04223.html#a573">y</a>*100+<a class="code" href="a04223.html#a572">x</a>])
+00521 {
+00522 emptyLine = <span class="keyword">false</span>;
+00523 <span class="keywordflow">if</span> (<a class="code" href="a04223.html#a572">x</a> &lt; _left)
+00524 _left = <a class="code" href="a04223.html#a572">x</a>;
+00525 <span class="keywordflow">if</span> (<a class="code" href="a04223.html#a572">x</a> &gt; right)
+00526 right = <a class="code" href="a04223.html#a572">x</a>;
+00527 }
+00528
+00529 <span class="comment">// printf (buf[y*100+x]?"*":".");</span>
+00530 }
+00531 <span class="keywordflow">if</span> (!emptyLine)
+00532 {
+00533 <span class="keywordflow">if</span> (_top == 0)
+00534 _top = <a class="code" href="a04223.html#a573">y</a>;
+00535
+00536 bottom = <a class="code" href="a04223.html#a573">y</a>;
+00537 }
+00538
+00539 <span class="comment">// printf ("\n");</span>
+00540 }
+00541 <a class="code" href="a04223.html#a632">width</a> = right - _left + 1;
+00542 <span class="keywordflow">if</span> (right - _left + 1 &lt; 0) <a class="code" href="a04223.html#a632">width</a> = 0;
+00543 <a class="code" href="a04223.html#a633">height</a> = bottom - _top + 1;
+00544 <span class="keywordflow">if</span> (bottom - _top + 1 &lt; 0) <a class="code" href="a04223.html#a633">height</a> = 0;
+00545 pitch = 100;
+00546 advx = point.x;
+00547
+00548 WORD ag = 0;
+00549 <span class="comment">/*uint t = GetGlyphIndices (hdcDib, &amp;cc, 1, &amp;ag, 0);</span>
+00550 <span class="comment"> if (t == GDI_ERROR)</span>
+00551 <span class="comment"> {</span>
+00552 <span class="comment"> nlstop;</span>
+00553 <span class="comment"> }</span>
+00554 <span class="comment">*/</span>
+00555 glyphIndex = ag;
+00556
+00557 top = -_top;
+00558 left = -_left;
+00559
+00560 <span class="comment">/* {</span>
+00561 <span class="comment"> for (sint y = _top; y &lt; _top + height; y++)</span>
+00562 <span class="comment"> {</span>
+00563 <span class="comment"> for (sint x = _left; x &lt; _left + width; x++)</span>
+00564 <span class="comment"> {</span>
+00565 <span class="comment"> printf (buf[y*100+x]?"*":".");</span>
+00566 <span class="comment"> }</span>
+00567 <span class="comment"> printf ("\n");</span>
+00568 <span class="comment"> }</span>
+00569 <span class="comment"> printf ("w: %d h: %d s: %d a: %d l: %d t: %d", width, height, size, advx, left, top);</span>
+00570 <span class="comment"> getchar();</span>
+00571 <span class="comment"> }</span>
+00572 <span class="comment">*/</span>
+00573 _top = _left = top = left = 0;
+00574 top = <a class="code" href="a04223.html#a626">s</a>.cy;
+00575 <a class="code" href="a04223.html#a632">width</a> = <a class="code" href="a04223.html#a626">s</a>.cx;
+00576 <a class="code" href="a04223.html#a633">height</a> = <a class="code" href="a04223.html#a626">s</a>.cy;
+00577
+00578 <span class="keywordflow">return</span> buf + _top * 100 + _left;
+00579 }
+00580
+00581
+00582
+00583
+00584 <span class="keywordtype">void</span> CFontGenerator::getKerning (<a class="code" href="a05167.html#a18">ucchar</a> left, <a class="code" href="a05167.html#a18">ucchar</a> right, <a class="code" href="a04558.html#a10">sint32</a> &amp;kernx)
+00585 {
+00586 <span class="comment">/* if (!FT_HAS_KERNING(_Face))</span>
+00587 <span class="comment"> {</span>
+00588 <span class="comment"> kernx = 0;</span>
+00589 <span class="comment"> }</span>
+00590 <span class="comment"> else</span>
+00591 <span class="comment"> {</span>
+00592 <span class="comment"> FT_Vector kerning;</span>
+00593 <span class="comment"> FT_Error error = FT_Get_Kerning (_Face, left, right, ft_kerning_default, &amp;kerning);</span>
+00594 <span class="comment"> if (error)</span>
+00595 <span class="comment"> {</span>
+00596 <span class="comment"> nlerror ("FT_Get_Kerning() failed: %s", getFT2Error(error));</span>
+00597 <span class="comment"> }</span>
+00598 <span class="comment"> kernx = kerning.x;</span>
+00599 <span class="comment"> }*/</span>
+00600 }
+00601
+00602
+00603
+00604 <a class="code" href="a04558.html#a11">uint32</a> CFontGenerator::getCharIndex (<a class="code" href="a05167.html#a18">ucchar</a> c)
+00605 {
+00606 <span class="comment">// return FT_Get_Char_Index (_Face, c);</span>
+00607 <span class="keywordflow">return</span> 0;
+00608 }
+00609
+00610
+00611 } <span class="comment">// NL3D</span>
+00612
+00613 <span class="preprocessor">#endif // NL_DONT_USE_EXTERNAL_CODE</span>
+00614 <span class="preprocessor"></span>
+</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Mar 16 06:25:03 2004 for NeL by
+<a href="http://www.doxygen.org/index.html">
+<img src="doxygen.png" alt="doxygen" align="middle" border=0 >
+</a>1.3.6 </small></address>
+</body>
+</html>