blob: 7ac3d437ab8549f3b2b931d20ec250f902a2eac8 [file] [log] [blame]
<!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>FTGL: FTCharToGlyphIndexMap.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.6 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</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="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a></div>
<h1>FTCharToGlyphIndexMap.h</h1><a href="FTCharToGlyphIndexMap_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="preprocessor">#ifndef __FTCharToGlyphIndexMap__</span>
00002 <span class="preprocessor"></span><span class="preprocessor">#define __FTCharToGlyphIndexMap__</span>
00003 <span class="preprocessor"></span>
00004 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
00005
00006 <span class="preprocessor">#include "<a class="code" href="FTGL_8h.html">FTGL.h</a>"</span>
00007
<a name="l00027"></a><a class="code" href="classFTCharToGlyphIndexMap.html">00027</a> <span class="keyword">class </span><a class="code" href="FTGL_8h.html#a3">FTGL_EXPORT</a> FTCharToGlyphIndexMap
00028 {
00029 <span class="keyword">public</span>:
00030
<a name="l00031"></a><a class="code" href="classFTCharToGlyphIndexMap.html#w0">00031</a> <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="classFTCharToGlyphIndexMap.html#w0">CharacterCode</a>;
<a name="l00032"></a><a class="code" href="classFTCharToGlyphIndexMap.html#w1">00032</a> <span class="keyword">typedef</span> <span class="keywordtype">signed</span> <span class="keywordtype">long</span> <a class="code" href="classFTCharToGlyphIndexMap.html#w1">GlyphIndex</a>;
00033
00034 <span class="keyword">enum</span>
00035 {
00036 NumberOfBuckets = 256,
00037 BucketSize = 256,
00038 IndexNotFound = -1
00039 };
00040
<a name="l00041"></a><a class="code" href="classFTCharToGlyphIndexMap.html#a0">00041</a> FTCharToGlyphIndexMap()
00042 {
00043 this-&gt;Indices = 0;
00044 }
00045
<a name="l00046"></a><a class="code" href="classFTCharToGlyphIndexMap.html#a1">00046</a> <span class="keyword">virtual</span> ~FTCharToGlyphIndexMap()
00047 {
00048 <span class="keywordflow">if</span>( this-&gt;Indices)
00049 {
00050 <span class="comment">// Free all buckets</span>
00051 this-&gt;clear();
00052
00053 <span class="comment">// Free main structure</span>
00054 <span class="keyword">delete</span> [] this-&gt;Indices;
00055 this-&gt;Indices = 0;
00056 }
00057 }
00058
<a name="l00059"></a><a class="code" href="classFTCharToGlyphIndexMap.html#a2">00059</a> <span class="keywordtype">void</span> clear()
00060 {
00061 <span class="keywordflow">if</span>(this-&gt;Indices)
00062 {
00063 <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classFTCharToGlyphIndexMap.html#w5w2">FTCharToGlyphIndexMap::NumberOfBuckets</a>; i++)
00064 {
00065 <span class="keywordflow">if</span>( this-&gt;Indices[i])
00066 {
00067 <span class="keyword">delete</span> [] this-&gt;Indices[i];
00068 this-&gt;Indices[i] = 0;
00069 }
00070 }
00071 }
00072 }
00073
<a name="l00074"></a><a class="code" href="classFTCharToGlyphIndexMap.html#a3">00074</a> <span class="keyword">const</span> <a class="code" href="classFTCharToGlyphIndexMap.html#w1">GlyphIndex</a> find( <a class="code" href="classFTCharToGlyphIndexMap.html#w0">CharacterCode</a> c)
00075 {
00076 <span class="keywordflow">if</span>( !this-&gt;Indices)
00077 {
00078 <span class="keywordflow">return</span> 0;
00079 }
00080
00081 <span class="comment">// Find position of char code in buckets</span>
00082 div_t pos = div( c, <a class="code" href="classFTCharToGlyphIndexMap.html#w5w3">FTCharToGlyphIndexMap::BucketSize</a>);
00083
00084 <span class="keywordflow">if</span>( !this-&gt;Indices[pos.quot])
00085 {
00086 <span class="keywordflow">return</span> 0;
00087 }
00088
00089 <span class="keyword">const</span> <a class="code" href="classFTCharToGlyphIndexMap.html#w1">FTCharToGlyphIndexMap::GlyphIndex</a> *ptr = &amp;this-&gt;Indices[pos.quot][pos.rem];
00090 <span class="keywordflow">if</span>( *ptr == <a class="code" href="classFTCharToGlyphIndexMap.html#w5w4">FTCharToGlyphIndexMap::IndexNotFound</a>)
00091 {
00092 <span class="keywordflow">return</span> 0;
00093 }
00094
00095 <span class="keywordflow">return</span> *ptr;
00096 }
00097
<a name="l00098"></a><a class="code" href="classFTCharToGlyphIndexMap.html#a4">00098</a> <span class="keywordtype">void</span> insert( <a class="code" href="classFTCharToGlyphIndexMap.html#w0">CharacterCode</a> c, <a class="code" href="classFTCharToGlyphIndexMap.html#w1">GlyphIndex</a> g)
00099 {
00100 <span class="keywordflow">if</span>( !this-&gt;Indices)
00101 {
00102 this-&gt;Indices = <span class="keyword">new</span> <a class="code" href="classFTCharToGlyphIndexMap.html#w1">GlyphIndex</a>* [<a class="code" href="classFTCharToGlyphIndexMap.html#w5w2">FTCharToGlyphIndexMap::NumberOfBuckets</a>];
00103 <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classFTCharToGlyphIndexMap.html#w5w2">FTCharToGlyphIndexMap::NumberOfBuckets</a>; i++)
00104 {
00105 this-&gt;Indices[i] = 0;
00106 }
00107 }
00108
00109 <span class="comment">// Find position of char code in buckets</span>
00110 div_t pos = div(c, <a class="code" href="classFTCharToGlyphIndexMap.html#w5w3">FTCharToGlyphIndexMap::BucketSize</a>);
00111
00112 <span class="comment">// Allocate bucket if does not exist yet</span>
00113 <span class="keywordflow">if</span>( !this-&gt;Indices[pos.quot])
00114 {
00115 this-&gt;Indices[pos.quot] = <span class="keyword">new</span> <a class="code" href="classFTCharToGlyphIndexMap.html#w1">GlyphIndex</a> [<a class="code" href="classFTCharToGlyphIndexMap.html#w5w3">FTCharToGlyphIndexMap::BucketSize</a>];
00116 <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classFTCharToGlyphIndexMap.html#w5w3">FTCharToGlyphIndexMap::BucketSize</a>; i++)
00117 {
00118 this-&gt;Indices[pos.quot][i] = <a class="code" href="classFTCharToGlyphIndexMap.html#w5w4">FTCharToGlyphIndexMap::IndexNotFound</a>;
00119 }
00120 }
00121
00122 this-&gt;Indices[pos.quot][pos.rem] = g;
00123 }
00124
00125 <span class="keyword">private</span>:
00126 GlyphIndex** Indices;
00127 };
00128
00129
00130 <span class="preprocessor">#endif // __FTCharToGlyphIndexMap__</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Dec 5 22:24:05 2004 for FTGL 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>