| <!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: FTFace.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>FTFace.cpp</h1><a href="FTFace_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="FTLibrary_8h.html">FTLibrary.h</a>"</span> |
| 00003 |
| 00004 <span class="preprocessor">#include FT_TRUETYPE_TABLES_H</span> |
| 00005 <span class="preprocessor"></span> |
| <a name="l00006"></a><a class="code" href="classFTFace.html#a0">00006</a> <a class="code" href="classFTFace.html#a0">FTFace::FTFace</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* fontFilePath) |
| 00007 : numGlyphs(0), |
| 00008 fontEncodingList(0), |
| 00009 err(0) |
| 00010 { |
| 00011 <span class="keyword">const</span> FT_Long DEFAULT_FACE_INDEX = 0; |
| 00012 ftFace = <span class="keyword">new</span> FT_Face; |
| 00013 |
| 00014 err = FT_New_Face( *FTLibrary::Instance().GetLibrary(), fontFilePath, DEFAULT_FACE_INDEX, ftFace); |
| 00015 |
| 00016 <span class="keywordflow">if</span>( err) |
| 00017 { |
| 00018 <span class="keyword">delete</span> ftFace; |
| 00019 ftFace = 0; |
| 00020 } |
| 00021 <span class="keywordflow">else</span> |
| 00022 { |
| 00023 numGlyphs = (*ftFace)->num_glyphs; |
| 00024 hasKerningTable = FT_HAS_KERNING((*ftFace)); |
| 00025 } |
| 00026 } |
| 00027 |
| 00028 |
| <a name="l00029"></a><a class="code" href="classFTFace.html#a1">00029</a> <a class="code" href="classFTFace.html#a0">FTFace::FTFace</a>( <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *pBufferBytes, size_t bufferSizeInBytes) |
| 00030 : numGlyphs(0), |
| 00031 err(0) |
| 00032 { |
| 00033 <span class="keyword">const</span> FT_Long DEFAULT_FACE_INDEX = 0; |
| 00034 ftFace = <span class="keyword">new</span> FT_Face; |
| 00035 |
| 00036 err = FT_New_Memory_Face( *FTLibrary::Instance().GetLibrary(), (FT_Byte *)pBufferBytes, bufferSizeInBytes, DEFAULT_FACE_INDEX, ftFace); |
| 00037 |
| 00038 <span class="keywordflow">if</span>( err) |
| 00039 { |
| 00040 <span class="keyword">delete</span> ftFace; |
| 00041 ftFace = 0; |
| 00042 } |
| 00043 <span class="keywordflow">else</span> |
| 00044 { |
| 00045 numGlyphs = (*ftFace)->num_glyphs; |
| 00046 } |
| 00047 } |
| 00048 |
| 00049 |
| <a name="l00050"></a><a class="code" href="classFTFace.html#a2">00050</a> <a class="code" href="classFTFace.html#a2">FTFace::~FTFace</a>() |
| 00051 { |
| 00052 <span class="keywordflow">if</span>( ftFace) |
| 00053 { |
| 00054 FT_Done_Face( *ftFace); |
| 00055 <span class="keyword">delete</span> ftFace; |
| 00056 ftFace = 0; |
| 00057 } |
| 00058 } |
| 00059 |
| 00060 |
| <a name="l00061"></a><a class="code" href="classFTFace.html#a3">00061</a> <span class="keywordtype">bool</span> <a class="code" href="classFTFace.html#a3">FTFace::Attach</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* fontFilePath) |
| 00062 { |
| 00063 err = FT_Attach_File( *ftFace, fontFilePath); |
| 00064 <span class="keywordflow">return</span> !err; |
| 00065 } |
| 00066 |
| 00067 |
| <a name="l00068"></a><a class="code" href="classFTFace.html#a4">00068</a> <span class="keywordtype">bool</span> <a class="code" href="classFTFace.html#a3">FTFace::Attach</a>( <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *pBufferBytes, size_t bufferSizeInBytes) |
| 00069 { |
| 00070 FT_Open_Args open; |
| 00071 |
| 00072 open.flags = <a class="code" href="FTGL_8h.html#a0">FT_OPEN_MEMORY</a>; |
| 00073 open.memory_base = (FT_Byte *)pBufferBytes; |
| 00074 open.memory_size = bufferSizeInBytes; |
| 00075 |
| 00076 err = FT_Attach_Stream( *ftFace, &open); |
| 00077 <span class="keywordflow">return</span> !err; |
| 00078 } |
| 00079 |
| 00080 |
| <a name="l00081"></a><a class="code" href="classFTFace.html#a6">00081</a> <span class="keyword">const</span> <a class="code" href="classFTSize.html">FTSize</a>& <a class="code" href="classFTFace.html#a6">FTFace::Size</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) |
| 00082 { |
| 00083 charSize.<a class="code" href="classFTSize.html#a2">CharSize</a>( ftFace, size, res, res); |
| 00084 err = charSize.<a class="code" href="classFTSize.html#a9">Error</a>(); |
| 00085 |
| 00086 <span class="keywordflow">return</span> charSize; |
| 00087 } |
| 00088 |
| 00089 |
| <a name="l00090"></a><a class="code" href="classFTFace.html#a7">00090</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classFTFace.html#a7">FTFace::CharMapCount</a>() |
| 00091 { |
| 00092 <span class="keywordflow">return</span> (*ftFace)->num_charmaps; |
| 00093 } |
| 00094 |
| 00095 |
| <a name="l00096"></a><a class="code" href="classFTFace.html#a8">00096</a> FT_Encoding* <a class="code" href="classFTFace.html#a8">FTFace::CharMapList</a>() |
| 00097 { |
| 00098 <span class="keywordflow">if</span>( 0 == fontEncodingList) |
| 00099 { |
| 00100 fontEncodingList = <span class="keyword">new</span> FT_Encoding[<a class="code" href="classFTFace.html#a7">CharMapCount</a>()]; |
| 00101 <span class="keywordflow">for</span>( size_t encodingIndex = 0; encodingIndex < <a class="code" href="classFTFace.html#a7">CharMapCount</a>(); ++encodingIndex) |
| 00102 { |
| 00103 fontEncodingList[encodingIndex] = (*ftFace)->charmaps[encodingIndex]->encoding; |
| 00104 } |
| 00105 } |
| 00106 |
| 00107 <span class="keywordflow">return</span> fontEncodingList; |
| 00108 } |
| 00109 |
| 00110 |
| <a name="l00111"></a><a class="code" href="classFTFace.html#a9">00111</a> <a class="code" href="classFTPoint.html">FTPoint</a> <a class="code" href="classFTFace.html#a9">FTFace::KernAdvance</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> index1, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> index2) |
| 00112 { |
| 00113 <span class="keywordtype">float</span> x, y; |
| 00114 x = y = 0.0f; |
| 00115 |
| 00116 <span class="keywordflow">if</span>( hasKerningTable && index1 && index2) |
| 00117 { |
| 00118 FT_Vector kernAdvance; |
| 00119 kernAdvance.x = kernAdvance.y = 0; |
| 00120 |
| 00121 err = FT_Get_Kerning( *ftFace, index1, index2, ft_kerning_unfitted, &kernAdvance); |
| 00122 <span class="keywordflow">if</span>( !err) |
| 00123 { |
| 00124 x = static_cast<float>( kernAdvance.x) / 64.0f; |
| 00125 y = static_cast<float>( kernAdvance.y) / 64.0f; |
| 00126 } |
| 00127 } |
| 00128 |
| 00129 <span class="keywordflow">return</span> <a class="code" href="classFTPoint.html">FTPoint</a>( x, y, 0.0); |
| 00130 } |
| 00131 |
| 00132 |
| <a name="l00133"></a><a class="code" href="classFTFace.html#a10">00133</a> FT_GlyphSlot <a class="code" href="classFTFace.html#a10">FTFace::Glyph</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> index, FT_Int load_flags) |
| 00134 { |
| 00135 err = FT_Load_Glyph( *ftFace, index, load_flags); |
| 00136 <span class="keywordflow">if</span>( err) |
| 00137 { |
| 00138 <span class="keywordflow">return</span> NULL; |
| 00139 } |
| 00140 |
| 00141 <span class="keywordflow">return</span> (*ftFace)->glyph; |
| 00142 } |
| 00143 |
| </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> |