| <!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: FTFont.cpp 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 Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</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> | <a class="qindex" href="globals.html">Globals</a></div> |
| <h1>FTFont.cpp</h1><a href="FTFont_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="preprocessor">#include "<a class="code" href="FTFace_8h.html">FTFace.h</a>"</span> |
| 00002 <span class="preprocessor">#include "<a class="code" href="FTFont_8h.html">FTFont.h</a>"</span> |
| 00003 <span class="preprocessor">#include "<a class="code" href="FTGlyphContainer_8h.html">FTGlyphContainer.h</a>"</span> |
| 00004 <span class="preprocessor">#include "<a class="code" href="FTBBox_8h.html">FTBBox.h</a>"</span> |
| 00005 |
| 00006 |
| <a name="l00007"></a><a class="code" href="classFTFont.html#a0">00007</a> <a class="code" href="classFTFont.html#a0">FTFont::FTFont</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* fontFilePath) |
| 00008 : face( fontFilePath), |
| 00009 useDisplayLists(true), |
| 00010 glyphList(0) |
| 00011 { |
| 00012 err = <a class="code" href="classFTFont.html#p0">face</a>.<a class="code" href="classFTFace.html#a12">Error</a>(); |
| 00013 <span class="keywordflow">if</span>( err == 0) |
| 00014 { |
| 00015 glyphList = <span class="keyword">new</span> <a class="code" href="classFTGlyphContainer.html">FTGlyphContainer</a>( &<a class="code" href="classFTFont.html#p0">face</a>); |
| 00016 } |
| 00017 } |
| 00018 |
| 00019 |
| <a name="l00020"></a><a class="code" href="classFTFont.html#a1">00020</a> <a class="code" href="classFTFont.html#a0">FTFont::FTFont</a>( <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *pBufferBytes, size_t bufferSizeInBytes) |
| 00021 : face( pBufferBytes, bufferSizeInBytes), |
| 00022 glyphList(0) |
| 00023 { |
| 00024 err = <a class="code" href="classFTFont.html#p0">face</a>.<a class="code" href="classFTFace.html#a12">Error</a>(); |
| 00025 <span class="keywordflow">if</span>( err == 0) |
| 00026 { |
| 00027 glyphList = <span class="keyword">new</span> <a class="code" href="classFTGlyphContainer.html">FTGlyphContainer</a>( &<a class="code" href="classFTFont.html#p0">face</a>); |
| 00028 } |
| 00029 } |
| 00030 |
| 00031 |
| <a name="l00032"></a><a class="code" href="classFTFont.html#a2">00032</a> <a class="code" href="classFTFont.html#a2">FTFont::~FTFont</a>() |
| 00033 { |
| 00034 <span class="keyword">delete</span> glyphList; |
| 00035 } |
| 00036 |
| 00037 |
| <a name="l00038"></a><a class="code" href="classFTFont.html#a3">00038</a> <span class="keywordtype">bool</span> <a class="code" href="classFTFont.html#a3">FTFont::Attach</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* fontFilePath) |
| 00039 { |
| 00040 <span class="keywordflow">if</span>( <a class="code" href="classFTFont.html#p0">face</a>.<a class="code" href="classFTFace.html#a3">Attach</a>( fontFilePath)) |
| 00041 { |
| 00042 err = 0; |
| 00043 <span class="keywordflow">return</span> <span class="keyword">true</span>; |
| 00044 } |
| 00045 <span class="keywordflow">else</span> |
| 00046 { |
| 00047 err = <a class="code" href="classFTFont.html#p0">face</a>.<a class="code" href="classFTFace.html#a12">Error</a>(); |
| 00048 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
| 00049 } |
| 00050 } |
| 00051 |
| 00052 |
| <a name="l00053"></a><a class="code" href="classFTFont.html#a4">00053</a> <span class="keywordtype">bool</span> <a class="code" href="classFTFont.html#a3">FTFont::Attach</a>( <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *pBufferBytes, size_t bufferSizeInBytes) |
| 00054 { |
| 00055 <span class="keywordflow">if</span>( <a class="code" href="classFTFont.html#p0">face</a>.<a class="code" href="classFTFace.html#a3">Attach</a>( pBufferBytes, bufferSizeInBytes)) |
| 00056 { |
| 00057 err = 0; |
| 00058 <span class="keywordflow">return</span> <span class="keyword">true</span>; |
| 00059 } |
| 00060 <span class="keywordflow">else</span> |
| 00061 { |
| 00062 err = <a class="code" href="classFTFont.html#p0">face</a>.<a class="code" href="classFTFace.html#a12">Error</a>(); |
| 00063 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
| 00064 } |
| 00065 } |
| 00066 |
| 00067 |
| <a name="l00068"></a><a class="code" href="classFTFont.html#a8">00068</a> <span class="keywordtype">bool</span> <a class="code" href="classFTFont.html#a9">FTFont::FaceSize</a>( <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> res ) |
| 00069 { |
| 00070 charSize = <a class="code" href="classFTFont.html#p0">face</a>.<a class="code" href="classFTFace.html#a6">Size</a>( size, res); |
| 00071 err = <a class="code" href="classFTFont.html#p0">face</a>.<a class="code" href="classFTFace.html#a12">Error</a>(); |
| 00072 |
| 00073 <span class="keywordflow">if</span>( err != 0) |
| 00074 { |
| 00075 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
| 00076 } |
| 00077 |
| 00078 <span class="keywordflow">if</span>( glyphList != NULL) |
| 00079 { |
| 00080 <span class="keyword">delete</span> glyphList; |
| 00081 } |
| 00082 |
| 00083 glyphList = <span class="keyword">new</span> <a class="code" href="classFTGlyphContainer.html">FTGlyphContainer</a>( &<a class="code" href="classFTFont.html#p0">face</a>); |
| 00084 <span class="keywordflow">return</span> <span class="keyword">true</span>; |
| 00085 } |
| 00086 |
| 00087 |
| <a name="l00088"></a><a class="code" href="classFTFont.html#a9">00088</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classFTFont.html#a9">FTFont::FaceSize</a>()<span class="keyword"> const</span> |
| 00089 <span class="keyword"></span>{ |
| 00090 <span class="keywordflow">return</span> charSize.<a class="code" href="classFTSize.html#a2">CharSize</a>(); |
| 00091 } |
| 00092 |
| 00093 |
| <a name="l00094"></a><a class="code" href="classFTFont.html#a5">00094</a> <span class="keywordtype">bool</span> <a class="code" href="classFTFont.html#a5">FTFont::CharMap</a>( FT_Encoding encoding) |
| 00095 { |
| 00096 <span class="keywordtype">bool</span> result = glyphList-><a class="code" href="classFTGlyphContainer.html#a2">CharMap</a>( encoding); |
| 00097 err = glyphList-><a class="code" href="classFTGlyphContainer.html#a9">Error</a>(); |
| 00098 <span class="keywordflow">return</span> result; |
| 00099 } |
| 00100 |
| 00101 |
| <a name="l00102"></a><a class="code" href="classFTFont.html#a6">00102</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classFTFont.html#a6">FTFont::CharMapCount</a>() |
| 00103 { |
| 00104 <span class="keywordflow">return</span> <a class="code" href="classFTFont.html#p0">face</a>.<a class="code" href="classFTFace.html#a7">CharMapCount</a>(); |
| 00105 } |
| 00106 |
| 00107 |
| <a name="l00108"></a><a class="code" href="classFTFont.html#a7">00108</a> FT_Encoding* <a class="code" href="classFTFont.html#a7">FTFont::CharMapList</a>() |
| 00109 { |
| 00110 <span class="keywordflow">return</span> <a class="code" href="classFTFont.html#p0">face</a>.<a class="code" href="classFTFace.html#a8">CharMapList</a>(); |
| 00111 } |
| 00112 |
| 00113 |
| <a name="l00114"></a><a class="code" href="classFTFont.html#a11">00114</a> <span class="keywordtype">void</span> <a class="code" href="classFTFont.html#a11">FTFont::UseDisplayList</a>( <span class="keywordtype">bool</span> useList) |
| 00115 { |
| 00116 <a class="code" href="classFTFont.html#p2">useDisplayLists</a> = useList; |
| 00117 } |
| 00118 |
| <a name="l00119"></a><a class="code" href="classFTFont.html#a12">00119</a> <span class="keywordtype">float</span> <a class="code" href="classFTFont.html#a12">FTFont::Ascender</a>()<span class="keyword"> const</span> |
| 00120 <span class="keyword"></span>{ |
| 00121 <span class="keywordflow">return</span> charSize.<a class="code" href="classFTSize.html#a4">Ascender</a>(); |
| 00122 } |
| 00123 |
| 00124 |
| <a name="l00125"></a><a class="code" href="classFTFont.html#a13">00125</a> <span class="keywordtype">float</span> <a class="code" href="classFTFont.html#a13">FTFont::Descender</a>()<span class="keyword"> const</span> |
| 00126 <span class="keyword"></span>{ |
| 00127 <span class="keywordflow">return</span> charSize.<a class="code" href="classFTSize.html#a5">Descender</a>(); |
| 00128 } |
| 00129 |
| <a name="l00130"></a><a class="code" href="classFTFont.html#a14">00130</a> <span class="keywordtype">float</span> <a class="code" href="classFTFont.html#a14">FTFont::LineHeight</a>()<span class="keyword"> const</span> |
| 00131 <span class="keyword"></span>{ |
| 00132 <span class="keywordflow">return</span> charSize.<a class="code" href="classFTSize.html#a6">Height</a>(); |
| 00133 } |
| 00134 |
| <a name="l00135"></a><a class="code" href="classFTFont.html#a15">00135</a> <span class="keywordtype">void</span> <a class="code" href="classFTFont.html#a15">FTFont::BBox</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* string, |
| 00136 <span class="keywordtype">float</span>& llx, <span class="keywordtype">float</span>& lly, <span class="keywordtype">float</span>& llz, <span class="keywordtype">float</span>& urx, <span class="keywordtype">float</span>& ury, <span class="keywordtype">float</span>& urz) |
| 00137 { |
| 00138 <a class="code" href="classFTBBox.html">FTBBox</a> totalBBox; |
| 00139 |
| 00140 <span class="keywordflow">if</span>((NULL != string) && (<span class="charliteral">'\0'</span> != *string)) |
| 00141 { |
| 00142 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* c = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)string; |
| 00143 <span class="keywordtype">float</span> advance = 0; |
| 00144 |
| 00145 <span class="keywordflow">if</span>(CheckGlyph( *c)) |
| 00146 { |
| 00147 totalBBox = glyphList-><a class="code" href="classFTGlyphContainer.html#a6">BBox</a>( *c); |
| 00148 advance = glyphList-><a class="code" href="classFTGlyphContainer.html#a7">Advance</a>( *c, *(c + 1)); |
| 00149 } |
| 00150 |
| 00151 <span class="keywordflow">while</span>( *++c) |
| 00152 { |
| 00153 <span class="keywordflow">if</span>(CheckGlyph( *c)) |
| 00154 { |
| 00155 <a class="code" href="classFTBBox.html">FTBBox</a> tempBBox = glyphList-><a class="code" href="classFTGlyphContainer.html#a6">BBox</a>( *c); |
| 00156 tempBBox.<a class="code" href="classFTBBox.html#a4">Move</a>( <a class="code" href="classFTPoint.html">FTPoint</a>( advance, 0.0f, 0.0f)); |
| 00157 totalBBox += tempBBox; |
| 00158 advance += glyphList-><a class="code" href="classFTGlyphContainer.html#a7">Advance</a>( *c, *(c + 1)); |
| 00159 } |
| 00160 } |
| 00161 } |
| 00162 |
| 00163 llx = totalBBox.<a class="code" href="classFTBBox.html#o0">lowerX</a>; |
| 00164 lly = totalBBox.<a class="code" href="classFTBBox.html#o1">lowerY</a>; |
| 00165 llz = totalBBox.<a class="code" href="classFTBBox.html#o2">lowerZ</a>; |
| 00166 urx = totalBBox.<a class="code" href="classFTBBox.html#o3">upperX</a>; |
| 00167 ury = totalBBox.<a class="code" href="classFTBBox.html#o4">upperY</a>; |
| 00168 urz = totalBBox.<a class="code" href="classFTBBox.html#o5">upperZ</a>; |
| 00169 } |
| 00170 |
| 00171 |
| <a name="l00172"></a><a class="code" href="classFTFont.html#a16">00172</a> <span class="keywordtype">void</span> <a class="code" href="classFTFont.html#a15">FTFont::BBox</a>( <span class="keyword">const</span> <span class="keywordtype">wchar_t</span>* string, |
| 00173 <span class="keywordtype">float</span>& llx, <span class="keywordtype">float</span>& lly, <span class="keywordtype">float</span>& llz, <span class="keywordtype">float</span>& urx, <span class="keywordtype">float</span>& ury, <span class="keywordtype">float</span>& urz) |
| 00174 { |
| 00175 <a class="code" href="classFTBBox.html">FTBBox</a> totalBBox; |
| 00176 |
| 00177 <span class="keywordflow">if</span>((NULL != string) && (<span class="charliteral">'\0'</span> != *string)) |
| 00178 { |
| 00179 <span class="keyword">const</span> <span class="keywordtype">wchar_t</span>* c = string; |
| 00180 <span class="keywordtype">float</span> advance = 0; |
| 00181 |
| 00182 <span class="keywordflow">if</span>(CheckGlyph( *c)) |
| 00183 { |
| 00184 totalBBox = glyphList-><a class="code" href="classFTGlyphContainer.html#a6">BBox</a>( *c); |
| 00185 advance = glyphList-><a class="code" href="classFTGlyphContainer.html#a7">Advance</a>( *c, *(c + 1)); |
| 00186 } |
| 00187 |
| 00188 <span class="keywordflow">while</span>( *++c) |
| 00189 { |
| 00190 <span class="keywordflow">if</span>(CheckGlyph( *c)) |
| 00191 { |
| 00192 <a class="code" href="classFTBBox.html">FTBBox</a> tempBBox = glyphList-><a class="code" href="classFTGlyphContainer.html#a6">BBox</a>( *c); |
| 00193 tempBBox.<a class="code" href="classFTBBox.html#a4">Move</a>( <a class="code" href="classFTPoint.html">FTPoint</a>( advance, 0.0f, 0.0f)); |
| 00194 totalBBox += tempBBox; |
| 00195 advance += glyphList-><a class="code" href="classFTGlyphContainer.html#a7">Advance</a>( *c, *(c + 1)); |
| 00196 } |
| 00197 } |
| 00198 } |
| 00199 |
| 00200 llx = totalBBox.<a class="code" href="classFTBBox.html#o0">lowerX</a>; |
| 00201 lly = totalBBox.<a class="code" href="classFTBBox.html#o1">lowerY</a>; |
| 00202 llz = totalBBox.<a class="code" href="classFTBBox.html#o2">lowerZ</a>; |
| 00203 urx = totalBBox.<a class="code" href="classFTBBox.html#o3">upperX</a>; |
| 00204 ury = totalBBox.<a class="code" href="classFTBBox.html#o4">upperY</a>; |
| 00205 urz = totalBBox.<a class="code" href="classFTBBox.html#o5">upperZ</a>; |
| 00206 } |
| 00207 |
| 00208 |
| <a name="l00209"></a><a class="code" href="classFTFont.html#a17">00209</a> <span class="keywordtype">float</span> <a class="code" href="classFTFont.html#a17">FTFont::Advance</a>( <span class="keyword">const</span> <span class="keywordtype">wchar_t</span>* string) |
| 00210 { |
| 00211 <span class="keyword">const</span> <span class="keywordtype">wchar_t</span>* c = string; |
| 00212 <span class="keywordtype">float</span> width = 0.0f; |
| 00213 |
| 00214 <span class="keywordflow">while</span>( *c) |
| 00215 { |
| 00216 <span class="keywordflow">if</span>(CheckGlyph( *c)) |
| 00217 { |
| 00218 width += glyphList-><a class="code" href="classFTGlyphContainer.html#a7">Advance</a>( *c, *(c + 1)); |
| 00219 } |
| 00220 ++c; |
| 00221 } |
| 00222 |
| 00223 <span class="keywordflow">return</span> width; |
| 00224 } |
| 00225 |
| 00226 |
| <a name="l00227"></a><a class="code" href="classFTFont.html#a18">00227</a> <span class="keywordtype">float</span> <a class="code" href="classFTFont.html#a17">FTFont::Advance</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* string) |
| 00228 { |
| 00229 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* c = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)string; |
| 00230 <span class="keywordtype">float</span> width = 0.0f; |
| 00231 |
| 00232 <span class="keywordflow">while</span>( *c) |
| 00233 { |
| 00234 <span class="keywordflow">if</span>(CheckGlyph( *c)) |
| 00235 { |
| 00236 width += glyphList-><a class="code" href="classFTGlyphContainer.html#a7">Advance</a>( *c, *(c + 1)); |
| 00237 } |
| 00238 ++c; |
| 00239 } |
| 00240 |
| 00241 <span class="keywordflow">return</span> width; |
| 00242 } |
| 00243 |
| 00244 |
| <a name="l00245"></a><a class="code" href="classFTFont.html#a19">00245</a> <span class="keywordtype">void</span> <a class="code" href="classFTFont.html#a19">FTFont::Render</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* string ) |
| 00246 { |
| 00247 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* c = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)string; |
| 00248 pen.<a class="code" href="classFTPoint.html#a7">X</a>(0); pen.<a class="code" href="classFTPoint.html#a8">Y</a>(0); |
| 00249 |
| 00250 <span class="keywordflow">while</span>( *c) |
| 00251 { |
| 00252 <span class="keywordflow">if</span>(CheckGlyph( *c)) |
| 00253 { |
| 00254 pen = glyphList-><a class="code" href="classFTGlyphContainer.html#a8">Render</a>( *c, *(c + 1), pen); |
| 00255 } |
| 00256 ++c; |
| 00257 } |
| 00258 } |
| 00259 |
| 00260 |
| <a name="l00261"></a><a class="code" href="classFTFont.html#a20">00261</a> <span class="keywordtype">void</span> <a class="code" href="classFTFont.html#a19">FTFont::Render</a>( <span class="keyword">const</span> <span class="keywordtype">wchar_t</span>* string ) |
| 00262 { |
| 00263 <span class="keyword">const</span> <span class="keywordtype">wchar_t</span>* c = string; |
| 00264 pen.<a class="code" href="classFTPoint.html#a7">X</a>(0); pen.<a class="code" href="classFTPoint.html#a8">Y</a>(0); |
| 00265 |
| 00266 <span class="keywordflow">while</span>( *c) |
| 00267 { |
| 00268 <span class="keywordflow">if</span>(CheckGlyph( *c)) |
| 00269 { |
| 00270 pen = glyphList-><a class="code" href="classFTGlyphContainer.html#a8">Render</a>( *c, *(c + 1), pen); |
| 00271 } |
| 00272 ++c; |
| 00273 } |
| 00274 } |
| 00275 |
| 00276 |
| 00277 <span class="keywordtype">bool</span> FTFont::CheckGlyph( <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> characterCode) |
| 00278 { |
| 00279 <span class="keywordflow">if</span>( NULL == glyphList-><a class="code" href="classFTGlyphContainer.html#a5">Glyph</a>( characterCode)) |
| 00280 { |
| 00281 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> glyphIndex = glyphList-><a class="code" href="classFTGlyphContainer.html#a3">FontIndex</a>( characterCode); |
| 00282 <a class="code" href="classFTGlyph.html">FTGlyph</a>* tempGlyph = <a class="code" href="classFTFont.html#b0">MakeGlyph</a>( glyphIndex); |
| 00283 <span class="keywordflow">if</span>( NULL == tempGlyph) |
| 00284 { |
| 00285 <span class="keywordflow">if</span>( 0 == err) |
| 00286 { |
| 00287 err = 0x13; |
| 00288 } |
| 00289 |
| 00290 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
| 00291 } |
| 00292 glyphList-><a class="code" href="classFTGlyphContainer.html#a4">Add</a>( tempGlyph, characterCode); |
| 00293 } |
| 00294 |
| 00295 <span class="keywordflow">return</span> <span class="keyword">true</span>; |
| 00296 } |
| 00297 |
| </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Dec 5 22:24:06 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> |