Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > ed1483a4d9709d82850bb84cf25535e7 > files > 42

sfml-1.5-1mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>SFML - Simple and Fast Multimedia Library</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="tabs.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="logo">
            <img src="./logo.jpg" width="770" height="200" title="SFML home" alt="SFML logo" />
        </div>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.htm"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.htm"><span>Namespaces</span></a></li>
      <li><a href="annotated.htm"><span>Classes</span></a></li>
      <li class="current"><a href="files.htm"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.htm"><span>File&nbsp;List</span></a></li>
    </ul>
  </div>
<h1>Font.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// SFML - Simple and Fast Multimedia Library</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)</span>
<a name="l00005"></a>00005 <span class="comment">//</span>
<a name="l00006"></a>00006 <span class="comment">// This software is provided 'as-is', without any express or implied warranty.</span>
<a name="l00007"></a>00007 <span class="comment">// In no event will the authors be held liable for any damages arising from the use of this software.</span>
<a name="l00008"></a>00008 <span class="comment">//</span>
<a name="l00009"></a>00009 <span class="comment">// Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00010"></a>00010 <span class="comment">// including commercial applications, and to alter it and redistribute it freely,</span>
<a name="l00011"></a>00011 <span class="comment">// subject to the following restrictions:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// 1. The origin of this software must not be misrepresented;</span>
<a name="l00014"></a>00014 <span class="comment">//    you must not claim that you wrote the original software.</span>
<a name="l00015"></a>00015 <span class="comment">//    If you use this software in a product, an acknowledgment</span>
<a name="l00016"></a>00016 <span class="comment">//    in the product documentation would be appreciated but is not required.</span>
<a name="l00017"></a>00017 <span class="comment">//</span>
<a name="l00018"></a>00018 <span class="comment">// 2. Altered source versions must be plainly marked as such,</span>
<a name="l00019"></a>00019 <span class="comment">//    and must not be misrepresented as being the original software.</span>
<a name="l00020"></a>00020 <span class="comment">//</span>
<a name="l00021"></a>00021 <span class="comment">// 3. This notice may not be removed or altered from any source distribution.</span>
<a name="l00022"></a>00022 <span class="comment">//</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00026"></a>00026 <span class="comment">// Headers</span>
<a name="l00028"></a>00028 <span class="comment"></span><span class="preprocessor">#include &lt;SFML/Graphics/Font.hpp&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;SFML/Graphics/FontLoader.hpp&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="keyword">namespace </span>sf
<a name="l00034"></a>00034 {
<a name="l00036"></a>00036 <span class="comment">// Static member data</span>
<a name="l00038"></a>00038 <span class="comment"></span>Uint32 Font::ourDefaultCharset[] =
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040     <span class="comment">// Printable characters in ASCII range</span>
<a name="l00041"></a>00041     0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
<a name="l00042"></a>00042     0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
<a name="l00043"></a>00043     0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
<a name="l00044"></a>00044     0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
<a name="l00045"></a>00045     0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
<a name="l00046"></a>00046     0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E,
<a name="l00047"></a>00047 
<a name="l00048"></a>00048     <span class="comment">// Printable characters in extended ASCII range</span>
<a name="l00049"></a>00049     0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0x2A, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
<a name="l00050"></a>00050     0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
<a name="l00051"></a>00051     0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
<a name="l00052"></a>00052     0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
<a name="l00053"></a>00053     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
<a name="l00054"></a>00054     0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE,
<a name="l00055"></a>00055 
<a name="l00056"></a>00056     <span class="comment">// To make it a valid string</span>
<a name="l00057"></a>00057     0x00
<a name="l00058"></a>00058 };
<a name="l00059"></a>00059 
<a name="l00060"></a>00060 
<a name="l00064"></a><a class="code" href="classsf_1_1Font.htm#506404655b8869ed60d1e7709812f583">00064</a> <a class="code" href="classsf_1_1Font.htm#506404655b8869ed60d1e7709812f583" title="Default constructor.">Font::Font</a>() :
<a name="l00065"></a>00065 myCharSize(0)
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067 
<a name="l00068"></a>00068 }
<a name="l00069"></a>00069 
<a name="l00070"></a>00070 
<a name="l00074"></a><a class="code" href="classsf_1_1Font.htm#c1f0de973bdb9485b5f0bf4aacb717e5">00074</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Font.htm#c1f0de973bdb9485b5f0bf4aacb717e5" title="Load the font from a file.">Font::LoadFromFile</a>(<span class="keyword">const</span> std::string&amp; Filename, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> CharSize, <span class="keyword">const</span> <a class="code" href="classsf_1_1Unicode_1_1Text.htm" title="This class is an abstract definition of a unicode text, it can be converted from...">Unicode::Text</a>&amp; Charset)
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076     <span class="comment">// Clear the previous character map</span>
<a name="l00077"></a>00077     myGlyphs.clear();
<a name="l00078"></a>00078 
<a name="l00079"></a>00079     <span class="comment">// Always add these special characters</span>
<a name="l00080"></a>00080     Unicode::UTF32String UTFCharset = Charset;
<a name="l00081"></a>00081     <span class="keywordflow">if</span> (UTFCharset.find(L<span class="charliteral">' '</span>)  != Unicode::UTF32String::npos) UTFCharset += L<span class="charliteral">' '</span>;
<a name="l00082"></a>00082     <span class="keywordflow">if</span> (UTFCharset.find(L<span class="charliteral">'\n'</span>) != Unicode::UTF32String::npos) UTFCharset += L<span class="charliteral">'\n'</span>;
<a name="l00083"></a>00083     <span class="keywordflow">if</span> (UTFCharset.find(L<span class="charliteral">'\v'</span>) != Unicode::UTF32String::npos) UTFCharset += L<span class="charliteral">'\v'</span>;
<a name="l00084"></a>00084     <span class="keywordflow">if</span> (UTFCharset.find(L<span class="charliteral">'\t'</span>) != Unicode::UTF32String::npos) UTFCharset += L<span class="charliteral">'\t'</span>;
<a name="l00085"></a>00085 
<a name="l00086"></a>00086     <span class="keywordflow">return</span> priv::FontLoader::GetInstance().LoadFontFromFile(Filename, CharSize, UTFCharset, *<span class="keyword">this</span>);
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088 
<a name="l00089"></a>00089 
<a name="l00093"></a><a class="code" href="classsf_1_1Font.htm#ecee6a8f62a20424a803508522e3607b">00093</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Font.htm#ecee6a8f62a20424a803508522e3607b" title="Load the font from a file in memory.">Font::LoadFromMemory</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* Data, std::size_t SizeInBytes, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> CharSize, <span class="keyword">const</span> <a class="code" href="classsf_1_1Unicode_1_1Text.htm" title="This class is an abstract definition of a unicode text, it can be converted from...">Unicode::Text</a>&amp; Charset)
<a name="l00094"></a>00094 {
<a name="l00095"></a>00095     <span class="comment">// Clear the previous character map</span>
<a name="l00096"></a>00096     myGlyphs.clear();
<a name="l00097"></a>00097 
<a name="l00098"></a>00098     <span class="comment">// Check parameters</span>
<a name="l00099"></a>00099     <span class="keywordflow">if</span> (!Data || (SizeInBytes == 0))
<a name="l00100"></a>00100     {
<a name="l00101"></a>00101         std::cerr &lt;&lt; <span class="stringliteral">"Failed to load font from memory, no data provided"</span> &lt;&lt; std::endl;
<a name="l00102"></a>00102         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00103"></a>00103     }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105     <span class="comment">// Always add these special characters</span>
<a name="l00106"></a>00106     Unicode::UTF32String UTFCharset = Charset;
<a name="l00107"></a>00107     <span class="keywordflow">if</span> (UTFCharset.find(L<span class="charliteral">' '</span>)  != Unicode::UTF32String::npos) UTFCharset += L<span class="charliteral">' '</span>;
<a name="l00108"></a>00108     <span class="keywordflow">if</span> (UTFCharset.find(L<span class="charliteral">'\n'</span>) != Unicode::UTF32String::npos) UTFCharset += L<span class="charliteral">'\n'</span>;
<a name="l00109"></a>00109     <span class="keywordflow">if</span> (UTFCharset.find(L<span class="charliteral">'\v'</span>) != Unicode::UTF32String::npos) UTFCharset += L<span class="charliteral">'\v'</span>;
<a name="l00110"></a>00110     <span class="keywordflow">if</span> (UTFCharset.find(L<span class="charliteral">'\t'</span>) != Unicode::UTF32String::npos) UTFCharset += L<span class="charliteral">'\t'</span>;
<a name="l00111"></a>00111 
<a name="l00112"></a>00112     <span class="keywordflow">return</span> priv::FontLoader::GetInstance().LoadFontFromMemory(Data, SizeInBytes, CharSize, UTFCharset, *<span class="keyword">this</span>);
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114 
<a name="l00115"></a>00115 
<a name="l00120"></a><a class="code" href="classsf_1_1Font.htm#85bd25d6eac95cd20ccc2e9d17ab90bc">00120</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classsf_1_1Font.htm#85bd25d6eac95cd20ccc2e9d17ab90bc" title="Get the base size of characters in the font; All glyphs dimensions are based on this...">Font::GetCharacterSize</a>()<span class="keyword"> const</span>
<a name="l00121"></a>00121 <span class="keyword"></span>{
<a name="l00122"></a>00122     <span class="keywordflow">return</span> myCharSize;
<a name="l00123"></a>00123 }
<a name="l00124"></a>00124 
<a name="l00125"></a>00125 
<a name="l00130"></a><a class="code" href="classsf_1_1Font.htm#044159ab533345fd030430c822cd2bd6">00130</a> <span class="keyword">const</span> <a class="code" href="classsf_1_1Glyph.htm" title="Structure describing a glyph (a visual character).">Glyph</a>&amp; <a class="code" href="classsf_1_1Font.htm#044159ab533345fd030430c822cd2bd6" title="Get the description of a glyph (character) given by its unicode value.">Font::GetGlyph</a>(Uint32 CodePoint)<span class="keyword"> const</span>
<a name="l00131"></a>00131 <span class="keyword"></span>{
<a name="l00132"></a>00132     std::map&lt;Uint32, Glyph&gt;::const_iterator It = myGlyphs.find(CodePoint);
<a name="l00133"></a>00133     <span class="keywordflow">if</span> (It != myGlyphs.end())
<a name="l00134"></a>00134     {
<a name="l00135"></a>00135         <span class="comment">// Valid glyph</span>
<a name="l00136"></a>00136         <span class="keywordflow">return</span> It-&gt;second;
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138     <span class="keywordflow">else</span>
<a name="l00139"></a>00139     {
<a name="l00140"></a>00140         <span class="comment">// Invalid glyph -- return an invalid glyph</span>
<a name="l00141"></a>00141         <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classsf_1_1Glyph.htm" title="Structure describing a glyph (a visual character).">Glyph</a> InvalidGlyph;
<a name="l00142"></a>00142         <span class="keywordflow">return</span> InvalidGlyph;
<a name="l00143"></a>00143     }
<a name="l00144"></a>00144 }
<a name="l00145"></a>00145 
<a name="l00146"></a>00146 
<a name="l00150"></a><a class="code" href="classsf_1_1Font.htm#e499022bb1bc6f8ce26096a05ab8a8e8">00150</a> <span class="keyword">const</span> <a class="code" href="classsf_1_1Image.htm" title="Image is the low-level class for loading and manipulating images.">Image</a>&amp; <a class="code" href="classsf_1_1Font.htm#e499022bb1bc6f8ce26096a05ab8a8e8" title="Get the image containing the rendered characters (glyphs).">Font::GetImage</a>()<span class="keyword"> const</span>
<a name="l00151"></a>00151 <span class="keyword"></span>{
<a name="l00152"></a>00152     <span class="keywordflow">return</span> myTexture;
<a name="l00153"></a>00153 }
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 
<a name="l00159"></a><a class="code" href="classsf_1_1Font.htm#128c377d51263288be98565771c48e36">00159</a> <span class="keyword">const</span> <a class="code" href="classsf_1_1Font.htm" title="Font is the low-level class for loading and manipulating character fonts.">Font</a>&amp; <a class="code" href="classsf_1_1Font.htm#128c377d51263288be98565771c48e36" title="Get the SFML default built-in font (Arial).">Font::GetDefaultFont</a>()
<a name="l00160"></a>00160 {
<a name="l00161"></a>00161     <span class="keyword">static</span> <a class="code" href="classsf_1_1Font.htm" title="Font is the low-level class for loading and manipulating character fonts.">Font</a>       DefaultFont;
<a name="l00162"></a>00162     <span class="keyword">static</span> <span class="keywordtype">bool</span>       DefaultFontLoaded = <span class="keyword">false</span>;
<a name="l00163"></a>00163     <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> DefaultFontData[] =
<a name="l00164"></a>00164     {
<a name="l00165"></a>00165 <span class="preprocessor">        #include &lt;SFML/Graphics/Arial.hpp&gt;</span>
<a name="l00166"></a>00166     };
<a name="l00167"></a>00167 
<a name="l00168"></a>00168     <span class="comment">// Load the default font on first call</span>
<a name="l00169"></a>00169     <span class="keywordflow">if</span> (!DefaultFontLoaded)
<a name="l00170"></a>00170     {
<a name="l00171"></a>00171         DefaultFont.<a class="code" href="classsf_1_1Font.htm#ecee6a8f62a20424a803508522e3607b" title="Load the font from a file in memory.">LoadFromMemory</a>(DefaultFontData, <span class="keyword">sizeof</span>(DefaultFontData), 30);
<a name="l00172"></a>00172         DefaultFontLoaded = <span class="keyword">true</span>;
<a name="l00173"></a>00173     }
<a name="l00174"></a>00174 
<a name="l00175"></a>00175     <span class="keywordflow">return</span> DefaultFont;
<a name="l00176"></a>00176 }
<a name="l00177"></a>00177 
<a name="l00178"></a>00178 } <span class="comment">// namespace sf</span>
</pre></div></div>

        <p id="footer">
            &nbsp;::&nbsp; Copyright &copy; 2007-2008 Laurent Gomila, all rights reserved &nbsp;::&nbsp;
            Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen 1.5.2</a> &nbsp;::&nbsp;
        </p>

    </body>
</html>